Skip to content
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
54 changes: 34 additions & 20 deletions bar/bar.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,48 +209,62 @@ func NewBar(
return b, nil
}

func (b *Bar) hasBarSection(section string) bool {
if b.ctx.Has(section) {
sectionMarkup := b.ctx.MustString(section)
if sectionMarkup != "<ModuleRow>\n</ModuleRow>\n" {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably check for more than just this static string.

return true
}
}

return false
}

func (b *Bar) createRoots() error {
if b.ctx.Has("bar_left") {
if b.hasBarSection("bar_left") {
ctx := b.ctx.New(ui.Context{"bar_align": "left"})
b.LeftRoot = ui.NewRoot(ctx, func() {
b.LeftRoot.Paint()
b.PaintLeft(b.LeftRoot.Image())
})


modules, err := b.mk.Parse(b.LeftRoot, nil, b.ctx.MustString("bar_left"))
if err != nil {
return fmt.Errorf("config: bar_left: %w", err)
}
b.LeftRoot.Inner = modules

}

if b.ctx.Has("bar_center") {
if b.hasBarSection("bar_center") {
ctx := b.ctx.New(ui.Context{"bar_align": "center"})
b.CenterRoot = ui.NewRoot(ctx, func() {
b.CenterRoot.Paint()
b.PaintCenter(b.CenterRoot.Image())
})


modules, err := b.mk.Parse(b.CenterRoot, nil, b.ctx.MustString("bar_center"))
if err != nil {
return fmt.Errorf("config: bar_center: %w", err)
}
b.CenterRoot.Inner = modules
}

if b.ctx.Has("bar_right") {
if b.hasBarSection("bar_right") {
ctx := b.ctx.New(ui.Context{"bar_align": "right"})
b.RightRoot = ui.NewRoot(ctx, func() {
b.RightRoot.Paint()
b.PaintRight(b.RightRoot.Image())
})
}

modules, err := b.mk.Parse(b.LeftRoot, nil, b.ctx.MustString("bar_left"))
if err != nil {
return fmt.Errorf("config: bar_left: %w", err)
}
b.LeftRoot.Inner = modules

modules, err = b.mk.Parse(b.CenterRoot, nil, b.ctx.MustString("bar_center"))
if err != nil {
return fmt.Errorf("config: bar_center: %w", err)
}
b.CenterRoot.Inner = modules

modules, err = b.mk.Parse(b.RightRoot, nil, b.ctx.MustString("bar_right"))
if err != nil {
return fmt.Errorf("config: bar_right: %w", err)
modules, err := b.mk.Parse(b.RightRoot, nil, b.ctx.MustString("bar_right"))
if err != nil {
return fmt.Errorf("config: bar_right: %w", err)
}
b.RightRoot.Inner = modules
}
b.RightRoot.Inner = modules

return nil
}
Expand Down
19 changes: 13 additions & 6 deletions bar/bars.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,19 @@ func (b *Bars) createBars() error {

func (b *Bars) onClockTick() {
for _, bar := range b.Bars {
bar.LeftRoot.Paint()
bar.CenterRoot.Paint()
bar.RightRoot.Paint()
if bar.LeftRoot != nil {
bar.LeftRoot.Paint()
bar.PaintLeft(bar.LeftRoot.Image())
}

if bar.CenterRoot != nil {
bar.CenterRoot.Paint()
bar.PaintCenter(bar.CenterRoot.Image())
}

bar.PaintLeft(bar.LeftRoot.Image())
bar.PaintCenter(bar.CenterRoot.Image())
bar.PaintRight(bar.RightRoot.Image())
if bar.RightRoot != nil {
bar.RightRoot.Paint()
bar.PaintRight(bar.RightRoot.Image())
}
}
}