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@
@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:
[[ OTHER PEOPLE INVOLVED IN DEVELOPING THIS LIBRARY ]]
* Phil Endecott (phil_achbq_endecott@chezphil.org)
+* Johan Bevemyr (jb@bevemyr.com)
[[ WHAT IS IT? ]]
#include "roteprivate.h"
#include "inject_csi.h"
#include <string.h>
+#include <stdio.h>
static void cursor_line_down(RoteTerm *rt) {
int i;
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++;
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);
#include "roteprivate.h"
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#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;
/* 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 */
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;
}
}
* 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
#include "rote.h"
#include "roteprivate.h"
#include <stdlib.h>
+#ifdef USE_PTY
#include <pty.h>
+#endif
#include <stdio.h>
#include <string.h>
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++) {
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);
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)) {
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;
rt->childpid = 0;
}
+#endif
+
void rote_vt_update(RoteTerm *rt) {
fd_set ifs;
struct timeval tvzero;
#ifndef btco_ROTE_rote_h
#define btco_ROTE_rote_h
+#ifdef USE_NCURSES
#include <ncurses.h>
+#else
+#include <stdbool.h>
+#endif
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
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) --- */
*/
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
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