Skip to content

Commit 6ac745e

Browse files
authored
Merge pull request #53 from wader/dim
Support dimmed text
2 parents e5699a6 + dd12773 commit 6ac745e

File tree

10 files changed

+109
-1
lines changed

10 files changed

+109
-1
lines changed

ansidecoder/ansidecoder.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func (cr codeRange) Is(c int) bool {
3232

3333
var sgrReset = codeRange{0, 0}
3434
var sgrIncreaseIntensity = codeRange{1, 1}
35+
var sgrDim = codeRange{2, 2}
3536
var sgrNormal = codeRange{22, 22}
3637
var sgrForeground = codeRange{30, 37}
3738
var sgrForegroundBright = codeRange{90, 97}
@@ -78,6 +79,7 @@ type Decoder struct {
7879
Background Color
7980
Underline bool
8081
Intensity bool
82+
Dim bool
8183
Invert bool
8284
Italic bool
8385
Strikethrough bool
@@ -218,13 +220,17 @@ func (d *Decoder) ReadRune() (r rune, size int, err error) {
218220
d.Background = Color{N: -1}
219221
d.Underline = false
220222
d.Intensity = false
223+
d.Dim = false
221224
d.Invert = false
222225
d.Italic = false
223226
d.Strikethrough = false
224227
case sgrIncreaseIntensity.Is(n):
225228
d.Intensity = true
226229
case sgrNormal.Is(n):
227230
d.Intensity = false
231+
d.Dim = false
232+
case sgrDim.Is(n):
233+
d.Dim = true
228234
case sgrForeground.Is(n):
229235
d.Foreground = Color{N: n - 30}
230236
case sgrForegroundBright.Is(n):

ansitosvg/ansisvg.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ func Convert(r io.Reader, w io.Writer, opts Options) error {
7474
Background: ad.Background.String(),
7575
Underline: ad.Underline,
7676
Intensity: ad.Intensity,
77+
Dim: ad.Dim,
7778
Invert: ad.Invert,
7879
Italic: ad.Italic,
7980
Strikethrough: ad.Strikethrough,

cli/testdata/dim_bightblack.ansi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello dim brightblack

cli/testdata/dim_bightblack.svg

Lines changed: 24 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
hello dim intense background inverted world
Lines changed: 35 additions & 0 deletions
Loading

cli/testdata/dim_uv.ansi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Using Python 3.11.10 environment at: env3.11
2+
Audited 1 package in 2ms

cli/testdata/dim_uv.svg

Lines changed: 26 additions & 0 deletions
Loading

svgscreen/svgscreen.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
_ "embed"
66
"encoding/base64"
77
"fmt"
8-
"github.com/wader/ansisvg/svgscreen/xydim"
98
"html/template"
109
"io"
1110
"strconv"
1211
"strings"
12+
13+
"github.com/wader/ansisvg/svgscreen/xydim"
1314
)
1415

1516
//go:embed template.svg
@@ -22,6 +23,7 @@ type Char struct {
2223
Background string
2324
Underline bool
2425
Intensity bool
26+
Dim bool
2527
Invert bool
2628
Italic bool
2729
Strikethrough bool
@@ -69,6 +71,7 @@ type SvgDom struct {
6971
Italic bool
7072
Underline bool
7173
Strikethrough bool
74+
Dim bool
7275
}
7376
}
7477

@@ -148,6 +151,10 @@ func (s *Screen) charToFgText(c Char) textSpan {
148151
classes = append(classes, "bold")
149152
s.Dom.ClassesUsed.Bold = true
150153
}
154+
if c.Dim {
155+
classes = append(classes, "dim")
156+
s.Dom.ClassesUsed.Dim = true
157+
}
151158
if c.Italic {
152159
classes = append(classes, "italic")
153160
s.Dom.ClassesUsed.Italic = true

svgscreen/template.svg

Lines changed: 5 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)