Fixes #8504
This commit is contained in:
dave caruso
2024-01-26 20:55:48 -08:00
committed by GitHub
parent 08c9511acc
commit 6faeef6dc2
4 changed files with 10 additions and 3 deletions

View File

@@ -244,8 +244,7 @@ pub const Prompt = struct {
bun.Output.flush();
// 7. Pause while waiting for the user's response.
var stdin = std.io.getStdIn();
var reader = stdin.reader();
const reader = bun.buffered_stdin.reader();
const first_byte = reader.readByte() catch {
// 8. Let result be null if the user aborts, or otherwise the string

View File

@@ -2453,3 +2453,9 @@ pub fn getUserName(output_buffer: []u8) ?[]const u8 {
copy(u8, output_buffer[0..size], user[0..size]);
return output_buffer[0..size];
}
/// This struct is a workaround a Windows terminal bug.
/// TODO: when https://github.com/microsoft/terminal/issues/16606 is resolved, revert this commit.
pub var buffered_stdin = std.io.BufferedReader(4096, std.fs.File.Reader){
.unbuffered_reader = std.fs.File.Reader{ .context = .{ .handle = if (Environment.isWindows) undefined else 0 } },
};

View File

@@ -39,7 +39,7 @@ pub const InitCommand = struct {
Output.flush();
var input = try std.io.getStdIn().reader().readUntilDelimiterAlloc(alloc, '\n', 1024);
var input = try bun.buffered_stdin.reader().readUntilDelimiterAlloc(alloc, '\n', 1024);
if (strings.endsWithChar(input, '\r')) {
input = input[0 .. input.len - 1];
}

View File

@@ -39,6 +39,8 @@ pub fn main() void {
bun.win32.STDERR_FD = bun.toFD(std.io.getStdErr().handle);
bun.win32.STDIN_FD = bun.toFD(std.io.getStdIn().handle);
bun.buffered_stdin.unbuffered_reader.context.handle = std.io.getStdIn().handle;
const w = std.os.windows;
// https://learn.microsoft.com/en-us/windows/console/setconsoleoutputcp