ui

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: Apache-2.0 Imports: 7 Imported by: 1

README

Component template (use rename symbol)

type HelloStyle struct {
	Fg string `defaults:"" type:"fg"`
}

type HelloComponent struct {
	Data  osui.ComponentData
	Style *HelloStyle
	Name  string
}

func (h *HelloComponent) GetComponentData() *osui.ComponentData {
	return &h.Data
}

func (h *HelloComponent) Render() string {
	osui.UseStyle(h.Style)
	return "Hello " + h.Style.Fg + h.Name + colors.Reset + "!"
}

func (h *HelloComponent) Update(key string) bool {
	return false
}

func (b *MenuComponent) Params(param MenuParams) *MenuComponent {
	b.Style = osui.SetDefaults(&param.Style).(*MenuStyle)
	return b
}

func Hello(name string) *HelloComponent {
	return osui.NewComponent(&HelloComponent{
		Name:  name,
		Style: osui.SetDefaults(&HelloStyle{}).(*HelloStyle),
	}).(*HelloComponent)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithPosition added in v0.1.0

func WithPosition(x, y int, c osui.Component) osui.Component

func WithSize added in v0.1.0

func WithSize(width, height int, c osui.Component) osui.Component

Types

type ButtonComponent added in v0.1.0

type ButtonComponent struct {
	Data    osui.ComponentData
	Style   *ButtonStyle
	Text    string
	Toggle  bool
	Clicked bool
	// contains filtered or unexported fields
}

func Button added in v0.1.0

func Button(text string) *ButtonComponent

func (*ButtonComponent) GetComponentData added in v0.1.0

func (b *ButtonComponent) GetComponentData() *osui.ComponentData

func (*ButtonComponent) Params added in v0.1.1

func (b *ButtonComponent) Params(param ButtonParams) *ButtonComponent

func (*ButtonComponent) Render added in v0.1.0

func (b *ButtonComponent) Render() string

func (*ButtonComponent) Update added in v0.1.0

func (b *ButtonComponent) Update(key string) bool

type ButtonParams added in v0.1.3

type ButtonParams struct {
	Style   ButtonStyle
	Toggle  bool
	OnClick func(*ButtonComponent) bool
	Width   int
}

type ButtonStyle added in v0.1.0

type ButtonStyle struct {
	Background string `default:"" type:"bg"`
	Foreground string `default:"" type:"fg"`
	Outline    string `default:"" type:"fg"`

	ActiveBackground string `default:"" type:"bg"`
	ActiveForeground string `default:"\x1b[34m" type:"fg"`
	ActiveOutline    string `default:"" type:"fg"`

	ClickedBackground string `default:"" type:"bg"`
	ClickedForeground string `default:"\x1b[32m" type:"fg"`
	ClickedOutline    string `default:"" type:"fg"`
}

type Class added in v0.1.3

type Class[T osui.Component] struct {
	// contains filtered or unexported fields
}

func (*Class[T]) Class added in v0.1.3

func (c *Class[T]) Class(co T) T

func (*Class[T]) SetProperties added in v0.1.3

func (c *Class[T]) SetProperties(ch func(T) T)

type DivComponent added in v0.1.0

type DivComponent struct {
	Data            osui.ComponentData
	Style           *DivStyle
	Components      []osui.Component
	ActiveComponent int
}

func Div added in v0.1.0

func Div(components ...osui.Component) *DivComponent

func (*DivComponent) GetComponentData added in v0.1.0

func (d *DivComponent) GetComponentData() *osui.ComponentData

func (*DivComponent) Params added in v0.1.1

func (b *DivComponent) Params(param DivParams) *DivComponent

func (*DivComponent) Render added in v0.1.0

func (d *DivComponent) Render() string

func (*DivComponent) Update added in v0.1.0

func (d *DivComponent) Update(key string) bool

type DivParams added in v0.1.1

type DivParams struct {
	Style  DivStyle
	Width  int
	Height int
}

type DivStyle added in v0.1.0

type DivStyle struct {
	Background string `default:"" type:"bg"`
	Foreground string `default:"" type:"fg"`
	Outline    string `default:"" type:"fg"`
}

type Id added in v0.1.3

type Id[T osui.Component] struct {
	Component T
	// contains filtered or unexported fields
}

func (*Id[T]) Id added in v0.1.3

func (i *Id[T]) Id(c T) T

func (*Id[T]) SetProperties added in v0.1.3

func (i *Id[T]) SetProperties(c func(T) T)

type InputBoxComponent

type InputBoxComponent struct {
	Data  osui.ComponentData
	Style *InputBoxStyle

	InputData string
	// contains filtered or unexported fields
}

func InputBox

func InputBox(max_size uint) *InputBoxComponent

func (*InputBoxComponent) GetComponentData

func (s *InputBoxComponent) GetComponentData() *osui.ComponentData

func (*InputBoxComponent) Params added in v0.1.1

func (b *InputBoxComponent) Params(p interface{}) *InputBoxComponent

func (InputBoxComponent) Render

func (s InputBoxComponent) Render() string

func (*InputBoxComponent) Update

func (s *InputBoxComponent) Update(key string) bool

type InputBoxParams added in v0.1.1

type InputBoxParams struct {
	Style  DivStyle
	Width  int
	Height int
}

type InputBoxStyle added in v0.1.0

type InputBoxStyle struct {
	Background string `default:"" type:"bg"`
	Foreground string `default:"" type:"fg"`
	Outline    string `default:"" type:"fg"`
	Cursor     string `default:"" type:"fg"`
}
type MenuComponent struct {
	Data         osui.ComponentData
	Style        *MenuStyle
	Items        []string
	SelectedItem int
	OnSelected   func(*MenuComponent, bool)
}
func Menu(items ...string) *MenuComponent
func (m *MenuComponent) GetComponentData() *osui.ComponentData
func (b *MenuComponent) Params(param MenuParams) *MenuComponent
func (m *MenuComponent) Render() string
func (m *MenuComponent) Update(key string) bool
type MenuParams struct {
	Style      MenuStyle
	OnSelected func(*MenuComponent, bool)
}
type MenuStyle struct {
	Fg             string `default:"" type:"fg"`
	Bg             string `default:"" type:"bg"`
	SelectedFg     string `default:"\x1b[34m" type:"fg"`
	SelectedBg     string `default:"" type:"bg"`
	Cursor         string `default:"> " type:"fg"`
	CursorInactive string `default:"  " type:"fg"`
}

type PaginatorComponent

type PaginatorComponent struct {
	Data            osui.ComponentData
	Style           *PaginatorStyle
	Components      []osui.Component
	ActiveComponent int
}

func Paginator

func Paginator(pages ...osui.Component) *PaginatorComponent

func (*PaginatorComponent) GetComponentData

func (p *PaginatorComponent) GetComponentData() *osui.ComponentData

func (*PaginatorComponent) Params added in v0.1.1

func (b *PaginatorComponent) Params(p interface{}) *PaginatorComponent

func (*PaginatorComponent) Render

func (p *PaginatorComponent) Render() string

func (*PaginatorComponent) Update added in v0.1.0

func (p *PaginatorComponent) Update(key string) bool

type PaginatorParams added in v0.1.1

type PaginatorParams struct {
	Style  DivStyle
	Width  int
	Height int
}

type PaginatorStyle

type PaginatorStyle struct {
	Active   string `default:"\033[32m"`
	Inactive string `default:""`
}

type TextComponent

type TextComponent struct {
	Data osui.ComponentData
	Text string
}

func Text

func Text(text string) *TextComponent

func (*TextComponent) GetComponentData

func (t *TextComponent) GetComponentData() *osui.ComponentData

func (TextComponent) Render

func (t TextComponent) Render() string

func (*TextComponent) Update added in v0.1.0

func (t *TextComponent) Update(string) bool

Jump to

Keyboard shortcuts

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