Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding alternate row shading for readability. #124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
type Markup struct {
Foreground termbox.Attribute // Foreground color.
Background termbox.Attribute // Background color (so far always termbox.ColorDefault).
RowShading termbox.Attribute // Background color for Row Shading.
RightAligned bool // True when the string is right aligned.
tags map[string]termbox.Attribute // Tags to Termbox translation hash.
regex *regexp.Regexp // Regex to identify the supported tag names.
Expand Down Expand Up @@ -74,6 +75,8 @@ func NewMarkup(profile *Profile) *Markup {
markup.Background = termbox.ColorDefault
markup.RightAligned = false

markup.RowShading = markup.tags[profile.Colors.RowShading]

markup.regex = markup.supportedTags() // Once we have the hash we could build the regex.

return markup
Expand Down
5 changes: 5 additions & 0 deletions profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ type Profile struct {
Grouped bool // True when stocks are grouped by advancing/declining.
Filter string // Filter in human form
UpDownJump int // Number of lines to go up/down when scrolling.
RowShading bool // Should alternate rows be shaded?
Colors struct { // User defined colors
Gain string
Loss string
Tag string
Header string
Time string
Default string
RowShading string
}
ShowTimestamp bool // Show or hide current time in the top right of the screen
filterExpression *govaluate.EvaluableExpression // The filter as a govaluate expression
Expand Down Expand Up @@ -86,6 +88,7 @@ func NewProfile(filename string) (*Profile, error) {
InitColor(&profile.Colors.Header, defaultHeaderColor)
InitColor(&profile.Colors.Time, defaultTimeColor)
InitColor(&profile.Colors.Default, defaultColor)
InitColor(&profile.Colors.RowShading, defaultColor)

profile.SetFilter(profile.Filter)
}
Expand Down Expand Up @@ -118,6 +121,8 @@ func (profile *Profile) InitDefaultProfile() {
profile.Colors.Header = defaultHeaderColor
profile.Colors.Time = defaultTimeColor
profile.Colors.Default = defaultColor
profile.Colors.RowShading = defaultColor
profile.RowShading = false
profile.ShowTimestamp = false
profile.Save()
}
Expand Down
19 changes: 17 additions & 2 deletions screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Screen struct {
layout *Layout // Pointer to layout (gets created by screen).
markup *Markup // Pointer to markup processor (gets created by screen).
pausedAt *time.Time // Timestamp of the pause request or nil if none.
profile *Profile // Pointer to profile passed to NewScreen
offset int // Offset for scolling
headerLine int // Line number of header for scroll feature
max int // highest offset
Expand All @@ -37,6 +38,7 @@ func NewScreen(profile *Profile) *Screen {
screen := &Screen{}
screen.layout = NewLayout()
screen.markup = NewMarkup(profile)
screen.profile = profile
screen.offset = 0

return screen.Resize()
Expand Down Expand Up @@ -188,8 +190,21 @@ func (screen *Screen) DrawLineFlush(x int, y int, str string, flush bool) {
} else {
start = screen.width - len(token) + i
}
termbox.SetCell(start, y, char, screen.markup.Foreground, screen.markup.Background)
if y % 2 == 0 && y > 4 && screen.profile.RowShading {
termbox.SetCell(start, y, char, screen.markup.Foreground, screen.markup.RowShading)
} else {
termbox.SetCell(start, y, char, screen.markup.Foreground, screen.markup.Background)
}

}
if screen.profile.RowShading {
if start < screen.width && y % 2 == 0 && y > 4 {
for i := start ; i < screen.width; i++ {
start ++;
termbox.SetCell(start, y, ' ', termbox.ColorDefault, screen.markup.RowShading);
}
}
}
}
if flush {
termbox.Flush()
Expand All @@ -213,7 +228,7 @@ func (screen *Screen) DrawLineFlushInverted(x int, y int, str string, flush bool
} else {
start = screen.width - len(token) + i
}
termbox.SetCell(start, y, char, screen.markup.tags[`black`], screen.markup.Foreground)
termbox.SetCell(start, y, char, screen.markup.tags[`black`], screen.markup.Foreground)
}
}
if flush {
Expand Down