summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2013-09-22 17:10:39 +0200
committerBoris Faure <billiob@gmail.com>2013-09-26 21:19:18 +0200
commitf539eba7ca61e5fe266668fda3d8c29673ee70f7 (patch)
tree3774869e199358a620205e4819998d7c3dc2fbd4
parented36063690c388d92644cd825a39b698f957d843 (diff)
screw terminfo: have a config to decide whether erase is del or backspace
One day I'll have to dig into the terminfo/termcap mess :( Maybe get the O'Reilly book about it…
-rw-r--r--src/bin/config.c5
-rw-r--r--src/bin/config.h1
-rw-r--r--src/bin/keyin.c23
-rw-r--r--src/bin/options_behavior.c20
-rw-r--r--src/bin/termio.c2
-rw-r--r--src/bin/termpty.c29
-rw-r--r--src/bin/termpty.h12
7 files changed, 86 insertions, 6 deletions
diff --git a/src/bin/config.c b/src/bin/config.c
index ecbd2c9..98b9e4f 100644
--- a/src/bin/config.c
+++ b/src/bin/config.c
@@ -86,6 +86,8 @@ config_init(void)
86 EET_DATA_DESCRIPTOR_ADD_BASIC 86 EET_DATA_DESCRIPTOR_ADD_BASIC
87 (edd_base, Config, "xterm_256color", xterm_256color, EET_T_UCHAR); 87 (edd_base, Config, "xterm_256color", xterm_256color, EET_T_UCHAR);
88 EET_DATA_DESCRIPTOR_ADD_BASIC 88 EET_DATA_DESCRIPTOR_ADD_BASIC
89 (edd_base, Config, "erase_is_del", erase_is_del, EET_T_UCHAR);
90 EET_DATA_DESCRIPTOR_ADD_BASIC
89 (edd_base, Config, "custom_geometry", custom_geometry, EET_T_UCHAR); 91 (edd_base, Config, "custom_geometry", custom_geometry, EET_T_UCHAR);
90 EET_DATA_DESCRIPTOR_ADD_BASIC 92 EET_DATA_DESCRIPTOR_ADD_BASIC
91 (edd_base, Config, "cg_width", cg_width, EET_T_INT); 93 (edd_base, Config, "cg_width", cg_width, EET_T_INT);
@@ -179,6 +181,7 @@ config_sync(const Config *config_src, Config *config)
179 config->application_server = config_src->application_server; 181 config->application_server = config_src->application_server;
180 config->application_server_restore_views = config_src->application_server_restore_views; 182 config->application_server_restore_views = config_src->application_server_restore_views;
181 config->xterm_256color = config_src->xterm_256color; 183 config->xterm_256color = config_src->xterm_256color;
184 config->erase_is_del = config_src->erase_is_del;
182 config->temporary = config_src->temporary; 185 config->temporary = config_src->temporary;
183 config->custom_geometry = config_src->custom_geometry; 186 config->custom_geometry = config_src->custom_geometry;
184 config->cg_width = config_src->cg_width; 187 config->cg_width = config_src->cg_width;
@@ -438,6 +441,7 @@ config_load(const char *key)
438 config->application_server = EINA_FALSE; 441 config->application_server = EINA_FALSE;
439 config->application_server_restore_views = EINA_FALSE; 442 config->application_server_restore_views = EINA_FALSE;
440 config->xterm_256color = EINA_FALSE; 443 config->xterm_256color = EINA_FALSE;
444 config->erase_is_del = EINA_FALSE;
441 config->custom_geometry = EINA_FALSE; 445 config->custom_geometry = EINA_FALSE;
442 config->cg_width = 80; 446 config->cg_width = 80;
443 config->cg_height = 24; 447 config->cg_height = 24;
@@ -489,6 +493,7 @@ config_fork(Config *config)
489 CPY(application_server); 493 CPY(application_server);
490 CPY(application_server_restore_views); 494 CPY(application_server_restore_views);
491 CPY(xterm_256color); 495 CPY(xterm_256color);
496 CPY(erase_is_del);
492 CPY(custom_geometry); 497 CPY(custom_geometry);
493 CPY(cg_width); 498 CPY(cg_width);
494 CPY(cg_height); 499 CPY(cg_height);
diff --git a/src/bin/config.h b/src/bin/config.h
index 29390a4..18d4f29 100644
--- a/src/bin/config.h
+++ b/src/bin/config.h
@@ -43,6 +43,7 @@ struct _Config
43 Eina_Bool application_server; 43 Eina_Bool application_server;
44 Eina_Bool application_server_restore_views; 44 Eina_Bool application_server_restore_views;
45 Eina_Bool xterm_256color; 45 Eina_Bool xterm_256color;
46 Eina_Bool erase_is_del;
46 Eina_Bool custom_geometry; 47 Eina_Bool custom_geometry;
47 Eina_Bool drag_links; 48 Eina_Bool drag_links;
48 int cg_width; 49 int cg_width;
diff --git a/src/bin/keyin.c b/src/bin/keyin.c
index a420893..42a9fcc 100644
--- a/src/bin/keyin.c
+++ b/src/bin/keyin.c
@@ -275,10 +275,27 @@ keyin_handle(Termpty *ty, Evas_Event_Key_Down *ev)
275 if (_key_try(ty, appcur_keyout, ev)) return; 275 if (_key_try(ty, appcur_keyout, ev)) return;
276 } 276 }
277 277
278 if ((ty->state.send_bs) && (!strcmp(ev->key, "BackSpace"))) 278 if (!strcmp(ev->key, "BackSpace"))
279 { 279 {
280 termpty_write(ty, "\b", 1); 280 if (ty->state.send_bs)
281 return; 281 {
282 termpty_write(ty, "\b", 1);
283 return;
284 }
285 else
286 {
287 Config *cfg = termpty_config_get(ty);
288
289 if (cfg->erase_is_del)
290 {
291 termpty_write(ty, "\177", sizeof("\177") - 1);
292 }
293 else
294 {
295 termpty_write(ty, "\b", sizeof("\b") - 1);
296 }
297 return;
298 }
282 } 299 }
283 if (_key_try(ty, keyout, ev)) return; 300 if (_key_try(ty, keyout, ev)) return;
284 if (ev->string) 301 if (ev->string)
diff --git a/src/bin/options_behavior.c b/src/bin/options_behavior.c
index 5b54412..6820249 100644
--- a/src/bin/options_behavior.c
+++ b/src/bin/options_behavior.c
@@ -154,6 +154,16 @@ _cb_op_behavior_xterm_256color_chg(void *data, Evas_Object *obj,
154} 154}
155 155
156static void 156static void
157_cb_op_behavior_erase_is_del_chg(void *data, Evas_Object *obj,
158 void *event EINA_UNUSED)
159{
160 Evas_Object *term = data;
161 Config *config = termio_config_get(term);
162 config->erase_is_del = elm_check_state_get(obj);
163 config_save(config, NULL);
164}
165
166static void
157_cb_op_behavior_wsep_chg(void *data, Evas_Object *obj, void *event EINA_UNUSED) 167_cb_op_behavior_wsep_chg(void *data, Evas_Object *obj, void *event EINA_UNUSED)
158{ 168{
159 Evas_Object *term = data; 169 Evas_Object *term = data;
@@ -369,6 +379,16 @@ options_behavior(Evas_Object *opbox, Evas_Object *term)
369 o = elm_check_add(bx); 379 o = elm_check_add(bx);
370 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0); 380 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
371 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5); 381 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
382 elm_object_text_set(o, "BackArrow sends Del (instead of BackSpace)");
383 elm_check_state_set(o, config->erase_is_del);
384 elm_box_pack_end(bx, o);
385 evas_object_show(o);
386 evas_object_smart_callback_add(o, "changed",
387 _cb_op_behavior_erase_is_del_chg, term);
388
389 o = elm_check_add(bx);
390 evas_object_size_hint_weight_set(o, EVAS_HINT_EXPAND, 0.0);
391 evas_object_size_hint_align_set(o, EVAS_HINT_FILL, 0.5);
372 elm_object_text_set(o, "Always open at size:"); 392 elm_object_text_set(o, "Always open at size:");
373 elm_check_state_set(o, config->custom_geometry); 393 elm_check_state_set(o, config->custom_geometry);
374 elm_box_pack_end(bx, o); 394 elm_box_pack_end(bx, o);
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 54bc60b..4937814 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -4173,7 +4173,7 @@ termio_add(Evas_Object *parent, Config *config, const char *cmd, Eina_Bool login
4173#endif 4173#endif
4174 4174
4175 sd->pty = termpty_new(cmd, login_shell, cd, w, h, config->scrollback, 4175 sd->pty = termpty_new(cmd, login_shell, cd, w, h, config->scrollback,
4176 config->xterm_256color); 4176 config->xterm_256color, config->erase_is_del);
4177 if (!sd->pty) 4177 if (!sd->pty)
4178 { 4178 {
4179 ERR("Cannot allocate termpty"); 4179 ERR("Cannot allocate termpty");
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 617825f..89b0b34 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -4,6 +4,7 @@
4#include "termptyesc.h" 4#include "termptyesc.h"
5#include "termptyops.h" 5#include "termptyops.h"
6#include "termptysave.h" 6#include "termptysave.h"
7#include "termio.h"
7#include <sys/types.h> 8#include <sys/types.h>
8#include <signal.h> 9#include <signal.h>
9#include <sys/wait.h> 10#include <sys/wait.h>
@@ -13,6 +14,8 @@
13#include <sys/ioctl.h> 14#include <sys/ioctl.h>
14#include <string.h> 15#include <string.h>
15#include <errno.h> 16#include <errno.h>
17#include <unistd.h>
18#include <termios.h>
16 19
17/* specific log domain to help debug only terminal code parser */ 20/* specific log domain to help debug only terminal code parser */
18int _termpty_log_dom = -1; 21int _termpty_log_dom = -1;
@@ -268,7 +271,8 @@ _limit_coord(Termpty *ty, Termstate *state)
268 271
269Termpty * 272Termpty *
270termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd, 273termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
271 int w, int h, int backscroll, Eina_Bool xterm_256color) 274 int w, int h, int backscroll, Eina_Bool xterm_256color,
275 Eina_Bool erase_is_del)
272{ 276{
273 Termpty *ty; 277 Termpty *ty;
274 const char *pty; 278 const char *pty;
@@ -334,6 +338,23 @@ termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
334 goto err; 338 goto err;
335 } 339 }
336 340
341 if (erase_is_del)
342 {
343 struct termios t;
344
345 tcgetattr(ty->fd, &t);
346 t.c_cc[VERASE] = 0x7f;
347 tcsetattr(ty->fd, TCSANOW, &t);
348 }
349 else
350 {
351 struct termios t;
352
353 tcgetattr(ty->fd, &t);
354 t.c_cc[VERASE] = 0x8;
355 tcsetattr(ty->fd, TCSANOW, &t);
356 }
357
337 ty->hand_exe_exit = ecore_event_handler_add(ECORE_EXE_EVENT_DEL, 358 ty->hand_exe_exit = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
338 _cb_exe_exit, ty); 359 _cb_exe_exit, ty);
339 if (!ty->hand_exe_exit) 360 if (!ty->hand_exe_exit)
@@ -1502,3 +1523,9 @@ termpty_cell_codepoint_att_fill(Termpty *ty, int codepoint, Termatt att, Termcel
1502 dst[i].att = att; 1523 dst[i].att = att;
1503 } 1524 }
1504} 1525}
1526
1527Config *
1528termpty_config_get(const Termpty *ty)
1529{
1530 return termio_config_get(ty->obj);
1531}
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index 0f22ca4..13203b5 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -1,3 +1,8 @@
1#ifndef _TERMPTY_H__
2#define _TERMPTY_H__ 1
3
4#include "config.h"
5
1typedef struct _Termpty Termpty; 6typedef struct _Termpty Termpty;
2typedef struct _Termcell Termcell; 7typedef struct _Termcell Termcell;
3typedef struct _Termatt Termatt; 8typedef struct _Termatt Termatt;
@@ -192,7 +197,8 @@ void termpty_init(void);
192void termpty_shutdown(void); 197void termpty_shutdown(void);
193 198
194Termpty *termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd, 199Termpty *termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
195 int w, int h, int backscroll, Eina_Bool xterm_256color); 200 int w, int h, int backscroll, Eina_Bool xterm_256color,
201 Eina_Bool erase_is_del);
196void termpty_free(Termpty *ty); 202void termpty_free(Termpty *ty);
197void termpty_cellcomp_freeze(Termpty *ty); 203void termpty_cellcomp_freeze(Termpty *ty);
198void termpty_cellcomp_thaw(Termpty *ty); 204void termpty_cellcomp_thaw(Termpty *ty);
@@ -217,9 +223,13 @@ void termpty_cell_codepoint_att_fill(Termpty *ty, int codepoint, Termatt a
217 223
218ssize_t termpty_line_length(const Termcell *cells, ssize_t nb_cells); 224ssize_t termpty_line_length(const Termcell *cells, ssize_t nb_cells);
219 225
226Config *termpty_config_get(const Termpty *ty);
227
220extern int _termpty_log_dom; 228extern int _termpty_log_dom;
221 229
222#define TERMPTY_SCREEN(Tpty, X, Y) \ 230#define TERMPTY_SCREEN(Tpty, X, Y) \
223 Tpty->screen[X + (((Y + Tpty->circular_offset) % Tpty->h) * Tpty->w)] 231 Tpty->screen[X + (((Y + Tpty->circular_offset) % Tpty->h) * Tpty->w)]
224#define TERMPTY_FMTCLR(Tatt) \ 232#define TERMPTY_FMTCLR(Tatt) \
225 (Tatt).autowrapped = (Tatt).newline = (Tatt).tab = 0 233 (Tatt).autowrapped = (Tatt).newline = (Tatt).tab = 0
234
235#endif