termios: new termios module (#17792)

* termio: new termio module

move the tcgetattr and tcsetattr functions in a new termio module.
The code needed refactoring as different OS have different fields
size, position and number for the C.termios structure, which
could not be correctly expressed consitently otherwise.

It has the positive side effect to reduce the number of unsafe calls.
New testing code was also added for the readline module as it is
relying of the feature.

* apply 2023 copyright to the new files too
This commit is contained in:
Thomas Mangin 2023-03-30 06:58:52 +01:00 committed by GitHub
parent 0826102e0a
commit 580d9cedc7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 921 additions and 723 deletions

View file

@ -0,0 +1,9 @@
#!/usr/bin/expect
spawn ./readline_ci
send "a"
expect "got 97"
send "1"
expect "got 49"
send "q"
expect "Goodbye."
expect eof

View file

@ -0,0 +1,2 @@
chdir('examples/readline')!
assert execute('./correct.expect').exit_code == 0

View file

@ -0,0 +1,29 @@
module main
import readline
fn main() {
run() or { panic('${err}') }
}
fn run() ! {
$if windows {
eprintln('skipping test on windows for now')
return
} $else {
mut r := readline.Readline{}
r.enable_raw_mode_nosig()
defer {
r.disable_raw_mode()
}
for {
entered := r.read_char()!
if entered == `q` {
break
}
println('got ${entered}')
}
println('Goodbye.')
}
}