tui

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: MIT Imports: 42 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package tui is mdsh's interactive mode: a terminal UI that shows a document, runs its blocks as they are picked, and saves their output back to the file.

Index

Constants

View Source
const MaxRecent = 10

MaxRecent is how many recent files are kept.

Variables

This section is empty.

Functions

func Run

func Run(c Config) error

Run shows the file, or the start screen, full screen until the user quits.

Types

type Config added in v1.3.0

type Config struct {
	Open Opener
	// File is the file to open. Without one, the start screen lists the
	// markdown files under Dir, and q in a file goes back to it.
	File string
	Dir  string
	// State is the file that keeps the files opened most recently, which
	// the start screen lists first, and the view the last file was left
	// in. Empty keeps neither.
	State string
}

Config is what Run shows.

type Model

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

Model is the TUI's state. It is a tea.Model.

func New

func New(d *doc.Document, opts Options) (*Model, error)

New sets up the TUI for d. Close the model when done with it.

func (*Model) Close

func (m *Model) Close()

Close ends the shells blocks ran in.

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init starts listening for run events, and watching the file.

func (*Model) Update

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

Update handles a key, a window size or a run event.

func (*Model) View

func (m *Model) View() string

View draws the document above a status line and a key help line.

type Opener added in v1.3.0

type Opener func(file string) (*doc.Document, Options, error)

Opener reads file and returns its document and the options to show it with. The TUI calls it to open a file from the start screen, to reload one and to follow one saved into another folder.

type Options

type Options struct {
	// Run are the options every run uses. Run.File must be set. The TUI
	// sets Confirm and OnEvent itself.
	Run run.Options
	// Yes runs confirm blocks, every block in step mode, and the
	// blocks depends= names, without
	// asking.
	Yes bool
	// Save writes the document's new contents to file: Run.File, or
	// the file picked by save as.
	Save func(file string, out []byte) error
	// AutoSave saves after every block that runs. Otherwise output is
	// saved when w or ctrl+s is pressed.
	AutoSave bool
	// Writable reports whether a file can be saved, with an error
	// wrapping writable.ErrReadOnly if it can't. If nil, writable.Check
	// is used.
	Writable func(file string) error
	// Images turns on image previews, drawn with colored half blocks.
	Images bool
	// Protocol is how v shows an image at full size. With termimg.None
	// it is drawn with half blocks, as large as the terminal allows.
	Protocol termimg.Protocol
	// Style is the glamour style prose is drawn in, such as "dark",
	// "light" or "notty".
	Style string
	// View is how the file is shown at first.
	View View
}

Options configure the TUI.

type RunOptions added in v1.3.0

type RunOptions struct {
	Args        []string
	Only        string
	Step        bool
	StopOnError bool
}

RunOptions are the run options the run options form sets.

type View added in v1.3.0

type View struct {
	// Outline shows the headings and blocks down the left.
	Outline bool `json:"outline"`
	// HideCode and HideOutput leave out the code and the output of
	// blocks.
	HideCode   bool `json:"hideCode"`
	HideOutput bool `json:"hideOutput"`
}

View is how a file is shown, as in mdsh-gui's View menu. The TUI keeps the last one used, so the next file opens the same way.

Jump to

Keyboard shortcuts

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