From f3f03edba8a51475503cc9c11144fa316a4abe1f Mon Sep 17 00:00:00 2001 From: Patrick Huesmann Date: Thu, 25 Jan 2024 11:05:13 +0100 Subject: [PATCH 1/4] Remove for empty background section --- svgscreen/template.svg | 2 ++ 1 file changed, 2 insertions(+) diff --git a/svgscreen/template.svg b/svgscreen/template.svg index ccd4651..0f04384 100644 --- a/svgscreen/template.svg +++ b/svgscreen/template.svg @@ -65,11 +65,13 @@ whitespace only tspan:s preventing underline to be properly rendered. {{- if not .Transparent}} {{- end}} +{{- if len $.Dom.BgRects}} {{- range $ri, $r := .Dom.BgRects}} {{- end}} +{{- end}} {{- range $li, $l := .Dom.TextElements}} {{- range $si, $s := $l.TextSpans}}{{$s.Content}}{{- /* no new line */ -}}{{- end}} From a438648fede0710615792e5e902cd55b5ec775fe Mon Sep 17 00:00:00 2001 From: Patrick Huesmann Date: Thu, 25 Jan 2024 11:40:18 +0100 Subject: [PATCH 2/4] Use CSS classes for font style & decoration --- svgscreen/svgscreen.go | 47 +++++++++++++++++++++++++----------------- svgscreen/template.svg | 22 +++++++++++++++++++- 2 files changed, 49 insertions(+), 20 deletions(-) diff --git a/svgscreen/svgscreen.go b/svgscreen/svgscreen.go index 34f72de..b58f6e7 100644 --- a/svgscreen/svgscreen.go +++ b/svgscreen/svgscreen.go @@ -37,11 +37,9 @@ type BoxSize struct { } type textSpan struct { - X string - Style template.CSS - Decoration template.CSS - Color string - Content string + X string + Class string + Content string } type textElement struct { @@ -68,6 +66,12 @@ type SvgDom struct { BgCustomColors []string BgRects []bgRect TextElements []textElement + ClassesUsed struct { + Bold bool + Italic bool + Underline bool + Strikethrough bool + } } type ColorMap struct { @@ -133,26 +137,32 @@ func (s *Screen) resolveColor(c string, cmap *ColorMap) string { } func (s *Screen) charToFgText(c Char) textSpan { - var styles []string - deco := "" + var classes []string if c.Intensity { - styles = append(styles, "font-weight:bold") + classes = append(classes, "bold") + s.Dom.ClassesUsed.Bold = true } if c.Italic { - styles = append(styles, "font-style:italic") + classes = append(classes, "italic") + s.Dom.ClassesUsed.Italic = true } if c.Underline { - deco = "underline" + classes = append(classes, "underline") + s.Dom.ClassesUsed.Underline = true } else if c.Strikethrough { - deco = "line-through" + classes = append(classes, "strikethrough") + s.Dom.ClassesUsed.Strikethrough = true + } + + color := s.resolveColor(c.Foreground, &s.Foreground) + if color != "" { + classes = append(classes, color) } return textSpan{ - Style: template.CSS(strings.Join(styles, ";")), - Decoration: template.CSS(deco), - Color: s.resolveColor(c.Foreground, &s.Foreground), - Content: c.Char, + Class: strings.Join(classes, " "), + Content: c.Char, } } @@ -161,9 +171,8 @@ func (s *Screen) charToFgText(c Char) textSpan { func (s *Screen) lineToTextElement(l Line) textElement { var t []textSpan currentSpan := textSpan{ - Style: "", - Decoration: "", - Content: "", + Class: "", + Content: "", } appendSpan := func() { @@ -179,7 +188,7 @@ func (s *Screen) lineToTextElement(l Line) textElement { tempSpan.X = s.columnCoordinate(col) } // Consolidate tempSpan to currentSpan only if not in grid mode and both spans have same style - if s.GridMode || tempSpan.Color != currentSpan.Color || tempSpan.Style != currentSpan.Style || tempSpan.Decoration != currentSpan.Decoration { + if s.GridMode || tempSpan.Class != currentSpan.Class { appendSpan() currentSpan = tempSpan continue diff --git a/svgscreen/template.svg b/svgscreen/template.svg index 0f04384..33a5a56 100644 --- a/svgscreen/template.svg +++ b/svgscreen/template.svg @@ -33,6 +33,26 @@ whitespace only tspan:s preventing underline to be properly rendered. .bg { stroke-width: "0.5px"; } +{{- if $.Dom.ClassesUsed.Bold}} + .bold { + font-weight: bold; + } +{{- end}} +{{- if $.Dom.ClassesUsed.Italic}} + .italic { + font-style: italic; + } +{{- end}} +{{- if $.Dom.ClassesUsed.Underline}} + .underline { + text-decoration: underline; + } +{{- end}} +{{- if $.Dom.ClassesUsed.Strikethrough}} + .strikethrough { + text-decoration: line-through; + } +{{- end}} {{- if anyColorUsed $.Background.ANSIUsed}} {{- end}} @@ -74,7 +94,7 @@ whitespace only tspan:s preventing underline to be properly rendered. {{- end}} {{- range $li, $l := .Dom.TextElements}} -{{- range $si, $s := $l.TextSpans}}{{$s.Content}}{{- /* no new line */ -}}{{- end}} +{{- range $si, $s := $l.TextSpans}}{{$s.Content}}{{- end}} {{- end}} From 5d3139ea893fc71343fdf118ec38ee127258c320 Mon Sep 17 00:00:00 2001 From: Patrick Huesmann Date: Thu, 25 Jan 2024 12:01:59 +0100 Subject: [PATCH 3/4] Consolidate whitespace regardless of CSS class --- svgscreen/svgscreen.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/svgscreen/svgscreen.go b/svgscreen/svgscreen.go index b58f6e7..30b9a10 100644 --- a/svgscreen/svgscreen.go +++ b/svgscreen/svgscreen.go @@ -182,18 +182,23 @@ func (s *Screen) lineToTextElement(l Line) textElement { t = append(t, currentSpan) } for col, c := range l.Chars { - tempSpan := s.charToFgText(c) + newSpan := s.charToFgText(c) if s.GridMode { - // If in grid mode, set X coordinate for each text span - tempSpan.X = s.columnCoordinate(col) + // In grid mode, set X coordinate for each text span + newSpan.X = s.columnCoordinate(col) + // In grid mode, we never consolidate + appendSpan() + currentSpan = newSpan + continue } - // Consolidate tempSpan to currentSpan only if not in grid mode and both spans have same style - if s.GridMode || tempSpan.Class != currentSpan.Class { + // Don't consolidate if class is changing, but ignore whitespace + if newSpan.Class != currentSpan.Class && strings.TrimSpace(newSpan.Content) != "" { appendSpan() - currentSpan = tempSpan + currentSpan = newSpan continue } - currentSpan.Content += tempSpan.Content + // Consolidate new content with previous one. + currentSpan.Content += newSpan.Content } appendSpan() From 997415bbbb09dc8a9b5a8cfeb672a21296d51549 Mon Sep 17 00:00:00 2001 From: Patrick Huesmann Date: Fri, 26 Jan 2024 16:36:04 +0100 Subject: [PATCH 4/4] Update testdata --- cli/testdata/b-it-ul-st.svg | 24 +++-- cli/testdata/charboxfontsize.svg | 2 - cli/testdata/colortest.svg | 37 ++++--- cli/testdata/colortest_slate.svg | 37 ++++--- cli/testdata/colortest_transparent.svg | 37 ++++--- cli/testdata/cowsay-osc-colon-color.svg | 18 ++-- cli/testdata/fontembedded.svg | 2 - cli/testdata/fontname.svg | 2 - cli/testdata/fontref.svg | 2 - cli/testdata/fq.svg | 19 ++-- cli/testdata/invert_color.svg | 2 +- cli/testdata/invert_default.svg | 2 +- cli/testdata/jq.svg | 27 ++--- cli/testdata/main.go.bat.svg | 100 +++++++++--------- cli/testdata/nonewline.svg | 2 - cli/testdata/onechar.svg | 2 - cli/testdata/onecharnewline.svg | 2 - cli/testdata/oneline.svg | 2 - cli/testdata/params-colon-semicolon.svg | 2 +- cli/testdata/powerline.svg | 5 +- cli/testdata/tabs.svg | 2 - cli/testdata/terminal-colors-n.svg | 28 ++--- cli/testdata/terminalwidth4.svg | 2 - cli/testdata/underlinedefault.svg | 9 +- cli/testdata/underlinenewline.svg | 9 +- cli/testdata/underlinetabs.svg | 21 ++-- .../underlinetabs_backgroundcolor.svg | 21 ++-- 27 files changed, 213 insertions(+), 205 deletions(-) diff --git a/cli/testdata/b-it-ul-st.svg b/cli/testdata/b-it-ul-st.svg index 855ac4a..7d1b9ed 100644 --- a/cli/testdata/b-it-ul-st.svg +++ b/cli/testdata/b-it-ul-st.svg @@ -13,16 +13,26 @@ .bg { stroke-width: "0.5px"; } + .bold { + font-weight: bold; + } + .italic { + font-style: italic; + } + .underline { + text-decoration: underline; + } + .strikethrough { + text-decoration: line-through; + } - - regular -bold -italic -bold italic -underline -strikethrough +bold +italic +bold italic +underline +strikethrough diff --git a/cli/testdata/charboxfontsize.svg b/cli/testdata/charboxfontsize.svg index 29fae3e..1aedbdf 100644 --- a/cli/testdata/charboxfontsize.svg +++ b/cli/testdata/charboxfontsize.svg @@ -15,8 +15,6 @@ } - - hello world diff --git a/cli/testdata/colortest.svg b/cli/testdata/colortest.svg index 0313fcf..d17f932 100644 --- a/cli/testdata/colortest.svg +++ b/cli/testdata/colortest.svg @@ -13,6 +13,9 @@ .bg { stroke-width: "0.5px"; } + .bold { + font-weight: bold; + } .ba0 { stroke: #000000; fill: #000000; } .ba1 { stroke: #bb0000; fill: #bb0000; } @@ -182,22 +185,22 @@ 40m 41m 42m 43m 44m 45m 46m 47m m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 30m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;30m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 31m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;31m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 32m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;32m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 33m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;33m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 34m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;34m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 35m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;35m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 36m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;36m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 37m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;37m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 30m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;30m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 31m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;31m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 32m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;32m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 33m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;33m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 34m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;34m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 35m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;35m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 36m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;36m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 37m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;37m gYw gYw gYw gYw gYw gYw gYw gYw gYw diff --git a/cli/testdata/colortest_slate.svg b/cli/testdata/colortest_slate.svg index c909e99..964fdfa 100644 --- a/cli/testdata/colortest_slate.svg +++ b/cli/testdata/colortest_slate.svg @@ -13,6 +13,9 @@ .bg { stroke-width: "0.5px"; } + .bold { + font-weight: bold; + } .ba0 { stroke: #222222; fill: #222222; } .ba1 { stroke: #e2a8bf; fill: #e2a8bf; } @@ -182,22 +185,22 @@ 40m 41m 42m 43m 44m 45m 46m 47m m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 30m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;30m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 31m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;31m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 32m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;32m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 33m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;33m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 34m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;34m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 35m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;35m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 36m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;36m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 37m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;37m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 30m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;30m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 31m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;31m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 32m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;32m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 33m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;33m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 34m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;34m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 35m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;35m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 36m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;36m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 37m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;37m gYw gYw gYw gYw gYw gYw gYw gYw gYw diff --git a/cli/testdata/colortest_transparent.svg b/cli/testdata/colortest_transparent.svg index d9750ca..73203f4 100644 --- a/cli/testdata/colortest_transparent.svg +++ b/cli/testdata/colortest_transparent.svg @@ -13,6 +13,9 @@ .bg { stroke-width: "0.5px"; } + .bold { + font-weight: bold; + } .ba0 { stroke: #000000; fill: #000000; } .ba1 { stroke: #bb0000; fill: #bb0000; } @@ -181,22 +184,22 @@ 40m 41m 42m 43m 44m 45m 46m 47m m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 30m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;30m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 31m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;31m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 32m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;32m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 33m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;33m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 34m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;34m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 35m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;35m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 36m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;36m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 37m gYw gYw gYw gYw gYw gYw gYw gYw gYw - 1;37m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 30m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;30m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 31m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;31m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 32m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;32m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 33m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;33m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 34m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;34m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 35m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;35m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 36m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;36m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 37m gYw gYw gYw gYw gYw gYw gYw gYw gYw + 1;37m gYw gYw gYw gYw gYw gYw gYw gYw gYw diff --git a/cli/testdata/cowsay-osc-colon-color.svg b/cli/testdata/cowsay-osc-colon-color.svg index 692ca09..224210a 100644 --- a/cli/testdata/cowsay-osc-colon-color.svg +++ b/cli/testdata/cowsay-osc-colon-color.svg @@ -62,16 +62,14 @@ .fc45 { fill: #fd324f; } - - - ____________ -< Hello ANSI > - ------------ - \ ^__^ - \ (oo)\_______ - (__)\ )\/\ - ||----w | - || || + ____________ +< Hello ANSI > + ------------ + \ ^__^ + \ (oo)\_______ + (__)\ )\/\ + ||----w | + || || diff --git a/cli/testdata/fontembedded.svg b/cli/testdata/fontembedded.svg index 9b32783..1bc4b06 100644 --- a/cli/testdata/fontembedded.svg +++ b/cli/testdata/fontembedded.svg @@ -19,8 +19,6 @@ } - - test diff --git a/cli/testdata/fontname.svg b/cli/testdata/fontname.svg index 49ddab6..21dd3ac 100644 --- a/cli/testdata/fontname.svg +++ b/cli/testdata/fontname.svg @@ -15,8 +15,6 @@ } - - test diff --git a/cli/testdata/fontref.svg b/cli/testdata/fontref.svg index 198ad16..0d7035f 100644 --- a/cli/testdata/fontref.svg +++ b/cli/testdata/fontref.svg @@ -19,8 +19,6 @@ } - - test diff --git a/cli/testdata/fq.svg b/cli/testdata/fq.svg index 186d2da..8081a81 100644 --- a/cli/testdata/fq.svg +++ b/cli/testdata/fq.svg @@ -13,6 +13,9 @@ .bg { stroke-width: "0.5px"; } + .underline { + text-decoration: underline; + } .fa3 { fill: #bbbb00; } .fa6 { fill: #00bbbb; } @@ -22,17 +25,15 @@ .fa15 { fill: #ffffff; } - - - |00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.: {} ../fq/testfiles/test.mp3 (mp3) -0x000|49 44 33 04 00 00 00 00 00 32 54 50 45 31 00 00|ID3......2TPE1..| headers: [1] -* |until 0x3b.7 (60) | | -0x030| ff fb 50 00| ..P.| frames: [3] -0x040|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00|................| -* |until 0x44e.7 (1043) | | + |00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|.: {} ../fq/testfiles/test.mp3 (mp3) +0x000|49 44 33 04 00 00 00 00 00 32 54 50 45 31 00 00|ID3......2TPE1..| headers: [1] +* |until 0x3b.7 (60) | | +0x030| ff fb 50 00| ..P.| frames: [3] +0x040|00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00|................| +* |until 0x44e.7 (1043) | | | | | footers: [0] 0x440| 61| a| unknown0: 61736461 -0x450|73 64 61| |sda| | +0x450|73 64 61| |sda| | diff --git a/cli/testdata/invert_color.svg b/cli/testdata/invert_color.svg index 8639aa9..b29e4ec 100644 --- a/cli/testdata/invert_color.svg +++ b/cli/testdata/invert_color.svg @@ -27,6 +27,6 @@ - red yellow red + red yellow red diff --git a/cli/testdata/invert_default.svg b/cli/testdata/invert_default.svg index 9fde64e..3c2cdae 100644 --- a/cli/testdata/invert_default.svg +++ b/cli/testdata/invert_default.svg @@ -23,6 +23,6 @@ - black write black + black write black diff --git a/cli/testdata/jq.svg b/cli/testdata/jq.svg index 8820416..2c04aee 100644 --- a/cli/testdata/jq.svg +++ b/cli/testdata/jq.svg @@ -13,24 +13,25 @@ .bg { stroke-width: "0.5px"; } + .bold { + font-weight: bold; + } .fa2 { fill: #00bb00; } .fa4 { fill: #0000bb; } - - -{ - "true": true, - "false": false, - "string": "string", - "number": 123.1, - "array": [ - 1, - 2, - 3 - ] -} +{ + "true": true, + "false": false, + "string": "string", + "number": 123.1, + "array": [ + 1, + 2, + 3 + ] +} diff --git a/cli/testdata/main.go.bat.svg b/cli/testdata/main.go.bat.svg index 8eff74a..87b6ae7 100644 --- a/cli/testdata/main.go.bat.svg +++ b/cli/testdata/main.go.bat.svg @@ -24,64 +24,62 @@ .fc7 { fill: #be84ff; } - - -package main -import ( - "flag" - "fmt" - "os" - "strconv" - "strings" - "github.com/wader/ansisvg/ansitosvg" +package main +import ( + "flag" + "fmt" + "os" + "strconv" + "strings" + "github.com/wader/ansisvg/ansitosvg" ) -type boxSize struct { - Width int - Height int +type boxSize struct { + Width int + Height int } -func (d *boxSize) String() string { - return fmt.Sprintf("%dx%d", d.Width, d.Height) +func (d *boxSize) String() string { + return fmt.Sprintf("%dx%d", d.Width, d.Height) } -func (d *boxSize) Set(s string) error { - parts := strings.Split(s, "x") - if len(parts) != 2 { - return fmt.Errorf("must be WxH") - } - d.Width, _ = strconv.Atoi(parts[0]) - d.Height, _ = strconv.Atoi(parts[1]) - return nil +func (d *boxSize) Set(s string) error { + parts := strings.Split(s, "x") + if len(parts) != 2 { + return fmt.Errorf("must be WxH") + } + d.Width, _ = strconv.Atoi(parts[0]) + d.Height, _ = strconv.Atoi(parts[1]) + return nil } -var fontFlag = flag.String("font", ansisvg.DefaultOptions.Font, "Font") -var fontSizeFlag = flag.Int("fontsize", ansisvg.DefaultOptions.FontSize, "Font size") -var terminalWidthFlag = flag.Int("width", 0, "Terminal width (auto)") -var characterBoxSize = boxSize{ - Width: ansisvg.DefaultOptions.CharacterBoxSize.Width, - Height: ansisvg.DefaultOptions.CharacterBoxSize.Height, +var fontFlag = flag.String("font", ansisvg.DefaultOptions.Font, "Font") +var fontSizeFlag = flag.Int("fontsize", ansisvg.DefaultOptions.FontSize, "Font size") +var terminalWidthFlag = flag.Int("width", 0, "Terminal width (auto)") +var characterBoxSize = boxSize{ + Width: ansisvg.DefaultOptions.CharacterBoxSize.Width, + Height: ansisvg.DefaultOptions.CharacterBoxSize.Height, } -var colorSchemeFlag = flag.String("colorscheme", ansisvg.DefaultOptions.ColorScheme, "Color scheme") -func init() { - flag.Var(&characterBoxSize, "charboxsize", "Character box size") +var colorSchemeFlag = flag.String("colorscheme", ansisvg.DefaultOptions.ColorScheme, "Color scheme") +func init() { + flag.Var(&characterBoxSize, "charboxsize", "Character box size") } -func main() { - flag.Parse() - if err := ansisvg.Convert( - os.Stdin, - os.Stdout, - ansisvg.Options{ - Font: *fontFlag, - FontSize: *fontSizeFlag, - TerminalWidth: *terminalWidthFlag, - CharacterBoxSize: ansisvg.BoxSize{ - Width: characterBoxSize.Width, - Height: characterBoxSize.Height, - }, - ColorScheme: *colorSchemeFlag, - }, - ); err != nil { - fmt.Fprintln(os.Stderr, err) - os.Exit(1) - } +func main() { + flag.Parse() + if err := ansisvg.Convert( + os.Stdin, + os.Stdout, + ansisvg.Options{ + Font: *fontFlag, + FontSize: *fontSizeFlag, + TerminalWidth: *terminalWidthFlag, + CharacterBoxSize: ansisvg.BoxSize{ + Width: characterBoxSize.Width, + Height: characterBoxSize.Height, + }, + ColorScheme: *colorSchemeFlag, + }, + ); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } } diff --git a/cli/testdata/nonewline.svg b/cli/testdata/nonewline.svg index dc99d3f..90e8906 100644 --- a/cli/testdata/nonewline.svg +++ b/cli/testdata/nonewline.svg @@ -15,8 +15,6 @@ } - - nonewline diff --git a/cli/testdata/onechar.svg b/cli/testdata/onechar.svg index ad93f32..32265e5 100644 --- a/cli/testdata/onechar.svg +++ b/cli/testdata/onechar.svg @@ -15,8 +15,6 @@ } - - a diff --git a/cli/testdata/onecharnewline.svg b/cli/testdata/onecharnewline.svg index ad93f32..32265e5 100644 --- a/cli/testdata/onecharnewline.svg +++ b/cli/testdata/onecharnewline.svg @@ -15,8 +15,6 @@ } - - a diff --git a/cli/testdata/oneline.svg b/cli/testdata/oneline.svg index dfe1103..26517bb 100644 --- a/cli/testdata/oneline.svg +++ b/cli/testdata/oneline.svg @@ -15,8 +15,6 @@ } - - oneline diff --git a/cli/testdata/params-colon-semicolon.svg b/cli/testdata/params-colon-semicolon.svg index ae32a17..db2c995 100644 --- a/cli/testdata/params-colon-semicolon.svg +++ b/cli/testdata/params-colon-semicolon.svg @@ -23,6 +23,6 @@ - params with mix colon semicolon red bg + params with mix colon semicolon red bg diff --git a/cli/testdata/powerline.svg b/cli/testdata/powerline.svg index bc9bdae..905352b 100644 --- a/cli/testdata/powerline.svg +++ b/cli/testdata/powerline.svg @@ -17,6 +17,9 @@ .bg { stroke-width: "0.5px"; } + .bold { + font-weight: bold; + } .ba3 { stroke: #bbbb00; fill: #bbbb00; } .ba4 { stroke: #0000bb; fill: #0000bb; } @@ -64,6 +67,6 @@ patrick@zenbook ~/src/ansisvg svgscreen-rewrite ± patrick@zenbook ~/src/ansisvg svgscreen-rewrite patrick@zenbook ~/src/ansisvg svgscreen-rewrite - 0 9h 52m 1 zsh 2 zsh + 0 9h 52m 1 zsh 2 zsh diff --git a/cli/testdata/tabs.svg b/cli/testdata/tabs.svg index 0c0bb3e..2ea3ac9 100644 --- a/cli/testdata/tabs.svg +++ b/cli/testdata/tabs.svg @@ -15,8 +15,6 @@ } - - 0 0 1 1 diff --git a/cli/testdata/terminal-colors-n.svg b/cli/testdata/terminal-colors-n.svg index a6b55d8..6f3f8e1 100644 --- a/cli/testdata/terminal-colors-n.svg +++ b/cli/testdata/terminal-colors-n.svg @@ -534,21 +534,21 @@ System colors: - 0 1 2 3 4 5 6 7 - 8 9 10 11 12 13 14 15 + 0 1 2 3 4 5 6 7 + 8 9 10 11 12 13 14 15 6x6x6 color cube and greyscale: - 16 22 28 34 40 46 52 58 64 70 76 82 88 94 100 106 112 118 - 17 23 29 35 41 47 53 59 65 71 77 83 89 95 101 107 113 119 - 18 24 30 36 42 48 54 60 66 72 78 84 90 96 102 108 114 120 - 19 25 31 37 43 49 55 61 67 73 79 85 91 97 103 109 115 121 - 20 26 32 38 44 50 56 62 68 74 80 86 92 98 104 110 116 122 - 21 27 33 39 45 51 57 63 69 75 81 87 93 99 105 111 117 123 -124 130 136 142 148 154 160 166 172 178 184 190 196 202 208 214 220 226 -125 131 137 143 149 155 161 167 173 179 185 191 197 203 209 215 221 227 -126 132 138 144 150 156 162 168 174 180 186 192 198 204 210 216 222 228 -127 133 139 145 151 157 163 169 175 181 187 193 199 205 211 217 223 229 -128 134 140 146 152 158 164 170 176 182 188 194 200 206 212 218 224 230 -129 135 141 147 153 159 165 171 177 183 189 195 201 207 213 219 225 231 + 16 22 28 34 40 46 52 58 64 70 76 82 88 94 100 106 112 118 + 17 23 29 35 41 47 53 59 65 71 77 83 89 95 101 107 113 119 + 18 24 30 36 42 48 54 60 66 72 78 84 90 96 102 108 114 120 + 19 25 31 37 43 49 55 61 67 73 79 85 91 97 103 109 115 121 + 20 26 32 38 44 50 56 62 68 74 80 86 92 98 104 110 116 122 + 21 27 33 39 45 51 57 63 69 75 81 87 93 99 105 111 117 123 +124 130 136 142 148 154 160 166 172 178 184 190 196 202 208 214 220 226 +125 131 137 143 149 155 161 167 173 179 185 191 197 203 209 215 221 227 +126 132 138 144 150 156 162 168 174 180 186 192 198 204 210 216 222 228 +127 133 139 145 151 157 163 169 175 181 187 193 199 205 211 217 223 229 +128 134 140 146 152 158 164 170 176 182 188 194 200 206 212 218 224 230 +129 135 141 147 153 159 165 171 177 183 189 195 201 207 213 219 225 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 diff --git a/cli/testdata/terminalwidth4.svg b/cli/testdata/terminalwidth4.svg index cdee554..d097d32 100644 --- a/cli/testdata/terminalwidth4.svg +++ b/cli/testdata/terminalwidth4.svg @@ -15,8 +15,6 @@ } - - 012345689 diff --git a/cli/testdata/underlinedefault.svg b/cli/testdata/underlinedefault.svg index f919d36..e73d9d2 100644 --- a/cli/testdata/underlinedefault.svg +++ b/cli/testdata/underlinedefault.svg @@ -13,12 +13,13 @@ .bg { stroke-width: "0.5px"; } + .underline { + text-decoration: underline; + } - - -under -line +under +line diff --git a/cli/testdata/underlinenewline.svg b/cli/testdata/underlinenewline.svg index f919d36..e73d9d2 100644 --- a/cli/testdata/underlinenewline.svg +++ b/cli/testdata/underlinenewline.svg @@ -13,12 +13,13 @@ .bg { stroke-width: "0.5px"; } + .underline { + text-decoration: underline; + } - - -under -line +under +line diff --git a/cli/testdata/underlinetabs.svg b/cli/testdata/underlinetabs.svg index fcb8d47..c954895 100644 --- a/cli/testdata/underlinetabs.svg +++ b/cli/testdata/underlinetabs.svg @@ -13,6 +13,9 @@ .bg { stroke-width: "0.5px"; } + .underline { + text-decoration: underline; + } .ba4 { stroke: #0000bb; fill: #0000bb; } @@ -23,14 +26,14 @@ -0 0 -1 1 -2 2 -3 3 -4 4 -5 5 -6 6 -7 7 -8 8 +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8 diff --git a/cli/testdata/underlinetabs_backgroundcolor.svg b/cli/testdata/underlinetabs_backgroundcolor.svg index b46cff3..43491bf 100644 --- a/cli/testdata/underlinetabs_backgroundcolor.svg +++ b/cli/testdata/underlinetabs_backgroundcolor.svg @@ -13,6 +13,9 @@ .bg { stroke-width: "0.5px"; } + .underline { + text-decoration: underline; + } .ba4 { stroke: #268bd2; fill: #268bd2; } @@ -23,14 +26,14 @@ -0 0 -1 1 -2 2 -3 3 -4 4 -5 5 -6 6 -7 7 -8 8 +0 0 +1 1 +2 2 +3 3 +4 4 +5 5 +6 6 +7 7 +8 8