diff --git a/doClean.go b/doClean.go index d5d2e86..8497d02 100644 --- a/doClean.go +++ b/doClean.go @@ -36,7 +36,7 @@ func scanTmp() { if !strings.HasPrefix(fname, "regex.") { return nil } - if count > 10 { + if count > 100 { return log.Errorf("count exceeded") } if strings.HasPrefix(fname, "regex.gemini-api-response") { diff --git a/windowBook.go b/windowBook.go new file mode 100644 index 0000000..b90e91a --- /dev/null +++ b/windowBook.go @@ -0,0 +1,95 @@ +// 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" +) + +func makeBookWindow(all *chatpb.Books) *gadgets.GenericWindow { + bookWin := gadgets.NewGenericWindow("regex Books", "Display Books") + bookWin.Win.Custom = func() { + log.Info("test delete window here") + } + grid := bookWin.Group.RawGrid() + + var t *chatpb.BooksTable + grid.NewButton("show", func() { + if t != nil { + log.Info("Delete the table first") + return + } + // display the protobuf + t = addBooksPB(bookWin, all) + f := func(chat *chatpb.Book) { + log.Info("got to BookTable.Custom() id =", chat.GetUuid(), chat.GetTitle()) + } + 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 = addBooksPB(bookWin, all) + f := func(chat *chatpb.Book) { + log.Info("got to BookTable.Custom() id =", chat.GetUuid(), chat.GetTitle()) + } + t.Custom(f) + log.Info("table has uuid", t.GetUuid()) + + return bookWin +} + +func addBooksPB(win *gadgets.GenericWindow, pb *chatpb.Books) *chatpb.BooksTable { + t := pb.NewTable("testForgeRepos") + t.NewUuid() + tbox := win.Bottom.Box().SetProgName("TBOX") + t.SetParent(tbox) + + sf := t.AddStringFunc("uuid", func(r *chatpb.Book) string { + return r.GetUuid() + }) + sf.Custom = func(r *chatpb.Book) { + 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.Book) string { return "show" }) + bf.Custom = func(r *chatpb.Book) { + log.Info("todo: show a chat window here", r.GetUuid()) + } + + // show the age of the chat + t.AddTimeFunc("age", func(book *chatpb.Book) time.Time { + return book.GetCtime().AsTime() + }) + t.AddTitle() + + // make a button to show content in the *genai.GeminiRequest structures + genaiButton := t.AddButtonFunc("# of parts", func(book *chatpb.Book) string { + if book.GeminiRequest == nil { + return "nil" + } + var req = book.GeminiRequest + return fmt.Sprintf("%d", len(req.Contents)) + }) + genaiButton.Custom = func(book *chatpb.Book) { + log.Info("show *genai.GeminiRequsts for", book.GetUuid()) + } + + // draw the tabel (send the gui protobuf to the GO plugin) + t.ShowTable() + return t +} diff --git a/windowChats.go b/windowChats.go index 39906b7..14e09ac 100644 --- a/windowChats.go +++ b/windowChats.go @@ -129,9 +129,30 @@ func addChatsPB(win *gadgets.GenericWindow, pb *chatpb.Chats) *chatpb.ChatsTable genaiButton.Custom = func(chat *chatpb.Chat) { log.Info("show *genai.GeminiRequsts for", chat.GetUuid()) chat.PrintChatGeminiTable() + pb := makeBooksTable(chat) + makeBookWindow(pb) } // draw the tabel (send the gui protobuf to the GO plugin) t.ShowTable() return t } + +func makeBooksTable(chat *chatpb.Chat) *chatpb.Books { + var pb *chatpb.Books + + pb = chatpb.NewBooks() + + for _, entry := range chat.GetEntries() { + if entry.GeminiRequest == nil { + continue + } + newb := new(chatpb.Book) + newb.Ctime = entry.Ctime + newb.Uuid = entry.Uuid + newb.From = entry.From + newb.GeminiRequest = entry.GeminiRequest + pb.Append(newb) + } + return pb +}