Skip to content

Commit

Permalink
API changes to allow toggling of status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
liamg committed Mar 4, 2020
1 parent 898ff5c commit ad05cee
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/decorators/decorator.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ type Decorator interface {
Draw(rows uint16, cols uint16) // Draw renders the decorator to StdOut
GetAnchor() Anchor // GetAnchor returns the anchor e.g. Top/Bottom
GetHeight() (rows uint16) // GetHeight returns the height of the decorator in terminal character rows
IsVisible() bool
}
10 changes: 10 additions & 0 deletions pkg/decorators/statusbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type StatusBar struct {
bg ansi.Colour
fg ansi.Colour
padding uint16
visible bool
}

// NewStatusBar creates a new status bar instance
Expand All @@ -30,9 +31,18 @@ func NewStatusBar() *StatusBar {
bg: ansi.ColourRed.Bg(),
fg: ansi.ColourWhite.Fg(),
padding: 0,
visible: true,
}
}

func (b *StatusBar) IsVisible() bool {
return b.visible
}

func (b *StatusBar) SetVisible(visible bool) {
b.visible = visible
}

// SetFormat controls the output format of the status bar
func (b *StatusBar) SetFormat(format string) {
b.format = format
Expand Down
13 changes: 13 additions & 0 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func (p *Proxy) HandleCoordinates(row, col uint16) (outRow uint16, outCol uint16
defer p.decMutex.Unlock()

for _, dec := range p.decorators {
if !dec.IsVisible() {
continue
}
rows := dec.GetHeight()
switch dec.GetAnchor() {
case decorators.AnchorTop:
Expand All @@ -123,6 +126,9 @@ func (p *Proxy) HandleResize(rows, cols uint16) (outRows uint16, outCols uint16)
p.realCols = cols

for _, dec := range p.decorators {
if !dec.IsVisible() {
continue
}
h := dec.GetHeight()

if h >= rows {
Expand Down Expand Up @@ -199,6 +205,10 @@ func (p *Proxy) process() {

}

func (p *Proxy) ForceRedraw() {
p.redraw()
}

func (p *Proxy) requestRedraw() {
select {
case p.redrawChan <- struct{}{}:
Expand All @@ -213,6 +223,9 @@ func (p *Proxy) redraw() {
return
}
for _, decorator := range p.decorators {
if !decorator.IsVisible() {
continue
}
decorator.Draw(p.realRows, p.realCols)
}
}
Expand Down
8 changes: 6 additions & 2 deletions pkg/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func (t *Terminal) SetNestingAllowed(allowed bool) {
t.enableNesting = allowed
}

func (t *Terminal) ForceRedraw() {
t.proxy.ForceRedraw()
}

// Run starts the terminal/shell proxying process
func (t *Terminal) Run() error {

Expand Down Expand Up @@ -125,8 +129,8 @@ func (t *Terminal) Run() error {
defer func() { _ = terminal.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.

// Copy stdin to the pty and the pty to stdout.
go func() { _ = lazyCopy(t.pty, os.Stdin) }()
go func() { _ = lazyCopy(os.Stdout, t.proxy) }()
go func() { _ = lazyCopy(t.pty, os.Stdin) }()
go func() { _ = lazyCopy(os.Stdout, t.proxy) }()
_ = lazyCopy(t.proxy, t.pty)
fmt.Printf("\r\n")
return nil
Expand Down

0 comments on commit ad05cee

Please sign in to comment.