util

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Ansi256ToHex

func Ansi256ToHex(code int) string

Ansi256ToHex converts ANSI 256 color code to hex color

func Ansi256ToRGB

func Ansi256ToRGB(code int) (r, g, b int)

Ansi256ToRGB converts ANSI 256 color code to RGB values

func FormatKeyBinding

func FormatKeyBinding(key tcell.Key, ch rune, mod tcell.ModMask) string

FormatKeyBinding returns a display string for a keyboard shortcut. It handles rune keys, special keys, modifiers (Shift, Ctrl, Alt), and control character sequences (Ctrl+A through Ctrl+Z).

Examples:

  • FormatKeyBinding(tcell.KeyCtrlS, 0, 0) → "Ctrl+S"
  • FormatKeyBinding(tcell.KeyEnter, 0, tcell.ModShift) → "Shift+Enter"
  • FormatKeyBinding(tcell.KeyEscape, 0, 0) → "Esc"
  • FormatKeyBinding(tcell.KeyRune, 's', tcell.ModCtrl) → "Ctrl+s"

func GeneratePointsVisual

func GeneratePointsVisual(points int, maxPoints int) string

GeneratePointsVisual formats points as a visual representation using filled/unfilled circles. Points are scaled to a 0-10 display range based on maxPoints configuration.

Parameters:

  • points: The task's point value
  • maxPoints: The configured maximum points value (for scaling)

Returns: A string with filled (●) and unfilled (◦) circles representing the points value.

Example:

GeneratePointsVisual(5, 10) returns "●●●●●◦◦◦◦◦" (5 filled, 5 unfilled)

func GetDefaultEditor

func GetDefaultEditor() string

GetDefaultEditor returns the user's preferred editor from environment variables. Checks VISUAL, then EDITOR, then falls back to vi.

func OpenInEditor

func OpenInEditor(filename string) error

OpenInEditor opens the specified file in the user's default editor. The function blocks until the editor exits. Returns any error that occurred while running the editor.

func TruncateText

func TruncateText(text string, maxWidth int) string

TruncateText truncates text to maxWidth and adds "..." if it exceeds. Does not account for color codes - use TruncateTextWithColors for colored text.

func TruncateTextWithColors

func TruncateTextWithColors(text string, maxWidth int) string

TruncateTextWithColors truncates text to fit within maxWidth, accounting for tview color codes. If truncation occurs, appends "..." to indicate the text was cut. Color codes like [#ffffff] or [red] are not counted toward the visible width.

Types

type AnsiConverter

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

AnsiConverter converts ANSI escape sequences to tview color tags

func NewAnsiConverter

func NewAnsiConverter(enabled bool) *AnsiConverter

NewAnsiConverter creates a new ANSI converter enabled: if false, returns text unchanged (uses tview.TranslateANSI as fallback)

func (*AnsiConverter) Convert

func (c *AnsiConverter) Convert(text string) string

Convert translates ANSI escape sequences to tview color tags Properly handles foreground, background, and bold attributes

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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