From 038aac7fd52c08ba46af8d781498819c59a04b8f Mon Sep 17 00:00:00 2001 From: David Herrmann Date: Mon, 1 Oct 2012 12:41:06 +0200 Subject: [PATCH] wlt: add --term, --login, --palette and --sb-size These terminal options are simply copied from kmscon and behave the same way. Signed-off-by: David Herrmann --- src/wlt_main.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/wlt_main.h | 11 +++++++++++ src/wlt_terminal.c | 10 ++++++++++ 3 files changed, 71 insertions(+) diff --git a/src/wlt_main.c b/src/wlt_main.c index f046bac..e6a0895 100644 --- a/src/wlt_main.c +++ b/src/wlt_main.c @@ -28,6 +28,7 @@ */ #include +#include #include #include #include @@ -197,6 +198,7 @@ static void print_help() "Usage:\n" "\t%1$s [options]\n" "\t%1$s -h [options]\n" + "\t%1$s -l [options] -- /bin/sh [sh-arguments]\n" "\n" "You can prefix boolean options with \"no-\" to negate it. If an argument is\n" "given multiple times, only the last argument matters if not otherwise stated.\n" @@ -207,6 +209,22 @@ static void print_help() "\t --debug [off] Enable debug mode\n" "\t --silent [off] Suppress notices and warnings\n" "\n" + "Terminal Options:\n" + "\t-l, --login [/bin/sh]\n" + "\t Start the given login process instead\n" + "\t of the default process; all arguments\n" + "\t following '--' will be be parsed as\n" + "\t argv to this process. No more options\n" + "\t after '--' will be parsed so use it at\n" + "\t the end of the argument string\n" + "\t-t, --term [xterm-256color]\n" + "\t Value of the TERM environment variable\n" + "\t for the child process\n" + "\t --palette [default]\n" + "\t Select the used color palette\n" + "\t --sb-size [1000]\n" + "\t Size of the scrollback-buffer in lines\n" + "\n" "Keyboard Shortcuts and Grabs:\n" "\t --grab-scroll-up [Up]\n" "\t Shortcut to scroll up\n" @@ -258,6 +276,31 @@ static int aftercheck_help(struct conf_option *opt, int argc, char **argv, return 0; } +static char *def_argv[] = { NULL, "-i", NULL }; + +static int aftercheck_login(struct conf_option *opt, int argc, char **argv, + int idx) +{ + int ret; + + /* parse "--login [...] -- args" arguments */ + if (wlt_conf.login) { + if (idx >= argc) { + fprintf(stderr, "Arguments for --login missing\n"); + return -EFAULT; + } + + wlt_conf.argv = &argv[idx]; + ret = argc - idx; + } else { + def_argv[0] = getenv("SHELL") ? : _PATH_BSHELL; + wlt_conf.argv = def_argv; + ret = 0; + } + + return ret; +} + static struct conf_grab def_grab_scroll_up = { .mods = SHL_SHIFT_MASK, .keysym = XKB_KEY_Up, @@ -283,10 +326,17 @@ struct conf_option options[] = { CONF_OPTION_BOOL('v', "verbose", NULL, &wlt_conf.verbose, false), CONF_OPTION_BOOL(0, "debug", aftercheck_debug, &wlt_conf.debug, false), CONF_OPTION_BOOL(0, "silent", NULL, &wlt_conf.silent, false), + + CONF_OPTION_BOOL('l', "login", aftercheck_login, &wlt_conf.login, false), + CONF_OPTION_STRING('t', "term", NULL, &wlt_conf.term, "xterm-256color"), + CONF_OPTION_STRING(0, "palette", NULL, &wlt_conf.palette, NULL), + CONF_OPTION_UINT(0, "sb-size", NULL, &wlt_conf.sb_size, 1000), + CONF_OPTION_GRAB(0, "grab-scroll-up", NULL, &wlt_conf.grab_scroll_up, &def_grab_scroll_up), CONF_OPTION_GRAB(0, "grab-scroll-down", NULL, &wlt_conf.grab_scroll_down, &def_grab_scroll_down), CONF_OPTION_GRAB(0, "grab-page-up", NULL, &wlt_conf.grab_page_up, &def_grab_page_up), CONF_OPTION_GRAB(0, "grab-page-down", NULL, &wlt_conf.grab_page_down, &def_grab_page_down), + CONF_OPTION_STRING(0, "font-engine", NULL, &wlt_conf.font_engine, "pango"), CONF_OPTION_UINT(0, "font-size", NULL, &wlt_conf.font_size, 12), CONF_OPTION_STRING(0, "font-name", NULL, &wlt_conf.font_name, "monospace"), diff --git a/src/wlt_main.h b/src/wlt_main.h index ce14606..99d90ed 100644 --- a/src/wlt_main.h +++ b/src/wlt_main.h @@ -46,6 +46,17 @@ struct wlt_conf_t { /* disable notices and warnings */ bool silent; + /* custom login process */ + bool login; + /* argv for login process */ + char **argv; + /* TERM value */ + char *term; + /* color palette */ + char *palette; + /* terminal scroll-back buffer size */ + unsigned int sb_size; + /* scroll-up grab */ struct conf_grab *grab_scroll_up; /* scroll-down grab */ diff --git a/src/wlt_terminal.c b/src/wlt_terminal.c index 0c02eda..b55dafa 100644 --- a/src/wlt_terminal.c +++ b/src/wlt_terminal.c @@ -364,12 +364,14 @@ int wlt_terminal_new(struct wlt_terminal **out, struct wlt_window *wnd) log_error("cannot create tsm-screen object"); goto err_font; } + tsm_screen_set_max_sb(term->scr, wlt_conf.sb_size); ret = tsm_vte_new(&term->vte, term->scr, vte_event, term, log_llog); if (ret) { log_error("cannot create tsm-vte object"); goto err_scr; } + tsm_vte_set_palette(term->vte, wlt_conf.palette); ret = kmscon_pty_new(&term->pty, pty_input, term); if (ret) { @@ -378,6 +380,14 @@ int wlt_terminal_new(struct wlt_terminal **out, struct wlt_window *wnd) } kmscon_pty_set_term(term->pty, "xterm-256color"); + ret = kmscon_pty_set_term(term->pty, wlt_conf.term); + if (ret) + goto err_pty; + + ret = kmscon_pty_set_argv(term->pty, wlt_conf.argv); + if (ret) + goto err_pty; + ret = ev_eloop_new_fd(term->eloop, &term->pty_fd, kmscon_pty_get_fd(term->pty), EV_READABLE, pty_event, term); -- 2.7.4