commit 3372c36

uint  ·  2026-07-14 13:57:56 +0000 UTC
parent 8ebce09
reload font with alt_r + r
2 files changed,  +40, -11
+8, -6
 1@@ -1,6 +1,13 @@
 2 ![](logo.png)  
 3 Is a tiny, cross-platform terminal emulator (written in C).
 4 
 5+### Building:
 6+``` sh
 7+./configure
 8+make
 9+cp cterm /usr/local/bin # or where you want it
10+```
11+
12 ### About
13 cterm is a tiny terminal emulator I built from frustrations of not being able
14 to use [st](https://st.suckless.org/) across different platforms. Much like
15@@ -22,10 +29,5 @@ no problem with adding other formats but no vector font support! If you want to
16 convert your vector font, you can use something like `otf2bdf` (thats what I
17 do!).
18 
19-### Building:
20-``` sh
21-./configure
22-make
23-cp cterm /usr/local/bin # or where you want it
24-```
25+Reloading the font can be done with `AltR + r`
26 
+32, -5
 1@@ -1,3 +1,4 @@
 2+#include "maus_input.h"
 3 #include <errno.h>
 4 #include <fcntl.h>
 5 #include <locale.h>
 6@@ -23,10 +24,11 @@
 7 #include "utils.h"
 8 
 9 static void cleanup(void);
10-static void handle_key(const MausEvent* ev);
11+static bool handle_key(const MausEvent* ev);
12 static void init(void);
13 static bool ptyread(void);
14 static void ptywrite(const char* s, size_t n);
15+static bool reload_font(void);
16 static void resize_pty(void);
17 static int resize_window(int w, int h);
18 static void resize_terminal(int w, int h);
19@@ -70,12 +72,17 @@ static void cleanup(void)
20  *
21  * @param c character check dispatch
22  */
23-static void handle_key(const MausEvent* ev)
24+static bool handle_key(const MausEvent* ev)
25 {
26 	char text;
27 
28 	if (ev->type != MAUS_EV_KEY || !ev->key.pressed)
29-		return;
30+		return false;
31+
32+	if (win->key_syms[MAUS_KEY_ALT_R] &&
33+	   (ev->key.key == MAUS_KEY_R ||
34+	    ev->key.key[MAUS_KEY_R_UP]))
35+		return reload_font();
36 
37 	switch(ev->key.key) {
38 	case MAUS_KEY_ENTER:
39@@ -99,6 +106,8 @@ static void handle_key(const MausEvent* ev)
40 			ptywrite(&text, 1);
41 		break;
42 	}
43+
44+	return false;
45 }
46 
47 /**
48@@ -205,6 +214,22 @@ static void ptywrite(const char* s, size_t n)
49 	}
50 }
51 
52+/* reload the font. true on success, false on failure.
53+   in event of failure, current font will still be in use  */
54+static bool reload_font(void)
55+{
56+	Fontface next;
57+	if (font_load(&next, font_path) < 0)
58+		return false;
59+
60+	font_free(&font);
61+	font = next;
62+	resize_terminal(winw, winh);
63+	term_damage_all(&term);
64+
65+	return true;
66+}
67+
68 /** 
69  * @brief resize pty to reflect window size
70  */
71@@ -291,8 +316,10 @@ static void run(void)
72 				continue;
73 			}
74 
75-
76-			handle_key(&ev);
77+			if (handle_key(&ev)) {
78+				dirty = true;
79+				redraw_all = true;
80+			}
81 		}
82 
83 		if (!running)