vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

Commit: 07bbc2d5ebc9ab37ea29ab9aa1b076aa4b1e56aa
Parent: bfa3e53438d2e2a9ac5e86a9d5661c3aa0e81723
Author: Randy Palamar
Date:   Mon, 19 Aug 2024 23:09:52 -0600

shuffle things around to remove config.h from main.c

Including it in main.c limits the ability to configure things in
debug/hot reloading mode.

Diffstat:
Mbuild.sh | 6+-----
Mconfig.def.h | 2--
Mfont.c | 5+++--
Mmain.c | 19+++++++++----------
Mtest.c | 10++++++----
Mutil.h | 8--------
Mvtgl.c | 18++++++++++++++++++
7 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/build.sh b/build.sh @@ -12,12 +12,8 @@ cflags="$cflags -D_DEBUG -Wno-unused-function -Wno-undefined-internal" libcflags="$cflags -fPIC -Wno-unused-function" libldflags="$ldflags -shared" -testcflags="-march=native -ggdb -O0 -Wall $(pkg-config --cflags freetype2)" -testcflags="$testcflags -D_DEBUG -Wno-unused-function -Wno-undefined-internal" -testldflags="-lfreetype" - if ! [ -s "./config.h" ]; then cp ./config.def.h ./config.h; fi cc $libcflags vtgl.c -o vtgl.so $libldflags cc $cflags -o vtgl main.c $ldflags -cc $testcflags -o test test.c $testldflags +cc $cflags -o test test.c $ldflags diff --git a/config.def.h b/config.def.h @@ -1,6 +1,4 @@ /* See LICENSE for copyright details */ -static s8 g_default_title = s8("vtgl"); - static char *g_fonts[] = { "monospace:style=Regular:pixelsize=16", }; diff --git a/font.c b/font.c @@ -107,8 +107,9 @@ set_font_sizes(FontAtlas *fa, u32 fontsize) } static void -init_fonts(Term *t, char **fontstrs, u32 nfontstrs, Arena *a) +init_fonts(Term *t, Arena *a) { + u32 nfontstrs = ARRAY_COUNT(g_fonts); if (FT_Init_FreeType(&t->fa.ftlib)) die("init_fonts: failed to init FreeType\n"); if (!(t->fa.fc = FcInitLoadConfigAndFonts())) @@ -118,7 +119,7 @@ init_fonts(Term *t, char **fontstrs, u32 nfontstrs, Arena *a) t->fa.fonts = alloc(a, Font, nfontstrs); for (t->fa.nfonts = 0; t->fa.nfonts < nfontstrs; t->fa.nfonts++) { valid_atlas |= init_font(&t->fa, t->fa.fonts + t->fa.nfonts, - (u8 *)fontstrs[t->fa.nfonts]); + (u8 *)g_fonts[t->fa.nfonts]); } if (!valid_atlas) { /* TODO: open some default font */ diff --git a/main.c b/main.c @@ -22,6 +22,9 @@ static do_terminal_fn *do_terminal; typedef void init_callbacks_fn(GLCtx *); static init_callbacks_fn *init_callbacks; +typedef void init_term_fn(Term *, Arena *); +static init_term_fn *init_term; + static void load_library(const char *lib) { @@ -37,6 +40,9 @@ load_library(const char *lib) init_callbacks = dlsym(libhandle, "init_callbacks"); if (!init_callbacks) fprintf(stderr, "do_debug: dlsym: %s\n", dlerror()); + init_term = dlsym(libhandle, "init_term"); + if (!init_term) + fprintf(stderr, "do_debug: dlsym: %s\n", dlerror()); } static void @@ -103,8 +109,7 @@ init_window(Term *t, Arena arena) glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); - char *title = s8_to_cstr(&arena, g_default_title); - t->gl.window = glfwCreateWindow(t->gl.window_size.w, t->gl.window_size.h, title, NULL, NULL); + t->gl.window = glfwCreateWindow(t->gl.window_size.w, t->gl.window_size.h, "vtgl", NULL, NULL); if (!t->gl.window) { glfwTerminate(); die("Failed to spawn GLFW window\n"); @@ -273,13 +278,8 @@ main(void) Term term = {0}; init_window(&term, memory); - init_fonts(&term, g_fonts, ARRAY_COUNT(g_fonts), &memory); - - for (u32 i = 0; i < ARRAY_COUNT(term.saved_cursors); i++) { - cursor_reset(&term); - cursor_move_to(&term, 0, 0); - cursor_alt(&term, 1); - } + do_debug(&term.gl); + init_term(&term, &memory); os_alloc_ring_buffer(&term.views[0].log, BACKLOG_SIZE); line_buf_alloc(&term.views[0].lines, &memory, term.views[0].log.buf, term.cursor.state, @@ -290,7 +290,6 @@ main(void) term.child = os_fork_child("/bin/sh"); - do_debug(&term.gl); init_callbacks(&term.gl); f32 last_time = 0; diff --git a/test.c b/test.c @@ -1,9 +1,11 @@ +#include "vtgl.c" + /* NOTE: stubs for stuff we aren't testing */ -typedef void *GLFWwindow; -static void glfwSetWindowTitle(GLFWwindow *w, const char *s) {}; -static const char *glfwGetWindowTitle(GLFWwindow *w) { return "test"; }; +#undef glfwSetWindowTitle +#undef glfwGetWindowTitle -#include "util.h" +void glfwSetWindowTitle(GLFWwindow *w, const char *s) {}; +const char *glfwGetWindowTitle(GLFWwindow *w) { return "test"; }; #include <string.h> /* memcmp */ diff --git a/util.h b/util.h @@ -294,12 +294,4 @@ typedef struct { char saved_title[1024]; } Term; -#include "config.h" -#include "font.c" -#include "terminal.c" - -#ifdef _DEBUG -#include "debug.c" -#endif - #endif /* _UTIL_H_ */ diff --git a/vtgl.c b/vtgl.c @@ -5,6 +5,13 @@ #include <GLFW/glfw3.h> #include "util.h" +#include "config.h" + +#include "font.c" +#include "terminal.c" +#ifdef _DEBUG +#include "debug.c" +#endif #define MAX_FONT_SIZE 128.0f #define TEXTURE_GLYPH_COUNT PUSH_BUFFER_CAP @@ -384,6 +391,17 @@ char_callback(GLFWwindow *win, u32 codepoint) } DEBUG_EXPORT void +init_term(Term *t, Arena *a) +{ + init_fonts(t, a); + for (u32 i = 0; i < ARRAY_COUNT(t->saved_cursors); i++) { + cursor_reset(t); + cursor_move_to(t, 0, 0); + cursor_alt(t, 1); + } +} + +DEBUG_EXPORT void init_callbacks(GLCtx *gl) { glfwSetCharCallback(gl->window, char_callback);