ui

package
v0.0.0-...-203dfb9 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package ui handles user input, JSON processing output, and sending interactions and commands to the JSON processor.

The basic layout of the UI should include: - One-row input for entering jq programs - The rest of the container for displaying JSON processor output

The data flow should flow through the following loop:

  • Initial state
  • Actions representing changes or events in the program
  • Functions that listen for a given action and call methods on a UI implementation to update the state
  • Render the new state into application UI

This should seem familiar to web programmers familiar with the Flux/Redux flow. However, since Go doesn't have union types that carry data, and since we want tighter control over memory, we use internal fields and buffers to manage interim states and reuse memory.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action uint8

Action defines the events and interactions possible in the application

const (
	ActionExit Action = iota
	ActionInput
	ActionInputBackspace
	ActionPrint
	ActionSaveInput
	ActionSavePrompt
	ActionSavePromptBackspace
	ActionSaveSubmit
	ActionSubmit
	ActionToggleCompact
	ActionToggleRaw
)

The following are the known Actions from the app to handle

type Termbox

type Termbox struct {
	Debug         io.WriteCloser
	Input         string
	SaveInputMode bool
	SavePath      string
	// contains filtered or unexported fields
}

Termbox draws the jq-live UI via termbox

func (*Termbox) Events

func (t *Termbox) Events() chan (Action)

Events returns a channel of Actions that are sent through the application

func (*Termbox) Flush

func (t *Termbox) Flush() error

Flush prints any unprinted UI changes to the screen

termbox-go Flush() is not goroutine safe, so we're protecting access if updates come in very quickly. https://github.com/nsf/termbox-go/issues/113

func (*Termbox) Quit

func (t *Termbox) Quit()

Quit ends the program, gives the display back to the terminal, and performs any required cleanup

func (*Termbox) RenderFilePrompt

func (t *Termbox) RenderFilePrompt() error

RenderFilePrompt switches the UI to the file input

func (*Termbox) RenderInput

func (t *Termbox) RenderInput() error

RenderInput updates the input display to match the internal buffer

func (*Termbox) RenderResults

func (t *Termbox) RenderResults(data io.Reader) error

RenderResults renders the results of jq output to the screen

func (*Termbox) Start

func (t *Termbox) Start(initialProgram string) error

Start initializes the UI and returns a handle to the manager

func (*Termbox) UpdateInput

func (t *Termbox) UpdateInput()

UpdateInput appends the new input character to the internal input buffer

func (*Termbox) UpdateInputBackspace

func (t *Termbox) UpdateInputBackspace()

UpdateInputBackspace removes the last character from the input

func (*Termbox) UpdateSaveInput

func (t *Termbox) UpdateSaveInput()

UpdateSaveInput appends the new input character to the internal input buffer

func (*Termbox) UpdateSaveInputBackspace

func (t *Termbox) UpdateSaveInputBackspace()

UpdateSaveInputBackspace removes the last character from the input

Jump to

Keyboard shortcuts

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