Move towards inputs in terminal

This commit is contained in:
2022-06-01 14:34:16 +01:00
parent b54864bbda
commit 2cedc1b968
13 changed files with 90 additions and 64 deletions
+15 -9
View File
@@ -1,7 +1,7 @@
{- | Deals with keyboard events. -}
module Dodge.Event.Keyboard
( handleKeyboardEvent
, handleTextInputEvent
, handleTextInput
) where
import qualified Data.IntMap.Strict as IM
import Dodge.Base
@@ -19,15 +19,21 @@ import LensHelp
import Data.Maybe
import qualified Data.Set as S
import SDL
import Data.Text (unpack)
--import Data.Text (unpack)
import qualified Data.Text as T
handleTextInputEvent :: TextInputEventData -> Universe -> IO (Maybe Universe)
handleTextInputEvent = handleTextInput . unpack . textInputEventText
handleTextInput :: T.Text -> Universe -> IO (Maybe Universe)
handleTextInput text = return . Just . -- case mState of
-- InputScreen {} ->
(menuLayers . ix 0 . scInput %~ updateText)
-- _ -> id
where
updateText s = case T.unpack text of
"\b" -> undefined
_ -> s `T.append` text
handleTextInput :: String -> Universe -> IO (Maybe Universe)
handleTextInput text w
| null (_menuLayers w) = return $ Just w
| otherwise = handleTextInMenu (head $ _menuLayers w) text w
-- | null (_menuLayers w) = return $ Just w
-- | otherwise = handleTextInMenu (head $ _menuLayers w) text w
{- | Handles keyboard press and release.
On release, remove scancode from the 'Set' of pressed keys.
@@ -78,7 +84,7 @@ toggleInspectInv he = case he of
gotoTerminal :: Universe -> Universe
gotoTerminal w = case _menuLayers w of
(InputScreen {} : _) -> w
_ -> w & menuLayers .:~ InputScreen [] "Enter command"
_ -> w & menuLayers .:~ InputScreen T.empty "Enter command"
spaceAction :: World -> World
spaceAction w = case _hudElement $ _hud w of