# Module `ttyutil` - A utility library for terminal-based input and output

A utility library for terminal-based input and output.

This library provides various utilities for use with VT220 compatible terminals.

## Index

- Group `ANSI` - VT220/ANSI rendering attributes
  - Constant `ANSI.BG.BLACK` - Black background
  - Constant `ANSI.BG.BLUE` - Blue background
  - Constant `ANSI.BG.CYAN` - Cyan background
  - Constant `ANSI.BG.GREEN` - Green background
  - Constant `ANSI.BG.MAGENTA` - Magenta background
  - Constant `ANSI.BG.RED` - Red background
  - Constant `ANSI.BG.WHITE` - White background
  - Constant `ANSI.BG.YELLOW` - Yellow background
  - Constant `ANSI.BLINK` - Blinking
  - Constant `ANSI.BOLD` - Bold rendering
  - Constant `ANSI.FG.BLACK` - Black foreground
  - Constant `ANSI.FG.BLUE` - Blue foreground
  - Constant `ANSI.FG.CYAN` - Cyan foreground
  - Constant `ANSI.FG.GREEN` - Green foreground
  - Constant `ANSI.FG.MAGENTA` - Magenta foreground
  - Constant `ANSI.FG.RED` - Red foreground
  - Constant `ANSI.FG.WHITE` - White foreground
  - Constant `ANSI.FG.YELLOW` - Yellow foreground
  - Constant `ANSI.INVERSE` - Inverse rendering
  - Constant `ANSI.NORMAL` - Normal/reset
- Group `KEY` - Key constants
  - Constant `KEY.F1` - Function keys
  - Constant `KEY.UP` - Arrow keys
- Protocol `TTYUTIL.DPY` - Basic display protocol
  - Tag `clear.screen` - Clear the screen
  - Tag `colours` - Set ANSI/VT220 attributes (see )
  - Tag `following` - Number of outputs to follow (when dealing with an unshared
  - Tag `int.xy` - Integer at specific position (x, y, value)
  - Tag `quit` - Quit the display process
  - Tag `string.xy` - String at specific position (x, y, string)
- Protocol `TTYUTIL.MENU` - Menu control protocol
  - Tag `add.item` - Add menu item
  - Tag `del.item` - Delete a particular item
  - Tag `insert.item` - Add menu item at a specific position
  - Tag `key.in` - Incoming key press
  - Tag `quit` - Shutdown menu
- Protocol `TTYUTIL.MENU.IN` - Menu item handler input protocol (menu -> handler)
  - Tag `get.text` - Get item text
  - Tag `key.left` - Key item left
  - Tag `key.other` - Other key (e.g
  - Tag `key.right` - Key item right
  - Tag `quit` - Menu quit (signals handler to quit)
- Protocol `TTYUTIL.MENU.OUT` - Menu item handler output protocol (handler -> menu)
  - Tag `remove` - Remove this item (self)
  - Tag `text` - Text update for menu
- Channel type `TTYUTIL.MENUITEM` - Menu item channel type
  - Variable `in?` - Menu item handler requests
  - Variable `out!` - Menu item handler responses
- Process `ttyutil.display` - Basic display process
- Process `ttyutil.display.shared` - Display process for shared screen output
- Process `ttyutil.keyhandler` - Keyboard handler
- Process `ttyutil.menu` - Produces a controllable on-screen menu

## Declarations

### `ttyutil.occ`:50Process `ttyutil.display`

`PROC ttyutil.display (CHAN TTYUTIL.DPY in?, CHAN BYTE out!)`

Basic display process.

#### Parameters:

`CHAN TTYUTIL.DPY` | `in` | Display commands in.
`CHAN BYTE` | `out` | Screen output.

### `ttyutil.occ`:105Process `ttyutil.display.shared`

`PROC ttyutil.display.shared (CHAN TTYUTIL.DPY in?, SHARED CHAN BYTE out!)`

Display process for shared screen output.

#### Parameters:

`CHAN TTYUTIL.DPY` | `in` | Display commands in.
`SHARED CHAN BYTE` | `out` | Screen output.

### `ttyutil.occ`:222Process `ttyutil.keyhandler`

`PROC ttyutil.keyhandler (CHAN BYTE in?, CHAN INT kill?, CHAN INT out!)`

Keyboard handler.

#### Parameters:

`CHAN BYTE` | `in` | Raw keyboard input in.
`CHAN INT` | `kill` | Kill channel.
`CHAN INT` | `out` | Processed keystrokes (see `KEY`).

### `ttyutil.occ`:278Process `ttyutil.menu`

`PROC ttyutil.menu (VAL INT x, y, width, height, VAL BOOL border, CHAN TTYUTIL.MENU in?, SHARED CHAN TTYUTIL.DPY out!)`

Produces a controllable on-screen menu. Expects the first inputs to be addition of new menu items.

#### Parameters:

`VAL INT` | `x` | X position on screen.
`VAL INT` | `y` | Y position on screen.
`VAL INT` | `width` | Width of menu.
`VAL INT` | `height` | Height of menu.
`VAL BOOL` | `border` | Whether or not to draw a border.
`CHAN TTYUTIL.MENU` | `in` | Menu control channel (including keys).
`SHARED CHAN TTYUTIL.DPY` | `out` | Display output channel.

### `ttyutil.inc`:33Group `ANSI`

``

VT220/ANSI rendering attributes.

### `ttyutil.inc`:34Constant `ANSI.NORMAL`

`VAL BYTE ANSI.NORMAL`

Normal/reset.

### `ttyutil.inc`:35Constant `ANSI.BOLD`

`VAL BYTE ANSI.BOLD`

Bold rendering.

### `ttyutil.inc`:36Constant `ANSI.INVERSE`

`VAL BYTE ANSI.INVERSE`

Inverse rendering.

### `ttyutil.inc`:37Constant `ANSI.BLINK`

`VAL BYTE ANSI.BLINK`

Blinking.

### `ttyutil.inc`:39Constant `ANSI.FG.BLACK`

`VAL BYTE ANSI.FG.BLACK`

Black foreground.

### `ttyutil.inc`:40Constant `ANSI.FG.RED`

`VAL BYTE ANSI.FG.RED`

Red foreground.

### `ttyutil.inc`:41Constant `ANSI.FG.GREEN`

`VAL BYTE ANSI.FG.GREEN`

Green foreground.

### `ttyutil.inc`:42Constant `ANSI.FG.YELLOW`

`VAL BYTE ANSI.FG.YELLOW`

Yellow foreground.

### `ttyutil.inc`:43Constant `ANSI.FG.BLUE`

`VAL BYTE ANSI.FG.BLUE`

Blue foreground.

### `ttyutil.inc`:44Constant `ANSI.FG.MAGENTA`

`VAL BYTE ANSI.FG.MAGENTA`

Magenta foreground.

### `ttyutil.inc`:45Constant `ANSI.FG.CYAN`

`VAL BYTE ANSI.FG.CYAN`

Cyan foreground.

### `ttyutil.inc`:46Constant `ANSI.FG.WHITE`

`VAL BYTE ANSI.FG.WHITE`

White foreground.

### `ttyutil.inc`:48Constant `ANSI.BG.BLACK`

`VAL BYTE ANSI.BG.BLACK`

Black background.

### `ttyutil.inc`:49Constant `ANSI.BG.RED`

`VAL BYTE ANSI.BG.RED`

Red background.

### `ttyutil.inc`:50Constant `ANSI.BG.GREEN`

`VAL BYTE ANSI.BG.GREEN`

Green background.

### `ttyutil.inc`:51Constant `ANSI.BG.YELLOW`

`VAL BYTE ANSI.BG.YELLOW`

Yellow background.

### `ttyutil.inc`:52Constant `ANSI.BG.BLUE`

`VAL BYTE ANSI.BG.BLUE`

Blue background.

### `ttyutil.inc`:53Constant `ANSI.BG.MAGENTA`

`VAL BYTE ANSI.BG.MAGENTA`

Magenta background.

### `ttyutil.inc`:54Constant `ANSI.BG.CYAN`

`VAL BYTE ANSI.BG.CYAN`

Cyan background.

### `ttyutil.inc`:55Constant `ANSI.BG.WHITE`

`VAL BYTE ANSI.BG.WHITE`

White background.

### `ttyutil.inc`:57Group `KEY`

``

Key constants. Values of 0-255 represent ASCII/locale-specific characters.

### `ttyutil.inc`:60Constant `KEY.UP`

`VAL INT KEY.UP`

Arrow keys.

### `ttyutil.inc`:66Constant `KEY.F1`

`VAL INT KEY.F1`

Function keys.

### `ttyutil.inc`:97Protocol `TTYUTIL.DPY`

`PROTOCOL TTYUTIL.DPY`

Basic display protocol.

### `ttyutil.inc`:99Tag `following`

`following; INT`

Number of outputs to follow (when dealing with an unshared

### `ttyutil.inc`:103Tag `clear.screen`

`clear.screen`

Clear the screen.

### `ttyutil.inc`:104Tag `int.xy`

`int.xy; INT; INT; INT`

Integer at specific position (x, y, value).

### `ttyutil.inc`:105Tag `string.xy`

`string.xy; INT; INT; MOBILE []BYTE`

String at specific position (x, y, string).

### `ttyutil.inc`:106Tag `colours`

`colours; MOBILE []BYTE`

Set ANSI/VT220 attributes (see `ANSI`).

### `ttyutil.inc`:108Tag `quit`

`quit`

Quit the display process.

### `ttyutil.inc`:112Protocol `TTYUTIL.MENU.IN`

`PROTOCOL TTYUTIL.MENU.IN`

Menu item handler input protocol (menu -> handler).

### `ttyutil.inc`:114Tag `get.text`

`get.text`

Get item text.

### `ttyutil.inc`:115Tag `key.left`

`key.left`

Key item left.

### `ttyutil.inc`:116Tag `key.right`

`key.right`

Key item right.

### `ttyutil.inc`:117Tag `key.other`

`key.other; INT`

Other key (e.g. return).

### `ttyutil.inc`:119Tag `quit`

`quit`

Menu quit (signals handler to quit).

### `ttyutil.inc`:123Protocol `TTYUTIL.MENU.OUT`

`PROTOCOL TTYUTIL.MENU.OUT`

Menu item handler output protocol (handler -> menu).

### `ttyutil.inc`:125Tag `text`

`text; MOBILE []BYTE`

Text update for menu.

### `ttyutil.inc`:126Tag `remove`

`remove`

Remove this item (self).

### `ttyutil.inc`:130Channel type `TTYUTIL.MENUITEM`

`CHAN TYPE TTYUTIL.MENUITEM`

Menu item channel type.

### `ttyutil.inc`:132Variable `in?`

`CHAN TTYUTIL.MENU.IN`

Menu item handler requests.

### `ttyutil.inc`:133Variable `out!`

`CHAN TTYUTIL.MENU.OUT`

Menu item handler responses.

### `ttyutil.inc`:137Protocol `TTYUTIL.MENU`

`PROTOCOL TTYUTIL.MENU`

Menu control protocol.

### `ttyutil.inc`:139Tag `add.item`

`add.item; TTYUTIL.MENUITEM!`

Add menu item.

### `ttyutil.inc`:140Tag `insert.item`

`insert.item; INT; TTYUTIL.MENUITEM!`

Add menu item at a specific position.

### `ttyutil.inc`:141Tag `del.item`

`del.item; INT`

Delete a particular item.

### `ttyutil.inc`:142Tag `quit`

`quit`

Shutdown menu.

### `ttyutil.inc`:144Tag `key.in`

`key.in; INT`

Incoming key press.