Refactor terminal prompt/maxlines into terminaltype

This commit is contained in:
2024-11-06 11:16:35 +00:00
parent 6168bf282e
commit bfd4649e1b
7 changed files with 39 additions and 27 deletions
+4 -2
View File
@@ -37,7 +37,6 @@ data Terminal = Terminal
, _tmName :: String
, _tmDisplayedLines :: [(String, Color)]
, _tmFutureLines :: [TerminalLine]
, _tmMaxLines :: Int
, _tmTitle :: String
, _tmInput :: TerminalInput
, _tmScrollCommands :: [TerminalCommand]
@@ -47,11 +46,13 @@ data Terminal = Terminal
, _tmCommandHistory :: [String]
, _tmToggles :: M.Map String TerminalToggle
, _tmPartialCommand :: Maybe TerminalCommand
, _tmPromptString :: String
, _tmType :: TerminalType
}
--deriving (Eq, Show, Read) --, Generic)
--h--deriving (Eq, Show, Read) --Generic, Flat)
data TerminalType = DefaultTerminal
data TerminalLineString = TerminalLineConst String Color
--deriving (Eq, Ord, Show, Read) --Generic, Flat)
@@ -140,4 +141,5 @@ concat <$> mapM (deriveJSON defaultOptions)
, ''TerminalCommandEffect
, ''TerminalCommand
, ''Terminal
, ''TerminalType
]
+1 -2
View File
@@ -15,7 +15,6 @@ defaultTerminal =
, _tmName = "TESTTERMINAL"
, _tmDisplayedLines = []
, _tmFutureLines = []
, _tmMaxLines = 14
, _tmTitle = "TERMINAL IN LOCATION"
, _tmInput = defaultTerminalInput
, _tmScrollCommands = []
@@ -25,7 +24,7 @@ defaultTerminal =
, _tmCommandHistory = []
, _tmToggles = mempty
, _tmPartialCommand = Nothing
, _tmPromptString = "$ "
, _tmType = DefaultTerminal
}
defaultTerminalInput :: TerminalInput
+3 -2
View File
@@ -6,6 +6,7 @@ module Dodge.Render.HUD (
selNumPosCardinal, -- this shoud probably be pushed back here
) where
import Dodge.Terminal.Type
import Dodge.CharacterEnums
import Dodge.Creature.Test
import Dodge.DoubleTree
@@ -354,14 +355,14 @@ displayTerminal tid cfig w = fromMaybe mempty $ do
thelist tm =
map toselitm . displayTermInput tm
. reverse
. take (_tmMaxLines tm)
. take (getMaxLinesTM (tm ^. tmType))
$ _tmDisplayedLines tm
displayTermInput tm = case _tmInput tm of
TerminalInput{_tiText = s, _tiFocus = hasfoc} ->
(++ [(displayInputText tm s ++ displayBlinkCursor hasfoc, white)])
partcommand tm = maybe "" (++ " ") $ tm ^? tmPartialCommand . _Just . tcString
displayInputText tm s
| _tmStatus tm == TerminalReady = partcommand tm ++ _tmPromptString tm ++ s
| _tmStatus tm == TerminalReady = partcommand tm ++ getPromptTM (tm ^. tmType) ++ s
| otherwise = ""
displayBlinkCursor hasfoc
-- | hasfoc = clockCycle 10 (V.fromList [[cFilledRect] , "."]) w
+2 -2
View File
@@ -18,6 +18,7 @@ module Dodge.Terminal (
terminalReturnEffect,
) where
import Dodge.Terminal.Type
import Control.Monad
import Color
import Data.Char
@@ -37,7 +38,6 @@ basicTerminal =
defaultTerminal
{ _tmDisplayedLines = []
, _tmFutureLines = []
, _tmMaxLines = 14
, _tmTitle = "TERMINAL"
, _tmScrollCommands = [quitCommand]
, _tmWriteCommands = [helpCommand, commandsCommand]
@@ -283,7 +283,7 @@ terminalReturnEffect tm w = fromMaybe w $ do
w
& cWorld . lWorld . terminals . ix (_tmID tm) . tmPartialCommand .~ Nothing
& cWorld . lWorld . terminals . ix (_tmID tm) . tmFutureLines
.~ [makeTermLine (pc ++ _tmPromptString tm ++ s)]
.~ [makeTermLine (pc ++ getPromptTM (tm ^. tmType) ++ s)]
runTerminalString :: String -> Terminal -> World -> World
runTerminalString s tm w =
-1
View File
@@ -79,7 +79,6 @@ lineOutputTerminal tls =
defaultTerminal
{ _tmDisplayedLines = []
, _tmFutureLines = []
, _tmMaxLines = 14
, _tmTitle = "TERMINAL"
, _tmScrollCommands = [quitCommand]
, _tmWriteCommands = [helpCommand, commandsCommand]