Something went wrong. Try again.
Making a new TUI editor maybe
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455module Glyph.State.Input where
----------------------------------------------------------------------------------------------------
import qualified Data.List as List
import Glyph.Class.Initializable ( Initializable (..) )import Glyph.Class.Stringable ( Stringable (..) )import Glyph.Key.Chord ( Chord )import Glyph.Key.Count ( Count (..) )
----------------------------------------------------------------------------------------------------
data InputState -- before I go and call yet another type "Chord | Modal"... = ChordInput { count :: Count , chords :: List Chord } | ModalInput { chars :: List Char } deriving (Eq, Show)
instance Stringable InputState where toString (ChordInput count' chords') = ( [toString count'] <> fmap toString chords' ) |> List.unwords toString (ModalInput chars') = chars'
-- One way fromString _ = Nothing
instance Initializable InputState where init = ChordInput{count = NoCount, chords = []}
----------------------------------------------------------------------------------------------------
idle :: InputStateidle = init
insertCount :: InputState -> Count -> InputStateinsertCount (ModalInput _) count' = ChordInput count' []insertCount input count = input{count}
insertChord :: InputState -> Chord -> InputStateinsertChord (ModalInput _) chords' = ChordInput NoCount [chords']insertChord input chords' = input{chords = input.chords <> [chords']}
insertModal :: InputState -> Char -> InputStateinsertModal (ChordInput _ _) char = ModalInput [char]insertModal input char = input{chars = input.chars <> [char]}