Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion gemini.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (g *GeminiClient) genTitle() string {
return strings.ReplaceAll(strings.Join(modelPart, ""), "*", "")
}

func (g *GeminiClient) sendMessageToTui(textChan chan string, historyChan chan string, genFlagChan chan bool, db *DB) {
func (g *GeminiClient) sendMessageToTui(textChan chan string, historyChan chan string, genFlagChan chan bool, titleChan chan string, db *DB) {
firstQuestion := true
for {
text := <-textChan
Expand Down Expand Up @@ -141,6 +141,7 @@ func (g *GeminiClient) sendMessageToTui(textChan chan string, historyChan chan s
firstQuestion = false
go func() {
title := g.genTitle()
titleChan <- title
db.InsertChat(GeminiChatList{
ChatID: int64(g.chatID),
ChatTitle: title,
Expand Down
13 changes: 11 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

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

func main() {
db := initDB()
Expand All @@ -38,6 +39,7 @@ func main() {
sendMsgChan := make(chan string)
historyChan := make(chan string)
genFlagChan := make(chan bool)
titleChan := make(chan string)

app := tview.NewApplication()

Expand All @@ -55,15 +57,15 @@ func main() {
geminiClient.startChat(history)
defer geminiClient.client.Close()

go geminiClient.sendMessageToTui(sendMsgChan, historyChan, genFlagChan, db)
go geminiClient.sendMessageToTui(sendMsgChan, historyChan, genFlagChan, titleChan, db)

chatLog := tview.NewTextView().
SetDynamicColors(true).
SetRegions(true)
chatLog.SetChangedFunc(func() {
app.Draw()
chatLog.ScrollToEnd()
}).SetBorder(true).SetTitle("Chat History <Ctrl-H>")
}).SetBorder(true).SetTitle(chatHistoryTitle)

go func() {
for {
Expand All @@ -74,6 +76,13 @@ func main() {
}
}()

go func() {
title := <-titleChan
app.QueueUpdateDraw(func() {
chatLog.SetTitle(chatHistoryTitle + " [" + title + "]")
})
}()

textArea := tview.NewTextArea()
textArea.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyCtrlS {
Expand Down