vinix-ports / tests / busybox / serial-line.v
43 lines · 40 sloc · 701 bytes · bab248237a1eca59fa104857d6fe6b268b9d69e0
Raw
1// Emit one edited serial line to ash. Vinix COM reads wait for exactly the
2// requested byte count. The port does not supply a terminal line discipline.
3module main
4
5#include <unistd.h>
6
7fn C.read(int, voidptr, uint) int
8fn C.write(int, voidptr, uint) int
9
10fn main() {
11 mut line := []u8{}
12 mut byte := u8(0)
13 for {
14 if C.read(0, &byte, 1) != 1 {
15 exit(1)
16 }
17 match byte {
18 3 {
19 eprintln('^C')
20 return
21 }
22 4 {
23 if line.len == 0 {
24 exit(1)
25 }
26 break
27 }
28 8, 127 {
29 if line.len > 0 {
30 line.delete_last()
31 eprint('\b \b')
32 }
33 }
34 10, 13 { break }
35 else {
36 line << byte
37 C.write(2, &byte, 1)
38 }
39 }
40 }
41 eprint('\r\n')
42 println(line.bytestr())
43}
44