Eric Bower
·
16 May 24
senpai.go
1package tui
2
3import (
4 "io"
5
6 tea "github.com/charmbracelet/bubbletea"
7 "github.com/picosh/pico/shared"
8 "github.com/picosh/pico/tui/common"
9)
10
11type SenpaiCmd struct {
12 shared common.SharedModel
13}
14
15func (m *SenpaiCmd) Run() error {
16 pass, err := m.shared.Dbpool.UpsertToken(m.shared.User.ID, "pico-chat")
17 if err != nil {
18 return err
19 }
20 app, err := shared.NewSenpaiApp(m.shared.Session, m.shared.User.Name, pass)
21 if err != nil {
22 return err
23 }
24 app.Run()
25 app.Close()
26 return nil
27}
28
29func (m *SenpaiCmd) SetStdin(io.Reader) {}
30func (m *SenpaiCmd) SetStdout(io.Writer) {}
31func (m *SenpaiCmd) SetStderr(io.Writer) {}
32
33func LoadChat(shrd common.SharedModel) tea.Cmd {
34 sp := &SenpaiCmd{
35 shared: shrd,
36 }
37 return tea.Exec(sp, func(err error) tea.Msg {
38 return tea.Quit()
39 })
40}