Skip to content

Commit

Permalink
Adding colours to the feed and an alternative highlighting mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
proycon committed Dec 20, 2022
1 parent f681520 commit e794f2a
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 19 deletions.
67 changes: 63 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,13 @@ type Style struct {
StatusBarViewBackground tcell.Color
StatusBarViewText tcell.Color

ListSelectedBackground tcell.Color
ListSelectedText tcell.Color
ListSelectedBackground tcell.Color
ListSelectedText tcell.Color
ListSelectedBoldUnderline int

ListSelectedInactiveBackground tcell.Color
ListSelectedInactiveText tcell.Color
ListSelectedInactiveBackground tcell.Color
ListSelectedInactiveText tcell.Color
ListSelectedInactiveBoldUnderline int

ControlsText tcell.Color
ControlsHighlight tcell.Color
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions config/default_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,8 @@ background=
# default=
text=
# The color to display subtle elements or subtle text. Like lines and help text.
# default=
subtle=
Expand Down Expand Up @@ -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.
#
Expand Down
2 changes: 1 addition & 1 deletion ui/composeview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down
18 changes: 14 additions & 4 deletions ui/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
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) {
Expand All @@ -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)
if style.ListSelectedBoldUnderline == 1 {
s := tcell.Style.Attributes(tcell.Style{}, tcell.AttrBold)
l.SetSelectedStyle(s)
} else {
l.SetSelectedBackgroundColor(style.ListSelectedInactiveBackground)
}
}

type Feed struct {
Expand Down Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions ui/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 += "! "
Expand All @@ -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 {
Expand All @@ -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), ""
Expand Down Expand Up @@ -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), ""
Expand Down
2 changes: 1 addition & 1 deletion ui/linkview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ui/loginview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion ui/pollview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion ui/preferenceview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{},
Expand Down
10 changes: 8 additions & 2 deletions ui/styled_elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Background)
s := tcell.Style.Attributes(tcell.Style{}, tcell.AttrBold|tcell.AttrUnderline)
l.SetSelectedStyle(s)
} else {
l.SetSelectedBackgroundColor(cnf.Style.ListSelectedBackground)
}
l.SetSelectedTextColor(cnf.Style.ListSelectedText)
return l
}
Expand Down
2 changes: 1 addition & 1 deletion ui/voteview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit e794f2a

Please sign in to comment.