display

package
v0.0.0-...-f2f0a72 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2016 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package display implements a display server (displayd) similar to the full featured X.org or Wayland on modern linux distributions, just very tiny and for a text-based LCD display.

In contrast to a normal lcd driver which can output characters at a specified position on the lcd display, displayd introduces the metaphor of "lines" (which have a position and a fixed width text with optional scrolling) and "windows" which group together a named set of lines. There can be more lines in a window then the lcd has physically, since windows can be "moved" and "truncated" to implement menus and similar constructs on the client-side. Clients can have many windows which they can swap easily by "switching" to a certain active window.

For writing on the actual LCD display it relies on a driver programm that reads lines from stdin with this simple protocol:

  <line>[,<offset> <Text...>

Examples:

  0 Text at line 0 (first line)
  1,5 Text at line 1 and offset 5

It is expected that the driver manages to not re-render unchanged areas. Displayd will then print the LCD matrix to the driver periodically. Why no event based loop? because the usual usecase of several scrolling lines will actually update more often than a polling based approach.

By it's architecture it also enables the simultaneous write to the display in an ordered fashion and makes it easy for the programmer to use normal utf8 encoding while silently subsituting it with lcd compatible codepoints.

displayd is controlled by a simple line based text protocol and supports currently the following commands:

switch <win>               -- Switch to <win>, creating it if needed.
line <win> <pos> <text>    -- Write <text> in, possibly new, line <pos> of <win>.
move <win> <off>           -- Move <win> down by <off> (may be negative)
truncate <win> <max>       -- Truncates <win> to <max> lines.
render                     -- Outputs the current active window to the socket.
close                      -- Terminates the connection.
quit                       -- Terminates displayd.
scroll <win> <pos> <delay> -- Make line <pos> of <win> scrolled with speed <delay>
                              (default: 0 -> disabled)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpClient

func DumpClient(cfg *Config, ctx context.Context, window string, update bool) error

DumpClient is a client that renders the content of `window` onto stdout. Optionally it will clear & update the screen if `update` is true.

func InputClient

func InputClient(cfg *Config, ctx context.Context, quit bool, window string) error

InputClient is a dump client that can be used to send arbitrary displayd lines in a netcat or telnet like fashion from the commandline.

func Run

func Run(cfg *Config, ctx context.Context) error

Run starts a new displayd server based on `cfg` and `ctx`.

Types

type Config

type Config struct {
	// Host of displayd (usually localhost)
	Host string

	// Port of displayd (usually 7777)
	Port int

	// Width is the number of runes per line in the LCD.
	Width int

	// Height is the number of lines on the LCD.
	Height int

	// DriverBinary is the name of the driver to write the output too.
	DriverBinary string

	// NoEncoding disables the special LCD encoding
	NoEncoding bool
}

Config gives the user to adjust some settings of displayd.

type Line

type Line struct {
	sync.Mutex
	Pos         int
	ScrollDelay time.Duration
	// contains filtered or unexported fields
}

Line is a fixed width buffer with scrolling support It also supports special names for special symbols.

func NewLine

func NewLine(pos int, w int) *Line

NewLine returns a new line at `pos`, `w` runes long.

func (*Line) Redraw

func (ln *Line) Redraw()

Redraw makes sure the line is up-to-date. It can be called if events happeneded that are out of reach of `Line`.

func (*Line) Render

func (ln *Line) Render() []rune

Render returns the current line contents with fixed width

func (*Line) SetScrollDelay

func (ln *Line) SetScrollDelay(delay time.Duration)

SetScrollDelay sets the scroll speed of the line (i.e. the delay between one "shift"). Shorter delay means faster scrolling.

func (*Line) SetText

func (ln *Line) SetText(text string, useEncoding bool)

SetText sets and updates the text of `Line`. If `useEncoding` is false the text is not converted to the special one-rune encoding of the LCD which is useful for debugging on a normal terminal.

type LineWriter

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

LineWriter is good at sending single formatted line to displayd. It's not an abstraction over the text protocol, but an easy access to it. It's methods will block if the displayd server does not exist yet or crashed. It then attempts a reconnect in the background.

func Connect

func Connect(cfg *Config, ctx context.Context) (*LineWriter, error)

Connect creates a LineWriter pointed to the displayd at $(cfg.Host):$(cfg.Port)

func (*LineWriter) Close

func (lw *LineWriter) Close() error

Close cancels all pending operations and frees resources.

func (*LineWriter) Line

func (lw *LineWriter) Line(window string, pos int, text string) error

Line writes a line in `window` at lineno `pos` consisting of `text`

func (*LineWriter) Move

func (lw *LineWriter) Move(window string, plus int) error

Move moves the window `window` down by `plus` lines. `plus` may be negative to go up again. Think of it as vertical scrolling.

func (*LineWriter) Printf

func (lw *LineWriter) Printf(format string, args ...interface{}) (int, error)

Printf formats and sends a message to displayd in a fmt.Printf like fashion.

func (*LineWriter) Quit

func (lw *LineWriter) Quit() error

Quit makes displayd quit.

func (*LineWriter) Read

func (lw *LineWriter) Read(p []byte) (int, error)

Read reads a response from the display server. This is only needed by the debugging dumping program.

func (*LineWriter) Render

func (lw *LineWriter) Render() ([]byte, error)

Render returns a display of the current active window.

func (*LineWriter) ScrollDelay

func (lw *LineWriter) ScrollDelay(window string, pos int, delay time.Duration) error

ScrollDelay sets the delay between a scroll increment of the line in the window `window` at position `pos` to `delay`.

func (*LineWriter) Switch

func (lw *LineWriter) Switch(window string) error

Switch makes `window` the active window.

func (*LineWriter) Truncate

func (lw *LineWriter) Truncate(window string, cutoff int) error

Truncate cuts off the window contents of `window` at the absolute offset `cutoff`. Lines above will be cleared.

func (*LineWriter) Write

func (lw *LineWriter) Write(p []byte) (int, error)

Write sends arbitrary bytes to displayd. You should use Printf() instead.

type Window

type Window struct {
	// Name of the window
	Name string

	// Lines are all lines of
	// Initially, those are `Height` lines.
	Lines []*Line

	// NLines is the number of lines a window has
	// (might be less than len(Lines) due to op-truncate)
	NLines int

	// LineOffset is the current offset in Lines
	// (as modified by Move and Truncate)
	LineOffset int

	// Width is the number of runes which fits in one line
	Width int

	// Height is the number of lines that can be shown simultaneously.
	Height int

	// UseEncoding defines if a special LCD encoding shall be used.
	UseEncoding bool
}

Window consists of a fixed number of lines and a handle name

func NewWindow

func NewWindow(name string, w, h int, useEncoding bool) *Window

NewWindow returns a new window with the dimensions `w`x`h`, named by `name`.

func (*Window) Move

func (win *Window) Move(n int)

Move moves the window contents vertically by `n`.

func (*Window) Render

func (win *Window) Render() [][]rune

Render returns the whole current LCD matrix as bytes.

func (*Window) SetLine

func (win *Window) SetLine(pos int, text string) error

SetLine sets text of line `pos` to `text`. If the line does not exist yet it will be created.

func (*Window) SetScrollDelay

func (win *Window) SetScrollDelay(pos int, delay time.Duration) error

SetScrollDelay sets the scroll shift delay of line `pos` to `delay`.

func (*Window) Switch

func (win *Window) Switch()

Switch makes `win` to the active window.

func (*Window) Truncate

func (win *Window) Truncate(n int) int

Truncate cuts off the window after `n` lines.

Jump to

Keyboard shortcuts

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