Skip to content

Commit

Permalink
fix(palette): use jj color mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
idursun committed Mar 6, 2025
1 parent 5faac9c commit 49154a6
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 109 deletions.
135 changes: 52 additions & 83 deletions internal/ui/common/styles.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,96 +21,65 @@ var (
IntenseWhite = lipgloss.Color("15")
)

var ()

var commitShortStyle = lipgloss.NewStyle().
Bold(true).
Foreground(Blue)

var commitIdRestStyle = lipgloss.NewStyle().
Foreground(IntenseBlack)

var authorStyle = lipgloss.NewStyle().
Foreground(Yellow)

var timestampStyle = lipgloss.NewStyle().
Foreground(Cyan)

var branchesStyle = lipgloss.NewStyle().
Foreground(Blue)

var conflictStyle = lipgloss.NewStyle().
Foreground(Red)

var normal = lipgloss.NewStyle().
Foreground(White)

var selected = lipgloss.NewStyle().
Foreground(Red)

var emptyStyle = lipgloss.NewStyle().
Bold(true).
Foreground(Green)

var nonEmptyStyle = lipgloss.NewStyle().
Bold(true).
Foreground(Yellow)

var DropStyle = lipgloss.NewStyle().
Bold(true).
Foreground(Black).
Background(Red)

var DefaultPalette = Palette{
CommitShortStyle: commitShortStyle,
CommitIdRestStyle: commitIdRestStyle,
AuthorStyle: authorStyle,
TimestampStyle: timestampStyle,
BookmarksStyle: branchesStyle,
ConflictStyle: conflictStyle,
Empty: emptyStyle,
NonEmpty: nonEmptyStyle,
Normal: normal,
Selected: selected,
ConfirmationText: lipgloss.NewStyle().Bold(true).Foreground(Magenta),
Button: lipgloss.NewStyle().Foreground(White).PaddingLeft(2).PaddingRight(2),
FocusedButton: lipgloss.NewStyle().Foreground(IntenseWhite).Background(Blue).PaddingLeft(2).PaddingRight(2),
ListTitle: lipgloss.NewStyle().Bold(true).Foreground(White),
ListItem: lipgloss.NewStyle().Foreground(Cyan).PaddingLeft(1).PaddingRight(1),
Added: lipgloss.NewStyle().Foreground(Green),
Deleted: lipgloss.NewStyle().Foreground(Red),
Modified: lipgloss.NewStyle().Foreground(Cyan),
Renamed: lipgloss.NewStyle().Foreground(Cyan),
Hint: lipgloss.NewStyle().Foreground(IntenseBlack).PaddingLeft(1),
StatusNormal: lipgloss.NewStyle(),
StatusSuccess: lipgloss.NewStyle().Foreground(Green),
StatusError: lipgloss.NewStyle().Foreground(Red),
StatusMode: lipgloss.NewStyle().Foreground(Black).Background(IntenseBlue),
ChangeId: lipgloss.NewStyle().Foreground(Magenta).Bold(true),
CommitId: lipgloss.NewStyle().Foreground(Blue).Bold(true),
Rest: lipgloss.NewStyle().Foreground(IntenseBlack),
Author: lipgloss.NewStyle().Foreground(Yellow),
Timestamp: lipgloss.NewStyle().Foreground(Cyan),
Bookmarks: lipgloss.NewStyle().Foreground(Magenta),
Conflict: lipgloss.NewStyle().Foreground(Red),
EmptyPlaceholder: lipgloss.NewStyle().Foreground(Green).Bold(true),
Placeholder: lipgloss.NewStyle().Foreground(Yellow).Bold(true),
Normal: lipgloss.NewStyle().Foreground(White),
Selected: lipgloss.NewStyle().Foreground(Red),
Elided: lipgloss.NewStyle().Foreground(IntenseBlack),
ConfirmationText: lipgloss.NewStyle().Foreground(Magenta).Bold(true),
Button: lipgloss.NewStyle().Foreground(White).PaddingLeft(2).PaddingRight(2),
FocusedButton: lipgloss.NewStyle().Foreground(IntenseWhite).Background(Blue).PaddingLeft(2).PaddingRight(2),
ListTitle: lipgloss.NewStyle().Foreground(White).Bold(true),
ListItem: lipgloss.NewStyle().Foreground(Cyan).PaddingLeft(1).PaddingRight(1),
Added: lipgloss.NewStyle().Foreground(Green),
Deleted: lipgloss.NewStyle().Foreground(Red),
Modified: lipgloss.NewStyle().Foreground(Cyan),
Renamed: lipgloss.NewStyle().Foreground(Cyan),
Hint: lipgloss.NewStyle().Foreground(IntenseBlack).PaddingLeft(1),
StatusNormal: lipgloss.NewStyle(),
StatusSuccess: lipgloss.NewStyle().Foreground(Green),
StatusError: lipgloss.NewStyle().Foreground(Red),
StatusMode: lipgloss.NewStyle().Foreground(Black).Bold(true).Background(Magenta),
}

type Palette struct {
CommitShortStyle lipgloss.Style
CommitIdRestStyle lipgloss.Style
AuthorStyle lipgloss.Style
TimestampStyle lipgloss.Style
BookmarksStyle lipgloss.Style
ConflictStyle lipgloss.Style
Empty lipgloss.Style
NonEmpty lipgloss.Style
Normal lipgloss.Style
Selected lipgloss.Style
ConfirmationText lipgloss.Style
Button lipgloss.Style
FocusedButton lipgloss.Style
ListTitle lipgloss.Style
ListItem lipgloss.Style
Added lipgloss.Style
Deleted lipgloss.Style
Modified lipgloss.Style
Renamed lipgloss.Style
Hint lipgloss.Style
StatusNormal lipgloss.Style
StatusMode lipgloss.Style
StatusSuccess lipgloss.Style
StatusError lipgloss.Style
Normal lipgloss.Style
ChangeId lipgloss.Style
CommitId lipgloss.Style
Rest lipgloss.Style
Author lipgloss.Style
Timestamp lipgloss.Style
Bookmarks lipgloss.Style
Conflict lipgloss.Style
EmptyPlaceholder lipgloss.Style
Placeholder lipgloss.Style
Selected lipgloss.Style
ConfirmationText lipgloss.Style
Button lipgloss.Style
FocusedButton lipgloss.Style
ListTitle lipgloss.Style
ListItem lipgloss.Style
Added lipgloss.Style
Deleted lipgloss.Style
Modified lipgloss.Style
Renamed lipgloss.Style
Hint lipgloss.Style
StatusNormal lipgloss.Style
StatusMode lipgloss.Style
StatusSuccess lipgloss.Style
StatusError lipgloss.Style
Elided lipgloss.Style
}
22 changes: 11 additions & 11 deletions internal/ui/graph/graph_row_renderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s SegmentedRenderer) RenderGlyph(connection jj.ConnectionType, commit *jj.
}

func (s SegmentedRenderer) RenderTermination(connection jj.ConnectionType) string {
return s.Palette.CommitIdRestStyle.Render(string(connection))
return s.Palette.Elided.Render(string(connection))
}

func (s SegmentedRenderer) RenderChangeId(commit *jj.Commit) string {
Expand All @@ -51,28 +51,28 @@ func (s SegmentedRenderer) RenderChangeId(commit *jj.Commit) string {
hidden = s.Palette.Normal.Render(" hidden")
}

return fmt.Sprintf("%s%s %s", s.Palette.CommitShortStyle.Render(commit.ChangeIdShort), s.Palette.CommitIdRestStyle.Render(commit.ChangeId[len(commit.ChangeIdShort):]), hidden)
return fmt.Sprintf("%s%s %s", s.Palette.ChangeId.Render(commit.ChangeIdShort), s.Palette.Rest.Render(commit.ChangeId[len(commit.ChangeIdShort):]), hidden)
}

func (s SegmentedRenderer) RenderCommitId(commit *jj.Commit) string {
if commit.IsRoot() {
return ""
}
return s.Palette.CommitShortStyle.Render(commit.CommitIdShort) + s.Palette.CommitIdRestStyle.Render(commit.CommitId[len(commit.ChangeIdShort):])
return s.Palette.CommitId.Render(commit.CommitIdShort) + s.Palette.Rest.Render(commit.CommitId[len(commit.ChangeIdShort):])
}

func (s SegmentedRenderer) RenderAuthor(commit *jj.Commit) string {
if commit.IsRoot() {
return s.Palette.Empty.Render("root()")
return s.Palette.EmptyPlaceholder.Render("root()")
}
return s.Palette.AuthorStyle.Render(commit.Author)
return s.Palette.Author.Render(commit.Author)
}

func (s SegmentedRenderer) RenderDate(commit *jj.Commit) string {
if commit.IsRoot() {
return ""
}
return s.Palette.TimestampStyle.Render(commit.Timestamp)
return s.Palette.Timestamp.Render(commit.Timestamp)
}

func (s SegmentedRenderer) RenderBookmarks(commit *jj.Commit) string {
Expand All @@ -81,14 +81,14 @@ func (s SegmentedRenderer) RenderBookmarks(commit *jj.Commit) string {
w.WriteString(s.Op.Render())
}
if len(commit.Bookmarks) > 0 {
w.WriteString(s.Palette.BookmarksStyle.Render(strings.Join(commit.Bookmarks, " ")))
w.WriteString(s.Palette.Bookmarks.Render(strings.Join(commit.Bookmarks, " ")))
}
return w.String()
}

func (s SegmentedRenderer) RenderMarkers(commit *jj.Commit) string {
if commit.Conflict {
return s.Palette.ConflictStyle.Render("conflict")
return s.Palette.Conflict.Render("conflict")
}
return ""
}
Expand All @@ -99,14 +99,14 @@ func (s SegmentedRenderer) RenderDescription(commit *jj.Commit) string {
}
var w strings.Builder
if commit.Empty {
w.WriteString(s.Palette.Empty.Render("(empty)"))
w.WriteString(s.Palette.EmptyPlaceholder.Render("(empty)"))
w.WriteString(" ")
}
if commit.Description == "" {
if commit.Empty {
w.WriteString(s.Palette.Empty.Render("(no description set)"))
w.WriteString(s.Palette.EmptyPlaceholder.Render("(no description set)"))
} else {
w.WriteString(s.Palette.NonEmpty.Render("(no description set)"))
w.WriteString(s.Palette.Placeholder.Render("(no description set)"))
}
} else {
w.WriteString(s.Palette.Normal.Render(commit.Description))
Expand Down
8 changes: 4 additions & 4 deletions internal/ui/helppage/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func (h *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
}

var (
keyStyle = common.DefaultPalette.CommitShortStyle
descStyle = common.DefaultPalette.CommitIdRestStyle
keyStyle = common.DefaultPalette.ChangeId
descStyle = common.DefaultPalette.Rest
)

func printHelp(k key.Binding) string {
Expand All @@ -70,12 +70,12 @@ func printHelpExt(key string, desc string) string {
}

func printHeader(header string) string {
return common.DefaultPalette.Empty.Render(header)
return common.DefaultPalette.EmptyPlaceholder.Render(header)
}

func printMode(key key.Binding, name string) string {
keyAligned := fmt.Sprintf("%9s", key.Help().Key)
help := fmt.Sprintf("%v %s", keyStyle.Render(keyAligned), common.DefaultPalette.Empty.Render(name))
help := fmt.Sprintf("%v %s", keyStyle.Render(keyAligned), common.DefaultPalette.EmptyPlaceholder.Render(name))
return help
}

Expand Down
10 changes: 5 additions & 5 deletions internal/ui/operations/rebase/rebase_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ func (r *Operation) Render() string {
lipgloss.Left,
common.DropStyle.Render("<< "+ret+" >>"),
" ",
common.DefaultPalette.CommitIdRestStyle.Render("rebase"),
common.DefaultPalette.Rest.Render("rebase"),
" ",
common.DefaultPalette.CommitIdRestStyle.Render(source),
common.DefaultPalette.CommitShortStyle.Render(r.From),
common.DefaultPalette.Rest.Render(source),
common.DefaultPalette.ChangeId.Render(r.From),
" ",
common.DefaultPalette.CommitIdRestStyle.Render(ret),
common.DefaultPalette.Rest.Render(ret),
" ",
common.DefaultPalette.CommitShortStyle.Render(r.To.ChangeIdShort),
common.DefaultPalette.ChangeId.Render(r.To.ChangeIdShort),
)
}

Expand Down
8 changes: 4 additions & 4 deletions internal/ui/revset/revset.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ func (m Model) IsFocused() bool {
}

var (
promptStyle = common.DefaultPalette.CommitShortStyle
cursorStyle = common.DefaultPalette.Empty
promptStyle = common.DefaultPalette.ChangeId
cursorStyle = common.DefaultPalette.EmptyPlaceholder
)

type keymap struct{}
Expand Down Expand Up @@ -132,8 +132,8 @@ func New(defaultRevSet string) Model {
ti.SetValue(defaultRevSet)

h := help.New()
h.Styles.ShortKey = common.DefaultPalette.CommitShortStyle
h.Styles.ShortDesc = common.DefaultPalette.CommitIdRestStyle
h.Styles.ShortKey = common.DefaultPalette.ChangeId
h.Styles.ShortDesc = common.DefaultPalette.Rest
return Model{
Editing: false,
Value: defaultRevSet,
Expand Down
4 changes: 2 additions & 2 deletions internal/ui/status/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func New(context context.AppContext) Model {
s := spinner.New()
s.Spinner = spinner.Dot
h := help.New()
h.Styles.ShortKey = common.DefaultPalette.CommitShortStyle
h.Styles.ShortDesc = common.DefaultPalette.CommitIdRestStyle
h.Styles.ShortKey = common.DefaultPalette.ChangeId
h.Styles.ShortDesc = common.DefaultPalette.Rest
h.ShortSeparator = " "
return Model{
context: context,
Expand Down

0 comments on commit 49154a6

Please sign in to comment.