sistema_progs

Programas para customizar o meu entorno de traballo nos meus equipos persoais
Log | Files | Refs

st-scrollback-0.8.5.diff (8914B)


      1 diff --git a/config.def.h b/config.def.h
      2 index 91ab8ca..e3b469b 100644
      3 --- a/config.def.h
      4 +++ b/config.def.h
      5 @@ -201,6 +201,8 @@ static Shortcut shortcuts[] = {
      6  	{ TERMMOD,              XK_Y,           selpaste,       {.i =  0} },
      7  	{ ShiftMask,            XK_Insert,      selpaste,       {.i =  0} },
      8  	{ TERMMOD,              XK_Num_Lock,    numlock,        {.i =  0} },
      9 +	{ ShiftMask,            XK_Page_Up,     kscrollup,      {.i = -1} },
     10 +	{ ShiftMask,            XK_Page_Down,   kscrolldown,    {.i = -1} },
     11  };
     12  
     13  /*
     14 diff --git a/st.c b/st.c
     15 index 51049ba..cd750f2 100644
     16 --- a/st.c
     17 +++ b/st.c
     18 @@ -35,6 +35,7 @@
     19  #define ESC_ARG_SIZ   16
     20  #define STR_BUF_SIZ   ESC_BUF_SIZ
     21  #define STR_ARG_SIZ   ESC_ARG_SIZ
     22 +#define HISTSIZE      2000
     23  
     24  /* macros */
     25  #define IS_SET(flag)		((term.mode & (flag)) != 0)
     26 @@ -42,6 +43,9 @@
     27  #define ISCONTROLC1(c)		(BETWEEN(c, 0x80, 0x9f))
     28  #define ISCONTROL(c)		(ISCONTROLC0(c) || ISCONTROLC1(c))
     29  #define ISDELIM(u)		(u && wcschr(worddelimiters, u))
     30 +#define TLINE(y)		((y) < term.scr ? term.hist[((y) + term.histi - \
     31 +				term.scr + HISTSIZE + 1) % HISTSIZE] : \
     32 +				term.line[(y) - term.scr])
     33  
     34  enum term_mode {
     35  	MODE_WRAP        = 1 << 0,
     36 @@ -115,6 +119,9 @@ typedef struct {
     37  	int col;      /* nb col */
     38  	Line *line;   /* screen */
     39  	Line *alt;    /* alternate screen */
     40 +	Line hist[HISTSIZE]; /* history buffer */
     41 +	int histi;    /* history index */
     42 +	int scr;      /* scroll back */
     43  	int *dirty;   /* dirtyness of lines */
     44  	TCursor c;    /* cursor */
     45  	int ocx;      /* old cursor col */
     46 @@ -184,8 +191,8 @@ static void tnewline(int);
     47  static void tputtab(int);
     48  static void tputc(Rune);
     49  static void treset(void);
     50 -static void tscrollup(int, int);
     51 -static void tscrolldown(int, int);
     52 +static void tscrollup(int, int, int);
     53 +static void tscrolldown(int, int, int);
     54  static void tsetattr(const int *, int);
     55  static void tsetchar(Rune, const Glyph *, int, int);
     56  static void tsetdirt(int, int);
     57 @@ -416,10 +423,10 @@ tlinelen(int y)
     58  {
     59  	int i = term.col;
     60  
     61 -	if (term.line[y][i - 1].mode & ATTR_WRAP)
     62 +	if (TLINE(y)[i - 1].mode & ATTR_WRAP)
     63  		return i;
     64  
     65 -	while (i > 0 && term.line[y][i - 1].u == ' ')
     66 +	while (i > 0 && TLINE(y)[i - 1].u == ' ')
     67  		--i;
     68  
     69  	return i;
     70 @@ -528,7 +535,7 @@ selsnap(int *x, int *y, int direction)
     71  		 * Snap around if the word wraps around at the end or
     72  		 * beginning of a line.
     73  		 */
     74 -		prevgp = &term.line[*y][*x];
     75 +		prevgp = &TLINE(*y)[*x];
     76  		prevdelim = ISDELIM(prevgp->u);
     77  		for (;;) {
     78  			newx = *x + direction;
     79 @@ -543,14 +550,14 @@ selsnap(int *x, int *y, int direction)
     80  					yt = *y, xt = *x;
     81  				else
     82  					yt = newy, xt = newx;
     83 -				if (!(term.line[yt][xt].mode & ATTR_WRAP))
     84 +				if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
     85  					break;
     86  			}
     87  
     88  			if (newx >= tlinelen(newy))
     89  				break;
     90  
     91 -			gp = &term.line[newy][newx];
     92 +			gp = &TLINE(newy)[newx];
     93  			delim = ISDELIM(gp->u);
     94  			if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
     95  					|| (delim && gp->u != prevgp->u)))
     96 @@ -571,14 +578,14 @@ selsnap(int *x, int *y, int direction)
     97  		*x = (direction < 0) ? 0 : term.col - 1;
     98  		if (direction < 0) {
     99  			for (; *y > 0; *y += direction) {
    100 -				if (!(term.line[*y-1][term.col-1].mode
    101 +				if (!(TLINE(*y-1)[term.col-1].mode
    102  						& ATTR_WRAP)) {
    103  					break;
    104  				}
    105  			}
    106  		} else if (direction > 0) {
    107  			for (; *y < term.row-1; *y += direction) {
    108 -				if (!(term.line[*y][term.col-1].mode
    109 +				if (!(TLINE(*y)[term.col-1].mode
    110  						& ATTR_WRAP)) {
    111  					break;
    112  				}
    113 @@ -609,13 +616,13 @@ getsel(void)
    114  		}
    115  
    116  		if (sel.type == SEL_RECTANGULAR) {
    117 -			gp = &term.line[y][sel.nb.x];
    118 +			gp = &TLINE(y)[sel.nb.x];
    119  			lastx = sel.ne.x;
    120  		} else {
    121 -			gp = &term.line[y][sel.nb.y == y ? sel.nb.x : 0];
    122 +			gp = &TLINE(y)[sel.nb.y == y ? sel.nb.x : 0];
    123  			lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
    124  		}
    125 -		last = &term.line[y][MIN(lastx, linelen-1)];
    126 +		last = &TLINE(y)[MIN(lastx, linelen-1)];
    127  		while (last >= gp && last->u == ' ')
    128  			--last;
    129  
    130 @@ -851,6 +858,9 @@ void
    131  ttywrite(const char *s, size_t n, int may_echo)
    132  {
    133  	const char *next;
    134 +	Arg arg = (Arg) { .i = term.scr };
    135 +
    136 +	kscrolldown(&arg);
    137  
    138  	if (may_echo && IS_SET(MODE_ECHO))
    139  		twrite(s, n, 1);
    140 @@ -1062,12 +1072,52 @@ tswapscreen(void)
    141  }
    142  
    143  void
    144 -tscrolldown(int orig, int n)
    145 +kscrolldown(const Arg* a)
    146 +{
    147 +	int n = a->i;
    148 +
    149 +	if (n < 0)
    150 +		n = term.row + n;
    151 +
    152 +	if (n > term.scr)
    153 +		n = term.scr;
    154 +
    155 +	if (term.scr > 0) {
    156 +		term.scr -= n;
    157 +		selscroll(0, -n);
    158 +		tfulldirt();
    159 +	}
    160 +}
    161 +
    162 +void
    163 +kscrollup(const Arg* a)
    164 +{
    165 +	int n = a->i;
    166 +
    167 +	if (n < 0)
    168 +		n = term.row + n;
    169 +
    170 +	if (term.scr <= HISTSIZE-n) {
    171 +		term.scr += n;
    172 +		selscroll(0, n);
    173 +		tfulldirt();
    174 +	}
    175 +}
    176 +
    177 +void
    178 +tscrolldown(int orig, int n, int copyhist)
    179  {
    180  	int i;
    181  	Line temp;
    182  
    183  	LIMIT(n, 0, term.bot-orig+1);
    184 +	if (copyhist) {
    185 +		term.histi = (term.histi - 1 + HISTSIZE) % HISTSIZE;
    186 +		temp = term.hist[term.histi];
    187 +		term.hist[term.histi] = term.line[term.bot];
    188 +		term.line[term.bot] = temp;
    189 +	}
    190 +
    191  
    192  	tsetdirt(orig, term.bot-n);
    193  	tclearregion(0, term.bot-n+1, term.col-1, term.bot);
    194 @@ -1078,17 +1128,28 @@ tscrolldown(int orig, int n)
    195  		term.line[i-n] = temp;
    196  	}
    197  
    198 -	selscroll(orig, n);
    199 +	if (term.scr == 0)
    200 +		selscroll(orig, n);
    201  }
    202  
    203  void
    204 -tscrollup(int orig, int n)
    205 +tscrollup(int orig, int n, int copyhist)
    206  {
    207  	int i;
    208  	Line temp;
    209  
    210  	LIMIT(n, 0, term.bot-orig+1);
    211  
    212 +	if (copyhist) {
    213 +		term.histi = (term.histi + 1) % HISTSIZE;
    214 +		temp = term.hist[term.histi];
    215 +		term.hist[term.histi] = term.line[orig];
    216 +		term.line[orig] = temp;
    217 +	}
    218 +
    219 +	if (term.scr > 0 && term.scr < HISTSIZE)
    220 +		term.scr = MIN(term.scr + n, HISTSIZE-1);
    221 +
    222  	tclearregion(0, orig, term.col-1, orig+n-1);
    223  	tsetdirt(orig+n, term.bot);
    224  
    225 @@ -1098,7 +1159,8 @@ tscrollup(int orig, int n)
    226  		term.line[i+n] = temp;
    227  	}
    228  
    229 -	selscroll(orig, -n);
    230 +	if (term.scr == 0)
    231 +		selscroll(orig, -n);
    232  }
    233  
    234  void
    235 @@ -1127,7 +1189,7 @@ tnewline(int first_col)
    236  	int y = term.c.y;
    237  
    238  	if (y == term.bot) {
    239 -		tscrollup(term.top, 1);
    240 +		tscrollup(term.top, 1, 1);
    241  	} else {
    242  		y++;
    243  	}
    244 @@ -1292,14 +1354,14 @@ void
    245  tinsertblankline(int n)
    246  {
    247  	if (BETWEEN(term.c.y, term.top, term.bot))
    248 -		tscrolldown(term.c.y, n);
    249 +		tscrolldown(term.c.y, n, 0);
    250  }
    251  
    252  void
    253  tdeleteline(int n)
    254  {
    255  	if (BETWEEN(term.c.y, term.top, term.bot))
    256 -		tscrollup(term.c.y, n);
    257 +		tscrollup(term.c.y, n, 0);
    258  }
    259  
    260  int32_t
    261 @@ -1736,11 +1798,11 @@ csihandle(void)
    262  		break;
    263  	case 'S': /* SU -- Scroll <n> line up */
    264  		DEFAULT(csiescseq.arg[0], 1);
    265 -		tscrollup(term.top, csiescseq.arg[0]);
    266 +		tscrollup(term.top, csiescseq.arg[0], 0);
    267  		break;
    268  	case 'T': /* SD -- Scroll <n> line down */
    269  		DEFAULT(csiescseq.arg[0], 1);
    270 -		tscrolldown(term.top, csiescseq.arg[0]);
    271 +		tscrolldown(term.top, csiescseq.arg[0], 0);
    272  		break;
    273  	case 'L': /* IL -- Insert <n> blank lines */
    274  		DEFAULT(csiescseq.arg[0], 1);
    275 @@ -2330,7 +2392,7 @@ eschandle(uchar ascii)
    276  		return 0;
    277  	case 'D': /* IND -- Linefeed */
    278  		if (term.c.y == term.bot) {
    279 -			tscrollup(term.top, 1);
    280 +			tscrollup(term.top, 1, 1);
    281  		} else {
    282  			tmoveto(term.c.x, term.c.y+1);
    283  		}
    284 @@ -2343,7 +2405,7 @@ eschandle(uchar ascii)
    285  		break;
    286  	case 'M': /* RI -- Reverse index */
    287  		if (term.c.y == term.top) {
    288 -			tscrolldown(term.top, 1);
    289 +			tscrolldown(term.top, 1, 1);
    290  		} else {
    291  			tmoveto(term.c.x, term.c.y-1);
    292  		}
    293 @@ -2557,7 +2619,7 @@ twrite(const char *buf, int buflen, int show_ctrl)
    294  void
    295  tresize(int col, int row)
    296  {
    297 -	int i;
    298 +	int i, j;
    299  	int minrow = MIN(row, term.row);
    300  	int mincol = MIN(col, term.col);
    301  	int *bp;
    302 @@ -2594,6 +2656,14 @@ tresize(int col, int row)
    303  	term.dirty = xrealloc(term.dirty, row * sizeof(*term.dirty));
    304  	term.tabs = xrealloc(term.tabs, col * sizeof(*term.tabs));
    305  
    306 +	for (i = 0; i < HISTSIZE; i++) {
    307 +		term.hist[i] = xrealloc(term.hist[i], col * sizeof(Glyph));
    308 +		for (j = mincol; j < col; j++) {
    309 +			term.hist[i][j] = term.c.attr;
    310 +			term.hist[i][j].u = ' ';
    311 +		}
    312 +	}
    313 +
    314  	/* resize each row to new width, zero-pad if needed */
    315  	for (i = 0; i < minrow; i++) {
    316  		term.line[i] = xrealloc(term.line[i], col * sizeof(Glyph));
    317 @@ -2652,7 +2722,7 @@ drawregion(int x1, int y1, int x2, int y2)
    318  			continue;
    319  
    320  		term.dirty[y] = 0;
    321 -		xdrawline(term.line[y], x1, y, x2);
    322 +		xdrawline(TLINE(y), x1, y, x2);
    323  	}
    324  }
    325  
    326 @@ -2673,8 +2743,9 @@ draw(void)
    327  		cx--;
    328  
    329  	drawregion(0, 0, term.col, term.row);
    330 -	xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
    331 -			term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
    332 +	if (term.scr == 0)
    333 +		xdrawcursor(cx, term.c.y, term.line[term.c.y][cx],
    334 +				term.ocx, term.ocy, term.line[term.ocy][term.ocx]);
    335  	term.ocx = cx;
    336  	term.ocy = term.c.y;
    337  	xfinishdraw();
    338 diff --git a/st.h b/st.h
    339 index 519b9bd..da36b34 100644
    340 --- a/st.h
    341 +++ b/st.h
    342 @@ -81,6 +81,8 @@ void die(const char *, ...);
    343  void redraw(void);
    344  void draw(void);
    345  
    346 +void kscrolldown(const Arg *);
    347 +void kscrollup(const Arg *);
    348  void printscreen(const Arg *);
    349  void printsel(const Arg *);
    350  void sendbreak(const Arg *);