ui

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Labels = map[rune]string{
	'a': "Visual imagination",
	'd': "Language thought",
	'e': "Language voice",
	'q': "Visual memory",
	's': "Auditory imagination",
	'w': "Auditory memory",
}

Labels is a map of each allowed key press (rune) to it's full string label.

View Source
var (
	// Version holds the program version.
	Version = "devel"
)

Functions

func AllowedEntry

func AllowedEntry(te termbox.Event) bool

AllowedEntry returns true if the termbox event received is a valid entry for the input. These include 0-9, '.', delete, backspaces and enter.

func Cells

func Cells() [][]Cell

Cells initializes all cells on screen and registers the inputs on the cells that should have them.

func Close

func Close()

Close should be deferred after initialization. It finalizes termbox library.

func CurrentHz

func CurrentHz(currentSecs int) float64

CurrentHz given the seconds passed, it returns the current Gz based on the formula: CurrentHz = ( Seconds * Abs((EndHz - StartHz)) / ((TotalTime - Offset) * 60) ) + StartHz for Offset < TotalTime

func CurrentHz(seconds int) float64 {
	offset := config.Offset
	if offset >= config.TotalTime {
		offset = 0
	}
	return (float64(seconds) * (math.Abs(config.EndHz - config.StartHz)) / float64((config.TotalTime-offset)*60)) + config.StartHz
}

func Debug

func Debug(s string)

Debug prints a debug message on the screen.

func DeselectAllInputs

func DeselectAllInputs()

DeselectAllInputs sets all inputs selected as false.

func DrawAll

func DrawAll()

DrawAll draws the title, the inputs, the key labels and the status bar. It should also be called when a resize event is received.

func Fill

func Fill(x, y, w, h int, r rune)

Fill fills cells of the screen with a rune r, starting from x, y and reaching a certain width w and height h.

func FormatTimer

func FormatTimer(seconds int) string

FormatTimer accepts seconds and returns them in a timer format.

func Init

func Init(version string) error

Init must be called before any other function. It initializes configuration and termbox.

func RecordedKeyText

func RecordedKeyText(key rune, seconds int) string

RecordedKeyText returns a message indicating the key pressed, it's hz value and a timestamp of when it was received.

func ReloadInputs

func ReloadInputs(c Config)

ReloadInputs updates each input with the values of a new configuration. It should be called after receiving a valid value from en enabled input.

func ResetText

func ResetText()

ResetText clears the status bar's text.

func ResetTimer

func ResetTimer()

ResetTimer clears the status bar's timer.

func Scan

func Scan(startX, endX, y int) string

Scan scans the cells of the screen that are contained at a certain y, between startX and endX. It returns the content of the scanned cells as a string.

func Text

func Text(x, y int, s string) (maxX, maxY int)

Text draws text on the screen. When it encounters a new line it continues to draw from the next line.

func UpdateConfig

func UpdateConfig(c Config)

UpdateConfig updates the configuration.

func UpdateText

func UpdateText(text string)

UpdateText is a helper function that updates the status bar's text.

func UpdateTimer

func UpdateTimer(seconds int)

UpdateTimer is a helper function that updates the status bar's timer.

Types

type Capture

type Capture struct {
	Value   rune
	Seconds int
	Hz      float64
}

Capture represents a captured key press at a specific second of the timer along with the value of Hz that was recorded.

func (*Capture) Label

func (c *Capture) Label() string

Label returns the description of the captured key value.

func (*Capture) Timestamp

func (c *Capture) Timestamp() string

Timestamp returns the timestamp of when a capture happened.

type Cell

type Cell struct {
	Input *Input
	termbox.Cell
}

Cell wraps a termbox cell. A single conceptual entity on the screen. A screen considered a 2d array of cells. Each cell also holds a reference to an input if it exists, thus by clicking a cell that contains an input we can easily access it.

func GetCell

func GetCell(x, y int) Cell

GetCell returns a cell based on the x, y points of the screen.

type Config

type Config struct {
	Mode      string // A = Binaural, B = Isochronic
	TotalTime int
	Offset    int
	BaseHz    float64
	StartHz   float64
	EndHz     float64
}

Config represents the program's configuration.

func GetConfig

func GetConfig() Config

GetConfig returns the configuration.

func (Config) BaseHzS

func (c Config) BaseHzS() string

BaseHzS returns a string representation of the base hz.

func (Config) EndHzS

func (c Config) EndHzS() string

EndHzS returns a string representation of the end hz.

func (*Config) Load

func (c *Config) Load() error

Load loads configuration from the config.json file.

func (Config) ModeS

func (c Config) ModeS() string

ModeS returns a string representation of the mode.

func (Config) OffsetS

func (c Config) OffsetS() string

OffsetS returns a string representation of the offset.

func (Config) Save

func (c Config) Save() error

Save writes the configuration to config.json file.

func (Config) StartHzS

func (c Config) StartHzS() string

StartHzS returns a string representation of the start hz.

func (Config) TotalTimeS

func (c Config) TotalTimeS() string

TotalTimeS returns a string representation of the total time.

func (*Config) Update

func (c *Config) Update(m map[string]interface{}) error

Update updates the configuration values be accepting a map of these values using the key of each configuration field.

func (Config) Validate

func (c Config) Validate() error

Validate returns an error if the values of the configuration are not valid.

type ConfigField

type ConfigField string

ConfigField is a key of each configuration value. Each input holds a configuration field so it's easier to update the config.

func (ConfigField) Val

func (cf ConfigField) Val() string

Val returns the configuration field's value.

type Entry

type Entry struct {
	Ch        rune
	Backspace bool
	Delete    bool
	Enter     bool
}

Entry represents a key entry that an input accpets. These include a character, backspace, delete and enter.

func NewEntry

func NewEntry(te termbox.Event) *Entry

NewEntry returns a new Entry based on a termbox event received.

func (Entry) String

func (e Entry) String() string

String returns a string representation of the entry.

type Input

type Input struct {
	X, Y   int
	LabelW int    // label width
	LabelT string // label text
	W      int    // width

	T string // text

	Type  InputType
	Field ConfigField
	// contains filtered or unexported fields
}

Input represents an input box on the screen.

func NewInput

func NewInput(x, y, labelW int, labelT string, w, bufW int, t string, a bool, it InputType, cf ConfigField) *Input

NewInput returns a new Input.

func SelectedInput

func SelectedInput() *Input

SelectedInput returns the input that is currently selected.

func (*Input) ClearBuf

func (in *Input) ClearBuf()

ClearBuf clears the inputs buffer.

func (Input) ClearText

func (in Input) ClearText()

ClearText clears the inputs text.

func (Input) Draw

func (in Input) Draw()

Draw draws the input on the screen.

func (Input) MaxX

func (in Input) MaxX() int

MaxX returns the maximum x that the input reaches on the screen.

func (Input) MaxY

func (in Input) MaxY() int

MaxY returns the maximum y that the input reaches on the screen.

func (Input) ResetText

func (in Input) ResetText()

ResetText clears the input's text and then resets it to it's original value.

func (Input) Selected

func (in Input) Selected() bool

Selected returns true of the input is selected.

func (*Input) SetBuf

func (in *Input) SetBuf(e *Entry)

SetBuf sets the input's buffer.

func (*Input) SetSelected

func (in *Input) SetSelected(selected bool)

SetSelected sets the input as selected after deselecting all other inputs.

func (Input) SetText

func (in Input) SetText(s string)

SetText sets the input's text.

func (*Input) Switch

func (in *Input) Switch() error

Switch switches the input between "Binaural" and "Isochronic" values.

func (Input) TextEndX

func (in Input) TextEndX() int

TextEndX returns the x where the input's text ends.

func (Input) TextStartX

func (in Input) TextStartX() int

TextStartX returns the x where the input's text starts.

func (Input) TextY

func (in Input) TextY() int

TextY returns the y of the input's text.

func (*Input) Valid

func (in *Input) Valid() error

Valid checks the current value of an input and returns an error if it's not valid.

func (*Input) ValueMap

func (in *Input) ValueMap() (map[string]interface{}, error)

ValueMap returns a map containing the value of the input. Each input corresponds to one configuration field. The key of the map is the configuration field's key. It is used to easilly update the JSON config file.

type InputType

type InputType uint8

InputType is the type of each input which can be either an input that accepts integers, an input that accepts float or an input that switches value on click.

const (
	// InputNumericInt is an input that accepts integers.
	InputNumericInt InputType = iota
	// InputNumericFloat is an input that accepts floats.
	InputNumericFloat
	// InputSwitch is an input that switches value on click.
	InputSwitch
)

type KeyLabel

type KeyLabel struct {
	X      int
	Y      int
	LabelW int    // label width
	LabelT string // label text
	W      int    // rest of width
	T      string // text describing the key

	S bool
	// contains filtered or unexported fields
}

KeyLabel holds a label with each allowed key press and right next, the coresponding text that describes the label.

func NewKeyLabel

func NewKeyLabel(x, y, labelW int, labelT string, w int, t string, a bool) *KeyLabel

NewKeyLabel creates a new KeyLabel.

func (KeyLabel) Draw

func (kl KeyLabel) Draw()

Draw draws the KeyLabel.

func (KeyLabel) MaxX

func (kl KeyLabel) MaxX() int

MaxX returns the maximum x that a KeyLabel reaches on the screen.

func (KeyLabel) MaxY

func (kl KeyLabel) MaxY() int

MaxY returns the maximum y that a KeyLabel reaches on the screen.

type StatusBar

type StatusBar struct {
	X     int
	Y     int
	Width int
	Text  string
	// contains filtered or unexported fields
}

StatusBar holds the data for drawing a status bar with a specified width and text. It also has space to the left for the timer.

func NewStatusBar

func NewStatusBar(x, y, width int, text string) *StatusBar

NewStatusBar returns a new StatusBar.

func (StatusBar) Draw

func (sb StatusBar) Draw()

Draw draws the StatusBar.

func (StatusBar) MaxX

func (sb StatusBar) MaxX() int

MaxX returns the maximum x that a StatusBar can reach on the screen.

func (StatusBar) MaxY

func (sb StatusBar) MaxY() int

MaxY returns the maximum y that a StatusBar can reach on the screen.

func (StatusBar) UpdateText

func (sb StatusBar) UpdateText(t string)

UpdateText updates the text of the status bar.

func (StatusBar) UpdateTimer

func (sb StatusBar) UpdateTimer(seconds int)

UpdateTimer updates the timer of the status bar by a specified amount of seconds.

Jump to

Keyboard shortcuts

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