Skip to content

Commit e736d0f

Browse files
authored
fix(prompt): fix display of non-ASCII characters on Windows (#8199)
1 parent 1c18898 commit e736d0f

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

cli/rt/41_prompt.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
22
((window) => {
3-
const { stdin, stdout } = window.__bootstrap.files;
3+
const { stdin } = window.__bootstrap.files;
44
const { isatty } = window.__bootstrap.tty;
55
const LF = "\n".charCodeAt(0);
66
const CR = "\r".charCodeAt(0);
7-
const encoder = new TextEncoder();
87
const decoder = new TextDecoder();
8+
const core = window.Deno.core;
99

1010
function alert(message = "Alert") {
1111
if (!isatty(stdin.rid)) {
1212
return;
1313
}
1414

15-
stdout.writeSync(encoder.encode(`${message} [Enter] `));
15+
core.print(`${message} [Enter] `, false);
1616

1717
readLineFromStdinSync();
1818
}
@@ -22,7 +22,7 @@
2222
return false;
2323
}
2424

25-
stdout.writeSync(encoder.encode(`${message} [y/N] `));
25+
core.print(`${message} [y/N] `, false);
2626

2727
const answer = readLineFromStdinSync();
2828

@@ -36,10 +36,10 @@
3636
return null;
3737
}
3838

39-
stdout.writeSync(encoder.encode(`${message} `));
39+
core.print(`${message} `, false);
4040

4141
if (defaultValue) {
42-
stdout.writeSync(encoder.encode(`[${defaultValue}] `));
42+
core.print(`[${defaultValue}] `, false);
4343
}
4444

4545
return readLineFromStdinSync() || defaultValue;

core/bindings.rs

+3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use futures::future::FutureExt;
1111
use rusty_v8 as v8;
1212
use std::cell::Cell;
1313
use std::convert::TryFrom;
14+
use std::io::{stdout, Write};
1415
use std::option::Option;
1516
use url::Url;
1617
use v8::MapFnTo;
@@ -352,8 +353,10 @@ fn print(
352353
};
353354
if is_err {
354355
eprint!("{}", str_.to_rust_string_lossy(tc_scope));
356+
stdout().flush().unwrap();
355357
} else {
356358
print!("{}", str_.to_rust_string_lossy(tc_scope));
359+
stdout().flush().unwrap();
357360
}
358361
}
359362

0 commit comments

Comments
 (0)