module 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 :: InputState idle = init insertCount :: InputState -> Count -> InputState insertCount (ModalInput _) count' = ChordInput count' [] insertCount input count = input{count} insertChord :: InputState -> Chord -> InputState insertChord (ModalInput _) chords' = ChordInput NoCount [chords'] insertChord input chords' = input{chords = input.chords <> [chords']} insertModal :: InputState -> Char -> InputState insertModal (ChordInput _ _) char = ModalInput [char] insertModal input char = input{chars = input.chars <> [char]}