Simplify (data-ify) command arguments
This commit is contained in:
+10
-6
@@ -38,7 +38,8 @@ import Data.Maybe
|
||||
--import Data.Char
|
||||
--import Data.List
|
||||
--import Data.Function (on)
|
||||
import qualified Data.Set as S
|
||||
import qualified Data.Map.Strict as M
|
||||
import qualified Data.Set as S
|
||||
import qualified Data.Text as T
|
||||
import SDL
|
||||
|
||||
@@ -157,14 +158,14 @@ wheelEvent y w = case _hudElement $ _hud w of
|
||||
& tmInput . tiText %~ replacewith tm newi
|
||||
updatetermsubsel tm = case tm ^? tmInput . tiSel of
|
||||
Nothing -> tm
|
||||
Just (i,j) -> let newj = (j - yi) `mod` (1 + length (_tcArguments (scrollCommands tm !! i) tm w))
|
||||
Just (i,j) -> let newj = (j - yi) `mod` (1 + length (getArguments (scrollCommands tm !! i) tm w))
|
||||
in tm & tmInput . tiSel .~ (i,newj)
|
||||
& tmInput . tiText %~ replacewith' tm i newj w
|
||||
replacewith tp newi _ = T.pack (_tcString (scrollCommands tp !! newi))
|
||||
replacewith' tp i j w' _ = T.pack $ _tcString tc ++ " " ++ arg-- ++ ((_tcArguments tp) w !! j)
|
||||
where
|
||||
arg :: String
|
||||
arg = ("": _tcArguments tc tp w' )!! j
|
||||
arg = ("": getArguments tc tp w' )!! j
|
||||
tc = scrollCommands tp !! i
|
||||
numcombs = length $ combineItemListYou w
|
||||
yi = round $ signum y
|
||||
@@ -173,6 +174,11 @@ wheelEvent y w = case _hudElement $ _hud w of
|
||||
lbDown = ButtonLeft `S.member` _mouseButtons w
|
||||
invKeyDown = ScancodeCapsLock `S.member` _keys w
|
||||
|
||||
getArguments :: TerminalCommand -> Terminal -> World -> [String]
|
||||
getArguments tc tm w = case _tcEffect tc tm w of
|
||||
NoArguments {} -> []
|
||||
OneArgument _ m -> M.keys m
|
||||
|
||||
scrollCommands :: Terminal -> [TerminalCommand]
|
||||
scrollCommands = (nullCommand :) . _tmScrollCommands
|
||||
nullCommand :: TerminalCommand
|
||||
@@ -180,9 +186,7 @@ nullCommand = TerminalCommand
|
||||
{ _tcString = ""
|
||||
, _tcAlias = []
|
||||
, _tcHelp = ""
|
||||
, _tcArgumentType = Nothing
|
||||
, _tcArguments = const (const [])
|
||||
, _tcEffect = \_ _ _ -> Right []
|
||||
, _tcEffect = \_ _ -> NoArguments []
|
||||
}
|
||||
|
||||
scrollRBOption :: Float -> World -> World
|
||||
|
||||
Reference in New Issue
Block a user