Skip to content

Commit

Permalink
feat: impl iterm colors converter
Browse files Browse the repository at this point in the history
  • Loading branch information
shiron-dev committed Dec 19, 2024
1 parent 637746e commit 51851ed
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 26 deletions.
8 changes: 8 additions & 0 deletions internal/converter/iterm.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ func GetItermTheme(cfgPath string, outPath string) error {

func colorsModelToItermColorsModel(colors *model.ColorsModel) *model.ItermColorsModel {
return &model.ItermColorsModel{
Foreground: colors.Foreground,
BoldColor: colors.HiForeground,
Background: colors.Background,
MatchBackground: colors.MatchBackground,
SelectionColor: colors.BackgroundAccent,
LinkColor: colors.ForegroundAccent,
BadgeColor: colors.ForegroundAccent,

Check warning on line 68 in internal/converter/iterm.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/iterm.go#L61-L68

Added lines #L61 - L68 were not covered by tests
TerminalAnsi: colors.TerminalAnsi,
}
}
1 change: 1 addition & 0 deletions internal/converter/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type ColorsModel struct {
SecondaryForeground string `yaml:"secondaryForeground"`
ForegroundAccent string `yaml:"foregroundAccent"`
WarningForeground string `yaml:"warningForeground"`
LinkForeground string `yaml:"linkForeground"`

Background string `yaml:"background"`
EditorBackground string `yaml:"editorBackground"`
Expand Down
71 changes: 45 additions & 26 deletions internal/converter/model/iterm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ type ItermColor struct {

//nolint:govet
type ItermPlistModel struct {
Ansi0Color ItermColor `xml:"Ansi 0 Color"`
Ansi1Color ItermColor `xml:"Ansi 1 Color"`
Ansi2Color ItermColor `xml:"Ansi 2 Color"`
Ansi3Color ItermColor `xml:"Ansi 3 Color"`
Ansi4Color ItermColor `xml:"Ansi 4 Color"`
Ansi5Color ItermColor `xml:"Ansi 5 Color"`
Ansi6Color ItermColor `xml:"Ansi 6 Color"`
Ansi7Color ItermColor `xml:"Ansi 7 Color"`
Ansi8Color ItermColor `xml:"Ansi 8 Color"`
Ansi9Color ItermColor `xml:"Ansi 9 Color"`
Ansi10Color ItermColor `xml:"Ansi 10 Color"`
Ansi11Color ItermColor `xml:"Ansi 11 Color"`
Ansi12Color ItermColor `xml:"Ansi 12 Color"`
Ansi13Color ItermColor `xml:"Ansi 13 Color"`
Ansi14Color ItermColor `xml:"Ansi 14 Color"`
Ansi15Color ItermColor `xml:"Ansi 15 Color"`
BackgroundColor ItermColor `xml:"Background Color"`
BadgeColor ItermColor `xml:"Badge Color"`
BoldColor ItermColor `xml:"Bold Color"`
CursorColor ItermColor `xml:"Cursor Color"`
CursorGuideColor ItermColor `xml:"Cursor Guide Color"`
Ansi0Color ItermColor `xml:"Ansi 0 Color"`

Check failure on line 18 in internal/converter/model/iterm.go

View workflow job for this annotation

GitHub Actions / golang-vet-check

struct field tag `xml:"Ansi 0 Color"` not compatible with reflect.StructTag.Get: suspicious space in struct tag value
Ansi1Color ItermColor `xml:"Ansi 1 Color"`

Check failure on line 19 in internal/converter/model/iterm.go

View workflow job for this annotation

GitHub Actions / golang-vet-check

struct field tag `xml:"Ansi 1 Color"` not compatible with reflect.StructTag.Get: suspicious space in struct tag value
Ansi2Color ItermColor `xml:"Ansi 2 Color"`

Check failure on line 20 in internal/converter/model/iterm.go

View workflow job for this annotation

GitHub Actions / golang-vet-check

struct field tag `xml:"Ansi 2 Color"` not compatible with reflect.StructTag.Get: suspicious space in struct tag value
Ansi3Color ItermColor `xml:"Ansi 3 Color"`

Check failure on line 21 in internal/converter/model/iterm.go

View workflow job for this annotation

GitHub Actions / golang-vet-check

struct field tag `xml:"Ansi 3 Color"` not compatible with reflect.StructTag.Get: suspicious space in struct tag value
Ansi4Color ItermColor `xml:"Ansi 4 Color"`

Check failure on line 22 in internal/converter/model/iterm.go

View workflow job for this annotation

GitHub Actions / golang-vet-check

struct field tag `xml:"Ansi 4 Color"` not compatible with reflect.StructTag.Get: suspicious space in struct tag value
Ansi5Color ItermColor `xml:"Ansi 5 Color"`

Check failure on line 23 in internal/converter/model/iterm.go

View workflow job for this annotation

GitHub Actions / golang-vet-check

struct field tag `xml:"Ansi 5 Color"` not compatible with reflect.StructTag.Get: suspicious space in struct tag value
Ansi6Color ItermColor `xml:"Ansi 6 Color"`

Check failure on line 24 in internal/converter/model/iterm.go

View workflow job for this annotation

GitHub Actions / golang-vet-check

struct field tag `xml:"Ansi 6 Color"` not compatible with reflect.StructTag.Get: suspicious space in struct tag value
Ansi7Color ItermColor `xml:"Ansi 7 Color"`

Check failure on line 25 in internal/converter/model/iterm.go

View workflow job for this annotation

GitHub Actions / golang-vet-check

struct field tag `xml:"Ansi 7 Color"` not compatible with reflect.StructTag.Get: suspicious space in struct tag value
Ansi8Color ItermColor `xml:"Ansi 8 Color"`

Check failure on line 26 in internal/converter/model/iterm.go

View workflow job for this annotation

GitHub Actions / golang-vet-check

struct field tag `xml:"Ansi 8 Color"` not compatible with reflect.StructTag.Get: suspicious space in struct tag value
Ansi9Color ItermColor `xml:"Ansi 9 Color"`

Check failure on line 27 in internal/converter/model/iterm.go

View workflow job for this annotation

GitHub Actions / golang-vet-check

struct field tag `xml:"Ansi 9 Color"` not compatible with reflect.StructTag.Get: suspicious space in struct tag value
Ansi10Color ItermColor `xml:"Ansi 10 Color"`
Ansi11Color ItermColor `xml:"Ansi 11 Color"`
Ansi12Color ItermColor `xml:"Ansi 12 Color"`
Ansi13Color ItermColor `xml:"Ansi 13 Color"`
Ansi14Color ItermColor `xml:"Ansi 14 Color"`
Ansi15Color ItermColor `xml:"Ansi 15 Color"`
BackgroundColor ItermColor `xml:"Background Color"`
BadgeColor ItermColor `xml:"Badge Color"`
BoldColor ItermColor `xml:"Bold Color"`
CursorColor ItermColor `xml:"Cursor Color"`
// CursorGuideColor ItermColor `xml:"Cursor Guide Color"`
CursorTextColor ItermColor `xml:"Cursor Text Color"`
ForegroundColor ItermColor `xml:"Foreground Color"`
LinkColor ItermColor `xml:"Link Color"`
Expand All @@ -45,11 +45,30 @@ type ItermPlistModel struct {
}

type ItermColorsModel struct {
Foreground string
BoldColor string
Background string
MatchBackground string
SelectionColor string
BadgeColor string
LinkColor string

TerminalAnsi TerminalAnsiModel
}

func ItermColorsModelToPlistModel(model *ItermColorsModel) *ItermPlistModel {
return &ItermPlistModel{
ForegroundColor: hexToItermColor(model.Foreground),
BoldColor: hexToItermColor(model.BoldColor),
BackgroundColor: hexToItermColor(model.Background),
MatchBackgroundColor: hexToItermColor(model.MatchBackground + "70"),
CursorColor: hexToItermColor(model.Foreground),
CursorTextColor: hexToItermColor(model.BoldColor),
SelectedTextColor: hexToItermColor(model.Foreground),
SelectionColor: hexToItermColor(model.SelectionColor + "70"),
BadgeColor: hexToItermColor(model.BadgeColor),
LinkColor: hexToItermColor(model.LinkColor),

Check warning on line 71 in internal/converter/model/iterm.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/model/iterm.go#L61-L71

Added lines #L61 - L71 were not covered by tests
Ansi0Color: hexToItermColor(model.TerminalAnsi.TerminalAnsiBlack),
Ansi1Color: hexToItermColor(model.TerminalAnsi.TerminalAnsiRed),
Ansi2Color: hexToItermColor(model.TerminalAnsi.TerminalAnsiGreen),
Expand Down Expand Up @@ -85,23 +104,23 @@ func hexToItermColor(hex string) ItermColor {

alpha := 1.0
if len(hex)%3 != 0 {
alpha, _ = hexSingleColorToRGBFloat(hex[len(hex)-len(hex)/4-1:])
alpha, _ = hexSingleColorToRGBFloat(hex[len(hex)-len(hex)/4:])

Check warning on line 107 in internal/converter/model/iterm.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/model/iterm.go#L107

Added line #L107 was not covered by tests
hex = hex[:len(hex)-len(hex)/4]
}

red, err := hexSingleColorToRGBFloat(hex[len(hex)/3:])
red, err := hexSingleColorToRGBFloat(hex[:len(hex)/3])

Check warning on line 111 in internal/converter/model/iterm.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/model/iterm.go#L111

Added line #L111 was not covered by tests
if err != nil {
red = 0
}

hex = hex[:len(hex)-len(hex)/3]
hex = hex[len(hex)/3:]

Check warning on line 116 in internal/converter/model/iterm.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/model/iterm.go#L116

Added line #L116 was not covered by tests

green, err := hexSingleColorToRGBFloat(hex[len(hex)/2:])
green, err := hexSingleColorToRGBFloat(hex[:len(hex)/2])

Check warning on line 118 in internal/converter/model/iterm.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/model/iterm.go#L118

Added line #L118 was not covered by tests
if err != nil {
green = 0
}

hex = hex[:len(hex)-len(hex)/2]
hex = hex[len(hex)/2:]

Check warning on line 123 in internal/converter/model/iterm.go

View check run for this annotation

Codecov / codecov/patch

internal/converter/model/iterm.go#L123

Added line #L123 was not covered by tests

blue, err := hexSingleColorToRGBFloat(hex)
if err != nil {
Expand Down

0 comments on commit 51851ed

Please sign in to comment.