| 1 |
package cellbuf |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/charmbracelet/colorprofile" |
| 5 |
) |
| 6 |
|
| 7 |
// ConvertStyle converts a style to respect the given color profile. |
| 8 |
func ConvertStyle(s Style, p colorprofile.Profile) Style { |
| 9 |
switch p { //nolint:exhaustive |
| 10 |
case colorprofile.TrueColor: |
| 11 |
return s |
| 12 |
case colorprofile.Ascii: |
| 13 |
s.Fg = nil |
| 14 |
s.Bg = nil |
| 15 |
s.Ul = nil |
| 16 |
case colorprofile.NoTTY: |
| 17 |
return Style{} |
| 18 |
} |
| 19 |
|
| 20 |
if s.Fg != nil { |
| 21 |
s.Fg = p.Convert(s.Fg) |
| 22 |
} |
| 23 |
if s.Bg != nil { |
| 24 |
s.Bg = p.Convert(s.Bg) |
| 25 |
} |
| 26 |
if s.Ul != nil { |
| 27 |
s.Ul = p.Convert(s.Ul) |
| 28 |
} |
| 29 |
|
| 30 |
return s |
| 31 |
} |