Skip to content

Commit

Permalink
Merge pull request #72 from krymtkts:feature/bottom-up
Browse files Browse the repository at this point in the history
Implementation of bottom up layout.
  • Loading branch information
krymtkts authored Nov 11, 2023
2 parents 34c9fc0 + a50e66f commit d68a172
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 22 deletions.
4 changes: 1 addition & 3 deletions src/pocof/Library.fs
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ type SelectPocofCommand() =
member val Prompt = "query" with get, set

[<Parameter>]
[<ValidateSet("TopDown"
// , "BottomUp"
)>]
[<ValidateSet("TopDown", "BottomUp")>]
member val Layout = string TopDown with get, set

[<Parameter>]
Expand Down
43 changes: 24 additions & 19 deletions src/pocof/UI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,28 @@ module PocofScreen =
line.PadRight __.rui.WindowSize.Width
|> Console.Write

member __.writeTopDown
member __.writeScreen
(layout: PocofData.Layout)
(state: PocofData.InternalState)
(x: int)
(entries: PocofData.Entry list)
(props: Result<string list, string>)
=
__.writeScreenLine 0
let basePosition, firstLine, toHeight =
match layout with
| PocofData.TopDown -> 0, 1, (+) 2
| PocofData.BottomUp ->
let basePosition = __.rui.WindowSize.Height - 1
basePosition, basePosition - 1, (-) (basePosition - 2)

__.writeScreenLine basePosition
<| __.prompt + ">" + state.Query

__.writeRightInfo state entries.Length 0
__.writeRightInfo state entries.Length basePosition

// PocofDebug.logFile "./debug.log" [ List.length entries ]

__.writeScreenLine 1
__.writeScreenLine firstLine
<| match state.Notification with
| "" ->
match props with
Expand All @@ -99,25 +107,22 @@ module PocofScreen =

seq { 0..h }
|> Seq.iter (fun i ->
match List.tryItem i out with
| Some s -> __.writeScreenLine <| i + 2 <| s
// logFile "./debug.log" [ s ]
| None -> __.writeScreenLine <| i + 2 <| String.Empty)
__.writeScreenLine
<| toHeight i
<| match List.tryItem i out with
| Some s ->
// logFile "./debug.log" [ s ]
s
| None -> String.Empty)

__.setCursorPosition
<| __.getCursorPositionX state.Query x
<| 0
<| basePosition

member __.writeBottomUp
(state: PocofData.InternalState)
(x: int)
(entries: PocofData.Entry list)
(props: Result<string list, string>)
=
// TODO: implement it from Write-BottomUp.
__.setCursorPosition
<| __.getCursorPositionX state.Query x
<| __.rui.CursorPosition.Y

member __.writeTopDown = __.writeScreen PocofData.TopDown

member __.writeBottomUp = __.writeScreen PocofData.BottomUp

let init (rui: PSHostRawUserInterface) (prompt: string) (invoke: list<obj> -> seq<string>) =
let buf = new Buff(rui, prompt, invoke, Console.TreatControlCAsInput)
Expand Down
18 changes: 18 additions & 0 deletions tests/pocof.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ Describe 'pocof' {
$_ | Should @p
}
}

Context 'Checking Select-Pocof parameters' -ForEach @{
InputObject = 'Hello,world'
Expected = 'Hello,world'
BaseParam = @{NonInteractive = $true };
} {
Context 'In <Layout> mode with empty query' -ForEach @(
@{ Layout = 'TopDown' },
@{ Layout = 'BottomUp' }
) {
It "Given Layout '<Layout>', '<Expected>' should be returned." -TestCases @(
@{Params = $BaseParam + $_ }
) {
$InputObject | Select-Pocof @Params -ErrorAction SilentlyContinue | Should -BeExactly -ExpectedValue $Expected
}
}
}

Context 'Select-Pocof cmdlet' -ForEach @{
InputObject = 'Hello,world'; BaseParam = @{NonInteractive = $true };
} {
Expand Down

0 comments on commit d68a172

Please sign in to comment.