tui

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// GitHub theme (default).
	GitHub = DiffTheme{
		Dark: map[color.ColorKey]string{
			color.Old:    "\x1b[38;2;248;81;73m",
			color.New:    "\x1b[38;2;63;185;80m",
			color.Frag:   "\x1b[38;2;88;166;255m",
			color.Commit: "\x1b[38;2;210;153;34m",
		},
		Light: map[color.ColorKey]string{
			color.Old:    "\x1b[38;2;215;58;73m",
			color.New:    "\x1b[38;2;40;167;69m",
			color.Frag:   "\x1b[38;2;0;92;197m",
			color.Commit: "\x1b[38;2;176;136;0m",
		},
	}

	// Dracula theme.
	Dracula = DiffTheme{
		Dark: map[color.ColorKey]string{
			color.Old:    "\x1b[38;2;255;85;85m",
			color.New:    "\x1b[38;2;80;250;123m",
			color.Frag:   "\x1b[38;2;139;233;253m",
			color.Commit: "\x1b[38;2;241;250;140m",
		},
		Light: map[color.ColorKey]string{
			color.Old:    "\x1b[38;2;215;58;73m",
			color.New:    "\x1b[38;2;40;167;69m",
			color.Frag:   "\x1b[38;2;0;92;197m",
			color.Commit: "\x1b[38;2;176;136;0m",
		},
	}

	// OneDark theme.
	OneDark = DiffTheme{
		Dark: map[color.ColorKey]string{
			color.Old:    "\x1b[38;2;224;108;117m",
			color.New:    "\x1b[38;2;152;195;121m",
			color.Frag:   "\x1b[38;2;97;175;239m",
			color.Commit: "\x1b[38;2;209;154;102m",
		},
		Light: map[color.ColorKey]string{
			color.Old:    "\x1b[38;2;228;86;73m",
			color.New:    "\x1b[38;2;80;161;79m",
			color.Frag:   "\x1b[38;2;56;125;203m",
			color.Commit: "\x1b[38;2;188;122;0m",
		},
	}

	// Catppuccin theme.
	Catppuccin = DiffTheme{
		Dark: map[color.ColorKey]string{
			color.Old:    "\x1b[38;2;243;139;168m",
			color.New:    "\x1b[38;2;166;227;161m",
			color.Frag:   "\x1b[38;2;137;180;250m",
			color.Commit: "\x1b[38;2;249;226;175m",
		},
		Light: map[color.ColorKey]string{
			color.Old:    "\x1b[38;2;210;15;57m",
			color.New:    "\x1b[38;2;64;160;43m",
			color.Frag:   "\x1b[38;2;30;102;245m",
			color.Commit: "\x1b[38;2;223;142;29m",
		},
	}

	// Nord theme.
	Nord = DiffTheme{
		Dark: map[color.ColorKey]string{
			color.Old:    "\x1b[38;2;191;97;106m",
			color.New:    "\x1b[38;2;163;190;140m",
			color.Frag:   "\x1b[38;2;136;192;208m",
			color.Commit: "\x1b[38;2;235;203;139m",
		},
		Light: map[color.ColorKey]string{
			color.Old:    "\x1b[38;2;191;97;106m",
			color.New:    "\x1b[38;2;163;190;140m",
			color.Frag:   "\x1b[38;2;136;192;208m",
			color.Commit: "\x1b[38;2;235;203;139m",
		},
	}
)

Predefined diff themes.

View Source
var ErrInterrupted = errors.New("interrupted")

ErrInterrupted is returned when user presses Ctrl+C or Ctrl+D.

Functions

func AskConfirm

func AskConfirm(confirm *bool, format string, a ...any) error

AskConfirm prompts for a confirmation using huh library. It provides a user-friendly yes/no confirmation dialog.

Note: Output goes to stderr to avoid interfering with stdout piping.

func AskInput

func AskInput(value *string, format string, a ...any) error

AskInput prompts for a text input with proper CJK/emoji backspace handling.

Note: Output goes to stderr to avoid interfering with stdout piping.

func AskPassword

func AskPassword(password *string, format string, a ...any) error

AskPassword prompts for a password input with asterisk masking. It properly handles UTF-8, CJK characters, emoji, and terminal control sequences. Cross-platform support: Windows, Linux, macOS (via golang.org/x/term).

Note: Output goes to stderr to avoid interfering with stdout piping.

func EncoderOptions added in v0.23.0

func EncoderOptions(level term.Level) []diferenco.EncoderOption

EncoderOptions returns diferenco.EncoderOption slice with appropriate color configuration based on the terminal's color level.

func SetDiffTheme added in v0.23.0

func SetDiffTheme(theme DiffTheme)

SetDiffTheme sets the current diff theme.

Types

type DiffTheme added in v0.23.0

type DiffTheme struct {
	Dark  map[color.ColorKey]string
	Light map[color.ColorKey]string
}

DiffTheme defines color scheme for diff output.

type Pager

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

Pager represents a simple terminal pager built with viewport. It implements io.Writer and must be closed to display content.

func NewPager

func NewPager(colorMode term.Level, useAltScreen bool) *Pager

NewPager creates a new pager with given color mode and alt screen setting. The pager implements io.Writer, content is accumulated via Write calls. Close must be called to display the content in the pager. useAltScreen controls whether to use alternate screen buffer (default true).

func (*Pager) Close

func (p *Pager) Close() error

Close finalizes the pager and displays the content. For short content that fits in the terminal, it outputs directly without starting the pager. For longer content, it starts an interactive pager with viewport. Close is idempotent - calling it multiple times is safe.

func (*Pager) ColorMode

func (p *Pager) ColorMode() term.Level

ColorMode returns the color mode of the pager.

func (*Pager) Write

func (p *Pager) Write(data []byte) (int, error)

Write implements io.Writer interface for the pager. It appends data to the internal buffer and returns an error if the pager is closed.

type StringObject added in v0.23.0

type StringObject string

StringObject implements viewport.Object for a single line

func (StringObject) GetItem added in v0.23.0

func (s StringObject) GetItem() item.Item

Jump to

Keyboard shortcuts

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