]> git.giacomolli.uk - onechat/blobdiff - terminal_markdown.go
Check the width of comment lines
[onechat] / terminal_markdown.go
index a13a4e949a2ea3cb2b25681be298617d411dab5f..73ae7d572d900a8c41eb60d7ffcc03ec3d6ae641 100644 (file)
@@ -46,7 +46,7 @@ func terminalMarkdown(text string, columns int) []string {
                        index = end
                case strings.TrimSpace(line) == "---":
                        out = append(out, "\x1b[2m"+strings.Repeat("-", columns)+"\x1b[0m")
-               case index+1 < len(lines) && terminalMarkdownSeparator(lines[index+1]) && len(terminalMarkdownCells(line)) > 1:
+               case index+1 < len(lines) && terminalMarkdownSeparator(lines[index+1]):
                        rows := [][]string{terminalMarkdownCells(line)}
                        index += 2
                        for index < len(lines) && strings.Contains(lines[index], "|") && strings.TrimSpace(lines[index]) != "" {
@@ -135,7 +135,7 @@ func terminalMarkdownPlain(text string, style int) []TerminalMarkdownGlyph {
 // terminalMarkdownSeparator tells if a line is a Markdown table separator.
 func terminalMarkdownSeparator(line string) bool {
        cells := terminalMarkdownCells(line)
-       if len(cells) < 2 {
+       if !strings.Contains(line, "|") {
                return false
        }
 
@@ -219,10 +219,14 @@ func terminalMarkdownTable(rows [][]string, columns int) []string {
        if required > columns {
                var out []string
 
-               for _, row := range cells {
-                       for _, cell := range row {
+               for row, values := range cells {
+                       for _, cell := range values {
                                out = append(out, terminalMarkdownLines(cell, columns, "", false)...)
                        }
+
+                       if row == 0 {
+                               out = append(out, "\x1b[2m"+strings.Repeat("-", columns)+"\x1b[0m")
+                       }
                }
 
                return out