📝 adjust test files
This commit is contained in:
parent
99298b86ab
commit
52dfd52f39
|
@ -37,11 +37,11 @@ var cpu_occupation = func() {
|
|||
while(1) {
|
||||
var cpu0 = cpu_stat();
|
||||
if (first_in) {
|
||||
unix.sleep(0.1);
|
||||
unix.sleep(0.05);
|
||||
first_in = 0;
|
||||
} else {
|
||||
for(var i = 0; i < 10; i += 1) {
|
||||
unix.sleep(0.1);
|
||||
unix.sleep(0.05);
|
||||
coroutine.yield(nil);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
use std.utils;
|
||||
use std.unix;
|
||||
|
||||
var screen_state = {
|
||||
width: 0,
|
||||
height: 0
|
||||
};
|
||||
|
||||
screen_state.update = func() {
|
||||
var res = utils.terminal_size();
|
||||
me.width = res.cols;
|
||||
me.height = res.rows;
|
||||
}
|
||||
|
||||
screen_state.clear_screen = func() {
|
||||
me.update();
|
||||
|
||||
var screen = "\e[0;0H";
|
||||
for (var i = 0; i < me.height; i+=1) {
|
||||
for (var j = 0; j < me.width; j+=1) {
|
||||
screen ~= " ";
|
||||
}
|
||||
if (i != me.height - 1)
|
||||
screen ~= "\n";
|
||||
}
|
||||
print(screen, "\e[0;0H");
|
||||
}
|
||||
|
||||
screen_state.put_pixel = func(x, y, c) {
|
||||
x = int(x);
|
||||
y = int(y);
|
||||
if (x < 0 or x >= me.width or y < 0 or y >= me.height)
|
||||
return;
|
||||
var coord = "\e[" ~ y ~ ";" ~ x ~ "H";
|
||||
print(coord, c, "\e[0;0H");
|
||||
}
|
||||
|
||||
var test_flush = func() {
|
||||
screen_state.clear_screen();
|
||||
for(var i=0; i<1e6; i+=1) {
|
||||
unix.sleep(0.001);
|
||||
screen_state.update();
|
||||
screen_state.put_pixel(
|
||||
rand()*screen_state.width,
|
||||
rand()*screen_state.height,
|
||||
"\e[38;5;" ~ int(256*rand()) ~ "m" ~ char(65 + 26*rand()) ~ "\e[0m"
|
||||
);
|
||||
print("\e[0;0H", i);
|
||||
}
|
||||
|
||||
screen_state.clear_screen();
|
||||
println();
|
||||
}
|
Loading…
Reference in New Issue