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 ¶
- func DumpClient(cfg *Config, ctx context.Context, window string, update bool) error
- func InputClient(cfg *Config, ctx context.Context, quit bool, window string) error
- func Run(cfg *Config, ctx context.Context) error
- type Config
- type Line
- type LineWriter
- func (lw *LineWriter) Close() error
- func (lw *LineWriter) Line(window string, pos int, text string) error
- func (lw *LineWriter) Move(window string, plus int) error
- func (lw *LineWriter) Printf(format string, args ...interface{}) (int, error)
- func (lw *LineWriter) Quit() error
- func (lw *LineWriter) Read(p []byte) (int, error)
- func (lw *LineWriter) Render() ([]byte, error)
- func (lw *LineWriter) ScrollDelay(window string, pos int, delay time.Duration) error
- func (lw *LineWriter) Switch(window string) error
- func (lw *LineWriter) Truncate(window string, cutoff int) error
- func (lw *LineWriter) Write(p []byte) (int, error)
- type Window
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DumpClient ¶
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 ¶
InputClient is a dump client that can be used to send arbitrary displayd lines in a netcat or telnet like fashion from the commandline.
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 (*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) SetScrollDelay ¶
SetScrollDelay sets the scroll speed of the line (i.e. the delay between one "shift"). Shorter delay means faster scrolling.
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) 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 ¶
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.
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 (*Window) SetLine ¶
SetLine sets text of line `pos` to `text`. If the line does not exist yet it will be created.
func (*Window) SetScrollDelay ¶
SetScrollDelay sets the scroll shift delay of line `pos` to `delay`.