billiob pushed a commit to branch master.

http://git.enlightenment.org/apps/terminology.git/commit/?id=f539eba7ca61e5fe266668fda3d8c29673ee70f7

commit f539eba7ca61e5fe266668fda3d8c29673ee70f7
Author: Boris Faure <bill...@gmail.com>
Date:   Sun Sep 22 17:10:39 2013 +0200

    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…
---
 src/bin/config.c           |  5 +++++
 src/bin/config.h           |  1 +
 src/bin/keyin.c            | 23 ++++++++++++++++++++---
 src/bin/options_behavior.c | 20 ++++++++++++++++++++
 src/bin/termio.c           |  2 +-
 src/bin/termpty.c          | 29 ++++++++++++++++++++++++++++-
 src/bin/termpty.h          | 12 +++++++++++-
 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)
    EET_DATA_DESCRIPTOR_ADD_BASIC
      (edd_base, Config, "xterm_256color", xterm_256color, EET_T_UCHAR);
    EET_DATA_DESCRIPTOR_ADD_BASIC
+     (edd_base, Config, "erase_is_del", erase_is_del, EET_T_UCHAR);
+   EET_DATA_DESCRIPTOR_ADD_BASIC
      (edd_base, Config, "custom_geometry", custom_geometry, EET_T_UCHAR);
    EET_DATA_DESCRIPTOR_ADD_BASIC
      (edd_base, Config, "cg_width", cg_width, EET_T_INT);
@@ -179,6 +181,7 @@ config_sync(const Config *config_src, Config *config)
    config->application_server = config_src->application_server;
    config->application_server_restore_views = 
config_src->application_server_restore_views;
    config->xterm_256color = config_src->xterm_256color;
+   config->erase_is_del = config_src->erase_is_del;
    config->temporary = config_src->temporary;
    config->custom_geometry = config_src->custom_geometry;
    config->cg_width = config_src->cg_width;
@@ -438,6 +441,7 @@ config_load(const char *key)
              config->application_server = EINA_FALSE;
              config->application_server_restore_views = EINA_FALSE;
              config->xterm_256color = EINA_FALSE;
+             config->erase_is_del = EINA_FALSE;
              config->custom_geometry = EINA_FALSE;
              config->cg_width = 80;
              config->cg_height = 24;
@@ -489,6 +493,7 @@ config_fork(Config *config)
    CPY(application_server);
    CPY(application_server_restore_views);
    CPY(xterm_256color);
+   CPY(erase_is_del);
    CPY(custom_geometry);
    CPY(cg_width);
    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
    Eina_Bool         application_server;
    Eina_Bool         application_server_restore_views;
    Eina_Bool         xterm_256color;
+   Eina_Bool         erase_is_del;
    Eina_Bool         custom_geometry;
    Eina_Bool         drag_links;
    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)
         if (_key_try(ty, appcur_keyout, ev)) return;
      }
 
-   if ((ty->state.send_bs) && (!strcmp(ev->key, "BackSpace")))
+   if (!strcmp(ev->key, "BackSpace"))
      {
-        termpty_write(ty, "\b", 1);
-        return;
+        if (ty->state.send_bs)
+          {
+             termpty_write(ty, "\b", 1);
+             return;
+          }
+        else
+          {
+             Config *cfg = termpty_config_get(ty);
+
+             if (cfg->erase_is_del)
+               {
+                  termpty_write(ty, "\177", sizeof("\177") - 1);
+               }
+             else
+               {
+                  termpty_write(ty, "\b", sizeof("\b") - 1);
+               }
+             return;
+        }
      }
    if (_key_try(ty, keyout, ev)) return;
    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,
 }
 
 static void
+_cb_op_behavior_erase_is_del_chg(void *data, Evas_Object *obj,
+                                 void *event EINA_UNUSED)
+{
+   Evas_Object *term = data;
+   Config *config = termio_config_get(term);
+   config->erase_is_del = elm_check_state_get(obj);
+   config_save(config, NULL);
+}
+
+static void
 _cb_op_behavior_wsep_chg(void *data, Evas_Object *obj, void *event EINA_UNUSED)
 {
    Evas_Object *term = data;
@@ -369,6 +379,16 @@ options_behavior(Evas_Object *opbox, Evas_Object *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, "BackArrow sends Del (instead of BackSpace)");
+   elm_check_state_set(o, config->erase_is_del);
+   elm_box_pack_end(bx, o);
+   evas_object_show(o);
+   evas_object_smart_callback_add(o, "changed",
+                                  _cb_op_behavior_erase_is_del_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, "Always open at size:");
    elm_check_state_set(o, config->custom_geometry);
    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
 #endif
    
    sd->pty = termpty_new(cmd, login_shell, cd, w, h, config->scrollback,
-                         config->xterm_256color);
+                         config->xterm_256color, config->erase_is_del);
    if (!sd->pty)
      {
         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 @@
 #include "termptyesc.h"
 #include "termptyops.h"
 #include "termptysave.h"
+#include "termio.h"
 #include <sys/types.h>
 #include <signal.h>
 #include <sys/wait.h>
@@ -13,6 +14,8 @@
 #include <sys/ioctl.h>
 #include <string.h>
 #include <errno.h>
+#include <unistd.h>
+#include <termios.h>
 
 /* specific log domain to help debug only terminal code parser */
 int _termpty_log_dom = -1;
@@ -268,7 +271,8 @@ _limit_coord(Termpty *ty, Termstate *state)
 
 Termpty *
 termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
-            int w, int h, int backscroll, Eina_Bool xterm_256color)
+            int w, int h, int backscroll, Eina_Bool xterm_256color,
+            Eina_Bool erase_is_del)
 {
    Termpty *ty;
    const char *pty;
@@ -334,6 +338,23 @@ termpty_new(const char *cmd, Eina_Bool login_shell, const 
char *cd,
            goto err;
         }
 
+   if (erase_is_del)
+     {
+        struct termios t;
+
+        tcgetattr(ty->fd, &t);
+        t.c_cc[VERASE] = 0x7f;
+        tcsetattr(ty->fd, TCSANOW, &t);
+     }
+   else
+     {
+        struct termios t;
+
+        tcgetattr(ty->fd, &t);
+        t.c_cc[VERASE] = 0x8;
+        tcsetattr(ty->fd, TCSANOW, &t);
+     }
+
    ty->hand_exe_exit = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
                                                _cb_exe_exit, ty);
    if (!ty->hand_exe_exit)
@@ -1502,3 +1523,9 @@ termpty_cell_codepoint_att_fill(Termpty *ty, int 
codepoint, Termatt att, Termcel
         dst[i].att = att;
      }
 }
+
+Config *
+termpty_config_get(const Termpty *ty)
+{
+   return termio_config_get(ty->obj);
+}
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 @@
+#ifndef _TERMPTY_H__
+#define _TERMPTY_H__ 1
+
+#include "config.h"
+
 typedef struct _Termpty       Termpty;
 typedef struct _Termcell      Termcell;
 typedef struct _Termatt       Termatt;
@@ -192,7 +197,8 @@ void       termpty_init(void);
 void       termpty_shutdown(void);
 
 Termpty   *termpty_new(const char *cmd, Eina_Bool login_shell, const char *cd,
-                      int w, int h, int backscroll, Eina_Bool xterm_256color);
+                      int w, int h, int backscroll, Eina_Bool xterm_256color,
+                      Eina_Bool erase_is_del);
 void       termpty_free(Termpty *ty);
 void       termpty_cellcomp_freeze(Termpty *ty);
 void       termpty_cellcomp_thaw(Termpty *ty);
@@ -217,9 +223,13 @@ void       termpty_cell_codepoint_att_fill(Termpty *ty, 
int codepoint, Termatt a
 
 ssize_t termpty_line_length(const Termcell *cells, ssize_t nb_cells);
 
+Config *termpty_config_get(const Termpty *ty);
+
 extern int _termpty_log_dom;
 
 #define TERMPTY_SCREEN(Tpty, X, Y) \
   Tpty->screen[X + (((Y + Tpty->circular_offset) % Tpty->h) * Tpty->w)]
 #define TERMPTY_FMTCLR(Tatt) \
    (Tatt).autowrapped = (Tatt).newline = (Tatt).tab = 0
+
+#endif

-- 


Reply via email to