Documentation
¶
Index ¶
- Constants
- Variables
- func AttemptPrettyPrint(w io.Writer, chatMessage pub_models.Message, username string, raw bool) error
- func ConfigDirPaths() []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 EscapeEditorString(edited string) string
- 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 NewMacroReader(inputs []string) io.Reader
- func NotificationBellEnabled() bool
- func PrepareDisplayMessage(msg pub_models.Message) pub_models.Message
- func Prompt(stdinReplace string, args []string) (string, error)
- func RandomPrefix() string
- func ReadAndUnmarshal[T any](filePath string, config *T) error
- func ReplaceTildeWithHome(s string) (string, error)
- func ResolveConfigDirPath(configDir string, components []string) (string, error)
- func ReturnNonDefault[T comparable](a, b, defaultVal T) (T, error)
- func RoleColor(role string) string
- func SaveBase64File(prefix, dir, b64JSON, extension string) (string, error)
- func ShortenedOutput(out string, maxShortenedNewlines int) string
- func TableTheme() table.Theme
- func ThemeConfigPath(configDirPath string) string
- func UnescapeEditorString(toEdit string) string
- func UpdateMessageTerminalMetadata(msg string, line *string, lineCount *int, termWidth int)
- func WriteFile[T any](path string, toWrite *T) error
- type ContextKey
- type Theme
Constants ¶
const MaxShortenedNewlines = 5
Variables ¶
var Live bool
Live controls whether macro mode switches to interactive stdin after consuming all macro inputs (true, default) or appends trailing "q\n" terminators for graceful auto-exit (false). Set by Setup() based on the --non-interactive flag.
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 the message has ReasoningContent, it is rendered with reasoning color before the main content.
If w is nil, os.Stdout is used.
func ConfigDirPaths ¶
func ConfigDirPaths() []string
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 EscapeEditorString ¶ added in v1.10.11
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. After loading, stores the theme for consumer access.
func NewMacroReader ¶ added in v1.10.17
NewMacroReader creates a reader that yields each input string as a line.
By default (Live=true), after all macro inputs are consumed the reader transparently switches to os.Stdin so the user continues interacting.
When Live is false (--non-interactive), 10 trailing "q\n" lines are appended for graceful termination through nested table loops.
Returns nil when inputs is empty or nil (caller should skip injection).
func NotificationBellEnabled ¶
func NotificationBellEnabled() bool
func PrepareDisplayMessage ¶ added in v1.10.10
func PrepareDisplayMessage(msg pub_models.Message) pub_models.Message
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 ReplaceTildeWithHome ¶
func ResolveConfigDirPath ¶
func ReturnNonDefault ¶
func ReturnNonDefault[T comparable](a, b, defaultVal T) (T, error)
func SaveBase64File ¶ added in v1.10.17
SaveBase64File decodes a base64 string and writes it to dir/prefix_random.extension. Falls back to /tmp on write failure.
func ShortenedOutput ¶
ShortenedOutput returns a shortened version of the output
func TableTheme ¶ added in v1.10.17
TableTheme returns the table.Theme derived from the current global theme.
func ThemeConfigPath ¶
ThemeConfigPath returns the fully qualified theme.json path.
func UnescapeEditorString ¶ added in v1.10.11
func UpdateMessageTerminalMetadata ¶
UpdateMessageTerminalMetadata updates the terminal metadata. Meaning the lineCount, to eventually clear the terminal
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"`
RoleReasoning string `json:"roleReasoning"`
RoleOther string `json:"roleOther"`
NotificationBell bool `json:"notificationBell"`
TableItems int `json:"tableItems"`
}
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.