embedit

package module
v0.0.0-...-4aa4c59 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2022 License: MIT Imports: 4 Imported by: 0

README

embedit

CLI line editing for embedded devices

embedit is a Go module for reading and editing a line of input (similar to readline). The principle design goals are:

  1. Usable with standard Go and TinyGo
  2. No dynamic memory allocation (see analysis below)
    • For operation on baremetal and embedded systems such as microcontrollers
  3. Minimal dependencies (no fmt, strconv, or any third-party packages)
    • Required to guarantee goals 1 & 2

Much of the original source code was based on golang.org/x/term by the standard Go authors.

Usage

See examples for a few different usages. The following gif shows examples/basic in action.

examples/basic

Heap Profile

The following tools are used to verify no dynamic memory allocation is performed:

  • pprof from standard Go
  • trace from standard Go
  • TinyGo's built-in escape analysis compile-time option (-print-allocs)

The last is straight-forward, so only pprof and trace are discussed here.

The examples/analysis demo is used to exercise the package API. Different build tags will configure the individual profiling tools. See the comments in examples/analysis/main.go for details.

So far, runtime heap allocation can only be eliminated from the package code and its direct dependencies. In standard Go, the runtime itself will perform heap allocation internally to create and manage core goroutines and system threads (e.g., Gs and Ms).

The following graph shows the total heap memory allocated throughout the lifetime of the program.

Heap profile (examples/analysis)

As you can see, most of the memory is attributed to the internal runtime constructs mentioned above. All remaining allocations are related to the main package of the analysis example such as the profiler tooling and command-line flag parser. None of these are directly related to the embedit package itself.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	RW        io.ReadWriter
	Prompt    []rune
	Width     int
	Height    int
	AutoFlush bool
}

Config defines the configuration parameters of an Embedit.

type Embedit

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

Embedit defines the state and configuration of a line-buffered, commandline user interface with some capabilities of a modern terminal.

It requires no dynamic memory allocation. Size limitations are defined by compile-time constants in package config.

Refer to the examples to see how to allocate and configure the object for common use cases.

func New

func New() Embedit

New allocates a new Embedit and returns a pointer to that object.

The object remains uninitialized and unusable until Configure has been called

func (*Embedit) Configure

func (e *Embedit) Configure(config Config) *Embedit

Configure initializes the Embedit configuration.

func (*Embedit) Cursor

func (e *Embedit) Cursor() *cursor.Cursor

func (*Embedit) Line

func (e *Embedit) Line() *line.Line

Line returns the Terminal's active user input line.

func (*Embedit) Terminal

func (e *Embedit) Terminal() *terminal.Terminal

Terminal returns the terminal.

Directories

Path Synopsis
config
examples
seq
eol
sys
key
wire
Package wire defines an API for transmitting serial data.
Package wire defines an API for transmitting serial data.

Jump to

Keyboard shortcuts

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