fui

package module
v0.0.0-...-2d3c06c Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 13 Imported by: 0

README

FUI

A library for creating simple terminal UIs quickly.

Status: active, work in progress

Writing this as a self-education project, exploring the following concepts:

  • Data Oriented Programming
  • API Design
  • Dev tools
  • Managing Scope and actually finishing projects
  • Immediate-Mode GUI

Documentation

Index

Constants

View Source
const (
	BOLD    mdFormatMask = 1 << 0
	ITALIC  mdFormatMask = 1 << 1
	LINK    mdFormatMask = 1 << 2
	HEADING mdFormatMask = 1 << 3
	LIST    mdFormatMask = 1 << 4
	HILITE  mdFormatMask = 1 << 7
)
View Source
const COLOR_HEADING = 0xE36840
View Source
const COLOR_LINK = 0xC20E68
View Source
const COLOR_LIST = 0x76E3A9
View Source
const TAB_SIZE = 4

Variables

View Source
var (
	Hz = time.Second / 60

	Mouse struct {
		X, Y         int
		PrevX, PrevY int
		Mask         tc.ButtonMask
		PrevMask     tc.ButtonMask
		HotZone      Zone
		ActZone      Zone
		HotID        int
		ActID        int
	}
	// This can be used to prevent your main function from returning
	//	<-fui.ExitSig // Blocks - signal is sent when fui.Exit is set to true.
	ExitSig chan interface{}
)
View Source
var (
	Redraw bool
	Exit   bool
)

Global state

Functions

func AttrToStyle

func AttrToStyle(mask mdFormatMask) tc.Style

func DrawButton

func DrawButton(id int, ui *UI)

func DrawTerminal

func DrawTerminal(id int, ui *UI)

func ProcessAttr

func ProcessAttr(mask mdFormatMask) (mdFormatMask, bool)

func ReflowLinesUTF8

func ReflowLinesUTF8(lines *[]Span, buf []byte, maxWidth int)

func Start

func Start()

func WriteMarkdown

func WriteMarkdown(id int, termData *TerminalData, inputBuf []byte)

Types

type AttrRanges

type AttrRanges struct {
	Starts []int
	Ends   []int
	Attrs  []mdFormatMask

	Links map[int]string
	// contains filtered or unexported fields
}

type Box

type Box struct {
	Toks    []string // Terminal, Prompt?
	Lines   []Span   // Terminal
	BoxType BoxType  // All x
	Name    string   // All x
	View    int      // Terminal, Prompt?
	X, Y    int      // All x
	W, H    int      // All x
	// contains filtered or unexported fields
}

type BoxType

type BoxType int
const (
	TerminalT BoxType = iota
	ButtonT
	PromptT
	TxtpadT
)

type ButtonData

type ButtonData struct {
	UserFunctions []func()
}

Not sure about this yet

type LayoutData

type LayoutData struct {
	Rects     []Rect
	RectsPrev []Rect
	Types     []BoxType
}

Shared fields, hot

type Rect

type Rect struct {
	X, Y, W, H int
}

func (*Rect) WhichZone

func (r *Rect) WhichZone(mX, mY int) Zone

type Span

type Span struct {
	Start    int
	End      int
	TabLevel int
}

type TerminalData

type TerminalData struct {
	Buffers    [][]byte
	Lines      [][]Span
	Views      []int
	AttrRanges []AttrRanges
	CursorXs   []int
	CursorYs   []int
}

func (*TerminalData) AppendAttrRange

func (td *TerminalData) AppendAttrRange(id, start, end int, attr mdFormatMask)

type UI

type UI struct {
	Layout  LayoutData
	Terms   TerminalData
	Buttons ButtonData
	Names   []string
	Count   int
}

func Init

func Init() *UI

func (*UI) AddButton

func (ui *UI) AddButton(name string, userFunction func()) int

func (*UI) AddTerminal

func (ui *UI) AddTerminal(name string) int

func (*UI) ApplyMouseState

func (ui *UI) ApplyMouseState()

func (*UI) DrawBorder

func (ui *UI) DrawBorder(id int)

func (*UI) FindAndHighlightRange

func (ui *UI) FindAndHighlightRange(id, mX, mY int)

TODO(Johan): Make more efficient

func (*UI) UpdateMouseState

func (ui *UI) UpdateMouseState()

func (*UI) WriteToBuffer

func (ui *UI) WriteToBuffer(id int, s string)

type Zone

type Zone uint8
const (
	ZoneNone Zone = iota
	ZoneTopL
	ZoneBotR
	ZoneFaceR
	ZoneInside
)

func (Zone) String

func (d Zone) String() string

Directories

Path Synopsis
calculator command
example command
sandbox command
internal

Jump to

Keyboard shortcuts

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