From 00e10bda2a26e29d13f33986062e69b7f7b91a06 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Sun, 5 Aug 2012 09:38:58 +0000 Subject: [PATCH] add bunch of option s to terminology suggested by Thanatermesis - not in the exact way asked due to ecore-getopt, but they are there functionally. SVN revision: 74884 --- src/bin/config.c | 3 ++ src/bin/config.h | 1 + src/bin/main.c | 99 +++++++++++++++++++++++++++++++++++--- src/bin/options_behavior.c | 19 ++++++++ src/bin/termio.c | 4 +- src/bin/termio.h | 2 +- src/bin/termpty.c | 23 ++++++++- src/bin/termpty.h | 2 +- 8 files changed, 140 insertions(+), 13 deletions(-) diff --git a/src/bin/config.c b/src/bin/config.c index 7a67dba4..0f407323 100644 --- a/src/bin/config.c +++ b/src/bin/config.c @@ -86,6 +86,8 @@ config_init(void) (edd_base, Config, "flicker_on_key", flicker_on_key, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC (edd_base, Config, "disable_cursor_blink", disable_cursor_blink, EET_T_UCHAR); + EET_DATA_DESCRIPTOR_ADD_BASIC + (edd_base, Config, "disable_visual_bell", disable_visual_bell, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC (edd_base, Config, "translucent", translucent, EET_T_UCHAR); EET_DATA_DESCRIPTOR_ADD_BASIC @@ -363,6 +365,7 @@ config_load(const char *key) config->jump_on_keypress = EINA_TRUE; config->flicker_on_key = EINA_TRUE; config->disable_cursor_blink = EINA_FALSE; + config->disable_visual_bell = EINA_FALSE; s = eina_unicode_unicode_to_utf8(sep, &slen); if (s) { diff --git a/src/bin/config.h b/src/bin/config.h index d2258887..231c5dce 100644 --- a/src/bin/config.h +++ b/src/bin/config.h @@ -31,6 +31,7 @@ struct _Config Eina_Bool jump_on_change; Eina_Bool flicker_on_key; Eina_Bool disable_cursor_blink; + Eina_Bool disable_visual_bell; Eina_Bool translucent; Eina_Bool mute; Eina_Bool urg_bell; diff --git a/src/bin/main.c b/src/bin/main.c index 93c945c4..e7c59bf4 100644 --- a/src/bin/main.c +++ b/src/bin/main.c @@ -17,6 +17,7 @@ static Evas_Object *popmedia = NULL; static Evas_Object *conform = NULL; static Ecore_Timer *flush_timer = NULL; static Eina_Bool focused = EINA_FALSE; +static Eina_Bool hold = EINA_FALSE; static void _cb_del(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__) @@ -85,7 +86,8 @@ _cb_change(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNU static void _cb_exited(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSED__) { - elm_exit(); + printf("hold = %i\n", hold); + if (!hold) elm_exit(); } static void @@ -93,7 +95,8 @@ _cb_bell(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event __UNUSE { Config *config = termio_config_get(term); - edje_object_signal_emit(bg, "bell", "terminology"); + if (!config->disable_visual_bell) + edje_object_signal_emit(bg, "bell", "terminology"); if (!config) return; if (config->urg_bell) { @@ -208,6 +211,8 @@ static const Ecore_Getopt options = { ECORE_GETOPT_STORE_STR ('e', "exec", "command to execute. " "Defaults to $SHELL (or passwd shel or /bin/sh)"), + ECORE_GETOPT_STORE_STR ('C', "current-directory", + "Change to directory for execution of terminal command."), ECORE_GETOPT_STORE_STR ('t', "theme", "Use the named edje theme or path to theme file."), ECORE_GETOPT_STORE_STR ('b', "background", @@ -222,10 +227,17 @@ static const Ecore_Getopt options = { "Set window title."), ECORE_GETOPT_STORE_STR ('i', "icon-name", "Set icon name."), + ECORE_GETOPT_STORE_STR ('f', "font", + "Set font (NAME/SIZE for scalable, NAME for bitmap."), ECORE_GETOPT_CHOICE ('v', "video-module", "Set emotion module to use.", emotion_choices), + ECORE_GETOPT_STORE_BOOL('m', "video-mute", "Set mute mode for video playback."), + ECORE_GETOPT_STORE_BOOL('c', "cursor-blink", + "Set cursor blink mode."), + ECORE_GETOPT_STORE_BOOL('V', "visual-bell", + "Set visual bell mode."), ECORE_GETOPT_STORE_TRUE('F', "fullscreen", "Go into the fullscreen mode from start."), ECORE_GETOPT_STORE_TRUE('I', "iconic", @@ -238,10 +250,13 @@ static const Ecore_Getopt options = { "Become maximized from the start."), ECORE_GETOPT_STORE_TRUE('W', "nowm", "Terminology is run without a wm."), - ECORE_GETOPT_VERSION('V', "version"), - ECORE_GETOPT_COPYRIGHT('C', "copyright"), - ECORE_GETOPT_LICENSE('L', "license"), - ECORE_GETOPT_HELP('h', "help"), + ECORE_GETOPT_STORE_TRUE('H', "hold", + "Don't exit when the command process exits."), + + ECORE_GETOPT_VERSION ('V', "version"), + ECORE_GETOPT_COPYRIGHT ('C', "copyright"), + ECORE_GETOPT_LICENSE ('L', "license"), + ECORE_GETOPT_HELP ('h', "help"), ECORE_GETOPT_SENTINEL } }; @@ -250,6 +265,7 @@ EAPI_MAIN int elm_main(int argc, char **argv) { char *cmd = NULL; + char *cd = NULL; char *theme = NULL; char *background = NULL; char *geometry = NULL; @@ -257,8 +273,11 @@ elm_main(int argc, char **argv) char *role = NULL; char *title = NULL; char *icon_name = NULL; + char *font = NULL; char *video_module = NULL; Eina_Bool video_mute = 0xff; /* unset */ + Eina_Bool cursor_blink = 0xff; /* unset */ + Eina_Bool visual_bell = 0xff; /* unset */ Eina_Bool fullscreen = EINA_FALSE; Eina_Bool iconic = EINA_FALSE; Eina_Bool borderless = EINA_FALSE; @@ -268,6 +287,7 @@ elm_main(int argc, char **argv) Eina_Bool quit_option = EINA_FALSE; Ecore_Getopt_Value values[] = { ECORE_GETOPT_VALUE_STR(cmd), + ECORE_GETOPT_VALUE_STR(cd), ECORE_GETOPT_VALUE_STR(theme), ECORE_GETOPT_VALUE_STR(background), ECORE_GETOPT_VALUE_STR(geometry), @@ -275,18 +295,25 @@ elm_main(int argc, char **argv) ECORE_GETOPT_VALUE_STR(role), ECORE_GETOPT_VALUE_STR(title), ECORE_GETOPT_VALUE_STR(icon_name), + ECORE_GETOPT_VALUE_STR(font), ECORE_GETOPT_VALUE_STR(video_module), + ECORE_GETOPT_VALUE_BOOL(video_mute), + ECORE_GETOPT_VALUE_BOOL(cursor_blink), + ECORE_GETOPT_VALUE_BOOL(visual_bell), ECORE_GETOPT_VALUE_BOOL(fullscreen), ECORE_GETOPT_VALUE_BOOL(iconic), ECORE_GETOPT_VALUE_BOOL(borderless), ECORE_GETOPT_VALUE_BOOL(override), ECORE_GETOPT_VALUE_BOOL(maximized), ECORE_GETOPT_VALUE_BOOL(nowm), + ECORE_GETOPT_VALUE_BOOL(hold), + ECORE_GETOPT_VALUE_BOOL(quit_option), ECORE_GETOPT_VALUE_BOOL(quit_option), ECORE_GETOPT_VALUE_BOOL(quit_option), ECORE_GETOPT_VALUE_BOOL(quit_option), + ECORE_GETOPT_VALUE_NONE }; int args, retval = EXIT_SUCCESS; @@ -349,6 +376,52 @@ elm_main(int argc, char **argv) config->temporary = EINA_TRUE; } + if (font) + { + if (strchr(font, '/')) + { + char *fname = alloca(strlen(font) + 1); + char *p; + + strcpy(fname, font); + p = strrchr(fname, '/'); + if (p) + { + int sz; + + *p = 0; + p++; + sz = atoi(p); + if (sz > 0) config->font.size = sz; + eina_stringshare_replace(&(config->font.name), fname); + } + config->font.bitmap = 0; + } + else + { + char buf[4096], *file; + Eina_List *files; + int n = strlen(font); + + snprintf(buf, sizeof(buf), "%s/fonts", elm_app_data_dir_get()); + files = ecore_file_ls(buf); + EINA_LIST_FREE(files, file) + { + if (n > 0) + { + if (!strncasecmp(file, font, n)) + { + n = -1; + eina_stringshare_replace(&(config->font.name), file); + config->font.bitmap = 1; + } + } + free(file); + } + } + config->temporary = EINA_TRUE; + } + if (video_module) { int i; @@ -369,7 +442,17 @@ elm_main(int argc, char **argv) config->mute = video_mute; config->temporary = EINA_TRUE; } - + if (cursor_blink != 0xff) + { + config->disable_cursor_blink = !cursor_blink; + config->temporary = EINA_TRUE; + } + if (visual_bell != 0xff) + { + config->disable_visual_bell = !visual_bell; + config->temporary = EINA_TRUE; + } + if (geometry) { if (sscanf(geometry,"%ix%i+%i+%i", &size_w, &size_h, &pos_x, &pos_y) == 4) @@ -472,7 +555,7 @@ elm_main(int argc, char **argv) evas_object_move(win, pos_x, pos_y); } - term = o = termio_add(win, config, cmd, size_w, size_h); + term = o = termio_add(win, config, cmd, cd, size_w, size_h); termio_win_set(o, win); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_size_hint_fill_set(o, EVAS_HINT_FILL, EVAS_HINT_FILL); diff --git a/src/bin/options_behavior.c b/src/bin/options_behavior.c index 22bc0429..78ddcf63 100644 --- a/src/bin/options_behavior.c +++ b/src/bin/options_behavior.c @@ -39,6 +39,15 @@ _cb_op_behavior_cursor_blink_chg(void *data, Evas_Object *obj, void *event __UNU config_save(config, NULL); } +static void +_cb_op_behavior_visual_bell_chg(void *data, Evas_Object *obj, void *event __UNUSED__) +{ + Evas_Object *term = data; + Config *config = termio_config_get(term); + config->disable_visual_bell = !elm_check_state_get(obj); + config_save(config, NULL); +} + static void _cb_op_behavior_flicker_chg(void *data, Evas_Object *obj, void *event __UNUSED__) { @@ -151,6 +160,16 @@ options_behavior(Evas_Object *opbox, Evas_Object *term) evas_object_smart_callback_add(o, "changed", _cb_op_behavior_cursor_blink_chg, term); + o = elm_check_add(bx); + evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); + evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); + elm_object_text_set(o, "Visual Bell"); + elm_check_state_set(o, !config->disable_visual_bell); + elm_box_pack_end(bx, o); + evas_object_show(o); + evas_object_smart_callback_add(o, "changed", + _cb_op_behavior_visual_bell_chg, term); + o = elm_check_add(bx); evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); diff --git a/src/bin/termio.c b/src/bin/termio.c index c5d4d803..3cd4e721 100644 --- a/src/bin/termio.c +++ b/src/bin/termio.c @@ -2187,7 +2187,7 @@ _smart_pty_command(void *data) } Evas_Object * -termio_add(Evas_Object *parent, Config *config, const char *cmd, int w, int h) +termio_add(Evas_Object *parent, Config *config, const char *cmd, const char *cd, int w, int h) { Evas *e; Evas_Object *obj, *g; @@ -2226,7 +2226,7 @@ termio_add(Evas_Object *parent, Config *config, const char *cmd, int w, int h) termpty_init(); - sd->pty = termpty_new(cmd, w, h, config->scrollback); + sd->pty = termpty_new(cmd, cd, w, h, config->scrollback); sd->pty->cb.change.func = _smart_pty_change; sd->pty->cb.change.data = obj; sd->pty->cb.scroll.func = _smart_pty_scroll; diff --git a/src/bin/termio.h b/src/bin/termio.h index 781a69eb..5fa3f0bd 100644 --- a/src/bin/termio.h +++ b/src/bin/termio.h @@ -3,7 +3,7 @@ #include "config.h" -Evas_Object *termio_add(Evas_Object *parent, Config *config, const char *cmd, int w, int h); +Evas_Object *termio_add(Evas_Object *parent, Config *config, const char *cmd, const char *cd, int w, int h); void termio_win_set(Evas_Object *obj, Evas_Object *win); char *termio_selection_get(Evas_Object *obj, int c1x, int c1y, int c2x, int c2y); void termio_config_update(Evas_Object *obj); diff --git a/src/bin/termpty.c b/src/bin/termpty.c index 8c7a2ccf..a762d5ff 100644 --- a/src/bin/termpty.c +++ b/src/bin/termpty.c @@ -150,6 +150,16 @@ _cb_exe_exit(void *data, int type __UNUSED__, void *event) if (ev->pid != ty->pid) return ECORE_CALLBACK_PASS_ON; ty->exit_code = ev->exit_code; if (ty->cb.exited.func) ty->cb.exited.func(ty->cb.exited.data); + + if (ty->hand_exe_exit) ecore_event_handler_del(ty->hand_exe_exit); + ty->hand_exe_exit = NULL; + if (ty->hand_fd) ecore_main_fd_handler_del(ty->hand_fd); + ty->hand_fd = NULL; + if (ty->fd >= 0) close(ty->fd); + ty->fd = -1; + if (ty->slavefd >= 0) close(ty->slavefd); + ty->slavefd = -1; + return ECORE_CALLBACK_PASS_ON; } @@ -219,7 +229,7 @@ _limit_coord(Termpty *ty, Termstate *state) } Termpty * -termpty_new(const char *cmd, int w, int h, int backscroll) +termpty_new(const char *cmd, const char *cd, int w, int h, int backscroll) { Termpty *ty; const char *pty; @@ -258,6 +268,16 @@ termpty_new(const char *cmd, int w, int h, int backscroll) Eina_Bool needs_shell; int i; + if (cd) + { + if (chdir(cd) != 0) + { + perror("chdir"); + ERR("Cannot change to directory '%s'", cd); + exit(127); + } + } + needs_shell = ((!cmd) || (strpbrk(cmd, " |&;<>()$`\\\"'*?#") != NULL)); DBG("cmd='%s' needs_shell=%u", cmd ? cmd : "", needs_shell); @@ -378,6 +398,7 @@ termpty_cellrow_get(Termpty *ty, int y, int *wret) void termpty_write(Termpty *ty, const char *input, int len) { + if (ty->fd < 0) return; if (write(ty->fd, input, len) < 0) ERR("write %s", strerror(errno)); } diff --git a/src/bin/termpty.h b/src/bin/termpty.h index 9582ef59..6a81ce8f 100644 --- a/src/bin/termpty.h +++ b/src/bin/termpty.h @@ -126,7 +126,7 @@ struct _Termsave void termpty_init(void); void termpty_shutdown(void); -Termpty *termpty_new(const char *cmd, int w, int h, int backscroll); +Termpty *termpty_new(const char *cmd, const char *cd, int w, int h, int backscroll); void termpty_free(Termpty *ty); Termcell *termpty_cellrow_get(Termpty *ty, int y, int *wret); void termpty_write(Termpty *ty, const char *input, int len);