Skip to content

Commit 8c2c887

Browse files
feat(cli): show installer download sizes in MB
1 parent f29838f commit 8c2c887

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

‎scripts/install.ps1‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ function Draw-Download([long] $bytes, [long] $total) {
4545
$filled = [int][Math]::Floor($percent * 32 / 100)
4646
$bar = ([string][char]0x25A0) * $filled
4747
$rest = ([string][char]0x00B7) * (32 - $filled)
48-
[Console]::Error.Write(("`r$esc[2K $accent$bar$reset$muted$rest$reset {0,3}%" -f $percent))
48+
[Console]::Error.Write(("`r$esc[2K $accent$bar$reset$muted$rest$reset {0,3}% $muted{1:F1} / {2:F1} MB$reset" -f $percent, ($bytes / 1MB), ($total / 1MB)))
4949
} else {
50-
[Console]::Error.Write("`r$esc[2K ${muted}Downloading$reset $([Math]::Floor($bytes / 1024)) KB")
50+
[Console]::Error.Write(("`r$esc[2K ${muted}Downloading$reset {0:F1} MB" -f ($bytes / 1MB)))
5151
}
5252
}
5353
function Fetch([string] $uri, [string] $destination, [switch] $progress) {

‎scripts/install.sh‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ fetch() {
6868
fi
6969
}
7070

71+
mb() {
72+
tenths=$((($1 * 10 + 524288) / 1048576))
73+
printf '%s.%s' "$((tenths / 10))" "$((tenths % 10))"
74+
}
7175
# Poll the file written by the downloader; no progress-output parsing or extra request.
7276
download() {
7377
if ! "$interactive"; then fetch "$1" "$2"; return; fi
@@ -99,9 +103,9 @@ download() {
99103
if [ "$n" -lt "$filled" ]; then bar="${bar}■"; else rest="${rest}·"; fi
100104
n=$((n + 1))
101105
done
102-
printf '\r\033[2K %s%s%s%s%s %3d%%' "$accent" "$bar" "$reset$muted" "$rest" "$reset" "$percent" >&2
106+
printf '\r\033[2K %s%s%s%s%s %3d%% %s%s / %s MB%s' "$accent" "$bar" "$reset$muted" "$rest" "$reset" "$percent" "$muted" "$(mb "$bytes")" "$(mb "$total")" "$reset" >&2
103107
else
104-
printf '\r\033[2K %sDownloading%s %s KB' "$muted" "$reset" "$((bytes / 1024))" >&2
108+
printf '\r\033[2K %sDownloading%s %s MB' "$muted" "$reset" "$(mb "$bytes")" >&2
105109
fi
106110
previous="$bytes"
107111
fi
@@ -114,7 +118,8 @@ download() {
114118
if [ -f "$2.errors" ]; then cat "$2.errors" >&2; else cat "$2.headers" >&2; fi
115119
return "$result"
116120
fi
117-
printf '\r\033[2K %s■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■%s 100%%\n' "$accent" "$reset" >&2
121+
size="$(mb "$(wc -c < "$2")")"
122+
printf '\r\033[2K %s■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■%s 100%% %s%s / %s MB%s\n' "$accent" "$reset" "$muted" "$size" "$size" "$reset" >&2
118123
rm -f "$2.headers" "$2.errors"
119124
}
120125

‎scripts/install.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ describe.skipIf(HostProcessPlatform.defaultValue() !== "linux")("installer termi
9292
expect(code).toBe(0);
9393
expect(sawPartialProgress).toBe(true);
9494
expect(output).toContain("100%");
95+
expect(output).toContain("0.1 / 0.1 MB");
9596
expect(output).toContain("Installed T3 Code 1.2.3");
9697
expect(
9798
await NodeFSP.readFile(NodePath.join(versions, version, ".install-complete"), "utf8"),

0 commit comments

Comments
 (0)