Skip to content

Commit

Permalink
write a status line for scrollable content
Browse files Browse the repository at this point in the history
  • Loading branch information
pgavlin committed Nov 8, 2022
1 parent 7d17bba commit 0e8d3e4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
30 changes: 27 additions & 3 deletions pkg/backend/display/tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/pulumi/pulumi/pkg/v3/engine"
"github.com/pulumi/pulumi/sdk/v3/go/common/diag/colors"
"github.com/pulumi/pulumi/sdk/v3/go/common/util/contract"
"github.com/rivo/uniseg"
)

type treeRenderer struct {
Expand Down Expand Up @@ -157,11 +158,14 @@ func (r *treeRenderer) done(display *ProgressDisplay) {
r.frame(true)
}

func (r *treeRenderer) println(display *ProgressDisplay, text string) {
func (r *treeRenderer) print(text string) {
_, err := fmt.Fprint(r.term, r.opts.Color.Colorize(strings.ReplaceAll(text, "\n", "\r\n")))
contract.IgnoreError(err)
_, err = fmt.Fprint(r.term, "\r\n")
contract.IgnoreError(err)
}

func (r *treeRenderer) println(display *ProgressDisplay, text string) {
r.print(text)
r.print("\n")
}

func (r *treeRenderer) render(display *ProgressDisplay) {
Expand Down Expand Up @@ -216,6 +220,9 @@ func (r *treeRenderer) markDirty() {
// +--------------------------------------------+
// | treetable header |
// | treetable contents... |
// | treetable footer |
// | system messages header |
// | system messages contents... |
// +--------------------------------------------+
func (r *treeRenderer) frame(done bool) {
r.m.Lock()
Expand Down Expand Up @@ -252,6 +259,7 @@ func (r *treeRenderer) frame(done bool) {
// - If there are no system messages, devote the entire display to the tree table
// - If there are system messages, devote the first two thirds of the display to the tree table and the
// last third to the system messages
var treeTableFooter string
if !done && totalHeight >= r.termHeight {
if systemMessagesHeight > 0 {
systemMessagesHeight = r.termHeight / 3
Expand All @@ -271,9 +279,22 @@ func (r *treeRenderer) frame(done bool) {
treeTableRows = treeTableRows[r.treeTableOffset : r.treeTableOffset+treeTableHeight-1]

totalHeight = treeTableHeight + systemMessagesHeight + 1

upArrow := " "
if r.treeTableOffset != 0 {
upArrow = "⬆ "
}
downArrow := " "
if r.treeTableOffset != r.maxTreeTableOffset {
downArrow = "⬇ "
}
footer := fmt.Sprintf("%smore%s", upArrow, downArrow)
padding := r.termWidth - uniseg.GraphemeClusterCount(footer)
treeTableFooter = strings.Repeat(" ", padding) + footer
}

// Re-home the cursor.
clearLine(r.term, r.termInfo)
for ; r.rewind > 0; r.rewind-- {
cursorUp(r.term, r.termInfo, 1)
clearLine(r.term, r.termInfo)
Expand All @@ -285,6 +306,9 @@ func (r *treeRenderer) frame(done bool) {
for _, row := range treeTableRows {
r.println(nil, row)
}
if treeTableFooter != "" {
r.print(treeTableFooter)
}

// Render the system messages.
if systemMessagesHeight > 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ require (
github.com/natefinch/atomic v1.0.1
github.com/pulumi/pulumi-java/pkg v0.6.0
github.com/pulumi/pulumi-yaml v1.0.1
github.com/rivo/uniseg v0.2.0
github.com/segmentio/encoding v0.3.5
github.com/shirou/gopsutil/v3 v3.22.3
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
Expand Down Expand Up @@ -176,7 +177,6 @@ require (
github.com/pkg/term v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
Expand Down

0 comments on commit 0e8d3e4

Please sign in to comment.