console

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 12 Imported by: 0 modules, 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 owns the virtual terminal while the splash shows: it keeps the kernel's text off the splash, reads keys already mapped by the console's keymap, and shows the splash as text when there is no graphical output.

Index

Constants

View Source
const (
	MaxLines     = 1000
	MaxLineWidth = 512
)

The bounds of a Scrollback.

View Source
const ClearScreen = "\x1b[H\x1b[2J"

ClearScreen clears a terminal and puts the cursor top left.

View Source
const (
	VTConsoles = "/sys/class/vtconsole"
)

Variables

View Source
var ErrNoVT = errors.New("console: the kernel has no virtual terminals")

ErrNoVT is what OpenActive wraps on a kernel without virtual terminals.

View Source
var SystemPaths = Paths{Sysfs: "/sys/class/tty", Dev: "/dev"}

SystemPaths are the kernel's: /sys/class/tty and /dev.

Functions

func Screen

func Screen(lines []string, rows int) []byte

Screen is what a terminal of rows lines shows of lines.

func UnbindFramebufferConsoles

func UnbindFramebufferConsoles(dir string) ([]string, error)

Types

type Capture

type Capture struct {
	// contains filtered or unexported fields
}

Capture is the console's output redirected into a pseudo-terminal with TIOCCONS, as plymouth's details view takes it: what is written to /dev/console, systemd's status lines among it, reaches Read instead of the console until Restore or Leave gives the console back.

func CaptureConsole

func CaptureConsole(p Paths) (*Capture, error)

CaptureConsole redirects the console under p.Dev into a new pseudo-terminal. It needs CAP_SYS_ADMIN, and fails while another process holds the console redirected.

func (*Capture) Leave

func (c *Capture) Leave() error

Leave gives the console back without writing to it, for a splash whose last frame stays on screen, and closes the pseudo-terminal.

func (*Capture) Read

func (c *Capture) Read(b []byte) (int, error)

Read reads the console's output, blocking until there is some.

func (*Capture) Restore

func (c *Capture) Restore(lines []string) error

Restore gives the console back and writes lines to it, so that what the splash captured is not lost, then closes the pseudo-terminal, which also ends a blocked Read.

type Paths

type Paths struct {
	Sysfs string
	Dev   string
}

Paths are where the VTs are found.

type Scrollback

type Scrollback struct {
	// contains filtered or unexported fields
}

Scrollback is the console's output as the lines a terminal would show: a carriage return goes back to the start of the line, a backspace back one character and an erase-line sequence clears from the cursor on; other escape sequences and control characters are dropped. It keeps the last MaxLines lines, each cut at MaxLineWidth characters.

func (*Scrollback) Lines

func (s *Scrollback) Lines() []string

Lines are the lines kept, oldest first, the one still being written last when it has anything on it.

func (*Scrollback) Screen

func (s *Scrollback) Screen(rows int) []byte

Screen is what a terminal of rows lines shows of the scrollback: the screen cleared, then the last lines, leaving the bottom row free.

func (*Scrollback) Write

func (s *Scrollback) Write(b []byte) (int, error)

Write takes the next of the console's output; it never fails.

type TextView

type TextView struct {
	W io.Writer
}

TextView shows the splash as text on a terminal, for a machine without graphical output: each message on a line of its own, the update progress, and the prompt on the last line, a question's answer echoed and a password's not.

func (TextView) Show

func (t TextView) Show(prev *theme.State, cur theme.State) error

Show writes what changed from prev to cur; with prev nil, everything.

type VT

type VT struct {
	// contains filtered or unexported fields
}

VT is the active virtual terminal, taken over: graphics mode keeps the kernel's text off the splash, and its keyboard reads characters one at a time without echo.

func OpenActive

func OpenActive(p Paths) (*VT, error)

OpenActive opens the active VT and takes it over. On a kernel without VTs it fails with an error wrapping ErrNoVT.

func (*VT) CapsLock

func (v *VT) CapsLock() (bool, error)

func (*VT) Graphics

func (v *VT) Graphics() error

Graphics switches the VT to graphics mode, so the kernel draws no text over the splash.

func (*VT) Leave

func (v *VT) Leave() error

Leave gives the keyboard and terminal settings back but keeps graphics mode, so the kernel's console does not draw over a frame the splash leaves on screen, and closes the VT. Only the first Restore or Leave acts.

func (*VT) Name

func (v *VT) Name() string

Name is the VT's device path.

func (*VT) Read

func (v *VT) Read(b []byte) (int, error)

Read reads keyboard input, blocking until there is some.

func (*VT) Reclaim

func (v *VT) Reclaim() error

Reclaim makes the terminal raw and the keyboard unicode again, for when another process reset the VT under the splash: systemd resets the console's terminal when it starts in the real root, which with the console on a VT leaves the splash reading whole lines.

func (*VT) Restore

func (v *VT) Restore() error

Restore gives the VT back as it was: its display mode, keyboard mode and terminal settings, then closes it, which also ends a blocked Read. Only the first Restore or Leave acts.

func (*VT) Rows

func (v *VT) Rows() (int, error)

Rows is how many lines of text the VT shows.

func (*VT) Text

func (v *VT) Text() error

Text switches the VT back to text mode, for boot messages or the text splash, keeping the keyboard the splash's.

func (*VT) Write

func (v *VT) Write(b []byte) (int, error)

Write writes text to the VT.

Jump to

Keyboard shortcuts

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