From 62d504945f3ac9ebc03565442f35481cc0194df2 Mon Sep 17 00:00:00 2001 From: Ce Gao Date: Thu, 12 May 2022 16:26:38 +0800 Subject: [PATCH] fix: Fix progress display reorder problem (#139) Signed-off-by: Ce Gao --- README.md | 27 +++++++++++++++------------ pkg/progress/compileui/display.go | 19 +++++++++++-------- pkg/progress/compileui/types.go | 2 +- 3 files changed, 27 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index ca5293330..a877712f2 100644 --- a/README.md +++ b/README.md @@ -55,18 +55,21 @@ jupyter(password="", port=8888) Then you can run `envd up` and open jupyter notebook at [`http://localhost:8888`](http://localhost:8888), or open vscode remote to attach to the container. ``` -[+] ⌚ parse build.envd and download/cache dependencies 0.0s ✅ (finished) - => 💽 (cached) download oh-my-zsh 0.0s - => 💽 (cached) download ms-vscode.cpptools-1.7.1 0.0s - => 💽 (cached) download github.copilot-1.12.5517 0.0s - => 💽 (cached) download dbaeumer.vscode-eslint-2.2.3 0.0s -[+] 🐋 build envd environment 1.3s (24/25) - => 💽 (cached) sh -c apt-get update && apt-get install -y --no-instal 0.0s - => 💽 (cached) apt-get install -y --no-install-recommends gcc 0.0s - => 💽 (cached) diff (sh -c apt-get update && apt-get install -y --no- 0.0s - => 💽 (cached) pip install jupyter 0.0s - => 💽 (cached) diff (sh -c apt-get update && apt-get install -y --no- 0.0s - => 💽 (cached) copy /usr/bin/envd-ssh /var/envd/bin/envd-ssh 0.0s +[+] ⌚ parse build.envd and download/cache dependencies 23.7s ✅ (finished) + => download oh-my-zsh 13.5s + => download ms-vscode.cpptools-1.7.1 2.1s + => download github.copilot-1.12.5517 1.3s + => download ms-python.python-2021.12.1559732655 6.7s +[+] 🐋 build envd environment 4.4s (23/24) + => 💽 (cached) copy /ms-python.python-2021.12.1559732655/extension /root/ 0.0s + => 💽 (cached) merge (copy /ms-vscode.cpptools-1.7.1/extension /root/.vsc 0.0s + => 💽 (cached) mkfile /etc/apt/sources.list 0.0s + => 💽 (cached) merge (docker-image://docker.io/nvidia/cuda:11.6.0-cudnn8- 0.0s + => 💽 (cached) mkfile /etc/pip.conf 0.0s + => 💽 (cached) merge (merge (docker-image://docker.io/nvidia/cuda:11.6.0- 0.0s + => 💽 (cached) sh -c apt-get update && apt-get install -y --no-install-re 0.0s + => 💽 (cached) pip install tensorflow numpy jupyter 0.0s + => 💽 (cached) diff (sh -c apt-get update && apt-get install -y --no-inst 0.0s ... # You are in the docker container for dev envd > diff --git a/pkg/progress/compileui/display.go b/pkg/progress/compileui/display.go index fb748617d..2435795a4 100644 --- a/pkg/progress/compileui/display.go +++ b/pkg/progress/compileui/display.go @@ -67,7 +67,7 @@ func New(ctx context.Context, out console.File, mode string) (Writer, error) { doneCh: make(chan bool), repeatd: false, result: &Result{ - plugins: make(map[string]*PluginInfo), + plugins: make([]*PluginInfo, 0), }, lineCount: 0, } @@ -81,17 +81,20 @@ func (w *generalWriter) LogVSCodePlugin(p vscode.Plugin, action Action, cached b switch action { case ActionStart: c := time.Now() - w.result.plugins[p.String()] = &PluginInfo{ + w.result.plugins = append(w.result.plugins, &PluginInfo{ Plugin: p, startTime: &c, cached: cached, - } + }) case ActionEnd: c := time.Now() - w.result.plugins[p.String()].endTime = &c - w.result.plugins[p.String()].cached = cached + for i, plugin := range w.result.plugins { + if plugin.String() == p.String() { + w.result.plugins[i].endTime = &c + w.result.plugins[i].cached = cached + } + } } - } func (w *generalWriter) LogZSH(action Action, cached bool) { @@ -163,7 +166,7 @@ func (w *generalWriter) output(finished bool) { if w.result.ZSHInfo.cached { template = " => 💽 (cached) download %s" } - timerStr := fmt.Sprintf(" %.1fs\n", timer) + timerStr := fmt.Sprintf(" %3.1fs\n", timer) out := fmt.Sprintf(template, w.result.ZSHInfo.OHMYZSH) out = align(out, timerStr, width) fmt.Fprint(w.console, out) @@ -179,7 +182,7 @@ func (w *generalWriter) output(finished bool) { if p.endTime != nil { timer = p.endTime.Sub(*p.startTime).Seconds() } - timerStr := fmt.Sprintf(" %.1fs\n", timer) + timerStr := fmt.Sprintf(" %3.1fs\n", timer) template := " => download %s" if p.cached { template = " => 💽 (cached) download %s" diff --git a/pkg/progress/compileui/types.go b/pkg/progress/compileui/types.go index c5fa2746c..0bc2c01f5 100644 --- a/pkg/progress/compileui/types.go +++ b/pkg/progress/compileui/types.go @@ -14,7 +14,7 @@ const ( ) type Result struct { - plugins map[string]*PluginInfo + plugins []*PluginInfo ZSHInfo *ZSHInfo }