License | BSD-3-Clause |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Swarm.TUI.Model.Repl
Description
Synopsis
- data REPLEntryType
- data REPLHistItemType
- data REPLHistItem = REPLHistItem {
- replItemType :: REPLHistItemType
- replItemTick :: TickNumber
- replItemText :: Text
- isREPLEntry :: REPLHistItem -> Bool
- getREPLSubmitted :: REPLHistItem -> Maybe Text
- isREPLSaved :: REPLHistItem -> Bool
- getREPLEntry :: REPLHistItem -> Maybe Text
- data REPLHistory
- replIndex :: Lens' REPLHistory Int
- replLength :: REPLHistory -> Int
- replHasExecutedManualInput :: Lens' REPLHistory Bool
- replSeq :: Lens' REPLHistory (Seq REPLHistItem)
- newREPLHistory :: [REPLHistItem] -> REPLHistory
- addREPLItem :: REPLHistItem -> REPLHistory -> REPLHistory
- restartREPLHistory :: REPLHistory -> REPLHistory
- getLatestREPLHistoryItems :: Int -> REPLHistory -> [REPLHistItem]
- getSessionREPLHistoryItems :: REPLHistory -> Seq REPLHistItem
- moveReplHistIndex :: TimeDir -> Text -> REPLHistory -> REPLHistory
- getCurrentItemText :: REPLHistory -> Maybe Text
- replIndexIsAtInput :: REPLHistory -> Bool
- data TimeDir
- data REPLPrompt
- removeEntry :: Text -> REPLHistory -> REPLHistory
- data REPLState
- data ReplControlMode
- replPromptType :: Lens' REPLState REPLPrompt
- replPromptEditor :: Lens' REPLState (Editor Text Name)
- replPromptText :: Lens' REPLState Text
- replValid :: Lens' REPLState (Either SrcLoc ())
- replLast :: Lens' REPLState Text
- replType :: Lens' REPLState (Maybe Polytype)
- replControlMode :: Lens' REPLState ReplControlMode
- replHistory :: Lens' REPLState REPLHistory
- newREPLEditor :: Text -> Editor Text Name
- initREPLState :: REPLHistory -> REPLState
- defaultPrompt :: REPLPrompt
- lastEntry :: Text -> REPLHistory -> Maybe Text
REPL
data REPLEntryType Source #
Whether a user REPL entry was submitted or merely saved.
Constructors
Submitted | The entry was submitted (with Enter) and should thus be shown in the REPL scrollback. |
Stashed | The entry was merely saved (e.g. by hitting down arrow) and should thus be available in the history but not shown in the scrollback. |
Instances
Read REPLEntryType Source # | |
Defined in Swarm.TUI.Model.Repl Methods readsPrec :: Int -> ReadS REPLEntryType # readList :: ReadS [REPLEntryType] # | |
Show REPLEntryType Source # | |
Defined in Swarm.TUI.Model.Repl Methods showsPrec :: Int -> REPLEntryType -> ShowS # show :: REPLEntryType -> String # showList :: [REPLEntryType] -> ShowS # | |
Eq REPLEntryType Source # | |
Defined in Swarm.TUI.Model.Repl Methods (==) :: REPLEntryType -> REPLEntryType -> Bool # (/=) :: REPLEntryType -> REPLEntryType -> Bool # | |
Ord REPLEntryType Source # | |
Defined in Swarm.TUI.Model.Repl Methods compare :: REPLEntryType -> REPLEntryType -> Ordering # (<) :: REPLEntryType -> REPLEntryType -> Bool # (<=) :: REPLEntryType -> REPLEntryType -> Bool # (>) :: REPLEntryType -> REPLEntryType -> Bool # (>=) :: REPLEntryType -> REPLEntryType -> Bool # max :: REPLEntryType -> REPLEntryType -> REPLEntryType # min :: REPLEntryType -> REPLEntryType -> REPLEntryType # |
data REPLHistItemType Source #
Various types of REPL history items (user input, output, error).
Constructors
REPLEntry REPLEntryType | Something entered by the user. |
REPLOutput | A response printed by the system. |
REPLError | An error printed by the system. |
Instances
Read REPLHistItemType Source # | |
Defined in Swarm.TUI.Model.Repl Methods readsPrec :: Int -> ReadS REPLHistItemType # readList :: ReadS [REPLHistItemType] # | |
Show REPLHistItemType Source # | |
Defined in Swarm.TUI.Model.Repl Methods showsPrec :: Int -> REPLHistItemType -> ShowS # show :: REPLHistItemType -> String # showList :: [REPLHistItemType] -> ShowS # | |
Eq REPLHistItemType Source # | |
Defined in Swarm.TUI.Model.Repl Methods (==) :: REPLHistItemType -> REPLHistItemType -> Bool # (/=) :: REPLHistItemType -> REPLHistItemType -> Bool # | |
Ord REPLHistItemType Source # | |
Defined in Swarm.TUI.Model.Repl Methods compare :: REPLHistItemType -> REPLHistItemType -> Ordering # (<) :: REPLHistItemType -> REPLHistItemType -> Bool # (<=) :: REPLHistItemType -> REPLHistItemType -> Bool # (>) :: REPLHistItemType -> REPLHistItemType -> Bool # (>=) :: REPLHistItemType -> REPLHistItemType -> Bool # max :: REPLHistItemType -> REPLHistItemType -> REPLHistItemType # min :: REPLHistItemType -> REPLHistItemType -> REPLHistItemType # |
data REPLHistItem Source #
An item in the REPL history.
Constructors
REPLHistItem | |
Fields
|
Instances
isREPLEntry :: REPLHistItem -> Bool Source #
Useful helper function to filter out REPL output. Returns True for all user input, including both submitted and saved history items.
getREPLSubmitted :: REPLHistItem -> Maybe Text Source #
Helper function to get only submitted user input text.
isREPLSaved :: REPLHistItem -> Bool Source #
Useful helper function to filter out saved REPL entries (which should not be shown in the scrollback).
getREPLEntry :: REPLHistItem -> Maybe Text Source #
Useful helper function to only get user input text. Gets all user input, including both submitted and saved history items.
data REPLHistory Source #
History of the REPL with indices (0 is first entry) to the current line and to the first entry since loading saved history. We also (ab)use the length of the REPL as the index of current input line, since that number is one past the index of last entry.
Instances
Show REPLHistory Source # | |
Defined in Swarm.TUI.Model.Repl Methods showsPrec :: Int -> REPLHistory -> ShowS # show :: REPLHistory -> String # showList :: [REPLHistory] -> ShowS # |
replIndex :: Lens' REPLHistory Int Source #
The current index in the REPL history (if the user is going back through the history using up/down keys).
replLength :: REPLHistory -> Int Source #
Current number lines of the REPL history - (ab)used as index of input buffer.
replHasExecutedManualInput :: Lens' REPLHistory Bool Source #
Keep track of whether the user has explicitly executed commands at the REPL prompt, thus making them ineligible for code size scoring.
Note: Instead of adding a dedicated field to the REPLHistory
record,
an early attempt entailed checking for:
_replIndex > _replStart
However, executing an initial script causes a REPLOutput to be appended to the REPL history, which increments the replIndex, and thus makes the Index greater than the Start even though the player has not input commands directly into the REPL.
Therefore, a dedicated boolean is introduced into REPLHistory
which simply latches True when the user has input a command.
An alternative is described in issue #974.
replSeq :: Lens' REPLHistory (Seq REPLHistItem) Source #
Sequence of REPL inputs and outputs, oldest entry is leftmost.
newREPLHistory :: [REPLHistItem] -> REPLHistory Source #
Create new REPL history (i.e. from loaded history file lines).
addREPLItem :: REPLHistItem -> REPLHistory -> REPLHistory Source #
Add new REPL input - the index must have been pointing one past the last element already, so we increment it to keep it that way.
restartREPLHistory :: REPLHistory -> REPLHistory Source #
Point the start of REPL history after current last line. See replStart
.
getLatestREPLHistoryItems :: Int -> REPLHistory -> [REPLHistItem] Source #
Get the latest N items in history, starting with the oldest one.
This is used to show previous REPL lines in UI, so we need the items sorted in the order they were entered and will be drawn top to bottom.
getSessionREPLHistoryItems :: REPLHistory -> Seq REPLHistItem Source #
Get only the items from the REPL history that were entered during the current session.
moveReplHistIndex :: TimeDir -> Text -> REPLHistory -> REPLHistory Source #
replIndexIsAtInput :: REPLHistory -> Bool Source #
Prompt utils
data REPLPrompt Source #
This data type tells us how to interpret the text typed by the player at the prompt (which is stored in Editor).
Constructors
CmdPrompt [Text] | Interpret the prompt text as a regular command. The list is for potential completions, which we can cycle through by hitting Tab repeatedly |
SearchPrompt REPLHistory | Interpret the prompt text as "search this text in history" |
removeEntry :: Text -> REPLHistory -> REPLHistory Source #
Given some text, removes the REPLEntry
within REPLHistory
which is equal to that.
This is used when the user enters search mode and wants to traverse the history.
If a command has been used many times, the history will be populated with it causing
the effect that search command always finds the same command.
REPL Panel Model
data ReplControlMode Source #
What is being done with user input to the REPL panel?
Constructors
Typing | The user is typing at the REPL. |
Piloting | The user is driving the base using piloting mode. |
Handling | A custom user key handler is processing user input. |
Instances
Bounded ReplControlMode Source # | |
Defined in Swarm.TUI.Model.Repl | |
Enum ReplControlMode Source # | |
Defined in Swarm.TUI.Model.Repl Methods succ :: ReplControlMode -> ReplControlMode # pred :: ReplControlMode -> ReplControlMode # toEnum :: Int -> ReplControlMode # fromEnum :: ReplControlMode -> Int # enumFrom :: ReplControlMode -> [ReplControlMode] # enumFromThen :: ReplControlMode -> ReplControlMode -> [ReplControlMode] # enumFromTo :: ReplControlMode -> ReplControlMode -> [ReplControlMode] # enumFromThenTo :: ReplControlMode -> ReplControlMode -> ReplControlMode -> [ReplControlMode] # | |
Eq ReplControlMode Source # | |
Defined in Swarm.TUI.Model.Repl Methods (==) :: ReplControlMode -> ReplControlMode -> Bool # (/=) :: ReplControlMode -> ReplControlMode -> Bool # |
replPromptType :: Lens' REPLState REPLPrompt Source #
The way we interpret text typed by the player in the REPL prompt.
replPromptEditor :: Lens' REPLState (Editor Text Name) Source #
The prompt where the user can type input at the REPL.
replPromptText :: Lens' REPLState Text Source #
Convenience lens to get text from editor and replace it with new one that has the provided text.
replValid :: Lens' REPLState (Either SrcLoc ()) Source #
Whether the prompt text is a valid Term
.
If it is invalid, the location of error. (NoLoc
means the whole
text causes the error.)
replLast :: Lens' REPLState Text Source #
The last thing the user has typed which isn't part of the history. This is used to restore the repl form after the user visited the history.
replType :: Lens' REPLState (Maybe Polytype) Source #
The type of the current REPL input which should be displayed to the user (if any).
replControlMode :: Lens' REPLState ReplControlMode Source #
The current REPL control mode, i.e. how user input to the REPL panel is being handled.
replHistory :: Lens' REPLState REPLHistory Source #
History of things the user has typed at the REPL, interleaved with outputs the system has generated.
Initialization
initREPLState :: REPLHistory -> REPLState Source #
lastEntry :: Text -> REPLHistory -> Maybe Text Source #
Get the last REPLEntry
in REPLHistory
matching the given text