Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class Terminal t where
- termType :: t -> ByteString
- termEvent :: t -> STM Event
- termInterrupt :: t -> STM Interrupt
- termCommand :: t -> Command -> IO ()
- termFlush :: t -> IO ()
- termGetWindowSize :: t -> IO Size
- termGetCursorPosition :: t -> IO Position
- data Command
- = PutLn
- | PutText Text
- | SetAttribute Attribute
- | ResetAttribute Attribute
- | ResetAttributes
- | MoveCursorUp Int
- | MoveCursorDown Int
- | MoveCursorForward Int
- | MoveCursorBackward Int
- | ShowCursor
- | HideCursor
- | SaveCursor
- | RestoreCursor
- | GetCursorPosition
- | SetCursorPosition Position
- | SetCursorRow Int
- | SetCursorColumn Int
- | InsertChars Int
- | DeleteChars Int
- | EraseChars Int
- | InsertLines Int
- | DeleteLines Int
- | EraseInLine EraseMode
- | EraseInDisplay EraseMode
- | SetAutoWrap Bool
- | SetAlternateScreenBuffer Bool
- data Attribute
- data Color
- = Black
- | Red
- | Green
- | Yellow
- | Blue
- | Magenta
- | Cyan
- | White
- | BrightBlack
- | BrightRed
- | BrightGreen
- | BrightYellow
- | BrightBlue
- | BrightMagenta
- | BrightCyan
- | BrightWhite
- newtype Decoder = Decoder {}
- defaultDecoder :: (Modifiers -> Char -> Maybe Event) -> Decoder
- defaultEncode :: Command -> Text
- data LocalTerminal
- data VirtualTerminal = VirtualTerminal {}
- data VirtualTerminalSettings = VirtualTerminalSettings {}
- withVirtualTerminal :: MonadIO m => VirtualTerminalSettings -> (VirtualTerminal -> m a) -> m a
Terminal
class Terminal t where Source #
Types that represent terminals need to implement this class in order to be driven by this library.
This library ships with two instances:
LocalTerminal
represents the local terminal wired to the process.VirtualTerminal
is a minimal in-process terminal emulator designed to be used for unit-testing terminal applications.
termType :: t -> ByteString Source #
The terminal identification string usually extracted from the
environment variable TERM
. Should contain values like xterm
or rxvt-unicode
.
termEvent :: t -> STM Event Source #
A stream of input events. The transaction will succeed as soon as the next input event becomes available.
Note: Trying to read more than one event within the same transaction might be successfull, but might also lead to undesired behaviour as the transaction will block until all of its preconditions are fulfilled.
termInterrupt :: t -> STM Interrupt Source #
This transaction succeeds as soon as an interrupt occurs. Executing the transaction shall reset an interrupt flag maintained by a supervising background thread.
It is mandatory to regularly check this transaction in order to signal
responsiveness to the background thread. The execution environment is otherwise
advised to throw an UserInterrupt
exception as soon as a
second interrupt arrives and it sees a previous one unhandled.
termCommand :: t -> Command -> IO () Source #
This operation shall send a command to the terminal. It shall block when the buffer exeeded its capacity and unblock as soon as space becomes available again.
Note: All implementations must limit the size of the output buffer or the application is at risk of running out of memory when writing much faster than the terminal can read.
termFlush :: t -> IO () Source #
This operations flushes the output buffer. Whether it blocks or not until the buffer has actually been flushed shall be undefined (there might be other buffers involved that cannot be force-flushed so it is probably better to not give any guarantees here).
termGetWindowSize :: t -> IO Size Source #
This operation shall return the latest known window size without blocking.
termGetCursorPosition :: t -> IO Position Source #
This operation shall return the current cursor position. It may block as depending on implementation it usually requires an in-band roundtrip to the terminal. Use it wisely.
Instances
Terminal LocalTerminal Source # | |
Defined in System.Terminal.Platform termType :: LocalTerminal -> ByteString Source # termEvent :: LocalTerminal -> STM Event Source # termInterrupt :: LocalTerminal -> STM Interrupt Source # termCommand :: LocalTerminal -> Command -> IO () Source # termFlush :: LocalTerminal -> IO () Source # termGetWindowSize :: LocalTerminal -> IO Size Source # termGetCursorPosition :: LocalTerminal -> IO Position Source # | |
Terminal VirtualTerminal Source # | |
Defined in System.Terminal.Virtual termType :: VirtualTerminal -> ByteString Source # termEvent :: VirtualTerminal -> STM Event Source # termInterrupt :: VirtualTerminal -> STM Interrupt Source # termCommand :: VirtualTerminal -> Command -> IO () Source # termFlush :: VirtualTerminal -> IO () Source # termGetWindowSize :: VirtualTerminal -> IO Size Source # termGetCursorPosition :: VirtualTerminal -> IO Position Source # |
The commands every terminal needs to understand.
This shall only be extended when something is missing that all terminals understand. Otherwise portability will be lost.
ANSI text attributes.
ANSI colors.
Black | |
Red | |
Green | |
Yellow | |
Blue | |
Magenta | |
Cyan | |
White | |
BrightBlack | |
BrightRed | |
BrightGreen | |
BrightYellow | |
BrightBlue | |
BrightMagenta | |
BrightCyan | |
BrightWhite |
The type Decoder
is a finite state transducer.
Intermediate state can be passed as closure. See below for an example.
defaultEncode :: Command -> Text Source #
LocalTerminal
data LocalTerminal Source #
Instances
Terminal LocalTerminal Source # | |
Defined in System.Terminal.Platform termType :: LocalTerminal -> ByteString Source # termEvent :: LocalTerminal -> STM Event Source # termInterrupt :: LocalTerminal -> STM Interrupt Source # termCommand :: LocalTerminal -> Command -> IO () Source # termFlush :: LocalTerminal -> IO () Source # termGetWindowSize :: LocalTerminal -> IO Size Source # termGetCursorPosition :: LocalTerminal -> IO Position Source # |
VirtualTerminal (for testing)
data VirtualTerminal Source #
Instances
Terminal VirtualTerminal Source # | |
Defined in System.Terminal.Virtual termType :: VirtualTerminal -> ByteString Source # termEvent :: VirtualTerminal -> STM Event Source # termInterrupt :: VirtualTerminal -> STM Interrupt Source # termCommand :: VirtualTerminal -> Command -> IO () Source # termFlush :: VirtualTerminal -> IO () Source # termGetWindowSize :: VirtualTerminal -> IO Size Source # termGetCursorPosition :: VirtualTerminal -> IO Position Source # |
withVirtualTerminal :: MonadIO m => VirtualTerminalSettings -> (VirtualTerminal -> m a) -> m a Source #