terminal-0.2.0.0: Portable terminal interaction library

Safe HaskellNone
LanguageHaskell2010

System.Terminal.Internal

Contents

Synopsis

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.

Methods

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.

data Color Source #

ANSI colors.

Instances
Eq Color Source # 
Instance details

Defined in System.Terminal.Terminal

Methods

(==) :: Color -> Color -> Bool #

(/=) :: Color -> Color -> Bool #

Ord Color Source # 
Instance details

Defined in System.Terminal.Terminal

Methods

compare :: Color -> Color -> Ordering #

(<) :: Color -> Color -> Bool #

(<=) :: Color -> Color -> Bool #

(>) :: Color -> Color -> Bool #

(>=) :: Color -> Color -> Bool #

max :: Color -> Color -> Color #

min :: Color -> Color -> Color #

Show Color Source # 
Instance details

Defined in System.Terminal.Terminal

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

newtype Decoder Source #

The type Decoder is a finite state transducer.

Intermediate state can be passed as closure. See below for an example.

Constructors

Decoder 

LocalTerminal

VirtualTerminal (for testing)