Skip to content

Commit

Permalink
open a new chat when starting
Browse files Browse the repository at this point in the history
  • Loading branch information
quantonganh committed Apr 22, 2023
1 parent bddd8e4 commit 15f60b6
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions main.go
Expand Up @@ -92,8 +92,9 @@ func main() {

var (
m = make(map[string]*Conversation)
isNewChat bool
isNewChat = true
)
list.SetSelectedFocusOnly(true)
db.View(func(tx *buntdb.Tx) error {
err := tx.Descend("time", func(key, value string) bool {
var c *Conversation
Expand All @@ -109,17 +110,13 @@ func main() {
return err
})

if list.GetItemCount() > 0 {
title, _ := list.GetItemText(list.GetCurrentItem())
textView.SetText(toConversation(m[title].Messages))
}

list.SetChangedFunc(func(index int, title string, secondaryText string, shortcut rune) {
if c, ok := m[title]; ok {
textView.SetText(toConversation(c.Messages))
}
})
list.SetSelectedFunc(func(index int, title string, secondaryText string, shortcut rune) {
list.SetSelectedFocusOnly(false)
if c, ok := m[title]; ok {
textView.SetText(toConversation(c.Messages))
}
Expand Down Expand Up @@ -329,6 +326,7 @@ func main() {

textView.ScrollToEnd()
if textView.GetText(false) != "" {
isNewChat = false
fmt.Fprintf(textView, "\n\n")
}
fmt.Fprintln(textView, "[red::]You:[-]")
Expand Down Expand Up @@ -449,19 +447,32 @@ func main() {
})

app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if textView.GetText(false) != "" {
list.SetSelectedFocusOnly(false)
}

switch event.Key() {
case tcell.KeyF1:
isNewChat = true
list.SetSelectedFocusOnly(true)
textView.Clear()
app.SetFocus(textArea)
case tcell.KeyF2:
app.SetFocus(list)
if list.GetItemCount() > 0 {
app.SetFocus(list)
title, _ := list.GetItemText(list.GetCurrentItem())
textView.SetText(toConversation(m[title].Messages))
}
case tcell.KeyF3:
app.SetFocus(textView)
if textView.GetText(false) != "" {
app.SetFocus(textView)
}
case tcell.KeyF4:
app.SetFocus(textArea)
case tcell.KeyCtrlS:
app.SetFocus(searchInputField)
if list.GetItemCount() > 0 {
app.SetFocus(searchInputField)
}
default:
return event
}
Expand Down

0 comments on commit 15f60b6

Please sign in to comment.