Compare commits
2 Commits
enha/codin
...
742f1ca838
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
742f1ca838 | ||
|
|
e36bade353 |
41
tui.go
41
tui.go
@@ -35,6 +35,8 @@ var (
|
|||||||
renameWindow *tview.InputField
|
renameWindow *tview.InputField
|
||||||
roleEditWindow *tview.InputField
|
roleEditWindow *tview.InputField
|
||||||
shellInput *tview.InputField
|
shellInput *tview.InputField
|
||||||
|
confirmModal *tview.Modal
|
||||||
|
confirmPageName = "confirm"
|
||||||
fullscreenMode bool
|
fullscreenMode bool
|
||||||
positionVisible bool = true
|
positionVisible bool = true
|
||||||
scrollToEndEnabled bool = true
|
scrollToEndEnabled bool = true
|
||||||
@@ -195,6 +197,40 @@ func init() {
|
|||||||
}
|
}
|
||||||
return event
|
return event
|
||||||
})
|
})
|
||||||
|
confirmModal = tview.NewModal().
|
||||||
|
SetText("You are trying to send an empty message.\nIt makes sense if the last message in the chat is from you.\nAre you sure?").
|
||||||
|
AddButtons([]string{"Yes", "No"}).
|
||||||
|
SetButtonBackgroundColor(tcell.ColorBlack).
|
||||||
|
SetButtonTextColor(tcell.ColorWhite).
|
||||||
|
SetDoneFunc(func(buttonIndex int, buttonLabel string) {
|
||||||
|
if buttonLabel == "Yes" {
|
||||||
|
persona := cfg.UserRole
|
||||||
|
if cfg.WriteNextMsgAs != "" {
|
||||||
|
persona = cfg.WriteNextMsgAs
|
||||||
|
}
|
||||||
|
chatRoundChan <- &models.ChatRoundReq{Role: persona, UserMsg: ""}
|
||||||
|
} // In both Yes and No, go back to the main page
|
||||||
|
pages.SwitchToPage("main") // or whatever your main page is named
|
||||||
|
})
|
||||||
|
confirmModal.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
|
||||||
|
switch event.Key() {
|
||||||
|
case tcell.KeyRune:
|
||||||
|
switch event.Rune() {
|
||||||
|
case 'y', 'Y':
|
||||||
|
persona := cfg.UserRole
|
||||||
|
if cfg.WriteNextMsgAs != "" {
|
||||||
|
persona = cfg.WriteNextMsgAs
|
||||||
|
}
|
||||||
|
chatRoundChan <- &models.ChatRoundReq{Role: persona, UserMsg: ""}
|
||||||
|
pages.SwitchToPage("main")
|
||||||
|
return nil
|
||||||
|
case 'n', 'N', 'x', 'X':
|
||||||
|
pages.SwitchToPage("main")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return event
|
||||||
|
})
|
||||||
textArea = tview.NewTextArea().
|
textArea = tview.NewTextArea().
|
||||||
SetPlaceholder("input is multiline; press <Enter> to start the next line;\npress <Esc> to send the message.")
|
SetPlaceholder("input is multiline; press <Enter> to start the next line;\npress <Esc> to send the message.")
|
||||||
textArea.SetBorder(true).SetTitle("input")
|
textArea.SetBorder(true).SetTitle("input")
|
||||||
@@ -997,7 +1033,6 @@ 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
|
||||||
@@ -1029,10 +1064,12 @@ func init() {
|
|||||||
textView.ScrollToEnd()
|
textView.ScrollToEnd()
|
||||||
}
|
}
|
||||||
colorText()
|
colorText()
|
||||||
|
} else {
|
||||||
|
pages.AddPage(confirmPageName, confirmModal, true, true)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
// go chatRound(msgText, persona, textView, false, false)
|
// go chatRound(msgText, persona, textView, false, false)
|
||||||
chatRoundChan <- &models.ChatRoundReq{Role: persona, UserMsg: msgText}
|
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