Something went wrong. Try again.
Making a new TUI editor maybe
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768module Glyph.Key.Trigger where
----------------------------------------------------------------------------------------------------
import qualified Data.Char as Charimport qualified Data.List as Listimport qualified Data.Maybe as Maybeimport qualified Data.Set as Set
import Glyph.Class.Stringable ( Stringable (..) )import Glyph.Config.Dhall.Action ( Action (..) )import Glyph.Key.Chord ( Chord (..) )import Glyph.Key.Count ( Count (..) )import qualified Glyph.Key.Count as Countimport Glyph.Key.Trie ( Captured (..) , KeyTrie (..) , Step (..) )import qualified Glyph.Key.Trie as Trieimport Glyph.State.Input ( InputState (..) )
import Graphics.Vty.Input.Events ( Key (..) )
----------------------------------------------------------------------------------------------------
data Triggered = Cancelled | DeadEnded | Waiting InputState | Fire Action Natural (List Captured) deriving (Eq, Show)
feedChord :: KeyTrie Chord -> Count -> List Chord -> Chord -> TriggeredfeedChord keytrie count previous pressed | Set.null pressed.modifiers, pressed.key == KEsc = Cancelled | otherwise = case Trie.resolve (previous <> [pressed]) keytrie of DeadEnd -> if Set.null pressed.modifiers `and` Count.canCount count previous pressed.key then Count.pushDigit pressed.key count |> \c -> ChordInput c [] |> Waiting else DeadEnded Pending _ -> ChordInput NoCount (previous <> [pressed]) |> Waiting Found action captured -> Fire action (Count.settle count) captured
feedModal :: KeyTrie Key -> List Char -> Key -> TriggeredfeedModal _ previous (KChar c) = if Char.isPrint c then ModalInput (previous <> [c]) |> Waiting else DeadEndedfeedModal _ _ KEsc = CancelledfeedModal _ previous KBS = case List.unsnoc previous of Just (head, _) -> ModalInput head |> Waiting Nothing -> CancelledfeedModal keytrie previous KEnter = case Trie.resolve (fmap KChar previous <> [KEnter]) keytrie of DeadEnd -> DeadEnded Pending _ -> ModalInput previous |> Waiting Found action captured -> Fire action 1 capturedfeedModal _ _ _ = DeadEnded