diff options
author | Grail Finder <wohilas@gmail.com> | 2024-12-02 19:58:03 +0300 |
---|---|---|
committer | Grail Finder <wohilas@gmail.com> | 2024-12-02 19:58:03 +0300 |
commit | a5ab816c9434022159548ac0d1872160b3c8908d (patch) | |
tree | a4e68c334f2a514f02afd65a1bb70eff415fb8cd /tui.go | |
parent | 8d3997baff25f28c23441699be7692f853cf1f0f (diff) |
Feat: add character card support
Diffstat (limited to 'tui.go')
-rw-r--r-- | tui.go | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -2,6 +2,7 @@ package main import ( "elefant/models" + "elefant/pngmeta" "fmt" "strconv" "time" @@ -119,22 +120,27 @@ func init() { }) sysModal = tview.NewModal(). SetText("Switch sys msg:"). - AddButtons(sysLabels). SetDoneFunc(func(buttonIndex int, buttonLabel string) { switch buttonLabel { case "cancel": pages.RemovePage("sys") return default: - sysMsg, ok := sysMap[buttonLabel] + cc, ok := sysMap[buttonLabel] if !ok { logger.Warn("no such sys msg", "name", buttonLabel) pages.RemovePage("sys") return } - chatBody.Messages[0].Content = sysMsg + // to replace it old role in text + // oldRole := chatBody.Messages[0].Role + // replace every role with char + // chatBody.Messages[0].Content = cc.SysPrompt + // chatBody.Messages[1].Content = cc.FirstMsg + applyCharCard(cc) // replace textview textView.SetText(chatToText(cfg.ShowSys)) + sysModal.ClearButtons() pages.RemovePage("sys") } }) @@ -312,6 +318,22 @@ func init() { } if event.Key() == tcell.KeyCtrlS { // switch sys prompt + cards, err := pngmeta.ReadDirCards(cfg.SysDir, cfg.UserRole) + if err != nil { + logger.Error("failed to read sys dir", "error", err) + if err := notifyUser("error", "failed to read: "+cfg.SysDir); err != nil { + logger.Debug("failed to notify user", "error", err) + } + return nil + } + labels := []string{} + labels = append(labels, sysLabels...) + for _, cc := range cards { + labels = append(labels, cc.Role) + sysMap[cc.Role] = cc + } + sysModal.AddButtons(labels) + // load all chars pages.AddPage("sys", sysModal, true, true) return nil } |