From e36bade353f04ab614a45ffb11e1610565234100 Mon Sep 17 00:00:00 2001 From: Grail Finder Date: Sun, 1 Mar 2026 13:33:25 +0300 Subject: Fix: escape with empty textarea not generating response --- tui.go | 60 +++++++++++++++++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) diff --git a/tui.go b/tui.go index 773ba4e..5103548 100644 --- a/tui.go +++ b/tui.go @@ -997,42 +997,40 @@ func init() { return nil } msgText := textArea.GetText() + nl := "\n\n" // keep empty lines between messages + prevText := textView.GetText(true) + persona := cfg.UserRole + // strings.LastIndex() + // newline is not needed is prev msg ends with one + if strings.HasSuffix(prevText, nl) { + nl = "" + } else if strings.HasSuffix(prevText, "\n") { + nl = "\n" // only one newline, add another + } if msgText != "" { - nl := "\n\n" // keep empty lines between messages - prevText := textView.GetText(true) - persona := cfg.UserRole - // strings.LastIndex() - // newline is not needed is prev msg ends with one - if strings.HasSuffix(prevText, nl) { - nl = "" - } else if strings.HasSuffix(prevText, "\n") { - nl = "\n" // only one newline, add another + // as what char user sends msg? + if cfg.WriteNextMsgAs != "" { + persona = cfg.WriteNextMsgAs } - if msgText != "" { - // as what char user sends msg? - if cfg.WriteNextMsgAs != "" { - persona = cfg.WriteNextMsgAs - } - // check if plain text - if !injectRole { - matches := roleRE.FindStringSubmatch(msgText) - if len(matches) > 1 { - persona = matches[1] - msgText = strings.TrimLeft(msgText[len(matches[0]):], " ") - } - } - // add user icon before user msg - fmt.Fprintf(textView, "%s[-:-:b](%d) <%s>: [-:-:-]\n%s\n", - nl, len(chatBody.Messages), persona, msgText) - textArea.SetText("", true) - if scrollToEndEnabled { - textView.ScrollToEnd() + // check if plain text + if !injectRole { + matches := roleRE.FindStringSubmatch(msgText) + if len(matches) > 1 { + persona = matches[1] + msgText = strings.TrimLeft(msgText[len(matches[0]):], " ") } - colorText() } - // go chatRound(msgText, persona, textView, false, false) - chatRoundChan <- &models.ChatRoundReq{Role: persona, UserMsg: msgText} + // add user icon before user msg + fmt.Fprintf(textView, "%s[-:-:b](%d) <%s>: [-:-:-]\n%s\n", + nl, len(chatBody.Messages), persona, msgText) + textArea.SetText("", true) + if scrollToEndEnabled { + textView.ScrollToEnd() + } + colorText() } + // go chatRound(msgText, persona, textView, false, false) + chatRoundChan <- &models.ChatRoundReq{Role: persona, UserMsg: msgText} return nil } if event.Key() == tcell.KeyPgUp || event.Key() == tcell.KeyPgDn { -- cgit v1.2.3