Fix (cli): tui panics
This commit is contained in:
@@ -77,6 +77,7 @@ type Config struct {
|
||||
PlaywrightDebug bool `toml:"PlaywrightDebug"` // !headless
|
||||
// CLI mode
|
||||
CLIMode bool
|
||||
UseNotifySend bool
|
||||
}
|
||||
|
||||
func LoadConfig(fn string) (*Config, error) {
|
||||
|
||||
22
helpfuncs.go
22
helpfuncs.go
@@ -98,6 +98,9 @@ func stripThinkingFromMsg(msg *models.RoleMsg) *models.RoleMsg {
|
||||
// It filters messages for the character the user is currently "writing as"
|
||||
// and updates the textView with the filtered conversation
|
||||
func refreshChatDisplay() {
|
||||
if cfg.CLIMode {
|
||||
return
|
||||
}
|
||||
// Determine which character's view to show
|
||||
viewingAs := cfg.UserRole
|
||||
if cfg.WriteNextMsgAs != "" {
|
||||
@@ -183,6 +186,9 @@ func colorText() {
|
||||
}
|
||||
|
||||
func updateStatusLine() {
|
||||
if cfg.CLIMode {
|
||||
return // no status line in cli mode
|
||||
}
|
||||
status := makeStatusLine()
|
||||
statusLineWidget.SetText(status)
|
||||
}
|
||||
@@ -1023,3 +1029,19 @@ func GetCardByRole(role string) *models.CharCard {
|
||||
}
|
||||
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
7
tui.go
@@ -144,6 +144,13 @@ func setShellMode(enabled bool) {
|
||||
// showToast displays a temporary notification in the bottom-right corner.
|
||||
// It auto-hides after 3 seconds.
|
||||
func showToast(title, message string) {
|
||||
if cfg.UseNotifySend {
|
||||
notifySend(title, message)
|
||||
return
|
||||
}
|
||||
if cfg.CLIMode {
|
||||
return
|
||||
}
|
||||
sanitize := func(s string, maxLen int) string {
|
||||
sanitized := strings.Map(func(r rune) rune {
|
||||
if r < 32 && r != '\t' {
|
||||
|
||||
Reference in New Issue
Block a user