Documentation
¶
Overview ¶
Package console puts the local terminal into raw mode and forwards keystrokes and window resizes to a remote terminal.
Windows needs the console API rather than termios, and the Python implementation needed three rounds of fixes for VT sequences, the GBK code page and held-key repeat counts (DESIGN.md「交互式终端」), so this is written against x/term plus x/sys/windows rather than hand-rolled escape handling.
The three Windows lessons are encoded here rather than re-learned:
- raw mode is a console-mode change, and the console host translates navigation keys into VT characters itself, so no escape decoding is needed and none is attempted;
- output goes out as a byte stream, which keeps a GBK code page from turning UTF-8 into mojibake;
- only stdin decides whether the console is interactive, so redirecting stdout does not disable raw mode.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var DefaultSize = Size{Cols: 200, Rows: 50}
DefaultSize is used when the real window size cannot be read.
Functions ¶
func IsTerminal ¶
IsTerminal reports whether fd is a terminal.
It is stdin-only on Windows, matching the fix the Python implementation needed for redirected output (DESIGN.md「交互式终端」): checking stdout reports false for `jms login > file`, which would silently disable raw mode for a perfectly interactive session.
Types ¶
type Options ¶
type Options struct {
// In is the local input; nil means os.Stdin.
In io.Reader
// Out is the local output; nil means os.Stdout.
Out io.Writer
// OnResize is consulted when the window size changes.
OnResize ResizeFunc
// Initial is the starting size; the zero value means DefaultSize.
Initial Size
// contains filtered or unexported fields
}
Options tunes an interactive session.
type ResizeFunc ¶
type ResizeFunc func(Size)
ResizeFunc is called when the local window changes size.
type Session ¶
type Session struct {
// Read returns the next bytes typed locally.
Read func(p []byte) (int, error)
// Write sends remote output to the local screen.
Write func(p []byte) (int, error)
// Size reports the current local window size.
Size func() Size
}
Session is a raw-mode local console attached to a remote terminal.