Skip to content

Commit

Permalink
Merge pull request #116 from krymtkts:feature/raw-ui
Browse files Browse the repository at this point in the history
Support full-width characters in query widndow
  • Loading branch information
krymtkts authored Jan 8, 2024
2 parents 73b9c5a + 3521028 commit a09fe9b
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 190 deletions.
69 changes: 60 additions & 9 deletions src/pocof.Test/Pocof.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,63 @@ open FsUnitTyped
open System
open pocof.Pocof
open pocof.PocofData
open pocof.PocofScreen
open PocofUI

module calculateWindowBeginningCursor =
[<Fact>]
let ``should return 0.`` () =
let state =
{ Query = "a"
Cursor = 1
WindowBeginningCursor = 0
WindowWidth = 30 }

let rui = new MockRawUI()
use buff = new Buff(rui, (fun _ -> Seq.empty))

let actual = calculateWindowBeginningCursor buff.GetLengthInBufferCells state

actual |> shouldEqual 0

[<Fact>]
let ``should return 1.`` () =
let state =
{ Query = String.replicate 31 "a"
Cursor = 31
WindowBeginningCursor = 0
WindowWidth = 30 }

let rui = new MockRawUI()
use buff = new Buff(rui, (fun _ -> Seq.empty))

let actual = calculateWindowBeginningCursor buff.GetLengthInBufferCells state

actual |> shouldEqual 1

[<Fact>]
let ``should return cursor value.`` () =
let state =
{ Query = String.replicate 31 "a"
Cursor = 0
WindowBeginningCursor = 31
WindowWidth = 30 }

let rui = new MockRawUI()
use buff = new Buff(rui, (fun _ -> Seq.empty))

let actual = calculateWindowBeginningCursor buff.GetLengthInBufferCells state

actual |> shouldEqual 0

module loop =
open System.Management.Automation
open PocofUI
open pocof.PocofScreen

let initState () : InternalState =
{ QueryState =
{ Query = ""
Cursor = 0
WindowBeginningX = 0
WindowBeginningCursor = 0
WindowWidth = 0 }
QueryCondition =
{ Matcher = MATCH
Expand Down Expand Up @@ -71,7 +117,8 @@ module loop =
propMap = propMap
writeScreen = writeScreen
getKey = m.getKey
getConsoleWidth = fun () -> 0 }
getConsoleWidth = fun () -> 60
getLengthInBufferCells = String.length }

let actual = loop args input state pos context
actual |> List.length |> shouldEqual 5
Expand All @@ -95,7 +142,8 @@ module loop =
propMap = propMap
writeScreen = writeScreen
getKey = m.getKey
getConsoleWidth = fun () -> 0 }
getConsoleWidth = fun () -> 60
getLengthInBufferCells = String.length }

let actual = loop args input state pos context
actual |> List.length |> shouldEqual 0
Expand All @@ -116,7 +164,8 @@ module loop =
propMap = propMap
writeScreen = writeScreen
getKey = m.getKey
getConsoleWidth = fun () -> 0 }
getConsoleWidth = fun () -> 60
getLengthInBufferCells = String.length }

let actual = loop args input state pos context
actual |> List.length |> shouldEqual 5
Expand Down Expand Up @@ -144,7 +193,8 @@ module loop =
propMap = propMap
writeScreen = writeScreen
getKey = m.getKey
getConsoleWidth = fun () -> 0 }
getConsoleWidth = fun () -> 60
getLengthInBufferCells = String.length }

let actual = loop args input state pos context
actual |> List.length |> shouldEqual 2
Expand Down Expand Up @@ -174,8 +224,9 @@ module loop =
getKey = m.getKey
getConsoleWidth =
fun () ->
rui.x <- 80
80 }
rui.width <- 80
80
getLengthInBufferCells = String.length }

let actual = loop args input state pos context
actual |> List.length |> shouldEqual 1
Expand Down
4 changes: 2 additions & 2 deletions src/pocof.Test/PocofData.fs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ module initConfig =
{ QueryState =
{ Query = ":name"
Cursor = 5
WindowBeginningX = 0
WindowBeginningCursor = 0
WindowWidth =
60
- (String.length "prompt>")
Expand Down Expand Up @@ -264,7 +264,7 @@ module QueryState =
let qs q x =
{ Query = q
Cursor = x
WindowBeginningX = 0
WindowBeginningCursor = 0
WindowWidth = 0 }

[<Fact>]
Expand Down
2 changes: 1 addition & 1 deletion src/pocof.Test/PocofHandle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module invokeAction =
{ QueryState =
{ Query = ""
Cursor = 0
WindowBeginningX = 0
WindowBeginningCursor = 0
WindowWidth = 0 }
QueryCondition =
{ Matcher = MATCH
Expand Down
2 changes: 1 addition & 1 deletion src/pocof.Test/PocofQuery.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let initState () : PocofData.InternalState =
{ QueryState = {
Query = ""
Cursor = 0
WindowBeginningX = 0
WindowBeginningCursor = 0
WindowWidth = 0}
QueryCondition =
{ Matcher = PocofData.Matcher.MATCH
Expand Down
Loading

0 comments on commit a09fe9b

Please sign in to comment.