From 2bca2a894ed9f4a4ce8ec15b30cc3e2ed487cc07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Wed, 3 Jul 2019 09:46:13 +0200 Subject: [PATCH] main: add --font/-f command line option --- main.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/main.c b/main.c index b82fa7a7..88c08998 100644 --- a/main.c +++ b/main.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -408,7 +409,6 @@ grid_render(struct context *c) last_buf = buf; } - tll_foreach(c->term.grid->scroll_damage, it) { switch (it->item.type) { case DAMAGE_SCROLL: @@ -803,10 +803,40 @@ keyboard_repeater(void *arg) } int -main(int argc, const char *const *argv) +main(int argc, char *const *argv) { int ret = EXIT_FAILURE; + static const struct option longopts[] = { + {"font", required_argument, 0, 'f'}, + {NULL, no_argument, 0, 0}, + }; + + const char *font_name = "Dina:pixelsize=12"; + + while (true) { + int c = getopt_long(argc, argv, ":f:h", longopts, NULL); + if (c == -1) + break; + + switch (c) { + case 'f': + font_name = optarg; + break; + + case 'h': + break; + + case ':': + fprintf(stderr, "error: -%c: missing required argument\n", optopt); + return EXIT_FAILURE; + + case '?': + fprintf(stderr, "error: -%c: invalid option\n", optopt); + return EXIT_FAILURE; + } + } + setlocale(LC_ALL, ""); int repeat_pipe_fds[2] = {-1, -1}; @@ -846,7 +876,6 @@ main(int argc, const char *const *argv) thrd_t keyboard_repeater_id; thrd_create(&keyboard_repeater_id, &keyboard_repeater, &c.term); - const char *font_name = "Dina:pixelsize=12"; c.fonts[0] = font_from_name(font_name); if (c.fonts[0] == NULL) goto out;