Skip to content

Commit 46e4e7e

Browse files
authored
Merge pull request moby#3378 from crazy-max/progress-desc
progress: solve status description
2 parents 0ad8d61 + 6b8fbed commit 46e4e7e

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

examples/build-using-dockerfile/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func action(clicontext *cli.Context) error {
107107
c = cn
108108
}
109109
// not using shared context to not disrupt display but let is finish reporting errors
110-
_, err = progressui.DisplaySolveStatus(context.TODO(), "", c, os.Stdout, ch)
110+
_, err = progressui.DisplaySolveStatus(context.TODO(), c, os.Stdout, ch)
111111
return err
112112
})
113113
eg.Go(func() error {

util/progress/progressui/display.go

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,37 @@ import (
2121
"golang.org/x/time/rate"
2222
)
2323

24-
func DisplaySolveStatus(ctx context.Context, phase string, c console.Console, w io.Writer, ch chan *client.SolveStatus) ([]client.VertexWarning, error) {
24+
type displaySolveStatusOpts struct {
25+
phase string
26+
textDesc string
27+
consoleDesc string
28+
}
29+
30+
type DisplaySolveStatusOpt func(b *displaySolveStatusOpts)
31+
32+
func WithPhase(phase string) DisplaySolveStatusOpt {
33+
return func(b *displaySolveStatusOpts) {
34+
b.phase = phase
35+
}
36+
}
37+
38+
func WithDesc(text string, console string) DisplaySolveStatusOpt {
39+
return func(b *displaySolveStatusOpts) {
40+
b.textDesc = text
41+
b.consoleDesc = console
42+
}
43+
}
44+
45+
func DisplaySolveStatus(ctx context.Context, c console.Console, w io.Writer, ch chan *client.SolveStatus, opts ...DisplaySolveStatusOpt) ([]client.VertexWarning, error) {
2546
modeConsole := c != nil
2647

27-
disp := &display{c: c, phase: phase}
28-
printer := &textMux{w: w}
48+
dsso := &displaySolveStatusOpts{}
49+
for _, opt := range opts {
50+
opt(dsso)
51+
}
52+
53+
disp := &display{c: c, phase: dsso.phase, desc: dsso.consoleDesc}
54+
printer := &textMux{w: w, desc: dsso.textDesc}
2955

3056
if disp.phase == "" {
3157
disp.phase = "Building"
@@ -711,6 +737,7 @@ func addTime(tm *time.Time, d time.Duration) *time.Time {
711737
type display struct {
712738
c console.Console
713739
phase string
740+
desc string
714741
lineCount int
715742
repeated bool
716743
}
@@ -784,7 +811,11 @@ func (disp *display) print(d displayInfo, width, height int, all bool) {
784811
defer fmt.Fprint(disp.c, aec.Show)
785812

786813
out := fmt.Sprintf("[+] %s %.1fs (%d/%d) %s", disp.phase, time.Since(d.startTime).Seconds(), d.countCompleted, d.countTotal, statusStr)
787-
out = align(out, "", width)
814+
if disp.desc != "" {
815+
out = align(out, disp.desc, width-1)
816+
} else {
817+
out = align(out, "", width)
818+
}
788819
fmt.Fprintln(disp.c, out)
789820
lineCount := 0
790821
for _, j := range d.jobs {

util/progress/progressui/printer.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ type textMux struct {
3232
last map[string]lastStatus
3333
notFirst bool
3434
nextIndex int
35+
desc string
3536
}
3637

3738
func (p *textMux) printVtx(t *trace, dgst digest.Digest) {
@@ -63,6 +64,9 @@ func (p *textMux) printVtx(t *trace, dgst digest.Digest) {
6364
if p.notFirst {
6465
fmt.Fprintln(p.w, "")
6566
} else {
67+
if p.desc != "" {
68+
fmt.Fprintf(p.w, "#0 %s\n\n", p.desc)
69+
}
6670
p.notFirst = true
6771
}
6872

util/progress/progresswriter/printer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func NewPrinter(ctx context.Context, out console.File, mode string) (Writer, err
8787

8888
go func() {
8989
// not using shared context to not disrupt display but let is finish reporting errors
90-
_, pw.err = progressui.DisplaySolveStatus(ctx, "", c, out, statusCh)
90+
_, pw.err = progressui.DisplaySolveStatus(ctx, c, out, statusCh)
9191
close(doneCh)
9292
}()
9393
return pw, nil

0 commit comments

Comments
 (0)