huninn

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2025 License: MPL-2.0 Imports: 7 Imported by: 0

README

WIP

This project is still under development.

Huninn

(Will be) A rich set of tools to create fency TUI for monitoring progress for your CLI application.

Documentation

Overview

Package huninn provides tools to build fency CLI applications. It uses the Bubble Tea framework under the hood.

WIP

Huninn is still a work in progress. The API may change without notice.

Overview

It focuses on information displaying, not user interaction. A Huninn component is a tea.Model with extra restrictions:

  • It accepts tapioca.ResizeMsg.
  • View() method output a string exactly fitting its size.

For example, a Huninn component with size 3x2 (specified by tapioca.ResizeMsg) must output exactly 3 columns and 2 rows of characters, like "abc\nd ". Tailing newlines are optional.

There are some predefined components in package pearl, and some tools to help you build your own components in package tapioca.

In this package, we provide some preset for application creators. These presets are separated by "Ice" and "Suguar". The more ice, the "cooler" (fencier) the look is. The more sugar, the "sweeter" the application can use (feature-rich).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LSLI added in v0.0.2

func LSLI(tlSize, logBufferSize int, factory JobFactory, wait bool, opts ...tea.ProgramOption) func(context.Context) error

LSLI (Light Sugar, Light Ice) adds some features to NSLI.

It accepts a JobFactory to create a job function, which will be run concurrently with the UI program. The job function is the main program of your application, and it should utilize the provided setStatus, task manager, and writer to interact with the UI.

The tlSize and logBufferSize parameters are passed to NSLIComponent.

The opts parameters are passed to tea.NewProgram.

If you set wait to true, the UI will remain active after the job completes successfully, allowing the user to review the final status and logs. UI always remain active if the job ends with an error.

func LSNI added in v0.0.2

func LSNI(tlSize, logBufferSize int, factory JobFactory, wait bool, opts ...tea.ProgramOption) func(context.Context) error

LSNI (Light Sugar, No Ice) adds some features to NSNI.

It accepts a JobFactory to create a job function, which will be run concurrently with the UI program. The job function is the main program of your application, and it should utilize the provided setStatus, task manager, and writer to interact with the UI.

The tlSize and logBufferSize parameters are passed to NSNIComponent.

The opts parameters are passed to tea.NewProgram.

If you set wait to true, the UI will remain active after the job completes successfully, allowing the user to review the final status and logs. UI always remain active if the job ends with an error.

func NSLI added in v0.0.2

func NSLI(tlSize, logBufferSize int, opts ...tea.ProgramOption) (
	prog func(context.Context) error,
	setStatus func(string),
	tm pearl.TaskManager,
	w io.Writer,
	s tapioca.ScrollController,
)

NSLI (No Sugar, Light Ice) wraps NSLIComponent to provide a ready-to-use program.

Cancelling the context will terminate the program, making it suitable for cooperating with signal.NotifyContext.

The tlSize and LogBufferSize parameters are passed to NSLIComponent.

The opts parameters are passed to tea.NewProgram.

func NSLIComponent added in v0.0.2

func NSLIComponent(tlSize int, logBufferSize int) (
	tea.Model,
	func(send func(tea.Msg)) (
		setStatus func(string),
		taskManager pearl.TaskManager,
		w io.Writer,
		logScroller tapioca.ScrollController,
	),
)

NSLIComponent returns bordered flavor of huninn UI.

The NSLI (No Sugar, Light Ice) UI consists of three parts with borders:

  • A status bar at the bottom, showing a single line of text.
  • A task list at the top, showing multiple tasks with progress in percentage.
  • A log panel in the middle, showing log messages.

It balances screen space and visual appeal.

The tlSize parameter specifies the height of the task list in rows. The logBufferSize parameter specifies the maximum number of log entries to keep. If tlSize is less than 3, the task list and log panel will have equal height. The logBufferSize is automatically adjusted to be at least 10.

The component also handles two shortcuts to terminate the program:

  • Ctrl+C
  • q

func NSNI added in v0.0.2

func NSNI(tlSize, logBufferSize int, opts ...tea.ProgramOption) (
	prog func(context.Context) error,
	setStatus func(string),
	tm pearl.TaskManager,
	w io.Writer,
	s tapioca.ScrollController,
)

NSNI (No Sugar, No Ice) wraps NSNIComponent to provide a ready-to-run program.

Cancelling the context will stop the program, making it suitable for cooperating with signal.NotifyContext.

The tlSize and logBufferSize parameters are passed to NSNIComponent.

The opts parameters are passed to tea.NewProgram.

func NSNIComponent added in v0.0.2

func NSNIComponent(tlSize, logBufferSize int) (
	m tea.Model, f func(func(tea.Msg)) (
		setStatus func(string),
		taskManager pearl.TaskManager,
		w io.Writer,
		logScroller tapioca.ScrollController,
	),
)

NSNIComponent returns simplified flavor of huninn UI.

The NSNI (No Sugar, No Ice) UI consists of three parts without any decorations:

  • A status bar at the bottom, showing a single line of text.
  • A task list at the top, showing multiple tasks with progress in percentage.
  • A log panel in the middle, showing log messages.

It maximizes the use of screen space, but can be less visually appealing than the xxLI (Light Ice) component.

The tlSize parameter specifies the height of the task list in rows. The logBufferSize parameter specifies the maximum number of log entries to keep. If tlSize is less than 3, the task list and log panel will have equal height. The logBufferSize is automatically adjusted to be at least 10.

The component also handles two shortcuts to terminate the program:

  • Ctrl+C
  • q

Types

type JobFactory added in v0.0.2

type JobFactory func(
	setStatus func(string),
	tskManager pearl.TaskManager,
	w io.Writer,
	logScroller tapioca.ScrollController,
	quit func(),
) func(context.Context) error

JobFactory wraps you program logic to create a job function.

It accepts four parameters:

  • setStatus: a function to update the status bar.
  • tskManager: a task manager to control task list component.
  • w: an io.Writer to write log messages.
  • logScroller: a scroll controller to control log panel component.
  • quit: a function to terminate the UI program.

You SHOULD NOT use quit() in most cases, returning from the job function is enough. But when you have to, you MUST remember returning from the job function after calling quit() ASAP, or the program may hang.

Directories

Path Synopsis
Package cup provides some "cup"s: a component can hold another component.
Package cup provides some "cup"s: a component can hold another component.
Package pearl provides some huninn components.
Package pearl provides some huninn components.
Package tapioca defines some common components.
Package tapioca defines some common components.

Jump to

Keyboard shortcuts

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