Work on terminal tab completion/scrolling

This commit is contained in:
2025-12-28 18:16:24 +00:00
parent bb376b0a56
commit 4390a82d64
4 changed files with 295 additions and 214 deletions
+1 -1
View File
@@ -422,7 +422,7 @@ updateKeysTextInputTerminal tmid u =
| otherwise = id
tryTabComplete
| u ^. uvWorld . input . pressedKeys . at ScancodeTab == Just 0 =
uvWorld . cWorld . lWorld . terminals . ix tmid %~ tabComplete (u ^. uvWorld)
uvWorld . cWorld . lWorld . terminals . ix tmid %~ doTabComplete (u ^. uvWorld)
| otherwise = id
updateKeyInGame :: Universe -> Scancode -> Int -> Universe
+67 -69
View File
@@ -1,11 +1,9 @@
--{-# LANGUAGE TupleSections #-}
module Dodge.Update.Scroll (
updateWheelEvent,
) where
module Dodge.Update.Scroll (updateWheelEvent) where
import Control.Applicative
import Control.Monad
import qualified Data.ListTrie.Patricia.Map.Enum as PTE
--import qualified Data.ListTrie.Patricia.Map.Enum as PTE
import qualified Data.Map.Strict as M
import Data.Maybe
import Dodge.Base
@@ -130,74 +128,74 @@ moveCombineSel yi =
terminalWheelEvent :: Int -> Int -> World -> World
terminalWheelEvent yi tmid w
| w & has (input . mouseButtons . ix ButtonRight)
, Just TerminalTextInput{} <- w ^? cWorld . lWorld . terminals . ix tmid . tmStatus =
w & cWorld . lWorld . terminals . ix tmid %~ f
| Just TerminalTextInput{} <- w ^? cWorld . lWorld . terminals . ix tmid . tmStatus =
w & cWorld . lWorld . terminals . ix tmid %~ g
-- | w & has (input . mouseButtons . ix ButtonRight)
-- , Just TerminalTextInput{} <- w ^? cWorld . lWorld . terminals . ix tmid . tmStatus =
-- w & cWorld . lWorld . terminals . ix tmid %~ f
-- | Just TerminalTextInput{} <- w ^? cWorld . lWorld . terminals . ix tmid . tmStatus =
-- w & cWorld . lWorld . terminals . ix tmid %~ f
| otherwise = w
where
dowrap = if yi > 0 then wrapup else wrapdown
wrapup s coms = PTE.findSuccessor s coms <|> PTE.findMin coms
wrapdown s coms = PTE.findPredecessor s coms <|> PTE.findMax coms
f tm = fromMaybe tm $ do
let coms = getCommands w tm
x <- tm ^? tmStatus . tiText
let s = fromMaybe "" $ x ^? to words . ix 0
(s', _) <- dowrap s coms
return $ tm & tmStatus . tiText .~ s'
g tm = fromMaybe tm $ do
let coms = getCommands w tm
x <- tm ^? tmStatus . tiText
let s = fromMaybe "" $ x ^? to words . ix 0
y = fromMaybe "" $ x ^? to words . ix 1
(s', arg, _) <-
if yi > 0
then doubleFindSucc s y coms <|> doubleFindMin coms
else doubleFindPred s y coms <|> doubleFindMax coms
return $ tm & tmStatus . tiText .~ s' ++ " " ++ arg
-- dowrap = if yi > 0 then wrapup else wrapdown
-- wrapup s coms = recComFindSuccessor (words s) coms <|> recComFindMin coms
-- wrapdown s coms = recComFindPredecessor (words s) coms <|> recComFindMax coms
-- f tm = fromMaybe tm $ do
-- let coms = getCommands w tm
-- x <- tm ^? tmStatus . tiText
-- let s = fromMaybe "" $ x ^? to words . ix 0
-- (s', _) <- dowrap s coms
-- return $ tm & tmStatus . tiText .~ unwords s'
---- g tm = fromMaybe tm $ do
---- let coms = getCommands w tm
---- x <- tm ^? tmStatus . tiText
---- let s = fromMaybe "" $ x ^? to words . ix 0
---- y = fromMaybe "" $ x ^? to words . ix 1
---- (s', arg, _) <-
---- if yi > 0
---- then doubleFindSucc s y coms <|> doubleFindMin coms
---- else doubleFindPred s y coms <|> doubleFindMax coms
---- return $ tm & tmStatus . tiText .~ s' ++ " " ++ arg
doubleFindMin :: (Enum a, Enum b) => PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
doubleFindMin m = do
(x, n) <- PTE.findMin m
case PTE.findMin n of
Just (y, z) -> Just (x, y, z)
Nothing -> Nothing
doubleFindSucc :: (Enum a, Enum b) => [a] -> [b] -> PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
doubleFindSucc xs ys m = case PTE.lookup xs m of
Just m' -> case PTE.findSuccessor ys m' of
Just (ys', z) -> Just (xs, ys', z)
Nothing -> dfs xs m
Nothing -> dfs xs m
where
dfs xs' m' = case PTE.findSuccessor xs' m' of
Just (xs'', n) -> case PTE.findMin n of
Just (ys', z) -> Just (xs'', ys', z)
Nothing -> dfs xs'' m'
Nothing -> Nothing
-- there are edge cases where this doesn't behave as might be expected
doubleFindMax :: (Enum a, Enum b) => PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
doubleFindMax m = do
(x, n) <- PTE.findMax m
case PTE.findMax n of
Just (y, z) -> Just (x, y, z)
Nothing -> Nothing
doubleFindPred ::
(Enum a, Enum b) => [a] -> [b] -> PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
doubleFindPred xs ys m = case PTE.lookup xs m of
Just m' -> case PTE.findPredecessor ys m' of
Just (ys', z) -> Just (xs, ys', z)
Nothing -> dfs xs m
Nothing -> dfs xs m
where
dfs xs' m' = case PTE.findPredecessor xs' m' of
Just (xs'', n) -> case PTE.findMax n of
Just (ys', z) -> Just (xs'', ys', z)
Nothing -> dfs xs'' m'
Nothing -> Nothing
--doubleFindMin :: (Enum a, Enum b) => PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
--doubleFindMin m = do
-- (x, n) <- PTE.findMin m
-- case PTE.findMin n of
-- Just (y, z) -> Just (x, y, z)
-- Nothing -> Nothing
--
--doubleFindSucc :: (Enum a, Enum b) => [a] -> [b] -> PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
--doubleFindSucc xs ys m = case PTE.lookup xs m of
-- Just m' -> case PTE.findSuccessor ys m' of
-- Just (ys', z) -> Just (xs, ys', z)
-- Nothing -> dfs xs m
-- Nothing -> dfs xs m
-- where
-- dfs xs' m' = case PTE.findSuccessor xs' m' of
-- Just (xs'', n) -> case PTE.findMin n of
-- Just (ys', z) -> Just (xs'', ys', z)
-- Nothing -> dfs xs'' m'
-- Nothing -> Nothing
--
---- there are edge cases where this doesn't behave as might be expected
--doubleFindMax :: (Enum a, Enum b) => PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
--doubleFindMax m = do
-- (x, n) <- PTE.findMax m
-- case PTE.findMax n of
-- Just (y, z) -> Just (x, y, z)
-- Nothing -> Nothing
--
--doubleFindPred ::
-- (Enum a, Enum b) => [a] -> [b] -> PTE.TrieMap a (PTE.TrieMap b c) -> Maybe ([a], [b], c)
--doubleFindPred xs ys m = case PTE.lookup xs m of
-- Just m' -> case PTE.findPredecessor ys m' of
-- Just (ys', z) -> Just (xs, ys', z)
-- Nothing -> dfs xs m
-- Nothing -> dfs xs m
-- where
-- dfs xs' m' = case PTE.findPredecessor xs' m' of
-- Just (xs'', n) -> case PTE.findMax n of
-- Just (ys', z) -> Just (xs'', ys', z)
-- Nothing -> dfs xs'' m'
-- Nothing -> Nothing
scrollRBOption :: Int -> Int -> Int -> Int
scrollRBOption dy ymax