tuikit

package module
v0.0.27 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Terminal UI Kit

Go Report Card Go Reference GitHub release

This repo contains types, interfaces, and utilities for building terminal user interfaces in Go. It's an opinionated framework that uses charm TUI components and packages for rendering and handling terminal events.

Usage

First, install the package:

go get -u github.com/jahvon/tuikit@latest

You can then use the package in your Go code:

package main

import (
    "context"

    "github.com/jahvon/tuikit"
    "github.com/jahvon/tuikit/views"
)

func main() {
    ctx := context.Background()
    // Define your application metadata
    app := &tuikit.Application{Name: "MyApp"}

    // Create and start the container
    container, err := tuikit.NewContainer(ctx, app)
    if err != nil {
        panic(err)
    }
    if err := container.Start(); err != nil {
        panic(err)
    }
    
    // Create and set your view - the example below used the Markdown view type.
    // There are other view types available in the views package.
    view := views.NewMarkdownView(container.RenderState(), "# Hello, world!")
    if err := container.SetView(view); err != nil {
        panic(err)
    }
    
    // Wait for the container to exit. Before getting here, you can handle events, update the view, etc.
    container.WaitForExit()
}

Also see the sample app for examples of how different views can be used.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application added in v0.0.23

type Application struct {
	Name string
	// contains filtered or unexported fields
}

func NewApplication added in v0.0.23

func NewApplication(name string, opts ...ApplicationOption) *Application

type ApplicationOption added in v0.0.23

type ApplicationOption func(*Application)

func WithLoadingMsg added in v0.0.23

func WithLoadingMsg(msg string) ApplicationOption

func WithNotice added in v0.0.23

func WithNotice(notice string) ApplicationOption

func WithState added in v0.0.23

func WithState(key, val string) ApplicationOption

func WithStateKey added in v0.0.23

func WithStateKey(key string) ApplicationOption

func WithStateVal added in v0.0.23

func WithStateVal(val string) ApplicationOption

type Container

type Container struct {
	// contains filtered or unexported fields
}

func NewContainer

func NewContainer(
	ctx context.Context,
	app *Application,
	opts ...ContainerOptions,
) (*Container, error)

func (*Container) ContentHeight

func (c *Container) ContentHeight() int

func (*Container) ContentWidth

func (c *Container) ContentWidth() int

func (*Container) CurrentView

func (c *Container) CurrentView() View

func (*Container) HandleError

func (c *Container) HandleError(err error)

func (*Container) Height

func (c *Container) Height() int

func (*Container) Init

func (c *Container) Init() tea.Cmd

func (*Container) NextView

func (c *Container) NextView() View

func (*Container) PreviousView

func (c *Container) PreviousView() View

func (*Container) Ready

func (c *Container) Ready() bool

func (*Container) RenderState added in v0.0.23

func (c *Container) RenderState() *types.RenderState

func (*Container) Send added in v0.0.23

func (c *Container) Send(msg tea.Msg, delay time.Duration)

func (*Container) SetNextView added in v0.0.23

func (c *Container) SetNextView(v View)

func (*Container) SetNotice added in v0.0.23

func (c *Container) SetNotice(notice string, lvl styles.OutputLevel)

func (*Container) SetSendFunc added in v0.0.23

func (c *Container) SetSendFunc(f func(msg tea.Msg))

func (*Container) SetState added in v0.0.23

func (c *Container) SetState(key, val string)

func (*Container) SetStateValue added in v0.0.23

func (c *Container) SetStateValue(val string)

func (*Container) SetView

func (c *Container) SetView(v View) error

func (*Container) Shutdown

func (c *Container) Shutdown(finalizers ...func())

func (*Container) SizeSet

func (c *Container) SizeSet() bool

func (*Container) Start added in v0.0.23

func (c *Container) Start() error

func (*Container) State added in v0.0.23

func (c *Container) State() (string, string)

func (*Container) Update

func (c *Container) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Container) View

func (c *Container) View() string

func (*Container) WaitForExit added in v0.0.23

func (c *Container) WaitForExit()

func (*Container) Width

func (c *Container) Width() int

type ContainerOptions added in v0.0.23

type ContainerOptions func(*Container)

func WithInitialTermSize added in v0.0.23

func WithInitialTermSize(width, height int) ContainerOptions

func WithInput added in v0.0.23

func WithInput(in io.Reader) ContainerOptions

func WithOutput added in v0.0.23

func WithOutput(out io.Writer) ContainerOptions

func WithTheme added in v0.0.23

func WithTheme(theme styles.Theme) ContainerOptions

type Program added in v0.0.23

type Program struct {
	// contains filtered or unexported fields
}

func NewProgram added in v0.0.23

func NewProgram(ctx context.Context, model tea.Model, in io.Reader, out io.Writer) *Program

func (*Program) Resume added in v0.0.23

func (p *Program) Resume() error

func (*Program) Run added in v0.0.23

func (p *Program) Run() (tea.Model, error)

func (*Program) Send added in v0.0.23

func (p *Program) Send(msg tea.Msg)

func (*Program) Started added in v0.0.23

func (p *Program) Started() bool

func (*Program) Suspend added in v0.0.23

func (p *Program) Suspend() error

func (*Program) Suspended added in v0.0.23

func (p *Program) Suspended() bool

type View

type View interface {
	tea.Model

	ShowFooter() bool
	HelpMsg() string
	Type() string
}

Directories

Path Synopsis
io
mocks
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳