Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
paperdave authored and ryoppippi committed Feb 1, 2024
1 parent 320ff06 commit aec21af
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/bun.js/webcore.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/bun.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 } },
};
2 changes: 1 addition & 1 deletion src/cli/init_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
2 changes: 2 additions & 0 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit aec21af

Please sign in to comment.