mirror of
https://github.com/ruby/ruby.git
synced 2026-10-28 16:36:20 +08:00
Return the byte count from IO#write to a Windows console
`rb_w32_write_console` returns the number of UTF-16 code units it wrote, so writing "あ" to a console returned 1 instead of 3 as it does for files and NUL. Use the result only to tell success, as the other callers do. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cd3657cf06
commit
7cdbc84614
2 files changed
+14
-2
Notes:
git
2026-09-27 00:02:58 +00:00
No files matched your search
@@ -2114,8 +2114,7 @@ io_fwrite(VALUE str, rb_io_t *fptr, int nosync)
|
||||
|
||||
#ifdef _WIN32
|
||||
if (fptr->mode & FMODE_TTY) {
|
||||
long len = rb_w32_write_console(str, fptr->fd);
|
||||
if (len > 0) return len;
|
||||
if (rb_w32_write_console(str, fptr->fd) > 0) return RSTRING_LEN(str);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2656,6 +2656,19 @@ EOT
|
||||
end
|
||||
end if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||
|
||||
def test_write_to_console
|
||||
begin
|
||||
con = File.open("CONOUT$", "r+")
|
||||
rescue SystemCallError
|
||||
omit "console is not available"
|
||||
end
|
||||
# non-ASCII, but leaves nothing visible on the console
|
||||
str = "\u00a0\b"
|
||||
assert_equal(str.bytesize, con.write(str))
|
||||
ensure
|
||||
con&.close
|
||||
end if /mswin|mingw/ =~ RUBY_PLATFORM
|
||||
|
||||
def test_cr_decorator_on_stdout
|
||||
with_pipe do |in_r, in_w|
|
||||
with_pipe do |out_r, out_w|
|
||||
|
||||
Reference in new issue
Block a user