Skip to content

Commit

Permalink
Merge pull request #53 from wader/dim
Browse files Browse the repository at this point in the history
Support dimmed text
  • Loading branch information
wader authored Dec 18, 2024
2 parents e5699a6 + dd12773 commit 6ac745e
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ansidecoder/ansidecoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (cr codeRange) Is(c int) bool {

var sgrReset = codeRange{0, 0}
var sgrIncreaseIntensity = codeRange{1, 1}
var sgrDim = codeRange{2, 2}
var sgrNormal = codeRange{22, 22}
var sgrForeground = codeRange{30, 37}
var sgrForegroundBright = codeRange{90, 97}
Expand Down Expand Up @@ -78,6 +79,7 @@ type Decoder struct {
Background Color
Underline bool
Intensity bool
Dim bool
Invert bool
Italic bool
Strikethrough bool
Expand Down Expand Up @@ -218,13 +220,17 @@ func (d *Decoder) ReadRune() (r rune, size int, err error) {
d.Background = Color{N: -1}
d.Underline = false
d.Intensity = false
d.Dim = false
d.Invert = false
d.Italic = false
d.Strikethrough = false
case sgrIncreaseIntensity.Is(n):
d.Intensity = true
case sgrNormal.Is(n):
d.Intensity = false
d.Dim = false
case sgrDim.Is(n):
d.Dim = true
case sgrForeground.Is(n):
d.Foreground = Color{N: n - 30}
case sgrForegroundBright.Is(n):
Expand Down
1 change: 1 addition & 0 deletions ansitosvg/ansisvg.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func Convert(r io.Reader, w io.Writer, opts Options) error {
Background: ad.Background.String(),
Underline: ad.Underline,
Intensity: ad.Intensity,
Dim: ad.Dim,
Invert: ad.Invert,
Italic: ad.Italic,
Strikethrough: ad.Strikethrough,
Expand Down
1 change: 1 addition & 0 deletions cli/testdata/dim_bightblack.ansi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello dim brightblack
24 changes: 24 additions & 0 deletions cli/testdata/dim_bightblack.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions cli/testdata/dim_intense_background_invert.ansi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello dim intense background inverted world
35 changes: 35 additions & 0 deletions cli/testdata/dim_intense_background_invert.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions cli/testdata/dim_uv.ansi
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Using Python 3.11.10 environment at: env3.11
Audited 1 package in 2ms
26 changes: 26 additions & 0 deletions cli/testdata/dim_uv.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 8 additions & 1 deletion svgscreen/svgscreen.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ import (
_ "embed"
"encoding/base64"
"fmt"
"github.com/wader/ansisvg/svgscreen/xydim"
"html/template"
"io"
"strconv"
"strings"

"github.com/wader/ansisvg/svgscreen/xydim"
)

//go:embed template.svg
Expand All @@ -22,6 +23,7 @@ type Char struct {
Background string
Underline bool
Intensity bool
Dim bool
Invert bool
Italic bool
Strikethrough bool
Expand Down Expand Up @@ -69,6 +71,7 @@ type SvgDom struct {
Italic bool
Underline bool
Strikethrough bool
Dim bool
}
}

Expand Down Expand Up @@ -148,6 +151,10 @@ func (s *Screen) charToFgText(c Char) textSpan {
classes = append(classes, "bold")
s.Dom.ClassesUsed.Bold = true
}
if c.Dim {
classes = append(classes, "dim")
s.Dom.ClassesUsed.Dim = true
}
if c.Italic {
classes = append(classes, "italic")
s.Dom.ClassesUsed.Italic = true
Expand Down
5 changes: 5 additions & 0 deletions svgscreen/template.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6ac745e

Please sign in to comment.