tui

package
v0.0.0-...-cf66963 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

+build linux

Index

Constants

This section is empty.

Variables

View Source
var DarkTheme = Theme{
	TextColor:                 "white",
	FieldTextColor:            "white",
	HighlightTextColor:        "yellow",
	FieldPlaceholderTextColor: "green",
	BackgroundColor:           "black",
	FieldBackgroundColor:      "blue",
	DropdownBackgroundColor:   "grey",
}

DarkTheme represents a dark theme

View Source
var LightTheme = Theme{
	TextColor:                 "black",
	FieldTextColor:            "black",
	HighlightTextColor:        "red",
	FieldPlaceholderTextColor: "white",
	BackgroundColor:           "white",
	FieldBackgroundColor:      "lightgrey",
	DropdownBackgroundColor:   "red",
}

LightTheme represents a light theme

View Source
var Themes = map[string]*Theme{
	"dark":  &DarkTheme,
	"light": &LightTheme,
}

Themes contains the string-to-theme map

Functions

func SetConsoleTitle

func SetConsoleTitle(title string) error

SetConsoleTitle sets the console title

Types

type AddRulePage

type AddRulePage struct {
	Page
	// contains filtered or unexported fields
}

AddRulePage is an input form to enter data for new rules

func NewRuleForm

func NewRuleForm(modal ModalHandler) *AddRulePage

NewRuleForm returns a new RuleForm

func (*AddRulePage) EditRule

func (p *AddRulePage) EditRule(rule *riddle.Rule)

EditRule sets up the form for editing an existing rule The given pointer will be supplied to the save function later, unless the user resets the form.

func (*AddRulePage) HandleSetup

func (p *AddRulePage) HandleSetup(setup riddle.Setup)

HandleSetup configured the autocomplete and dropdown fields

func (*AddRulePage) Reset

func (p *AddRulePage) Reset()

Reset resets the form

func (*AddRulePage) Save

func (p *AddRulePage) Save()

Save calls the save function on the currently edited or new rule

func (*AddRulePage) SetSaveFunc

func (p *AddRulePage) SetSaveFunc(saveFunc func(*riddle.Rule))

SetSaveFunc sets a function that gets called on save

type App

type App struct {
	*PageHandler
	SetupForm *SetupPage
	RuleForm  *AddRulePage
	RuleList  *RulesPage
	// contains filtered or unexported fields
}

App handles the user interface

func NewApp

func NewApp(debug bool) *App

NewApp returns a new App

func (*App) GetRiddle

func (app *App) GetRiddle() (*riddle.Riddle, error)

GetRiddle returns the current riddle

func (*App) Run

func (app *App) Run() error

Run runs the user interface

func (*App) SetRiddle

func (app *App) SetRiddle(r *riddle.Riddle) error

SetRiddle sets the current riddle

type LoadPage

type LoadPage struct {
	Page
	// contains filtered or unexported fields
}

LoadPage is a UI list element that contains loadable riddles

func NewLoadPage

func NewLoadPage(modal ModalHandler) *LoadPage

NewLoadPage returns a new LoadPage

func (*LoadPage) AddRiddle

func (p *LoadPage) AddRiddle(name string, loadFunc func() (*riddle.Riddle, error))

AddRiddle adds a riddle to the list

func (*LoadPage) Reset

func (p *LoadPage) Reset()

Reset resets and updates the page

func (*LoadPage) SetRiddleSetter

func (p *LoadPage) SetRiddleSetter(setter func(*riddle.Riddle) error)

SetRiddleSetter sets the function that gets called when a riddle is selected

type ModalHandler

type ModalHandler interface {
	ModalMessage(msg string)
	ModalYesNo(msg string, yes func())
}

ModalHandler is an interface that handles modal dialogs

type Page

type Page interface {
	tview.Primitive
	GetName() string
	SetSelectFunc(func())
	Select()
}

Page represents a selectable page handled by PageHandler

func NewPage

func NewPage(primitive tview.Primitive, name string) Page

NewPage returns a new Page

type PageHandler

type PageHandler struct {
	tview.Primitive
	Quit chan bool
	// contains filtered or unexported fields
}

PageHandler handles the layout of the application, pages and modal dialogs

func NewPageHandler

func NewPageHandler() *PageHandler

NewPageHandler returns a new PageHandler

func (*PageHandler) AddPage

func (ph *PageHandler) AddPage(page Page) *PageHandler

AddPage adds a publicly listed page to the frame

func (*PageHandler) InputCapture

func (ph *PageHandler) InputCapture() func(event *tcell.EventKey) *tcell.EventKey

InputCapture returns a function that handles input capture for PageHandler

func (*PageHandler) ModalMessage

func (ph *PageHandler) ModalMessage(msg string)

ModalMessage displays a modal window with a message and OK button

func (*PageHandler) ModalYesNo

func (ph *PageHandler) ModalYesNo(msg string, yes func())

ModalYesNo displays a modal dialog with a message and yes/no options

func (*PageHandler) SwitchToPage

func (ph *PageHandler) SwitchToPage(page int)

SwitchToPage switches to the page with the number 'page'

type ResultsPage

type ResultsPage struct {
	Page
	// contains filtered or unexported fields
}

ResultsPage is a UI tree element that lets the user browse the riddle results

func NewResultsTree

func NewResultsTree(modal ModalHandler) *ResultsPage

NewResultsTree returns a new ResultsTree

func (*ResultsPage) HandleRules

func (p *ResultsPage) HandleRules(rules []riddle.Rule)

HandleRules updates the inner stored rules

func (*ResultsPage) HandleSetup

func (p *ResultsPage) HandleSetup(setup riddle.Setup)

HandleSetup updates the inner stored setup

func (*ResultsPage) Update

func (p *ResultsPage) Update()

Update updates the results based on the latest setup and rules

type RulesPage

type RulesPage struct {
	Page
	// contains filtered or unexported fields
}

RulesPage is a UI element that contains the list of rules

func NewRuleList

func NewRuleList(modal ModalHandler) *RulesPage

NewRuleList returns a new RuleList

func (*RulesPage) GetRules

func (p *RulesPage) GetRules() []riddle.Rule

GetRules returns the rules list in a slice

func (*RulesPage) HandleSetup

func (p *RulesPage) HandleSetup(setup riddle.Setup)

HandleSetup filters the list based on the new setup

func (*RulesPage) Reset

func (p *RulesPage) Reset()

Reset resets the list

func (*RulesPage) Save

func (p *RulesPage) Save()

Save calls the save function/callback with the list of rules

func (*RulesPage) SaveRule

func (p *RulesPage) SaveRule(rule *riddle.Rule)

SaveRule adds a new rule to the list or updates an existing one

func (*RulesPage) SetEditFunc

func (p *RulesPage) SetEditFunc(editFunc func(*riddle.Rule))

SetEditFunc sets a function that gets called on the selected rule

func (*RulesPage) SetRules

func (p *RulesPage) SetRules(rules []riddle.Rule)

SetRules resets the list and inserts the provided rules

func (*RulesPage) SetSaveFunc

func (p *RulesPage) SetSaveFunc(saveFunc func([]riddle.Rule))

SetSaveFunc sets a function that gets the list of all rules upon an update

type SavePage

type SavePage struct {
	Page
	// contains filtered or unexported fields
}

SavePage is UI form element for saving the current riddle

func NewSavePage

func NewSavePage(modal ModalHandler) *SavePage

NewSavePage returns a new SavePage

func (*SavePage) Save

func (p *SavePage) Save()

Save saves the current riddle

func (*SavePage) SetRiddleGetter

func (p *SavePage) SetRiddleGetter(getter func() (*riddle.Riddle, error))

SetRiddleGetter sets the function that returns the current riddle for saving

type SetupPage

type SetupPage struct {
	Page
	// contains filtered or unexported fields
}

SetupPage is a form where the user can input riddle item types and values

func NewSetupForm

func NewSetupForm(modal ModalHandler) *SetupPage

NewSetupForm returns a new SetupForm

func (*SetupPage) AddItemType

func (p *SetupPage) AddItemType(itemType string, values ...string)

AddItemType adds a new item type field with the provided values or uses an existing empty one

func (*SetupPage) GetSetup

func (p *SetupPage) GetSetup() (riddle.Setup, error)

GetSetup returns the current setup

func (*SetupPage) Reset

func (p *SetupPage) Reset()

Reset resets the form to its initial state

func (*SetupPage) Save

func (p *SetupPage) Save()

Save collects all the form data and passes it to the save function

func (*SetupPage) SetSaveFunc

func (p *SetupPage) SetSaveFunc(saveFunc func(riddle.Setup))

SetSaveFunc sets a function that gets called when data is saved

func (*SetupPage) SetSetup

func (p *SetupPage) SetSetup(setup riddle.Setup)

SetSetup resets the form and inserts the values from the provided setup

type SolverDebugPage

type SolverDebugPage struct {
	Page
	// contains filtered or unexported fields
}

SolverDebugPage shows solver internals

func NewSolverDebugTree

func NewSolverDebugTree(modal ModalHandler) *SolverDebugPage

NewSolverDebugTree returns a new SolverDebugTree

func (*SolverDebugPage) HandleRules

func (p *SolverDebugPage) HandleRules(rules []riddle.Rule)

HandleRules updates the inner stored rules

func (*SolverDebugPage) HandleSetup

func (p *SolverDebugPage) HandleSetup(setup riddle.Setup)

HandleSetup updates the inner stored setup

func (*SolverDebugPage) Update

func (p *SolverDebugPage) Update()

Update updates the results based on the latest setup and rules

type Theme

type Theme struct {
	TextColor                 string
	FieldTextColor            string
	HighlightTextColor        string
	FieldPlaceholderTextColor string
	BackgroundColor           string
	FieldBackgroundColor      string
	DropdownBackgroundColor   string
}

Theme contains the colors used by the UI

func (*Theme) Apply

func (theme *Theme) Apply()

Apply applies the theme

Jump to

Keyboard shortcuts

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