Fix (cli): tui panics

This commit is contained in:
Grail Finder
2026-04-11 16:07:15 +03:00
parent 76cc48eb54
commit 50035e667b
3 changed files with 31 additions and 1 deletions

View File

@@ -76,7 +76,8 @@ type Config struct {
PlaywrightEnabled bool `toml:"PlaywrightEnabled"` PlaywrightEnabled bool `toml:"PlaywrightEnabled"`
PlaywrightDebug bool `toml:"PlaywrightDebug"` // !headless PlaywrightDebug bool `toml:"PlaywrightDebug"` // !headless
// CLI mode // CLI mode
CLIMode bool CLIMode bool
UseNotifySend bool
} }
func LoadConfig(fn string) (*Config, error) { func LoadConfig(fn string) (*Config, error) {

View File

@@ -98,6 +98,9 @@ func stripThinkingFromMsg(msg *models.RoleMsg) *models.RoleMsg {
// It filters messages for the character the user is currently "writing as" // It filters messages for the character the user is currently "writing as"
// and updates the textView with the filtered conversation // and updates the textView with the filtered conversation
func refreshChatDisplay() { func refreshChatDisplay() {
if cfg.CLIMode {
return
}
// Determine which character's view to show // Determine which character's view to show
viewingAs := cfg.UserRole viewingAs := cfg.UserRole
if cfg.WriteNextMsgAs != "" { if cfg.WriteNextMsgAs != "" {
@@ -183,6 +186,9 @@ func colorText() {
} }
func updateStatusLine() { func updateStatusLine() {
if cfg.CLIMode {
return // no status line in cli mode
}
status := makeStatusLine() status := makeStatusLine()
statusLineWidget.SetText(status) statusLineWidget.SetText(status)
} }
@@ -1023,3 +1029,19 @@ func GetCardByRole(role string) *models.CharCard {
} }
return sysMap[cardID] return sysMap[cardID]
} }
func notifySend(topic, message string) error {
// Sanitize message to remove control characters that notify-send doesn't handle
sanitized := strings.Map(func(r rune) rune {
if r < 32 && r != '\t' {
return -1
}
return r
}, message)
// Truncate if too long
if len(sanitized) > 200 {
sanitized = sanitized[:197] + "..."
}
cmd := exec.Command("notify-send", topic, sanitized)
return cmd.Run()
}

7
tui.go
View File

@@ -144,6 +144,13 @@ func setShellMode(enabled bool) {
// showToast displays a temporary notification in the bottom-right corner. // showToast displays a temporary notification in the bottom-right corner.
// It auto-hides after 3 seconds. // It auto-hides after 3 seconds.
func showToast(title, message string) { func showToast(title, message string) {
if cfg.UseNotifySend {
notifySend(title, message)
return
}
if cfg.CLIMode {
return
}
sanitize := func(s string, maxLen int) string { sanitize := func(s string, maxLen int) string {
sanitized := strings.Map(func(r rune) rune { sanitized := strings.Map(func(r rune) rune {
if r < 32 && r != '\t' { if r < 32 && r != '\t' {