Skip to content

Support dimmed text #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading