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
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/muesli/termenv

go 1.17

replace github.com/muesli/termenv => github.com/rahji/termenv v0.16.1

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1
github.com/lucasb-eyer/go-colorful v1.3.0
Expand Down
16 changes: 15 additions & 1 deletion style.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ func (t Style) String() string {

// Styled renders s with all applied styles.
func (t Style) Styled(s string) string {
return t.styled(s, true)
}

// Styled renders s with all applied styles, but no trailing reset
func (t Style) StyledWithoutReset(s string) string {
return t.styled(s, false)
}

// styled is a private function that is called by both Styled and StyledWithout Reset
func (t Style) styled(s string, reset bool) string {
if t.profile == Ascii {
return s
}
Expand All @@ -53,7 +63,11 @@ func (t Style) Styled(s string) string {
return s
}

return fmt.Sprintf("%s%sm%s%sm", CSI, seq, s, CSI+ResetSeq)
var end string
if reset {
end = fmt.Sprintf("%s%sm", CSI, ResetSeq)
}
return fmt.Sprintf("%s%sm%s%s", CSI, seq, s, end)
}

// Foreground sets a foreground color.
Expand Down