Add foreign static getter `isRaw` and setter `isRaw=(value)` to the Stdin class, backed by a new `isStdinRaw` boolean flag and `uv_tty_set_mode` calls. The getter returns the current raw mode state, while the setter initializes the stdin stream if needed and applies raw or normal mode only when stdin is a TTY. Also includes a test file verifying default false, reading bytes in normal mode, enabling raw mode, and reading subsequent bytes.
29 lines
573 B
Plaintext
29 lines
573 B
Plaintext
import "io" for Stdin
|
|
|
|
// Defaults to false.
|
|
System.print(Stdin.isRaw) // expect: false
|
|
|
|
// stdin: abcdefgh
|
|
for (i in 1..4) {
|
|
System.print(Stdin.readByte())
|
|
}
|
|
// expect: 97
|
|
// expect: 98
|
|
// expect: 99
|
|
// expect: 100
|
|
|
|
Stdin.isRaw = true
|
|
System.print(Stdin.isRaw) // expect: true
|
|
|
|
for (i in 1..4) {
|
|
System.print(Stdin.readByte())
|
|
}
|
|
// expect: 101
|
|
// expect: 102
|
|
// expect: 103
|
|
// expect: 104
|
|
|
|
// TODO: This doesn't actually detect a visible difference between raw and
|
|
// non-raw mode. Maybe add support to the test runner for writing non-printing
|
|
// characters to stdin?
|