summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorGrail Finder <wohilas@gmail.com>2024-11-21 20:16:47 +0300
committerGrail Finder <wohilas@gmail.com>2024-11-21 20:16:47 +0300
commitcc84c037ece2a89424d490d9ee819f06cf4bb347 (patch)
treec2248cc666884bc475c32970a13d086b9aec159d /main.go
parentc35af037203ac5c39a4f704d5343bc2b5cc56a0c (diff)
Enha: match tool call with regexp; clear panics
Diffstat (limited to 'main.go')
-rw-r--r--main.go21
1 files changed, 10 insertions, 11 deletions
diff --git a/main.go b/main.go
index 6a1311e..c7528f5 100644
--- a/main.go
+++ b/main.go
@@ -2,7 +2,6 @@ package main
import (
"elefant/models"
- "encoding/json"
"fmt"
"strconv"
"time"
@@ -63,7 +62,7 @@ func main() {
chatOpts := []string{"cancel", "new"}
fList, err := loadHistoryChats()
if err != nil {
- panic(err)
+ logger.Error("failed to load chat history", "error", err)
}
chatOpts = append(chatOpts, fList...)
chatActModal := tview.NewModal().
@@ -74,15 +73,10 @@ func main() {
case "new":
// set chat body
chatBody.Messages = defaultStarter
- // TODO: use predefined var since it is the same each time
- msgsBytes, err := json.Marshal(chatBody.Messages)
- if err != nil {
- logger.Error(err.Error())
- }
textView.SetText(chatToText(showSystemMsgs))
newChat := &models.Chat{
Name: fmt.Sprintf("%v_%v", "new", time.Now().Unix()),
- Msgs: string(msgsBytes),
+ Msgs: string(defaultStarterBytes),
}
// activeChatName = path.Join(historyDir, fmt.Sprintf("%d_chat.json", time.Now().Unix()))
activeChatName = newChat.Name
@@ -166,10 +160,10 @@ func main() {
textView.ScrollToEnd()
app.SetInputCapture(func(event *tcell.EventKey) *tcell.EventKey {
if event.Key() == tcell.KeyF1 {
- // fList, err := listHistoryFiles(historyDir)
fList, err := loadHistoryChats()
if err != nil {
- panic(err)
+ logger.Error("failed to load chat history", "error", err)
+ return nil
}
chatOpts = append(chatOpts, fList...)
pages.AddPage("history", chatActModal, true, true)
@@ -220,6 +214,10 @@ func main() {
pages.AddPage("getIndex", indexPickWindow, true, true)
return nil
}
+ if event.Key() == tcell.KeyCtrlE {
+ textArea.SetText("pressed ctrl+e", true)
+ return nil
+ }
// cannot send msg in editMode or botRespMode
if event.Key() == tcell.KeyEscape && !editMode && !botRespMode {
fromRow, fromColumn, _, _ := textArea.GetCursor()
@@ -251,6 +249,7 @@ func main() {
pages.AddPage("main", flex, true, true)
if err := app.SetRoot(pages,
true).EnableMouse(true).Run(); err != nil {
- panic(err)
+ logger.Error("failed to start tview app", "error", err)
+ return
}
}