commit 951fca9

seiko  ·  2026-05-30 16:38:32 +0000 UTC
parent c7c714c
use config font options

also fill a few todo function descriptions
2 files changed,  +16, -32
+4, -19
 1@@ -6,11 +6,11 @@
 2 #include <stdlib.h>
 3 
 4 static const char* font_path = "./Xanh.bdf";
 5-static const float font_size = 24.0f;/* BDF fonts ignore font_size */
 6-static const int   antialias = true; /* BDF fonts are not affected */
 7+static const float font_size = 24.0f; /* Bitmap fonts ignore font_size */
 8+static const int   antialias = true;  /* Bitmap fonts are not affected */
 9 
10-static const int   win_width = 800;
11-static const int   win_height = 600;
12+static const int   win_width = 80;  /* in columns */
13+static const int   win_height = 24; /* in rows */
14 static const char* win_title = "cterm";
15 
16 static const int   pad_x = 8;
17@@ -45,20 +45,5 @@ static const uint32_t color_table[16] = {
18 	0xffffffff, /* bright white */
19 };
20 
21-/* Key sequences
22-   These are for physical/special keys only.
23-   Text input should come from translated character events.
24- */
25-static const char *key_up        = "\x1b[A";
26-static const char *key_down      = "\x1b[B";
27-static const char *key_right     = "\x1b[C";
28-static const char *key_left      = "\x1b[D";
29-static const char *key_home      = "\x1b[H";
30-static const char *key_end       = "\x1b[F";
31-static const char *key_insert    = "\x1b[2~";
32-static const char *key_delete    = "\x1b[3~";
33-static const char *key_page_up   = "\x1b[5~";
34-static const char *key_page_down = "\x1b[6~";
35-
36 #endif /* CONFIG_H */
37 
+12, -13
 1@@ -19,14 +19,12 @@
 2 #include <RGFW.h>
 3 #include <schrift.h>
 4 
 5+#include "config.h"
 6 #include "draw.h"
 7 #include "font.h"
 8 #include "term.h"
 9 #include "utils.h"
10 
11-#define START_COLS   80
12-#define START_ROWS   24
13-
14 static void cleanup(void);
15 static void handle_key(RGFW_event ev);
16 static void init(void);
17@@ -140,19 +138,18 @@ static void init(void)
18 	setlocale(LC_CTYPE, "");
19 
20 	/* font */
21-	/* TODO: paths */
22-	if (font_load(&font, "./Xanh.ttf", 24.0) < 0)
23+	if (font_load(&font, font_path, font_size) < 0)
24 		die(1, "failed to load font");
25-	font.aa = true;
26+	font.aa = antialias;
27 
28-	winw = START_COLS*font.cellw;
29-	winh = START_ROWS*font.cellh;
30+	winw = win_width*font.cellw;
31+	winh = win_height*font.cellh;
32 
33-	if (term_resize(&term, &car, START_COLS, START_ROWS) < 0)
34+	if (term_resize(&term, &car, win_width, win_height) < 0)
35 		die(1, "failed to resize terminal");
36 
37 	/* window */
38-	if (!(win = RGFW_createWindow("cterm", 0, 0, winw, winh, 0)))
39+	if (!(win = RGFW_createWindow(win_title, 0, 0, winw, winh, 0)))
40 		die(1, "failed to create window");
41 
42 	pixels = calloc(winw*winh, sizeof(*pixels));
43@@ -177,7 +174,7 @@ static void init(void)
44 		die(EXIT_FAILURE, "failed to fork pty");
45 	if (term.ptypid == 0) {
46 		/* TODO: change later */
47-		setenv("TERM", "vt100", 1);
48+		setenv("TERM", term_name, 1);
49 
50 		/* shell */
51 		if (shell == NULL)
52@@ -243,7 +240,8 @@ static void ptywrite(const char* s, size_t n)
53 	}
54 }
55 
56-/** TODO
57+/** 
58+ * @brief resize pty to reflect window size
59  */
60 static void resize_pty(void)
61 {
62@@ -258,7 +256,8 @@ static void resize_pty(void)
63 		ioctl(term.ptyfd, TIOCSWINSZ, &ws);
64 }
65 
66-/** TODO
67+/** 
68+ * @brief resize window surface to reflect resized size
69  */
70 static int resize_surface(int w, int h)
71 {