diff options
Diffstat (limited to 'src/Chelleport')
| -rw-r--r-- | src/Chelleport/KeySequence.hs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/Chelleport/KeySequence.hs b/src/Chelleport/KeySequence.hs index 88658f1..1046a98 100644 --- a/src/Chelleport/KeySequence.hs +++ b/src/Chelleport/KeySequence.hs @@ -2,8 +2,15 @@ module Chelleport.KeySequence where import Data.List (isPrefixOf, nub) import qualified Data.Map as Map +import Data.Maybe (isJust) import qualified SDL +-- padded :: Int -> a -> [a] -> [a] +-- padded 0 _ ls = ls +-- padded n x ls +-- | length ls > n = ls +-- | otherwise = padded (n - 1) x (ls ++ [x]) + safeHead :: a -> [a] -> a safeHead def [] = def safeHead _ (x : _) = x @@ -17,6 +24,19 @@ nextChars keys cells = matches = concatMap (filter (isPrefixOf keys)) cells result = concatMap (take 1 . drop (length keys)) matches +findMatchPosition :: [Char] -> [[[Char]]] -> Maybe (Int, Int) +findMatchPosition keys = findWithIndex findMatch 0 + where + findMatch row = + fst <$> findWithIndex (\c -> if c == keys then Just () else Nothing) 0 row + + findWithIndex :: (x -> Maybe r) -> Int -> [x] -> Maybe (Int, r) + findWithIndex _pred _index [] = Nothing + findWithIndex predicate index (x : ls) = + case predicate x of + Just item -> Just (index, item) + Nothing -> findWithIndex predicate (index + 1) ls + isValidKey :: SDL.Keycode -> Bool isValidKey key = Map.member key keycodeMapping |
