tuiutil

package
v0.0.0-...-f106031 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HighlightKey                = "Highlight"
	HeaderBackgroundKey         = "HeaderBackground"
	HeaderBorderBackgroundKey   = "HeaderBorderBackground"
	HeaderForegroundKey         = "HeaderForeground"
	FooterForegroundColorKey    = "FooterForeground"
	HeaderBottomColorKey        = "HeaderBottom"
	HeaderTopForegroundColorKey = "HeaderTopForeground"
	BorderColorKey              = "BorderColor"
	TextColorKey                = "TextColor"
)
View Source
const DefaultBlinkSpeed = time.Millisecond * 530

Variables

View Source
var (
	Highlight = func() string {
		return ThemesMap[SelectedTheme][HighlightKey]
	} // change to whatever
	HeaderBackground = func() string {
		return ThemesMap[SelectedTheme][HeaderBackgroundKey]
	}
	HeaderBorderBackground = func() string {
		return ThemesMap[SelectedTheme][HeaderBorderBackgroundKey]
	}
	HeaderForeground = func() string {
		return ThemesMap[SelectedTheme][HeaderForegroundKey]
	}
	FooterForeground = func() string {
		return ThemesMap[SelectedTheme][FooterForegroundColorKey]
	}
	HeaderBottom = func() string {
		return ThemesMap[SelectedTheme][HeaderBottomColorKey]
	}
	HeaderTopForeground = func() string {
		return ThemesMap[SelectedTheme][HeaderTopForegroundColorKey]
	}
	BorderColor = func() string {
		return ThemesMap[SelectedTheme][BorderColorKey]
	}
	TextColor = func() string {
		return ThemesMap[SelectedTheme][TextColorKey]
	}
)

styling functions

View Source
var (
	SelectedTheme = 0
	ValidThemes   = []string{
		"default",
		"nord",
		"solarized",
	}
	ThemesMap = map[int]map[string]string{
		2: {
			HeaderBackgroundKey:         "#268bd2",
			HeaderBorderBackgroundKey:   "#268bd2",
			HeaderBottomColorKey:        "#586e75",
			BorderColorKey:              "#586e75",
			TextColorKey:                "#fdf6e3",
			HeaderForegroundKey:         "#fdf6e3",
			HighlightKey:                "#2aa198",
			FooterForegroundColorKey:    "#d33682",
			HeaderTopForegroundColorKey: "#d33682",
		},
		1: {
			HeaderBackgroundKey:         "#5e81ac",
			HeaderBorderBackgroundKey:   "#5e81ac",
			HeaderBottomColorKey:        "#5e81ac",
			BorderColorKey:              "#eceff4",
			TextColorKey:                "#eceff4",
			HeaderForegroundKey:         "#eceff4",
			HighlightKey:                "#88c0d0",
			FooterForegroundColorKey:    "#b48ead",
			HeaderTopForegroundColorKey: "#b48ead",
		},
		0: {
			HeaderBackgroundKey:         "#505050",
			HeaderBorderBackgroundKey:   "#505050",
			HeaderBottomColorKey:        "#FFFFFF",
			BorderColorKey:              "#FFFFFF",
			TextColorKey:                "#FFFFFF",
			HeaderForegroundKey:         "#FFFFFF",
			HighlightKey:                "#A0A0A0",
			FooterForegroundColorKey:    "#C2C2C2",
			HeaderTopForegroundColorKey: "#C2C2C2",
		},
	}
)
View Source
var (
	Ascii bool
)

Internal ID management for text inputs. Necessary for blink integrity when multiple text inputs are involved.

Functions

func Blink() tea.Msg

Blink is a command used to initialize cursor blinking.

func Clamp

func Clamp(v, low, high int) int

func Convert

func Convert(csvFileName, tableName string, keepOrigCols bool) string

func Indent

func Indent(input string, prefix string, prefixAll bool) string

Indent a string with the given prefix at the start of either the first, or all lines.

input     - The input string to indent.
prefix    - The prefix to add.
prefixAll - If true, prefix all lines with the given prefix.

Example usage:

indented := wordwrap.Indent("Hello\nWorld", "-", true)

func Paste

func Paste() tea.Msg

Paste is a command for pasting from the clipboard into the text input.

func SQLFileName

func SQLFileName(csvFileName string) string

Types

type CursorMode

type CursorMode int

CursorMode describes the behavior of the cursor.

const (
	CursorBlink CursorMode = iota
	CursorStatic
	CursorHide
)

Available cursor modes.

func (CursorMode) String

func (c CursorMode) String() string

String returns a the cursor mode in a human-readable format. This method is provisional and for informational purposes only.

type EchoMode

type EchoMode int

EchoMode sets the input behavior of the text input field.

const (
	// EchoNormal displays text as is. This is the default behavior.
	EchoNormal EchoMode = iota

	// EchoPassword displays the EchoCharacter mask instead of actual
	// characters.  This is commonly used for password fields.
	EchoPassword

	// EchoNone displays nothing as characters are entered. This is commonly
	// seen for password fields on the command line.
	EchoNone
)

type TextInputModel

type TextInputModel struct {
	Err error

	// General settings.
	Prompt        string
	Placeholder   string
	BlinkSpeed    time.Duration
	EchoMode      EchoMode
	EchoCharacter rune

	// Styles. These will be applied as inline styles.
	//
	// For an introduction to styling with Lip Gloss see:
	// https://github.com/charmbracelet/lipgloss
	PromptStyle      lipgloss.Style
	TextStyle        lipgloss.Style
	BackgroundStyle  lipgloss.Style
	PlaceholderStyle lipgloss.Style
	CursorStyle      lipgloss.Style

	// CharLimit is the maximum amount of characters this input element will
	// accept. If 0 or less, there's no limit.
	CharLimit int

	// Width is the maximum number of characters that can be displayed at once.
	// It essentially treats the text field like a horizontally scrolling
	// Viewport. If 0 or less this setting is ignored.
	Width int

	// Focus indicates whether user input Focus should be on this input
	// component. When false, ignore keyboard input and hide the cursor.
	Focus bool

	// Used to emulate a Viewport when width is set and the content is
	// overflowing.
	Offset      int
	OffsetRight int
	// contains filtered or unexported fields
}

TextInputModel is the Bubble Tea model for this text input element.

func NewModel

func NewModel() TextInputModel

NewModel creates a new model with default settings.

func (*TextInputModel) Blur

func (m *TextInputModel) Blur()

Blur removes the Focus state on the model. When the model is blurred it can not receive keyboard input and the cursor will be hidden.

func (TextInputModel) Cursor

func (m TextInputModel) Cursor() int

Cursor returns the cursor position.

func (*TextInputModel) CursorEnd

func (m *TextInputModel) CursorEnd()

CursorEnd moves the cursor to the end of the input field

func (TextInputModel) CursorMode

func (m TextInputModel) CursorMode() CursorMode

CursorMode returns the model's cursor mode. For available cursor modes, see type CursorMode.

func (*TextInputModel) CursorStart

func (m *TextInputModel) CursorStart()

CursorStart moves the cursor to the start of the input field.

func (*TextInputModel) FocusCommand

func (m *TextInputModel) FocusCommand() tea.Cmd

FocusCommand sets the Focus state on the model. When the model is in Focus it can receive keyboard input and the cursor will be hidden.

func (TextInputModel) Focused

func (m TextInputModel) Focused() bool

Focused returns the Focus state on the model.

func (*TextInputModel) Reset

func (m *TextInputModel) Reset() bool

Reset sets the input to its default state with no input. Returns whether or not the cursor blink should reset.

func (*TextInputModel) SetCursor

func (m *TextInputModel) SetCursor(pos int)

SetCursor moves the cursor to the given position. If the position is out of bounds the cursor will be moved to the start or end accordingly.

func (*TextInputModel) SetCursorMode

func (m *TextInputModel) SetCursorMode(mode CursorMode) tea.Cmd

SetCursorMode CursorMode sets the model's cursor mode. This method returns a command.

For available cursor modes, see type CursorMode.

func (*TextInputModel) SetValue

func (m *TextInputModel) SetValue(s string)

SetValue sets the value of the text input.

func (TextInputModel) Update

func (m TextInputModel) Update(msg tea.Msg) (TextInputModel, tea.Cmd)

Update is the Bubble Tea update loop.

func (TextInputModel) Value

func (m TextInputModel) Value() string

Value returns the value of the text input.

func (TextInputModel) View

func (m TextInputModel) View() string

View renders the textinput in its current state.

Jump to

Keyboard shortcuts

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