From 1748b4c1fc413781b4e6cf1a66ed0c1c6980be5d Mon Sep 17 00:00:00 2001 From: btakahashi Date: Fri, 8 Sep 2006 22:29:56 +0000 Subject: [PATCH] Added patch by Johan Bevemyr (jb@bevemyr.com) --- Makefile.in | 6 +++--- README | 1 + inject.c | 11 ++++++++++- inject_csi.c | 28 ++++++++++++++-------------- inject_csi.h | 10 ++++++++++ rote.c | 17 +++++++++++++++++ rote.h | 7 +++++++ 7 files changed, 62 insertions(+), 18 deletions(-) diff --git a/Makefile.in b/Makefile.in index ee01933..a31f3ff 100644 --- a/Makefile.in +++ b/Makefile.in @@ -27,7 +27,7 @@ ROTE_VERSION=@PACKAGE_VERSION@ ROTE_SONAME=librote.so.0 CC=@CC@ -CFLAGS=@CFLAGS@ -Wall -fPIC +CFLAGS=@CFLAGS@ -Wall -fPIC -DUSE_NCURSES -DUSE_PTY LIBS=@LIBS@ LDFLAGS=@LDFLAGS@ prefix=@prefix@ @@ -60,13 +60,13 @@ install: all @echo "compile programs that use rote, use the rote-config" @echo "program (make sure $(DESTDIR)$(bindir) is in your path)." @echo "-----------------------------------------------------------" - + librote.so.$(ROTE_VERSION): $(OBJECTS) $(CC) $(CFLAGS) -shared -o $@ -Wl,-soname=$(ROTE_SONAME) $(OBJECTS) $(LDFLAGS) $(LIBS) .depends: $(SOURCES) $(HEADERS) $(CC) $(CFLAGS) -MM $(SOURCES) >.depends - + -include .depends clean: diff --git a/README b/README index 94d87ce..8254441 100644 --- a/README +++ b/README @@ -13,6 +13,7 @@ The project home page is: [[ OTHER PEOPLE INVOLVED IN DEVELOPING THIS LIBRARY ]] * Phil Endecott (phil_achbq_endecott@chezphil.org) +* Johan Bevemyr (jb@bevemyr.com) [[ WHAT IS IT? ]] diff --git a/inject.c b/inject.c index f9f40e8..031b809 100644 --- a/inject.c +++ b/inject.c @@ -23,6 +23,7 @@ Copyright (c) 2004 Bruno T. C. de Oliveira #include "roteprivate.h" #include "inject_csi.h" #include +#include static void cursor_line_down(RoteTerm *rt) { int i; @@ -80,6 +81,13 @@ static inline void put_normal_char(RoteTerm *rt, char c) { cursor_line_down(rt); } + if (rt->insert) { + int i; + + for(i = rt->cols - 1; i >= rt->ccol+1; i--) + rt->cells[rt->crow][i] = rt->cells[rt->crow][i-1]; + } + rt->cells[rt->crow][rt->ccol].ch = c; rt->cells[rt->crow][rt->ccol].attr = rt->curattr; rt->ccol++; @@ -128,7 +136,8 @@ static void handle_control_char(RoteTerm *rt, char c) { rt->curpos_dirty = true; break; case '\t': /* tab */ - while (rt->ccol % 8) put_normal_char(rt, ' '); + rt->ccol += 8 - (rt->ccol % 8); + clamp_cursor_to_bounds(rt); break; case '\x1B': /* begin escape sequence (aborting previous one if any) */ new_escape_sequence(rt); diff --git a/inject_csi.c b/inject_csi.c index e2b6430..3942304 100644 --- a/inject_csi.c +++ b/inject_csi.c @@ -23,20 +23,10 @@ Copyright (c) 2004 Bruno T. C. de Oliveira #include "roteprivate.h" #include #include +#include #define MAX_CSI_ES_PARAMS 32 -static inline void clamp_cursor_to_bounds(RoteTerm *rt) { - if (rt->crow < 0) rt->curpos_dirty = true, rt->crow = 0; - if (rt->ccol < 0) rt->curpos_dirty = true, rt->ccol = 0; - - if (rt->crow >= rt->rows) - rt->curpos_dirty = true, rt->crow = rt->rows - 1; - - if (rt->ccol >= rt->cols) - rt->curpos_dirty = true, rt->ccol = rt->cols - 1; -} - /* interprets a 'set attribute' (SGR) CSI escape sequence */ static void interpret_csi_SGR(RoteTerm *rt, int param[], int pcount) { int i; @@ -328,6 +318,14 @@ void rote_es_interpret_csi(RoteTerm *rt) { /* delegate handling depending on command character (verb) */ switch (verb) { + case 'h': + if (param_count == 1 && csiparam[0] == 4) /* insert mode */ + rt->insert = true; + break; + case 'l': + if (param_count == 1 && csiparam[0] == 4) /* replace mode */ + rt->insert = false; + break; case 'm': /* it's a 'set attribute' sequence */ interpret_csi_SGR(rt, csiparam, param_count); break; case 'J': /* it's an 'erase display' sequence */ @@ -356,10 +354,12 @@ void rote_es_interpret_csi(RoteTerm *rt) { interpret_csi_SAVECUR(rt, csiparam, param_count); break; case 'u': /* restore cursor location */ interpret_csi_RESTORECUR(rt, csiparam, param_count); break; - #ifdef DEBUG default: - fprintf(stderr, "Unrecogized CSI: <%s>\n", rt->pd->esbuf); break; - #endif + #ifdef DEBUG + fprintf(stderr, "Unrecogized CSI: verb=%c <%s>\n", + verb, rt->pd->esbuf); + #endif + break; } } diff --git a/inject_csi.h b/inject_csi.h index a372bcd..b350a12 100644 --- a/inject_csi.h +++ b/inject_csi.h @@ -30,5 +30,15 @@ Copyright (c) 2004 Bruno T. C. de Oliveira * related fields in it */ void rote_es_interpret_csi(RoteTerm *rt); +static inline void clamp_cursor_to_bounds(RoteTerm *rt) { + if (rt->crow < 0) rt->curpos_dirty = true, rt->crow = 0; + if (rt->ccol < 0) rt->curpos_dirty = true, rt->ccol = 0; + + if (rt->crow >= rt->rows) + rt->curpos_dirty = true, rt->crow = rt->rows - 1; + + if (rt->ccol >= rt->cols) + rt->curpos_dirty = true, rt->ccol = rt->cols - 1; +} #endif diff --git a/rote.c b/rote.c index 6d61820..442e1d0 100644 --- a/rote.c +++ b/rote.c @@ -22,7 +22,9 @@ Copyright (c) 2004 Bruno T. C. de Oliveira #include "rote.h" #include "roteprivate.h" #include +#ifdef USE_PTY #include +#endif #include #include @@ -41,6 +43,9 @@ RoteTerm *rote_vt_create(int rows, int cols) { rt->rows = rows; rt->cols = cols; + /* default mode is replace */ + rt->insert = false; + /* create the cell matrix */ rt->cells = (RoteCell**) malloc(sizeof(RoteCell*) * rt->rows); for (i = 0; i < rt->rows; i++) { @@ -89,6 +94,8 @@ void rote_vt_destroy(RoteTerm *rt) { free(rt); } +#ifdef USE_NCURSES + static void default_cur_set_attr(WINDOW *win, unsigned char attr) { int cp = ROTE_ATTR_BG(attr) * 8 + 7 - ROTE_ATTR_FG(attr); if (!cp) wattrset(win, A_NORMAL); @@ -98,9 +105,13 @@ static void default_cur_set_attr(WINDOW *win, unsigned char attr) { if (ROTE_ATTR_BLINK(attr)) wattron(win, A_BLINK); } +#endif + static inline unsigned char ensure_printable(unsigned char ch) { return ch >= 32 ? ch : 32; } +#ifdef USE_NCURSES + void rote_vt_draw(RoteTerm *rt, WINDOW *win, int srow, int scol, void (*cur_set_attr)(WINDOW*,unsigned char)) { @@ -119,6 +130,10 @@ void rote_vt_draw(RoteTerm *rt, WINDOW *win, int srow, int scol, wmove(win, srow + rt->crow, scol + rt->ccol); } +#endif + +#ifdef USE_PTY + pid_t rote_vt_forkpty(RoteTerm *rt, const char *command) { struct winsize ws; pid_t childpid; @@ -155,6 +170,8 @@ void rote_vt_forsake_child(RoteTerm *rt) { rt->childpid = 0; } +#endif + void rote_vt_update(RoteTerm *rt) { fd_set ifs; struct timeval tvzero; diff --git a/rote.h b/rote.h index 62846d6..7654784 100644 --- a/rote.h +++ b/rote.h @@ -29,7 +29,11 @@ Copyright (c) 2004 Bruno T. C. de Oliveira #ifndef btco_ROTE_rote_h #define btco_ROTE_rote_h +#ifdef USE_NCURSES #include +#else +#include +#endif #include #include #include @@ -126,6 +130,7 @@ typedef struct RoteTerm_ { RoteTermPrivate *pd; /* private state data */ + bool insert; /* insert or replace mode */ /* --- dirtiness flags: the following flags will be raised when the * corresponding items are modified. They can only be unset by YOU * (when, for example, you redraw the term or something) --- */ @@ -200,6 +205,7 @@ void rote_vt_write(RoteTerm *rt, const char *data, int length); */ void rote_vt_inject(RoteTerm *rt, const char *data, int length); +#ifdef USE_NCURSES /* Paints the virtual terminal screen on the given window, putting * the top-left corner at the given position. The cur_set_attr * function must set the curses attributes given a Rote attribute @@ -221,6 +227,7 @@ void rote_vt_inject(RoteTerm *rt, const char *data, int length); void rote_vt_draw(RoteTerm *rt, WINDOW *win, int startrow, int startcol, void (*cur_set_attr)(WINDOW *win, unsigned char attr)); +#endif /* Indicates to the terminal that the given key has been pressed. * This will cause the terminal to rote_vt_write() the appropriate * escape sequence for that key (that is, the escape sequence -- 2.20.1