Fix: escape with empty textarea not generating response
This commit is contained in:
68
tui.go
68
tui.go
@@ -997,42 +997,40 @@ func init() {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
msgText := textArea.GetText()
|
msgText := textArea.GetText()
|
||||||
if msgText != "" {
|
nl := "\n\n" // keep empty lines between messages
|
||||||
nl := "\n\n" // keep empty lines between messages
|
prevText := textView.GetText(true)
|
||||||
prevText := textView.GetText(true)
|
persona := cfg.UserRole
|
||||||
persona := cfg.UserRole
|
// strings.LastIndex()
|
||||||
// strings.LastIndex()
|
// newline is not needed is prev msg ends with one
|
||||||
// newline is not needed is prev msg ends with one
|
if strings.HasSuffix(prevText, nl) {
|
||||||
if strings.HasSuffix(prevText, nl) {
|
nl = ""
|
||||||
nl = ""
|
} else if strings.HasSuffix(prevText, "\n") {
|
||||||
} else if strings.HasSuffix(prevText, "\n") {
|
nl = "\n" // only one newline, add another
|
||||||
nl = "\n" // only one newline, add another
|
|
||||||
}
|
|
||||||
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()
|
|
||||||
}
|
|
||||||
colorText()
|
|
||||||
}
|
|
||||||
// go chatRound(msgText, persona, textView, false, false)
|
|
||||||
chatRoundChan <- &models.ChatRoundReq{Role: persona, UserMsg: msgText}
|
|
||||||
}
|
}
|
||||||
|
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()
|
||||||
|
}
|
||||||
|
colorText()
|
||||||
|
}
|
||||||
|
// go chatRound(msgText, persona, textView, false, false)
|
||||||
|
chatRoundChan <- &models.ChatRoundReq{Role: persona, UserMsg: msgText}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if event.Key() == tcell.KeyPgUp || event.Key() == tcell.KeyPgDn {
|
if event.Key() == tcell.KeyPgUp || event.Key() == tcell.KeyPgDn {
|
||||||
|
|||||||
Reference in New Issue
Block a user