diff --git a/src/pocof/Library.fs b/src/pocof/Library.fs index d22d3202..3041f58d 100644 --- a/src/pocof/Library.fs +++ b/src/pocof/Library.fs @@ -125,9 +125,7 @@ type SelectPocofCommand() = member val Prompt = "query" with get, set [] - [] + [] member val Layout = string TopDown with get, set [] diff --git a/src/pocof/UI.fs b/src/pocof/UI.fs index 8fdc10f5..ef697cf5 100644 --- a/src/pocof/UI.fs +++ b/src/pocof/UI.fs @@ -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) = - __.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 @@ -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) - = - // 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 -> seq) = let buf = new Buff(rui, prompt, invoke, Console.TreatControlCAsInput) diff --git a/tests/pocof.Tests.ps1 b/tests/pocof.Tests.ps1 index 091a508b..377e2da4 100644 --- a/tests/pocof.Tests.ps1 +++ b/tests/pocof.Tests.ps1 @@ -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 mode with empty query' -ForEach @( + @{ Layout = 'TopDown' }, + @{ Layout = 'BottomUp' } + ) { + It "Given Layout '', '' 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 }; } {