Documentation
¶
Overview ¶
Package console is the terminal of the browser build of hail (D20, W19). A host page, which draws the terminal with xterm.js, gives hail the bytes that the user types, the size of the terminal and the interrupt, and shows what hail writes. A Console holds them for the shell and for rline, which takes it through rline.WithTerminal (rline's D79).
A terminal of Unix has a line discipline in the kernel, which echoes the keys, keeps the line until Enter, and turns Ctrl-C into SIGINT, while no program reads the keys in raw mode. A web page has no kernel, so a Console does this work itself. It has no build constraint, so that every build compiles it and its tests run under Go and TinyGo on Linux.
The plumbing of the browser build goes to a repository that hail and usql share (D21). This package holds the part that hail needs until that repository exists.
Index ¶
- type Console
- func (c *Console) Close()
- func (c *Console) Input(p []byte)
- func (c *Console) Read(p []byte) (int, error)
- func (c *Console) Resize(cols, rows int)
- func (c *Console) Resized() <-chan struct{}
- func (c *Console) SetInterrupt(f func())
- func (c *Console) SetRaw(on bool) error
- func (c *Console) Size() (cols, rows int)
- func (c *Console) Stdin() io.Reader
- func (c *Console) Write(p []byte) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Console ¶
type Console struct {
// contains filtered or unexported fields
}
Console is a terminal that a host gives hail, such as xterm.js in a web page. The host gives it the bytes that the user types, through Input, and the size of the terminal, through Resize. It shows what the Console writes to the writer of New.
A Console has two modes, as a terminal of Unix has. In raw mode, the line editor reads each key through Read. rline turns raw mode on and off through SetRaw, while it reads a line. In the other mode, the Console keeps a line of its own: it echoes each key, takes Backspace and Ctrl-U, and gives the line to Stdin after Enter. Ctrl-C then calls the function of SetInterrupt, as a terminal sends SIGINT. Ctrl-D at the start of a line ends the input of one read.
A Console satisfies rline.Terminal, with Resized and SetRaw. Its methods can be called from any goroutine.
func New ¶
New returns a Console that writes what the terminal shows to out, with a size of cols columns and rows rows.
func (*Console) Close ¶
func (c *Console) Close()
Close ends the input. Each read after the input that waits returns io.EOF.
func (*Console) Read ¶
Read reads the keys of raw mode, for the line editor. It waits while the Console is not in raw mode. It returns io.EOF after Close.
func (*Console) Resized ¶
func (c *Console) Resized() <-chan struct{}
Resized returns a channel that gets a value when the size changes.
func (*Console) SetInterrupt ¶
func (c *Console) SetInterrupt(f func())
SetInterrupt sets the function that the Console calls when the user types Ctrl-C and the line editor does not read keys. The shell cancels the command that runs, as it does for SIGINT.
func (*Console) SetRaw ¶
SetRaw turns raw mode on or off. The input that waits goes to the new mode: the line editor reads the lines that the user typed ahead, and a key that it did not read goes to the line of the other mode.
func (*Console) Stdin ¶
Stdin returns the reader of the lines that the user types while the line editor does not read keys, for descriptor 0 of the shell. A read returns at most one line. It returns 0 and io.EOF once for each Ctrl-D at the start of a line, when Ctrl-C comes while it waits, and after Close.