console

package
v0.0.0-...-79e800d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 2, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

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

func New(out io.Writer, cols, rows int) *Console

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) Input

func (c *Console) Input(p []byte)

Input gives the Console the bytes that the user typed.

func (*Console) Read

func (c *Console) Read(p []byte) (int, error)

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) Resize

func (c *Console) Resize(cols, rows int)

Resize sets the size of the terminal to cols columns and rows rows.

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

func (c *Console) SetRaw(on bool) error

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) Size

func (c *Console) Size() (cols, rows int)

Size returns the width and the height of the terminal, in characters.

func (*Console) Stdin

func (c *Console) Stdin() io.Reader

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.

func (*Console) Write

func (c *Console) Write(p []byte) (int, error)

Write writes what the terminal shows. It turns each new line into a carriage return and a new line, as a terminal of Unix does with its output, in raw mode too.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL