Skip to content

Commit 1c9bd64

Browse files
fix(cli): handle narrow terminals and legacy console encodings
1 parent 8c2c887 commit 1c9bd64

3 files changed

Lines changed: 15 additions & 7 deletions

File tree

‎apps/server/src/cli/updateProgress.test.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ it("shows bytes for an unknown size and leaves a clean line on interruption", ()
6363
expect(output.text()).not.toContain("%");
6464
});
6565

66-
it("fits a narrow terminal without wrapping", () => {
67-
const output = terminal(true, 30);
66+
it.each([1, 2, 7, 8, 9, 30])("fits a %i-column terminal without wrapping", (columns) => {
67+
const output = terminal(true, columns);
6868
output.report({ stage: "download", received: 50, total: 100 });
69-
const line = output.text().split("\x1b[2K").at(-1)!;
70-
expect(line.length).toBeLessThan(30);
69+
for (const line of output.text().split("\r\x1b[2K")) {
70+
expect(line.length).toBeLessThan(columns);
71+
}
7172
});
7273

7374
it("draws the final size of a fast chunked download even inside the throttle window", () => {

‎apps/server/src/cli/updateProgress.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ export function createUpdateProgress(
1717
};
1818
const status = (message: string) => {
1919
finish();
20-
if (interactive) message = message.slice(0, Math.max(0, (output.columns || 80) - 3));
21-
output.write(interactive ? `\r\x1b[2K ${style(2, message)}` : ` ${message}\n`);
20+
let line = ` ${message}`;
21+
if (interactive) line = line.slice(0, Math.max(0, (output.columns || 80) - 1));
22+
output.write(interactive ? `\r\x1b[2K${style(2, line)}` : `${line}\n`);
2223
lineOpen = Boolean(interactive);
2324
downloadLine = false;
2425
};
@@ -56,7 +57,7 @@ export function createUpdateProgress(
5657
columns >= 32
5758
? ` ${style(2, "Downloading")} ${mb(received)} MB`
5859
: ` ${mb(received)} MB`.slice(0, Math.max(0, columns - 1));
59-
if (total !== undefined && total > 0) {
60+
if (total !== undefined && total > 0 && columns >= 9) {
6061
const percent = Math.min(100, Math.floor((received / total) * 100));
6162
const width = Math.max(1, Math.min(32, columns - 10));
6263
const filled = Math.floor((percent * width) / 100);

‎scripts/install.ps1‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ function Fail([string] $message) {
2828

2929
$terminal = -not [Console]::IsErrorRedirected -and $env:TERM -ne "dumb"
3030
$interactive = $terminal -and $Host.UI.SupportsVirtualTerminal
31+
if ($interactive) {
32+
# Legacy code pages may support ANSI escapes but not the logo or bar glyphs.
33+
$glyphs = -join [char[]](0x2588, 0x2580, 0x2584, 0x25A0, 0x00B7)
34+
$encoding = [Console]::Error.Encoding
35+
$interactive = $encoding.GetString($encoding.GetBytes($glyphs)) -eq $glyphs
36+
}
3137
$esc = [char]27
3238
$reset = $bold = $muted = $accent = $green = ""
3339
if ($interactive -and -not $env:NO_COLOR) {

0 commit comments

Comments
 (0)