From c0d4d51de4f11107988c2970aebdcd8af61450d7 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Mon, 23 May 2022 17:25:27 -0400 Subject: [PATCH] feat: repos list title & styles --- ui/components/code/code.go | 12 +++++++++++- ui/pages/repo/logitem.go | 11 ++++++----- ui/pages/selection/selection.go | 3 ++- ui/ui.go | 5 ++++- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/ui/components/code/code.go b/ui/components/code/code.go index 44ab06ffa3d1983661d7a1bc5cf39dc407535302..18e96655abab0953c81b907a46ed6422349a7c7f 100644 --- a/ui/components/code/code.go +++ b/ui/components/code/code.go @@ -199,7 +199,17 @@ func (r *Code) renderFile(path, content string, width int) (string, error) { Language: lang, } s := strings.Builder{} - err := formatter.Render(&s, r.renderContext) + rc := r.renderContext + if r.showLineNumber { + st := common.StyleConfig() + var m uint = 0 + st.CodeBlock.Margin = &m + rc = gansi.NewRenderContext(gansi.Options{ + ColorProfile: termenv.TrueColor, + Styles: st, + }) + } + err := formatter.Render(&s, rc) if err != nil { return "", err } diff --git a/ui/pages/repo/logitem.go b/ui/pages/repo/logitem.go index 8f1110f94e2760f47a431e45c038527855cd7185..418c14520a1380c268480ce6d19ec86882c5c228 100644 --- a/ui/pages/repo/logitem.go +++ b/ui/pages/repo/logitem.go @@ -74,7 +74,7 @@ func (d LogItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { } var ( - highlight = lipgloss.NewStyle().Foreground(lipgloss.Color("#F1F1F1")) + faint = func(s string) string { return lipgloss.NewStyle().Faint(true).Render(s) } ) // Render renders the item. Implements list.ItemDelegate. @@ -113,17 +113,18 @@ func (d LogItemDelegate) Render(w io.Writer, m list.Model, index int, listItem l hashStyle = hashStyle.Bold(true) } hash = hashStyle.Render(hash) - author := highlight.Render(i.Author.Name) - commiter := highlight.Render(i.Committer.Name) + author := i.Author.Name + commiter := i.Committer.Name who := "" if author != "" && commiter != "" { - who = fmt.Sprintf("%s committed", commiter) + who = commiter + faint(" committed") if author != commiter { - who = fmt.Sprintf("%s authored and %s", author, who) + who = author + faint(" authored and ") + who } who += " " } date := fmt.Sprintf("on %s", i.Committer.When.Format("Feb 02")) + date = faint(date) if i.Committer.When.Year() != time.Now().Year() { date += fmt.Sprintf(" %d", i.Committer.When.Year()) } diff --git a/ui/pages/selection/selection.go b/ui/pages/selection/selection.go index 7f21a2f655a59f9f18c9653e144112b1bf424eba..bef7352140594c8ac703ead94692f5b279fcdc35 100644 --- a/ui/pages/selection/selection.go +++ b/ui/pages/selection/selection.go @@ -43,7 +43,8 @@ func New(s session.Session, common common.Common) *Selection { selector := selector.New(common, []selector.IdentifiableItem{}, ItemDelegate{&common, &sel.activeBox}) - selector.SetShowTitle(false) + selector.SetShowTitle(true) + selector.Title = "Repositories" selector.SetShowHelp(false) selector.SetShowStatusBar(false) selector.DisableQuitKeybindings() diff --git a/ui/ui.go b/ui/ui.go index bf2219a3987bbe2ef946dd5032e92b2c1da20e1d..7bbf72048b17dff9f44479e697d673e6a7495299 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -2,6 +2,7 @@ package ui import ( "log" + "os" "github.com/charmbracelet/bubbles/key" tea "github.com/charmbracelet/bubbletea" @@ -139,7 +140,9 @@ func (ui *UI) Init() tea.Cmd { // Update implements tea.Model. func (ui *UI) Update(msg tea.Msg) (tea.Model, tea.Cmd) { - log.Printf("msg: %T", msg) + if os.Getenv("DEBUG") == "true" { + log.Printf("ui msg: %T", msg) + } cmds := make([]tea.Cmd, 0) switch msg := msg.(type) { case tea.WindowSizeMsg: