moved code from header to source files
This commit is contained in:
16
test/color.c
16
test/color.c
@@ -2,27 +2,27 @@
|
||||
|
||||
#include "tim.h"
|
||||
|
||||
static void foo(int x, int y, int c) {
|
||||
static void foo(i32 x, i32 y, i32 c) {
|
||||
char buf[16] = {0};
|
||||
sprintf(buf, " %02x ", c);
|
||||
draw_str(buf, x * 4, y, 4, 0, c);
|
||||
tim_draw_str(buf, x * 4, y, 4, 0, c);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
i32 main(void) {
|
||||
while (tim_run(0)) {
|
||||
for (int i = 0; i < 16; i++) {
|
||||
for (i32 i = 0; i < 16; i++) {
|
||||
foo(i % 8, i / 8, i);
|
||||
}
|
||||
for (int i = 0; i < 108; i++) {
|
||||
for (i32 i = 0; i < 108; i++) {
|
||||
foo(i % 6, i / 6 + 3, i + 16);
|
||||
}
|
||||
for (int i = 0; i < 108; i++) {
|
||||
for (i32 i = 0; i < 108; i++) {
|
||||
foo(i % 6 + 7, i / 6 + 3, i + 124);
|
||||
}
|
||||
for (int i = 0; i < 24; i++) {
|
||||
for (i32 i = 0; i < 24; i++) {
|
||||
foo(i % 12, i / 12 + 22, i + 232);
|
||||
}
|
||||
if (is_key_press('q') || is_key_press(TimKey_Escape)) {
|
||||
if (tim_is_key_press('q') || tim_is_key_press(TimKey_Escape)) {
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
104
test/string.c
104
test/string.c
@@ -2,69 +2,69 @@
|
||||
|
||||
#include "tim.h"
|
||||
|
||||
#define U(s) (uint8_t*)(""s), (sizeof(s) - 1)
|
||||
#define U(s) (u8*)(""s), (sizeof(s) - 1)
|
||||
#define TEST(t) printf("\33[3%s\33[0m %s\n", (t) ? "2mpass" : "1mfail", #t)
|
||||
|
||||
int main(void) {
|
||||
i32 main(void) {
|
||||
(void)tim_run;
|
||||
|
||||
TEST(ztrlen(NULL) == 0);
|
||||
TEST(ztrlen("") == 0);
|
||||
TEST(ztrlen("$") == 1);
|
||||
TEST(ztrlen("£") == 2);
|
||||
TEST(ztrlen("€") == 3);
|
||||
TEST(ztrlen("𐍈") == 4);
|
||||
TEST(tim_ztrlen(NULL) == 0);
|
||||
TEST(tim_ztrlen("") == 0);
|
||||
TEST(tim_ztrlen("$") == 1);
|
||||
TEST(tim_ztrlen("£") == 2);
|
||||
TEST(tim_ztrlen("€") == 3);
|
||||
TEST(tim_ztrlen("𐍈") == 4);
|
||||
|
||||
TEST(bsr8(128) == 0);
|
||||
TEST(bsr8(64) == 1);
|
||||
TEST(bsr8(1) == 7);
|
||||
TEST(bsr8(0) == 8);
|
||||
TEST(tim_bsr8(128) == 0);
|
||||
TEST(tim_bsr8(64) == 1);
|
||||
TEST(tim_bsr8(1) == 7);
|
||||
TEST(tim_bsr8(0) == 8);
|
||||
|
||||
TEST(utfchr(NULL) == 0);
|
||||
TEST(utfchr("") == 0);
|
||||
TEST(utfchr("$") == 0x24);
|
||||
TEST(utfchr("£") == 0xA3);
|
||||
TEST(utfchr("И") == 0x418);
|
||||
TEST(utfchr("ह") == 0x939);
|
||||
TEST(utfchr("€") == 0x20AC);
|
||||
TEST(utfchr("한") == 0xD55C);
|
||||
TEST(utfchr("𐍈") == 0x10348);
|
||||
TEST(tim_utf8_to_i32(NULL) == 0);
|
||||
TEST(tim_utf8_to_i32("") == 0);
|
||||
TEST(tim_utf8_to_i32("$") == 0x24);
|
||||
TEST(tim_utf8_to_i32("£") == 0xA3);
|
||||
TEST(tim_utf8_to_i32("И") == 0x418);
|
||||
TEST(tim_utf8_to_i32("ह") == 0x939);
|
||||
TEST(tim_utf8_to_i32("€") == 0x20AC);
|
||||
TEST(tim_utf8_to_i32("한") == 0xD55C);
|
||||
TEST(tim_utf8_to_i32("𐍈") == 0x10348);
|
||||
|
||||
TEST(utflen(NULL) == 0);
|
||||
TEST(utflen("") == 0);
|
||||
TEST(utflen("$") == 1);
|
||||
TEST(utflen("$$") == 2);
|
||||
TEST(utflen("$£") == 2);
|
||||
TEST(utflen("$€𐍈") == 3);
|
||||
TEST(tim_utf8_len(NULL) == 0);
|
||||
TEST(tim_utf8_len("") == 0);
|
||||
TEST(tim_utf8_len("$") == 1);
|
||||
TEST(tim_utf8_len("$$") == 2);
|
||||
TEST(tim_utf8_len("$£") == 2);
|
||||
TEST(tim_utf8_len("$€𐍈") == 3);
|
||||
|
||||
TEST(utfpos(NULL, 0) == 0);
|
||||
TEST(utfpos("ab", -1) == 0);
|
||||
TEST(utfpos("äbc", 0) == 0);
|
||||
TEST(utfpos("äbc", 1) == 2);
|
||||
TEST(utfpos("äbc", 2) == 3);
|
||||
TEST(utfpos("äbc", 9) == 4);
|
||||
TEST(tim_utf8_pos(NULL, 0) == 0);
|
||||
TEST(tim_utf8_pos("ab", -1) == 0);
|
||||
TEST(tim_utf8_pos("äbc", 0) == 0);
|
||||
TEST(tim_utf8_pos("äbc", 1) == 2);
|
||||
TEST(tim_utf8_pos("äbc", 2) == 3);
|
||||
TEST(tim_utf8_pos("äbc", 9) == 4);
|
||||
|
||||
TEST(scan_str(NULL).lines == 0);
|
||||
TEST(scan_str("").lines == 0);
|
||||
TEST(scan_str("abc").lines == 1);
|
||||
TEST(scan_str("a\no").lines == 2);
|
||||
TEST(scan_str("a").width == 1);
|
||||
TEST(scan_str("äß\no").width == 2);
|
||||
TEST(tim_scan_str(NULL).lines == 0);
|
||||
TEST(tim_scan_str("").lines == 0);
|
||||
TEST(tim_scan_str("abc").lines == 1);
|
||||
TEST(tim_scan_str("a\no").lines == 2);
|
||||
TEST(tim_scan_str("a").width == 1);
|
||||
TEST(tim_scan_str("äß\no").width == 2);
|
||||
|
||||
TimLine_t ln = {.s = "foo\nbar"};
|
||||
TEST(next_line(&ln) == true);
|
||||
TimLine ln = {.s = "foo\nbar"};
|
||||
TEST(tim_next_line(&ln) == true);
|
||||
TEST(!memcmp(ln.line, "foo", ln.size));
|
||||
TEST(next_line(&ln) == true);
|
||||
TEST(tim_next_line(&ln) == true);
|
||||
TEST(!memcmp(ln.line, "bar", ln.size));
|
||||
TEST(next_line(&ln) == false);
|
||||
TEST(tim_next_line(&ln) == false);
|
||||
|
||||
TEST(is_wide_perhaps(NULL, 0) == false);
|
||||
TEST(is_wide_perhaps(U("")) == false);
|
||||
TEST(is_wide_perhaps(U("$")) == false);
|
||||
TEST(is_wide_perhaps(U("£")) == false);
|
||||
TEST(is_wide_perhaps(U("ह")) == false);
|
||||
TEST(is_wide_perhaps(U("€")) == true);
|
||||
TEST(is_wide_perhaps(U("┌")) == false);
|
||||
TEST(is_wide_perhaps(U("한")) == true);
|
||||
TEST(is_wide_perhaps(U("𐍈")) == true);
|
||||
TEST(tim_utf8_is_wide_perhaps(NULL, 0) == false);
|
||||
TEST(tim_utf8_is_wide_perhaps(U("")) == false);
|
||||
TEST(tim_utf8_is_wide_perhaps(U("$")) == false);
|
||||
TEST(tim_utf8_is_wide_perhaps(U("£")) == false);
|
||||
TEST(tim_utf8_is_wide_perhaps(U("ह")) == false);
|
||||
TEST(tim_utf8_is_wide_perhaps(U("€")) == true);
|
||||
TEST(tim_utf8_is_wide_perhaps(U("┌")) == false);
|
||||
TEST(tim_utf8_is_wide_perhaps(U("한")) == true);
|
||||
TEST(tim_utf8_is_wide_perhaps(U("𐍈")) == true);
|
||||
}
|
||||
|
||||
52
test/test.c
52
test/test.c
@@ -1,9 +1,9 @@
|
||||
#include "tim.h"
|
||||
|
||||
static inline void test_screen(TimEvent_t* e) {
|
||||
static TimEvent_t me;
|
||||
static TimEvent_t ke;
|
||||
static int render_us;
|
||||
static inline void test_screen(TimEvent* e) {
|
||||
static TimEvent me;
|
||||
static TimEvent ke;
|
||||
static i32 render_us;
|
||||
char buf[64];
|
||||
|
||||
ke = (e->type == KEY_EVENT) ? *e : ke;
|
||||
@@ -46,8 +46,8 @@ static inline void test_screen(TimEvent_t* e) {
|
||||
label("multi\nliñe\nlabël", 24, 1, A, A, 0xf);
|
||||
|
||||
// colors
|
||||
scope (1, 5, 16, 5) {
|
||||
frame(0, 0, ~0, ~0, 0xf);
|
||||
tim_scope(1, 5, 16, 5) {
|
||||
tim_frame(0, 0, ~0, ~0, 0xf);
|
||||
label(" Red ", 1, 1, 7, A, 0x0900);
|
||||
label(" ", 8, 1, 7, A, 0xc400);
|
||||
label(" Green ", 1, 2, 7, A, 0x0a00);
|
||||
@@ -57,16 +57,16 @@ static inline void test_screen(TimEvent_t* e) {
|
||||
}
|
||||
|
||||
// button
|
||||
static uint64_t bc = 0x100;
|
||||
static u64 bc = 0x100;
|
||||
if (button("Click Me", 17, 5, 16, 5, bc)) {
|
||||
bc = (bc + 0x100) & 0xff00;
|
||||
}
|
||||
|
||||
// edit
|
||||
static TimEdit_t ed1;
|
||||
static TimEdit_t ed2;
|
||||
edit_init(&ed1, 32, "Edit 1");
|
||||
edit_init(&ed2, 32, "");
|
||||
static TimEditState ed1;
|
||||
static TimEditState ed2;
|
||||
TimEditState_init(&ed1, 32, "Edit 1");
|
||||
TimEditState_init(&ed2, 32, "");
|
||||
edit(&ed1, 1, 10, 32, 0xff00ff);
|
||||
sprintf(buf, "cursor: %d length: %d", ed1.cursor, ed1.length);
|
||||
label(buf, 2, 13, A, A, 0xf);
|
||||
@@ -74,46 +74,46 @@ static inline void test_screen(TimEvent_t* e) {
|
||||
label(ed2.s, 2, 17, A, A, 0xf);
|
||||
|
||||
// checkbox
|
||||
static int chk[2] = {-1, 1};
|
||||
static i32 chk[2] = {-1, 1};
|
||||
check("Check 1", &chk[0], 1, 18, A, 0xa000f);
|
||||
check("Check 2", &chk[1], 14, 18, A, 0xa000f);
|
||||
|
||||
// radiobox
|
||||
static int rad = 0;
|
||||
static i32 rad = 0;
|
||||
radio("Radio 1", &rad, 1, 1, 19, A, 0xa000f);
|
||||
radio("Radio 2", &rad, 2, 14, 19, A, 0xa000f);
|
||||
radio("Radio 3", &rad, 3, 1, 20, A, 0xa000f);
|
||||
radio("Radio 4", &rad, 4, 14, 20, A, 0xa000f);
|
||||
|
||||
// scope nesting
|
||||
scope(~1, 1, 20, 10) {
|
||||
scope(0, 0, 10, 5) {
|
||||
frame(0, 0, ~0, ~0, 0x9);
|
||||
tim_scope(~1, 1, 20, 10) {
|
||||
tim_scope(0, 0, 10, 5) {
|
||||
tim_frame(0, 0, ~0, ~0, 0x9);
|
||||
}
|
||||
scope(~0, 0, 10, 5) {
|
||||
frame(0, 0, ~0, ~0, 0xa);
|
||||
tim_scope(~0, 0, 10, 5) {
|
||||
tim_frame(0, 0, ~0, ~0, 0xa);
|
||||
}
|
||||
scope(~0, ~0, 10, 5) {
|
||||
frame(0, 0, ~0, ~0, 0xb);
|
||||
tim_scope(~0, ~0, 10, 5) {
|
||||
tim_frame(0, 0, ~0, ~0, 0xb);
|
||||
}
|
||||
scope(0, ~0, 10, 5) {
|
||||
frame(0, 0, ~0, ~0, 0xc);
|
||||
tim_scope(0, ~0, 10, 5) {
|
||||
tim_frame(0, 0, ~0, ~0, 0xc);
|
||||
}
|
||||
}
|
||||
|
||||
// funny characters
|
||||
scope (~1, ~3, 11, 5) {
|
||||
frame(0, 0, ~0, ~0, 0xf);
|
||||
tim_scope(~1, ~3, 11, 5) {
|
||||
tim_frame(0, 0, ~0, ~0, 0xf);
|
||||
label("123456789", 1, 1, 9, A, 0x0f05);
|
||||
label("$£ह€𐍈6789", 1, 2, A, A, 0x0f05);
|
||||
label("圍棋56789", 1, 3, A, A, 0x0f05);
|
||||
}
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
i32 main(void) {
|
||||
while (tim_run(1.5)) {
|
||||
test_screen(&tim.event);
|
||||
if (is_key_press('q') || is_key_press(TimKey_Escape)) {
|
||||
if (tim_is_key_press('q') || tim_is_key_press(TimKey_Escape)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
22
test/width.c
22
test/width.c
@@ -3,7 +3,7 @@
|
||||
#include <assert.h>
|
||||
#include "tim.h"
|
||||
|
||||
static int cp_to_utf8(int32_t cp, char* s) {
|
||||
static i32 cp_to_utf8(i32 cp, char* s) {
|
||||
assert(cp > 0 && cp < 0x110000);
|
||||
|
||||
if (cp < 0x80) {
|
||||
@@ -29,33 +29,33 @@ static int cp_to_utf8(int32_t cp, char* s) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int cursor_pos() {
|
||||
static i32 cursor_pos() {
|
||||
write(STDOUT_FILENO, S("\33[6n"));
|
||||
char buf[64] = {0};
|
||||
int n = read(STDIN_FILENO, buf, 64);
|
||||
i32 n = read(STDIN_FILENO, buf, 64);
|
||||
if (n < 6 || buf[0] != '\33' || buf[n - 1] != 'R') {
|
||||
return -1;
|
||||
}
|
||||
int r = atoi(buf + 2);
|
||||
int c = atoi(buf + 4 + (r > 9));
|
||||
i32 r = atoi(buf + 2);
|
||||
i32 c = atoi(buf + 4 + (r > 9));
|
||||
return c;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
i32 main(i32 argc, char** argv) {
|
||||
assert(argc == 2);
|
||||
(void)tim_run;
|
||||
|
||||
FILE* f = fopen(argv[1], "w");
|
||||
assert(f);
|
||||
|
||||
init_terminal();
|
||||
tim_init_terminal();
|
||||
|
||||
for (int i = 32; i < 0x110000; i++) {
|
||||
for (i32 i = 32; i < 0x110000; i++) {
|
||||
write(STDOUT_FILENO, S("\33[0;0H"));
|
||||
char buf[5] = {0};
|
||||
int n = cp_to_utf8(i, buf);
|
||||
i32 n = cp_to_utf8(i, buf);
|
||||
write(STDOUT_FILENO, buf, n);
|
||||
int w = cursor_pos() - 1;
|
||||
i32 w = cursor_pos() - 1;
|
||||
if (w) {
|
||||
fprintf(f, "u+%06x %d %s\n", i, w, buf);
|
||||
} else {
|
||||
@@ -63,7 +63,7 @@ int main(int argc, char** argv) {
|
||||
}
|
||||
}
|
||||
|
||||
reset_terminal();
|
||||
tim_reset_terminal();
|
||||
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user