Skip to content

Commit 87b8eea

Browse files
authored
Merge pull request #2 from greycodee/tui
gen title
2 parents e727ad7 + 5849a1c commit 87b8eea

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

gemini.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (g *GeminiClient) genTitle() string {
7777
return strings.ReplaceAll(strings.Join(modelPart, ""), "*", "")
7878
}
7979

80-
func (g *GeminiClient) sendMessageToTui(textChan chan string, historyChan chan string, genFlagChan chan bool, db *DB) {
80+
func (g *GeminiClient) sendMessageToTui(textChan chan string, historyChan chan string, genFlagChan chan bool, titleChan chan string, db *DB) {
8181
firstQuestion := true
8282
for {
8383
text := <-textChan
@@ -141,6 +141,7 @@ func (g *GeminiClient) sendMessageToTui(textChan chan string, historyChan chan s
141141
firstQuestion = false
142142
go func() {
143143
title := g.genTitle()
144+
titleChan <- title
144145
db.InsertChat(GeminiChatList{
145146
ChatID: int64(g.chatID),
146147
ChatTitle: title,

main.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414

1515
var HOME_PATH = os.Getenv("HOME")
1616
var chatID = 1
17+
var chatHistoryTitle = "Chat History <Ctrl-H>"
1718

1819
func main() {
1920
db := initDB()
@@ -38,6 +39,7 @@ func main() {
3839
sendMsgChan := make(chan string)
3940
historyChan := make(chan string)
4041
genFlagChan := make(chan bool)
42+
titleChan := make(chan string)
4143

4244
app := tview.NewApplication()
4345

@@ -55,15 +57,15 @@ func main() {
5557
geminiClient.startChat(history)
5658
defer geminiClient.client.Close()
5759

58-
go geminiClient.sendMessageToTui(sendMsgChan, historyChan, genFlagChan, db)
60+
go geminiClient.sendMessageToTui(sendMsgChan, historyChan, genFlagChan, titleChan, db)
5961

6062
chatLog := tview.NewTextView().
6163
SetDynamicColors(true).
6264
SetRegions(true)
6365
chatLog.SetChangedFunc(func() {
6466
app.Draw()
6567
chatLog.ScrollToEnd()
66-
}).SetBorder(true).SetTitle("Chat History <Ctrl-H>")
68+
}).SetBorder(true).SetTitle(chatHistoryTitle)
6769

6870
go func() {
6971
for {
@@ -74,6 +76,13 @@ func main() {
7476
}
7577
}()
7678

79+
go func() {
80+
title := <-titleChan
81+
app.QueueUpdateDraw(func() {
82+
chatLog.SetTitle(chatHistoryTitle + " [" + title + "]")
83+
})
84+
}()
85+
7786
textArea := tview.NewTextArea()
7887
textArea.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
7988
if event.Key() == tcell.KeyCtrlS {

0 commit comments

Comments
 (0)