cui

package module
v0.0.0-...-62f9be7 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2022 License: MPL-2.0 Imports: 7 Imported by: 0

README

Console User Interface utilities

cui is a Golang library that allows an application to run a terminal display à-la-ncurses. No big fancy features, just selection of lists and display of items.

The application will query the items in a first field (TODO: with a , filters the fetched items with a kind of wildcard on the primary key of each item, then presents the items passing the filter in a scrollable list, to eventually dump the selected item in a side panel.

Example

go run github.com/jfsmig/cui/examples/test-paths
┌─Query───────────────────────────────────────────────────────────────────┐┌─Error─────────────────────────────────────┐
│/var/log                                                                 ││                                           │
└─────────────────────────────────────────────────────────────────────────┘│                                           │
┌─Filter──────────────────────────────────────────────────────────────────┐│                                           │
│.*                                                                       ││                                           │
└─────────────────────────────────────────────────────────────────────────┘└───────────────────────────────────────────┘
┌─Objects───────────┐┌─Detail──────────────────────────────────────────────────────────────────────────────────────────┐
│alternatives.log   ││{                                                                                                │
│alternatives.log.1 ││ "path": "alternatives.log.2.gz",                                                                │
│alternatives.log.2.││ "size": 611,                                                                                    │
│alternatives.log.3.││ "mode": 420,                                                                                    │
│alternatives.log.4.││ "ctime": "2022-10-26T00:45:43.90924422+02:00"                                                   │
│alternatives.log.5.││}                                                                                                │
│alternatives.log.6.││                                                                                                 │
│alternatives.log.7.││                                                                                                 │
│apport.log         ││                                                                                                 │
│apport.log.1       ││                                                                                                 │
│apport.log.2.gz    ││                                                                                                 │
│apport.log.3.gz    ││                                                                                                 │
│apport.log.4.gz    ││                                                                                                 │
│apport.log.5.gz    ││                                                                                                 │
│apport.log.6.gz    ││                                                                                                 │
└───────────────────┘└─────────────────────────────────────────────────────────────────────────────────────────────────┘

TODO

This is work in progress, however the subsequent actions have been identified:

  • fix display quirks on small terminal windows
  • make it responsive on all the fields
  • document all that

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Monitor

func Monitor(listable Monitorable, firstQuery string) error

Monitor displays a terminal application that navigates in the data source

Types

type Monitorable

type Monitorable interface {
	// FetchAll returns the whole list of items. They will be saved in the CLI app. until the next FetchAll call.
	FetchAll(query string) ([]MonitoredItem, error)
}

Monitorable implements a source of items. The application is responsible to call for a new list of objects. The list is cached in the application between two fetches.

type MonitoredItem

type MonitoredItem interface {

	// GetPrimaryKey returns the defauly key that will be used by the application if none is explicitly selected.
	// The returned primary key should be an element of the array of all the possible keys returned by GetKeys.
	GetPrimaryKey() string

	// GetKeys Return all the keys of the metadata properties.
	// Subsequent calls should return the same array: same entries, same order.
	// The array should contain the value returned by GetPrimaryKey.
	GetKeys() []string

	// GetValue returns the value of a single given key. Any error results in an empty output.
	GetValue(k string) string

	// GetDetail generates a description of the object, that will be displayed in the "detail" panel when not in
	// "table" mode. The MonitoredItem implementation MAY return a dump of the metadata (i.e the keys and their
	// respective values), the application doesn't care.
	GetDetail() string
}

MonitoredItem describe the expectation for any monitorable item: just a set of metadata tha can be queried independently.

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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