summaryrefslogtreecommitdiff
path: root/samples/input.golem
blob: 6cdbb1d0e8189981718194cf0adf2d2f5d9f53a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
main() => input(">>> ") |> print();

define INPUT_BUF_SIZE = 256;
global input_buf[INPUT_BUF_SIZE] = 0;
input(prompt) {
	local i = 0;
	local c;
	print(prompt);
	loop {
		if (i >= INPUT_BUF_SIZE)
			return input_buf;
		red &c;
		if (c == 0x7f) {
			// backspace
			if (i > 0) {
				i = i - 1;
				[input_buf + i] = 0;
				wrt '\r';
				print(prompt);
				print(input_buf);
				wrt ' ';
			}
		} else
			[input_buf + i++] = c;
		wrt '\r';
		print(prompt);
		print(input_buf);
		if (c == '\n')
			return input_buf;
	}
	return input_buf;
}

print(s) {
	loop {
		if ([s] == 0)
			return;
		wrt [s];
		s = s + 1;
	}
}