summaryrefslogtreecommitdiff
path: root/windowChats.go
blob: 39906b764c8116dd4643326c8c0cba625bcf22a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"fmt"
	"time"

	"go.wit.com/lib/gadgets"
	"go.wit.com/lib/protobuf/chatpb"
	"go.wit.com/log"
)

/*
type stdReposTableWin struct {
	sync.Mutex
	win    *gadgets.GenericWindow // the machines gui window
	boxTB  *gui.Node              // the machines gui parent box widget
	TB     *gitpb.ReposTable      // the gui table buffer
	pb     *gitpb.Repos           // the current repos protobuf
	update bool                   // if the window should be updated
}

func (w *stdReposTableWin) Toggle() {
	if w == nil {
		return
	}
	if w.win == nil {
		return
	}
	w.win.Toggle()
}
*/

func makeChatsWindow() *gadgets.GenericWindow {
	insertWin := gadgets.NewGenericWindow("regex Chats", "Display Chats")
	insertWin.Win.Custom = func() {
		log.Info("test delete window here")
	}
	grid := insertWin.Group.RawGrid()

	var t *chatpb.ChatsTable
	grid.NewButton("show", func() {
		if t != nil {
			log.Info("Delete the table first")
			return
		}
		// display the protobuf
		t = addChatsPB(insertWin, me.chats)
		f := func(chat *chatpb.Chat) {
			log.Info("got to ChatTable.Custom() id =", chat.GetUuid(), chat.GetChatName())
		}
		t.Custom(f)
		log.Info("table has uuid", t.GetUuid())
	})

	grid.NewButton("delete PB table", func() {
		if t != nil {
			t.Delete()
			t = nil
			log.Info("Table should have been deleted")
		}
	})
	// display the protobuf
	t = addChatsPB(insertWin, me.chats)
	f := func(chat *chatpb.Chat) {
		log.Info("got to ChatTable.Custom() id =", chat.GetUuid(), chat.GetChatName())
	}
	t.Custom(f)
	log.Info("table has uuid", t.GetUuid())

	return insertWin
}

func addChatsPB(win *gadgets.GenericWindow, pb *chatpb.Chats) *chatpb.ChatsTable {
	t := pb.NewTable("testForgeRepos")
	t.NewUuid()
	tbox := win.Bottom.Box().SetProgName("TBOX")
	t.SetParent(tbox)

	sf := t.AddStringFunc("uuid", func(r *chatpb.Chat) string {
		return r.GetUuid()
	})
	sf.Custom = func(r *chatpb.Chat) {
		log.Info("todo: fix mouseClick() on stringFunc in GUI table", r.GetUuid())
	}

	// add a general show button
	bf := t.AddButtonFunc("cur version", func(chat *chatpb.Chat) string { return "show" })
	bf.Custom = func(r *chatpb.Chat) {
		log.Info("todo: show a chat window here", r.GetUuid())
	}

	// show the age of the chat
	t.AddTimeFunc("age", func(chat *chatpb.Chat) time.Time {
		return chat.GetCtime().AsTime()
	})
	t.AddChatName()

	// make a button to show the ChatEntries
	entryButton := t.AddButtonFunc("Entries", func(chat *chatpb.Chat) string {
		return fmt.Sprintf("%d", len(chat.GetEntries()))
	})
	entryButton.Custom = func(chat *chatpb.Chat) {
		log.Info("show entries for", chat.GetUuid())
		chat.PrintChatEntriesTable()
	}

	// make a button to show the Stats (old stuff from gemini-cli)
	statsButton := t.AddButtonFunc("Stats", func(chat *chatpb.Chat) string {
		return fmt.Sprintf("%d", len(chat.GetSession()))
	})
	statsButton.Custom = func(chat *chatpb.Chat) {
		log.Info("show gemini-cli /stats for", chat.GetUuid())
		chat.PrintChatStatsTable()
	}

	// make a button to show content in the *genai.GeminiRequest structures
	genaiButton := t.AddButtonFunc("# of genai.Req's", func(chat *chatpb.Chat) string {
		var counter int
		for _, entry := range chat.GetEntries() {
			if entry.GeminiRequest != nil {
				counter += 1
			}
		}
		return fmt.Sprintf("%d", counter)
	})
	genaiButton.Custom = func(chat *chatpb.Chat) {
		log.Info("show *genai.GeminiRequsts for", chat.GetUuid())
		chat.PrintChatGeminiTable()
	}

	// draw the tabel (send the gui protobuf to the GO plugin)
	t.ShowTable()
	return t
}