mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Workaround https://github.com/microsoft/terminal/issues/16606 (#8506)
Fixes #8504
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 } },
|
||||
};
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user