]> git.giacomolli.uk - onechat/blobdiff - view.go
Name and order the ChatGPT login code
[onechat] / view.go
diff --git a/view.go b/view.go
index 70182d0114470f36df90543f70a7faab103a086b..a75b1d8418fc9857d6aafbf38a822c989a817d77 100644 (file)
--- a/view.go
+++ b/view.go
@@ -280,15 +280,25 @@ func (v *View) lineSize(line nodeKey) int {
 // Render returns the view as the model reads it: one line "id+n|text" for each
 // node inside <chat> tags, with the newlines of the text as spaces.
 func (v *View) Render() string {
 // Render returns the view as the model reads it: one line "id+n|text" for each
 // node inside <chat> tags, with the newlines of the text as spaces.
 func (v *View) Render() string {
-       var text strings.Builder
-       text.WriteString("<chat>\n")
+       return "<chat>\n" + strings.Join(v.LinesWithout(nil), "") + "</chat>"
+}
+
+// LinesWithout returns the lines of the view as the model reads them, each with
+// its newline, without the leaf lines of the messages in skip. A line that
+// merges such a message with others stays.
+func (v *View) LinesWithout(skip map[int]bool) []string {
+       lines := make([]string, 0, len(v.lines))
        for _, line := range v.lines {
        for _, line := range v.lines {
+               if line.level == 0 && skip[line.index] {
+                       continue
+               }
+
+               var text strings.Builder
                v.renderLine(&text, line)
                v.renderLine(&text, line)
+               lines = append(lines, text.String())
        }
 
        }
 
-       text.WriteString("</chat>")
-
-       return text.String()
+       return lines
 }
 
 // renderLine writes one view line, "id+n|text", and a newline.
 }
 
 // renderLine writes one view line, "id+n|text", and a newline.