mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
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:
parent
0826102e0a
commit
580d9cedc7
25 changed files with 921 additions and 723 deletions
9
examples/readline/correct.expect
Executable file
9
examples/readline/correct.expect
Executable 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
|
2
examples/readline/readline.vsh
Normal file
2
examples/readline/readline.vsh
Normal file
|
@ -0,0 +1,2 @@
|
|||
chdir('examples/readline')!
|
||||
assert execute('./correct.expect').exit_code == 0
|
29
examples/readline/readline_ci.v
Normal file
29
examples/readline/readline_ci.v
Normal 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.')
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue