Center log indicator

Previously all options were padded with spaces which caused the
indicator to be visually uncentered.
mine
Christian Köhn 2020-05-02 23:41:40 +02:00
parent bd151db6d3
commit 5f228f1f9a
No known key found for this signature in database
GPG Key ID: C91DB54295A5F8D7
3 changed files with 13 additions and 8 deletions

View File

@ -93,10 +93,10 @@ func (l *LogIndicator) ToggleAutoScroll() {
// Refresh updates the view. // Refresh updates the view.
func (l *LogIndicator) Refresh() { func (l *LogIndicator) Refresh() {
l.Clear() l.Clear()
l.update("Autoscroll: " + l.onOff(l.AutoScroll())) l.update("Autoscroll", l.AutoScroll(), true)
l.update("FullScreen: " + l.onOff(l.fullScreen)) l.update("FullScreen", l.fullScreen, true)
l.update("Timestamps: " + l.onOff(l.showTime)) l.update("Timestamps", l.showTime, true)
l.update("Wrap: " + l.onOff(l.textWrap)) l.update("Wrap", l.textWrap, false)
} }
func (l *LogIndicator) onOff(b bool) string { func (l *LogIndicator) onOff(b bool) string {
@ -106,6 +106,11 @@ func (l *LogIndicator) onOff(b bool) string {
return "Off" return "Off"
} }
func (l *LogIndicator) update(status string) { func (l *LogIndicator) update(title string, state bool, pad bool) {
fmt.Fprintf(l, "[::b]%-20s", status) const spacer = " "
var padding string
if pad {
padding = spacer
}
fmt.Fprintf(l, "[::b]%s: %s%s", title, l.onOff(state), padding)
} }

View File

@ -13,5 +13,5 @@ func TestLogIndicatorRefresh(t *testing.T) {
v := view.NewLogIndicator(config.NewConfig(nil), defaults) v := view.NewLogIndicator(config.NewConfig(nil), defaults)
v.Refresh() v.Refresh()
assert.Equal(t, "[::b]Autoscroll: On [::b]FullScreen: Off [::b]Timestamps: Off [::b]Wrap: Off \n", v.GetText(false)) assert.Equal(t, "[::b]Autoscroll: On [::b]FullScreen: Off [::b]Timestamps: Off [::b]Wrap: Off\n", v.GetText(false))
} }

View File

@ -19,7 +19,7 @@ func TestLogAutoScroll(t *testing.T) {
assert.Equal(t, 13, len(v.Hints())) assert.Equal(t, 13, len(v.Hints()))
v.toggleAutoScrollCmd(nil) v.toggleAutoScrollCmd(nil)
assert.Equal(t, "Autoscroll: Off FullScreen: Off Timestamps: Off Wrap: Off ", v.Indicator().GetText(true)) assert.Equal(t, "Autoscroll: Off FullScreen: Off Timestamps: Off Wrap: Off", v.Indicator().GetText(true))
} }
func TestLogViewNav(t *testing.T) { func TestLogViewNav(t *testing.T) {