// viewFile is the content of view.json.
type viewFile struct {
- Chat viewState `json:"chat"`
- Compaction viewState `json:"compaction"`
+ Chat ViewState `json:"chat"`
+ Compaction ViewState `json:"compaction"`
}
// openMemory opens the chat in root and starts the builds that are ready. The
func (m *Memory) load() error {
data, err := os.ReadFile(m.viewPath())
if errors.Is(err, os.ErrNotExist) && m.log.Len() == 0 {
- m.chat = newView(chatHigh, chatLow)
- m.cview = newView(compactionHigh, compactionLow)
+ m.chat = newView(viewChatHigh, viewChatLow)
+ m.cview = newView(viewCompactionHigh, viewCompactionLow)
return nil
}
return fmt.Errorf("decode view: %w", err)
}
- m.chat, err = restoreView(file.Chat, chatHigh, chatLow, m.tree)
+ m.chat, err = restoreView(file.Chat, viewChatHigh, viewChatLow, m.tree)
if err != nil {
return fmt.Errorf("chat view: %w", err)
}
- m.cview, err = restoreView(file.Compaction, compactionHigh, compactionLow, m.tree)
+ m.cview, err = restoreView(file.Compaction, viewCompactionHigh, viewCompactionLow, m.tree)
if err != nil {
return fmt.Errorf("compaction view: %w", err)
}
return m.chat.Render()
}
+// ViewLines returns the lines of the chat view, each with its newline, without
+// the leaf lines of the messages in skip.
+func (m *Memory) ViewLines(skip map[int]bool) []string {
+ m.mutex.Lock()
+ defer m.mutex.Unlock()
+
+ return m.chat.LinesWithout(skip)
+}
+
// Len returns the number of messages in the log.
func (m *Memory) Len() int {
m.mutex.Lock()