Skip to content
Open
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
24 changes: 15 additions & 9 deletions internal/svg/svg.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ func parseCast(c *Canvas) {
}

func (c *Canvas) getColors(cell vt10x.Glyph) {
fg := color.GetColor(cell.FG)

if _, ok := c.colors[fg]; !ok {
c.colors[fg] = c.id.String()
c.id.Next()
if cell.FG != vt10x.DefaultFG {
fg := color.GetColor(cell.FG)
if _, ok := c.colors[fg]; !ok {
c.colors[fg] = c.id.String()
c.id.Next()
}
}

if cell.BG != vt10x.DefaultBG {
Expand Down Expand Up @@ -158,10 +159,11 @@ func (c *Canvas) addStyles() {
styles += css.Block{Selector: ".dim", Rules: css.Rules{"opacity": "0.5"}}.String()
// If custom colors have been provided, use them instead
if foregroundColorOverride != "" {
styles += fmt.Sprintf(".a{fill:%s}", foregroundColorOverride)
styles += css.Block{Selector: "text", Rules: css.Rules{"fill": foregroundColorOverride}}.String()
} else {
styles += colors.String()
styles += css.Block{Selector: "text", Rules: css.Rules{"fill": color.GetColor(vt10x.DefaultFG)}}.String()
}
styles += colors.String()
c.Style("text/css", styles)
}

Expand Down Expand Up @@ -222,7 +224,8 @@ func (c *Canvas) renderRow(term vt10x.Terminal, row int) {
}

if strings.TrimSpace(frame) != "" {
c.Text(lastColummn*colWidth, row*rowHeight, frame, fmt.Sprintf(`class="%s"`, c.colors[color.GetColor(lastColor)]))
colorClass := c.buildClassString(lastColor, false, false, false, false)
c.Text(lastColummn*colWidth, row*rowHeight, frame, colorClass)
}
}

Expand All @@ -235,7 +238,10 @@ func (c *Canvas) cellAttributesChanged(
}

func (c *Canvas) buildClassString(fgColor vt10x.Color, bold, italic, underline, dim bool) string {
class := c.colors[color.GetColor(fgColor)]
class := ""
if fgColor != vt10x.DefaultFG {
class = c.colors[color.GetColor(fgColor)]
}
if bold {
class += " bold"
}
Expand Down
12 changes: 6 additions & 6 deletions internal/svg/testdata/TestExportOutput.golden
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@
<g style="animation-duration:3.35s;animation-iteration-count:infinite;animation-name:k;animation-timing-function:steps(1,end);font-family:Monago,Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;font-size:20px">
<style type="text/css">
<![CDATA[
@keyframes k {79.807%{transform:translateX(-0px)}82.298%{transform:translateX(-2596px)}87.777%{transform:translateX(-5192px)}92.767%{transform:translateX(-7788px)}100.000%{transform:translateX(-10384px)}}.bold{font-weight:bold}.italic{font-style:italic}.underline{text-decoration:underline}.dim{opacity:0.5}.a{fill:#e5e5e5}
@keyframes k {79.807%{transform:translateX(-0px)}82.298%{transform:translateX(-2596px)}87.777%{transform:translateX(-5192px)}92.767%{transform:translateX(-7788px)}100.000%{transform:translateX(-10384px)}}.bold{font-weight:bold}.italic{font-style:italic}.underline{text-decoration:underline}.dim{opacity:0.5}text{fill:#e5e5e5}
]]>
</style>
<g transform="translate(0)">
<text x="0" y="0" class="a" >h</text>
<text x="0" y="0" class="" >h</text>
</g>
<g transform="translate(2596)">
<text x="0" y="0" class="a" >he</text>
<text x="0" y="0" class="" >he</text>
</g>
<g transform="translate(5192)">
<text x="0" y="0" class="a" >hel</text>
<text x="0" y="0" class="" >hel</text>
</g>
<g transform="translate(7788)">
<text x="0" y="0" class="a" >hell</text>
<text x="0" y="0" class="" >hell</text>
</g>
<g transform="translate(10384)">
<text x="0" y="0" class="a" >hello</text>
<text x="0" y="0" class="" >hello</text>
</g>
</g>
</g>
Expand Down
12 changes: 6 additions & 6 deletions internal/svg/testdata/TestExportOutputNoWindow.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@
<g style="animation-duration:3.35s;animation-iteration-count:infinite;animation-name:k;animation-timing-function:steps(1,end);font-family:Monago,Monaco,Consolas,Menlo,'Bitstream Vera Sans Mono','Powerline Symbols',monospace;font-size:20px">
<style type="text/css">
<![CDATA[
@keyframes k {79.807%{transform:translateX(-0px)}82.298%{transform:translateX(-2596px)}87.777%{transform:translateX(-5192px)}92.767%{transform:translateX(-7788px)}100.000%{transform:translateX(-10384px)}}.bold{font-weight:bold}.italic{font-style:italic}.underline{text-decoration:underline}.dim{opacity:0.5}.a{fill:#e5e5e5}
@keyframes k {79.807%{transform:translateX(-0px)}82.298%{transform:translateX(-2596px)}87.777%{transform:translateX(-5192px)}92.767%{transform:translateX(-7788px)}100.000%{transform:translateX(-10384px)}}.bold{font-weight:bold}.italic{font-style:italic}.underline{text-decoration:underline}.dim{opacity:0.5}text{fill:#e5e5e5}
]]>
</style>
<g transform="translate(0)">
<text x="0" y="0" class="a" >h</text>
<text x="0" y="0" class="" >h</text>
</g>
<g transform="translate(2596)">
<text x="0" y="0" class="a" >he</text>
<text x="0" y="0" class="" >he</text>
</g>
<g transform="translate(5192)">
<text x="0" y="0" class="a" >hel</text>
<text x="0" y="0" class="" >hel</text>
</g>
<g transform="translate(7788)">
<text x="0" y="0" class="a" >hell</text>
<text x="0" y="0" class="" >hell</text>
</g>
<g transform="translate(10384)">
<text x="0" y="0" class="a" >hello</text>
<text x="0" y="0" class="" >hello</text>
</g>
</g>
</g>
Expand Down