Documentation
¶
Index ¶
- Variables
- func AttemptPrettyPrint(w io.Writer, chatMessage pub_models.Message, username string, raw bool) error
- func ClearTermTo(w io.Writer, termWidth, upTo int) error
- func Colorize(color, s string) string
- func CreateConfigDir(configPath string) error
- func CreateFile[T any](path string, toCreate *T) error
- func DeleteRange[T any](s []T, start, end int) ([]T, error)
- func GetClaiCacheDir() (string, error)
- func GetClaiConfigDir() (string, error)
- func GetFirstTokens(prompt []string, n int) []string
- func LoadConfigFromFile[T any](configDirPath, configFileName string, migrationCb func(string) error, dflt *T) (T, error)
- func LoadTheme(configDirPath string) error
- func NoColor() bool
- func Prompt(stdinReplace string, args []string) (string, error)
- func RandomPrefix() string
- func ReadAndUnmarshal[T any](filePath string, config *T) error
- func ReadUserInput() (string, error)
- func ReplaceTildeWithHome(s string) (string, error)
- func ReturnNonDefault[T comparable](a, b, defaultVal T) (T, error)
- func RoleColor(role string) string
- func SelectFromTable[T any](header string, items []T, choicesFormat string, ...) ([]int, error)
- func ShortenedOutput(out string, maxShortenedNewlines int) string
- func TermWidth() (int, error)
- func ThemeBreadtextColor() string
- func ThemeConfigPath(configDirPath string) string
- func ThemePrimaryColor() string
- func ThemeSecondaryColor() string
- func UpdateMessageTerminalMetadata(msg string, line *string, lineCount *int, termWidth int)
- func WidthAppropriateStringTrunc(toShorten, prefix string, padding int) (string, error)
- func WidthAppropriateStringTruncColored(toShorten, prefix, prefixColor, truncColor string, padding int) (string, error)
- func WriteFile[T any](path string, toWrite *T) error
- type ContextKey
- type Theme
Constants ¶
This section is empty.
Variables ¶
var ErrUserInitiatedExit = errors.New("user exit")
Functions ¶
func AttemptPrettyPrint ¶
func AttemptPrettyPrint(w io.Writer, chatMessage pub_models.Message, username string, raw bool) error
AttemptPrettyPrint by first checking if the glow command is available, and if so, pretty print the chat message. If not found, simply print the message as is.
If w is nil, os.Stdout is used.
func ClearTermTo ¶
ClearTermTo a certain amount of rows upwards by printing termWidth amount of empty spaces.
If w is nil, os.Stdout is used.
func Colorize ¶
Colorize wraps s with the given ANSI color code unless NO_COLOR is set or color is empty.
func CreateConfigDir ¶
func CreateFile ¶
func DeleteRange ¶
DeleteRange removes elements in [start, end] (inclusive) from the slice and returns the new slice. Panics if indices are invalid. Works for any slice type (Go 1.18+).
func GetClaiCacheDir ¶
GetClaiCacheDir returns the path to the clai cache directory. The directory is located inside the user's cache directory as <UserCacheDir>/clai, unless overridden by CLAI_CACHE_DIR.
func GetClaiConfigDir ¶
GetClaiConfigDir returns the path to the clai configuration directory. The directory is located inside the user's configuration directory as <UserConfigDir>/.clai, unless overridden by CLAI_CONFIG_DIR.
func GetFirstTokens ¶
GetFirstTokens returns the first n tokens of the prompt, or the whole prompt if it has less than n tokens
func LoadConfigFromFile ¶
func LoadTheme ¶
LoadTheme loads (and possibly creates) the theme.json file within the config dir. It is safe to call multiple times.
func Prompt ¶
Prompt returns the prompt by checking all the arguments and stdin. If there is no arguments, but data in stdin, stdin will become the prompt. If there are arguments and data in stdin, all stdinReplace tokens will be substituted with the data in stdin
func RandomPrefix ¶
func RandomPrefix() string
func ReadAndUnmarshal ¶
ReadAndUnmarshal by first finding the file, then attempting to read + unmarshal to T
func ReadUserInput ¶
ReadUserInput and return on interrupt channel
func ReplaceTildeWithHome ¶
func ReturnNonDefault ¶
func ReturnNonDefault[T comparable](a, b, defaultVal T) (T, error)
func SelectFromTable ¶
func SelectFromTable[T any](header string, items []T, choicesFormat string, rowFormater func(int, T) (string, error), pageSize int, onlyOneSelect bool, ) ([]int, error)
SelectFromTable by: 1. Listing rows according to rowFormater 2. Returning a list of chosen numbers
Valid inputs:
- nr = int < len(items)
- nr,nr,nr - This selects multiple numbers
- nr:nr,nr,nr:nr - This selects two ranges of nr, as well as a singular nr
func ShortenedOutput ¶
ShortenedOutput returns a shortened version of the output
func TermWidth ¶
TermWidth returns the current terminal width.
In CI / tests there is often no TTY attached, so ioctl(TIOCGWINSZ) returns "inappropriate ioctl for device". In that case we fall back to a sane default width (80) or the value from $COLUMNS if present.
func ThemeBreadtextColor ¶
func ThemeBreadtextColor() string
func ThemeConfigPath ¶
ThemeConfigPath returns the fully qualified theme.json path.
func ThemePrimaryColor ¶
func ThemePrimaryColor() string
func ThemeSecondaryColor ¶
func ThemeSecondaryColor() string
func UpdateMessageTerminalMetadata ¶
UpdateMessageTerminalMetadata updates the terminal metadata. Meaning the lineCount, to eventually clear the terminal
func WidthAppropriateStringTruncColored ¶
func WidthAppropriateStringTruncColored(toShorten, prefix, prefixColor, truncColor string, padding int) (string, error)
WidthAppropriateStringTruncColored is like WidthAppropriateStringTrunc but allows coloring of the prefix and the truncation infix.
prefixColor and truncColor are raw ANSI sequences (or empty). Colors are disabled when NO_COLOR is truthy.
Types ¶
type Theme ¶
type Theme struct {
Primary string `json:"primary"`
Secondary string `json:"secondary"`
Breadtext string `json:"breadtext"`
RoleSystem string `json:"roleSystem"`
RoleUser string `json:"roleUser"`
RoleTool string `json:"roleTool"`
RoleOther string `json:"roleOther"`
}
Theme holds ANSI color configuration for terminal output. Values are raw ANSI escape sequences (e.g. "\u001b[38;2;120;140;160m").
This file is loaded from <clai-config-dir>/theme.json on startup. If NO_COLOR is set truthy, all colorization should be disabled.
Keep this config stable; new fields should be appended with defaults. Users can customize their own theme.json.