mirror of
https://github.com/denoland/deno.git
synced 2025-03-04 01:44:26 -05:00
fix(prompt): fix display of non-ASCII characters on Windows (#8199)
This commit is contained in:
parent
1c1889851d
commit
e736d0f60f
2 changed files with 9 additions and 6 deletions
|
@ -1,18 +1,18 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
((window) => {
|
((window) => {
|
||||||
const { stdin, stdout } = window.__bootstrap.files;
|
const { stdin } = window.__bootstrap.files;
|
||||||
const { isatty } = window.__bootstrap.tty;
|
const { isatty } = window.__bootstrap.tty;
|
||||||
const LF = "\n".charCodeAt(0);
|
const LF = "\n".charCodeAt(0);
|
||||||
const CR = "\r".charCodeAt(0);
|
const CR = "\r".charCodeAt(0);
|
||||||
const encoder = new TextEncoder();
|
|
||||||
const decoder = new TextDecoder();
|
const decoder = new TextDecoder();
|
||||||
|
const core = window.Deno.core;
|
||||||
|
|
||||||
function alert(message = "Alert") {
|
function alert(message = "Alert") {
|
||||||
if (!isatty(stdin.rid)) {
|
if (!isatty(stdin.rid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.writeSync(encoder.encode(`${message} [Enter] `));
|
core.print(`${message} [Enter] `, false);
|
||||||
|
|
||||||
readLineFromStdinSync();
|
readLineFromStdinSync();
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.writeSync(encoder.encode(`${message} [y/N] `));
|
core.print(`${message} [y/N] `, false);
|
||||||
|
|
||||||
const answer = readLineFromStdinSync();
|
const answer = readLineFromStdinSync();
|
||||||
|
|
||||||
|
@ -36,10 +36,10 @@
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
stdout.writeSync(encoder.encode(`${message} `));
|
core.print(`${message} `, false);
|
||||||
|
|
||||||
if (defaultValue) {
|
if (defaultValue) {
|
||||||
stdout.writeSync(encoder.encode(`[${defaultValue}] `));
|
core.print(`[${defaultValue}] `, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return readLineFromStdinSync() || defaultValue;
|
return readLineFromStdinSync() || defaultValue;
|
||||||
|
|
|
@ -11,6 +11,7 @@ use futures::future::FutureExt;
|
||||||
use rusty_v8 as v8;
|
use rusty_v8 as v8;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
use std::io::{stdout, Write};
|
||||||
use std::option::Option;
|
use std::option::Option;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
use v8::MapFnTo;
|
use v8::MapFnTo;
|
||||||
|
@ -352,8 +353,10 @@ fn print(
|
||||||
};
|
};
|
||||||
if is_err {
|
if is_err {
|
||||||
eprint!("{}", str_.to_rust_string_lossy(tc_scope));
|
eprint!("{}", str_.to_rust_string_lossy(tc_scope));
|
||||||
|
stdout().flush().unwrap();
|
||||||
} else {
|
} else {
|
||||||
print!("{}", str_.to_rust_string_lossy(tc_scope));
|
print!("{}", str_.to_rust_string_lossy(tc_scope));
|
||||||
|
stdout().flush().unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue