From bdd4898f4d65317371832f86faa62b316bf4062c Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Tue, 20 Dec 2022 00:40:57 +0100 Subject: [PATCH] Adding colours to the feed and an alternative highlighting mechanism --- config/config.go | 59 ++++++++++++++++++++++++++++++++++++++++ config/default_config.go | 14 ++++++++++ ui/composeview.go | 2 +- ui/feed.go | 22 +++++++++++---- ui/item.go | 12 ++++++-- ui/linkview.go | 2 +- ui/loginview.go | 2 +- ui/pollview.go | 2 +- ui/preferenceview.go | 2 +- ui/styled_elements.go | 10 +++++-- ui/voteview.go | 2 +- 11 files changed, 112 insertions(+), 17 deletions(-) diff --git a/config/config.go b/config/config.go index 85ab6bf..0e8f716 100644 --- a/config/config.go +++ b/config/config.go @@ -195,9 +195,11 @@ type Style struct { ListSelectedBackground tcell.Color ListSelectedText tcell.Color + ListSelectedBoldUnderline int ListSelectedInactiveBackground tcell.Color ListSelectedInactiveText tcell.Color + ListSelectedInactiveBoldUnderline int ControlsText tcell.Color ControlsHighlight tcell.Color @@ -217,6 +219,11 @@ type Style struct { IconColor tcell.Color CommandText tcell.Color + + DateTimeText tcell.Color + BoostText tcell.Color + MediaText tcell.Color + CardText tcell.Color } type Media struct { @@ -596,6 +603,8 @@ func parseStyle(cfg *ini.File, cnfPath string, cnfDir string) Style { s = tcfg.Section("").Key("list-selected-text").String() style.ListSelectedText = tcell.GetColor(s) + style.ListSelectedBoldUnderline = tcfg.Section("").Key("list-selected-boldunderline").MustInt(0) + s = tcfg.Section("").Key("list-selected-inactive-background").String() if len(s) > 0 { style.ListSelectedInactiveBackground = tcell.GetColor(s) @@ -685,6 +694,30 @@ func parseStyle(cfg *ini.File, cnfPath string, cnfDir string) Style { } else { style.CommandText = style.StatusBarText } + s = tcfg.Section("").Key("datetime-text").String() + if len(s) > 0 { + style.DateTimeText = tcell.GetColor(s) + } else { + style.DateTimeText = style.Subtle + } + s = tcfg.Section("").Key("boost-text").String() + if len(s) > 0 { + style.BoostText = tcell.GetColor(s) + } else { + style.BoostText = style.Text + } + s = tcfg.Section("").Key("media-text").String() + if len(s) > 0 { + style.MediaText = tcell.GetColor(s) + } else { + style.MediaText = style.Text + } + s = tcfg.Section("").Key("card-text").String() + if len(s) > 0 { + style.CardText = tcell.GetColor(s) + } else { + style.CardText = style.Text + } } else { s := cfg.Section("style").Key("background").String() style.Background = parseColor(s, "#27822", xrdbColors) @@ -728,6 +761,8 @@ func parseStyle(cfg *ini.File, cnfPath string, cnfDir string) Style { s = cfg.Section("style").Key("list-selected-text").String() style.ListSelectedText = parseColor(s, "white", xrdbColors) + style.ListSelectedBoldUnderline = cfg.Section("style").Key("list-selected-boldunderline").MustInt(0) + s = cfg.Section("style").Key("list-selected-inactive-background").String() if len(s) > 0 { style.ListSelectedInactiveBackground = parseColor(s, "#ae81ff", xrdbColors) @@ -811,6 +846,30 @@ func parseStyle(cfg *ini.File, cnfPath string, cnfDir string) Style { } else { style.CommandText = style.StatusBarText } + s = cfg.Section("style").Key("datetime-text").String() + if len(s) > 0 { + style.DateTimeText = parseColor(s, "#808080", xrdbColors) + } else { + style.DateTimeText = style.Subtle + } + s = cfg.Section("style").Key("boost-text").String() + if len(s) > 0 { + style.BoostText = parseColor(s, "white", xrdbColors) + } else { + style.BoostText = style.Text + } + s = cfg.Section("style").Key("media-text").String() + if len(s) > 0 { + style.MediaText = parseColor(s, "white", xrdbColors) + } else { + style.MediaText = style.Text + } + s = cfg.Section("style").Key("card-text").String() + if len(s) > 0 { + style.CardText = parseColor(s, "white", xrdbColors) + } else { + style.CardText = style.Text + } } return style diff --git a/config/default_config.go b/config/default_config.go index ce09bfb..4b7fce8 100644 --- a/config/default_config.go +++ b/config/default_config.go @@ -391,6 +391,8 @@ background= # default= text= + + # The color to display subtle elements or subtle text. Like lines and help text. # default= subtle= @@ -493,6 +495,18 @@ timeline-name-background= # default= timeline-name-text= +# The text color used for date/time in the timeline view +# defaults to the same color as subtle +datetime-text= + +# The text color used for boosts in the timeline view +# defaults to the primary text color +boost-text= + +# The text color used for toots with media or cards in the timeline view +# defaults to the primary text color +media-text= + [input] # You can edit the keys for tut below. # diff --git a/ui/composeview.go b/ui/composeview.go index 990870b..c7d8e5c 100644 --- a/ui/composeview.go +++ b/ui/composeview.go @@ -510,7 +510,7 @@ func NewMediaList(tv *TutView) *MediaList { tutView: tv, heading: NewTextView(tv.tut.Config), text: NewTextView(tv.tut.Config), - list: NewList(tv.tut.Config), + list: NewList(tv.tut.Config, false), } ml.scrollSleep = NewScrollSleep(ml.Next, ml.Prev) ml.heading.SetText(fmt.Sprintf("Media files: %d", ml.list.GetItemCount())) diff --git a/ui/feed.go b/ui/feed.go index a8e3082..de97d1c 100644 --- a/ui/feed.go +++ b/ui/feed.go @@ -28,8 +28,13 @@ func (fl *FeedList) InFocus(style config.Style) { func inFocus(l *tview.List, style config.Style) { l.SetBackgroundColor(style.Background) l.SetMainTextColor(style.Text) - l.SetSelectedBackgroundColor(style.ListSelectedBackground) - l.SetSelectedTextColor(style.ListSelectedText) + l.SetSelectedTextColor(style.ListSelectedText) + if style.ListSelectedBoldUnderline == 1 { + s := tcell.Style.Attributes(tcell.Style{}, tcell.AttrBold | tcell.AttrUnderline) + l.SetSelectedStyle(s) + } else { + l.SetSelectedBackgroundColor(style.ListSelectedBackground) + } } func (fl *FeedList) OutFocus(style config.Style) { @@ -40,8 +45,13 @@ func (fl *FeedList) OutFocus(style config.Style) { func outFocus(l *tview.List, style config.Style) { l.SetBackgroundColor(style.Background) l.SetMainTextColor(style.Text) - l.SetSelectedBackgroundColor(style.ListSelectedInactiveBackground) - l.SetSelectedTextColor(style.ListSelectedInactiveText) + l.SetSelectedTextColor(style.ListSelectedInactiveText) + if style.ListSelectedBoldUnderline == 1 { + s := tcell.Style.Attributes(tcell.Style{}, tcell.AttrBold) + l.SetSelectedStyle(s) + } else { + l.SetSelectedBackgroundColor(style.ListSelectedInactiveBackground) + } } type Feed struct { @@ -513,8 +523,8 @@ func NewFollowRequests(tv *TutView) *Feed { func NewFeedList(t *Tut, stickyCount int) *FeedList { fl := &FeedList{ - Text: NewList(t.Config), - Symbol: NewList(t.Config), + Text: NewList(t.Config, true), + Symbol: NewList(t.Config, true), stickyCount: stickyCount, } return fl diff --git a/ui/item.go b/ui/item.go index 060c587..72323a4 100644 --- a/ui/item.go +++ b/ui/item.go @@ -17,10 +17,12 @@ func DrawListItem(cfg *config.Config, item api.Item) (string, string) { case api.StatusType: s := item.Raw().(*mastodon.Status) symbol := "" + textcolor := cfg.Style.Text status := s if s.Reblog != nil { status = s.Reblog symbol += "♺ " + textcolor = cfg.Style.BoostText } if item.Pinned() { symbol += "! " @@ -38,9 +40,13 @@ func DrawListItem(cfg *config.Config, item api.Item) (string, string) { symbol += "⚑ " } if len(s.MediaAttachments) > 0 { + textcolor = cfg.Style.MediaText symbol += "⚭ " } if s.Card != nil { + if len(s.MediaAttachments) == 0 { + textcolor = cfg.Style.CardText + } symbol += "⚯ " } if status.RepliesCount > 0 { @@ -57,12 +63,12 @@ func DrawListItem(cfg *config.Config, item api.Item) (string, string) { if symbol != "" { symbol = fmt.Sprintf(cfg.General.SymbolFormat, symbol) } - return fmt.Sprintf("%s %s", d, acc), symbol + return fmt.Sprintf("[#%06x]%s[#%06x] %s",cfg.Style.DateTimeText.Hex(), d, textcolor.Hex() , acc), symbol case api.StatusHistoryType: s := item.Raw().(*mastodon.StatusHistory) acc := strings.TrimSpace(s.Account.Acct) d := OutputDate(cfg, s.CreatedAt.Local()) - return fmt.Sprintf("%s %s", d, acc), "" + return fmt.Sprintf("[#%06x]%s[#%06x] %s",cfg.Style.DateTimeText.Hex(), d, cfg.Style.Text.Hex() , acc), "" case api.UserType: a := item.Raw().(*api.User) return strings.TrimSpace(a.Data.Acct), "" @@ -91,7 +97,7 @@ func DrawListItem(cfg *config.Config, item api.Item) (string, string) { symbol = fmt.Sprintf(cfg.General.SymbolFormat, symbol) } d := OutputDate(cfg, a.Item.CreatedAt.Local()) - return fmt.Sprintf("%s %s", d, strings.TrimSpace(a.Item.Account.Acct)), symbol + return fmt.Sprintf("[#%06x]%s[#%06x] %s",cfg.Style.DateTimeText.Hex(), d, cfg.Style.Text.Hex() , strings.TrimSpace(a.Item.Account.Acct)), symbol case api.ListsType: a := item.Raw().(*mastodon.List) return tview.Escape(a.Title), "" diff --git a/ui/linkview.go b/ui/linkview.go index bcf9cd2..4bd7bd3 100644 --- a/ui/linkview.go +++ b/ui/linkview.go @@ -17,7 +17,7 @@ type LinkView struct { } func NewLinkView(tv *TutView) *LinkView { - l := NewList(tv.tut.Config) + l := NewList(tv.tut.Config, false) c := NewControlView(tv.tut.Config) lv := &LinkView{ tutView: tv, diff --git a/ui/loginview.go b/ui/loginview.go index ef042a7..8fe23b3 100644 --- a/ui/loginview.go +++ b/ui/loginview.go @@ -17,7 +17,7 @@ type LoginView struct { func NewLoginView(tv *TutView, accs *auth.AccountData) *LoginView { tv.Shared.Top.SetText("select account") - list := NewList(tv.tut.Config) + list := NewList(tv.tut.Config, false) for _, a := range accs.Accounts { list.AddItem(fmt.Sprintf("%s - %s", a.Name, a.Server), "", 0, nil) } diff --git a/ui/pollview.go b/ui/pollview.go index 4ad3294..8a32f77 100644 --- a/ui/pollview.go +++ b/ui/pollview.go @@ -47,7 +47,7 @@ func NewPollView(tv *TutView) *PollView { info: NewTextView(tv.tut.Config), expiration: NewDropDown(tv.tut.Config), controls: NewControlView(tv.tut.Config), - list: NewList(tv.tut.Config), + list: NewList(tv.tut.Config, false), } p.scrollSleep = NewScrollSleep(p.Next, p.Prev) p.Reset() diff --git a/ui/preferenceview.go b/ui/preferenceview.go index 25b6339..716cdfa 100644 --- a/ui/preferenceview.go +++ b/ui/preferenceview.go @@ -40,7 +40,7 @@ func NewPreferenceView(tv *TutView) *PreferenceView { shared: tv.Shared, displayName: NewTextView(tv.tut.Config), bio: NewTextView(tv.tut.Config), - fields: NewList(tv.tut.Config), + fields: NewList(tv.tut.Config, false), visibility: NewDropDown(tv.tut.Config), controls: NewControlView(tv.tut.Config), preferences: &preferences{}, diff --git a/ui/styled_elements.go b/ui/styled_elements.go index 8f28ab8..ff797e3 100644 --- a/ui/styled_elements.go +++ b/ui/styled_elements.go @@ -56,13 +56,19 @@ func NewControlButton(tv *TutView, control Control) *tview.Button { return btn } -func NewList(cnf *config.Config) *tview.List { +func NewList(cnf *config.Config, is_feed bool) *tview.List { l := tview.NewList() l.ShowSecondaryText(false) l.SetHighlightFullLine(true) l.SetBackgroundColor(cnf.Style.Background) l.SetMainTextColor(cnf.Style.Text) - l.SetSelectedBackgroundColor(cnf.Style.ListSelectedBackground) + if is_feed && cnf.Style.ListSelectedBoldUnderline == 1 { + l.SetSelectedBackgroundColor(cnf.Style.ListSelectedBackground) + s := tcell.Style.Attributes(tcell.Style{}, tcell.AttrBold | tcell.AttrUnderline) + l.SetSelectedStyle(s) + } else { + l.SetSelectedBackgroundColor(cnf.Style.Background) + } l.SetSelectedTextColor(cnf.Style.ListSelectedText) return l } diff --git a/ui/voteview.go b/ui/voteview.go index 599db67..162ef9d 100644 --- a/ui/voteview.go +++ b/ui/voteview.go @@ -25,7 +25,7 @@ func NewVoteView(tv *TutView) *VoteView { shared: tv.Shared, textTop: NewTextView(tv.tut.Config), controls: NewControlView(tv.tut.Config), - list: NewList(tv.tut.Config), + list: NewList(tv.tut.Config, false), } v.scrollSleep = NewScrollSleep(v.Next, v.Prev) v.View = voteViewUI(v)