Re: [hackers] [st] st-scrollback update 1/2

2018-03-11 Thread Gary Allen Vollink
Sorry, just got back to this.  I pushed the sites change a few minutes
ago.  Hopefully I did it right.  :)

Thank you,
Gary

On Sun, Mar 11, 2018 at 6:57 AM, Hiltjo Posthuma  wrote:
> On Sun, Mar 11, 2018 at 03:40:39AM -0400, Gary Allen Vollink wrote:
>> I took a few hours to get st-scrollback and st-scrollback-mouse working
>> again after the 9 March 2018 patches. I did NOT update
>> st-scrollback-mouse-altscreen.
>>
>> Following, st-scrollback-20180311-c5ba9c0.diff
>>
>> I hope this is helpful to someone.
>>
>> Sincerely,
>> Gary Allen Vollink
>>
>>
>>
>>
>> diff -U 3 a/config.def.h b/config.def.h
>> --- a/config.def.h2018-03-10 17:55:12.445254900 -0500
>> +++ b/config.def.h2018-03-10 23:55:54.468236300 -0500
>> @@ -178,6 +178,8 @@
>>  { TERMMOD,  XK_Y,   selpaste,   {.i =  0} },
>>  { TERMMOD,  XK_Num_Lock,numlock,{.i =  0} },
>>  { TERMMOD,  XK_I,   iso14755,   {.i =  0} },
>> +{ ShiftMask,XK_Page_Up, kscrollup,  {.i = -1} },
>> +{ ShiftMask,XK_Page_Down,   kscrolldown,{.i = -1} },
>>  };
>>
>>  /*
>> diff -U 3 a/st.c b/st.c
>> --- a/st.c2018-03-10 17:55:12.449266800 -0500
>> +++ b/st.c2018-03-11 00:36:36.437966200 -0500
>> @@ -121,6 +121,9 @@
>>  int col;  /* nb col */
>>  Line *line;   /* screen */
>>  Line *alt;/* alternate screen */
>> +Line hist[HISTSIZE]; /* history buffer */
>> +int histi;/* history index */
>> +int scr;  /* scroll back */
>>  int *dirty;   /* dirtyness of lines */
>>  TCursor c;/* cursor */
>>  int ocx;  /* old cursor col */
>> @@ -188,8 +191,8 @@
>>  static void tputtab(int);
>>  static void tputc(Rune);
>>  static void treset(void);
>> -static void tscrollup(int, int);
>> -static void tscrolldown(int, int);
>> +static void tscrollup(int, int, int);
>> +static void tscrolldown(int, int, int);
>>  static void tsetattr(int *, int);
>>  static void tsetchar(Rune, Glyph *, int, int);
>>  static void tsetdirt(int, int);
>> @@ -431,10 +434,10 @@
>>  {
>>  int i = term.col;
>>
>> -if (term.line[y][i - 1].mode & ATTR_WRAP)
>> +if (TLINE(y)[i - 1].mode & ATTR_WRAP)
>>  return i;
>>
>> -while (i > 0 && term.line[y][i - 1].u == ' ')
>> +while (i > 0 && TLINE(y)[i - 1].u == ' ')
>>  --i;
>>
>>  return i;
>> @@ -543,7 +546,7 @@
>>   * Snap around if the word wraps around at the end or
>>   * beginning of a line.
>>   */
>> -prevgp = [*y][*x];
>> +prevgp = (*y)[*x];
>>  prevdelim = ISDELIM(prevgp->u);
>>  for (;;) {
>>  newx = *x + direction;
>> @@ -558,14 +561,14 @@
>>  yt = *y, xt = *x;
>>  else
>>  yt = newy, xt = newx;
>> -if (!(term.line[yt][xt].mode & ATTR_WRAP))
>> +if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
>>  break;
>>  }
>>
>>  if (newx >= tlinelen(newy))
>>  break;
>>
>> -gp = [newy][newx];
>> +gp = (newy)[newx];
>>  delim = ISDELIM(gp->u);
>>  if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
>>  || (delim && gp->u != prevgp->u)))
>> @@ -586,14 +589,14 @@
>>  *x = (direction < 0) ? 0 : term.col - 1;
>>  if (direction < 0) {
>>  for (; *y > 0; *y += direction) {
>> -if (!(term.line[*y-1][term.col-1].mode
>> +if (!(TLINE(*y-1)[term.col-1].mode
>>  & ATTR_WRAP)) {
>>  break;
>>  }
>>  }
>>  } else if (direction > 0) {
>>  for (; *y < term.row-1; *y += direction) {
>> -if (!(term.line[*y][term.col-1].mode
>> +if (!(TLINE(*y)[term.col-1].mode
>>  & ATTR_WRAP)) {
>>  break;
>>  }
>> @@ -624,13 +627,13 @@
>>  }
>>
>>  if (sel.type == SEL_RECTANGULAR) {
>> -gp = [y][sel.nb.x];
>> +gp = (y)[sel.nb.x];
>>  lastx = sel.ne.x;
>>  } else {
>> -gp = [y][sel.nb.y == y ? sel.nb.x : 0];
>> +gp = (y)[sel.nb.y == y ? sel.nb.x : 0];
>>  lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
>>  }
>> -last = [y][MIN(lastx, linelen-1)];
>> +last = (y)[MIN(lastx, linelen-1)];
>>  while (last >= gp && last->u == ' ')
>>  --last;
>>
>> @@ -836,6 +839,9 @@
>>  if (buflen > 0)
>>  memmove(buf, buf + written, buflen);
>>
>> +if (term.scr > 0 && term.scr < HISTSIZE-1)
>> +term.scr++;
>> +
>>  return ret;
>>  }
>>
>> @@ -843,6 +849,9 @@
>>  ttywrite(const char *s, size_t n, int may_echo)
>>  {
>>  const char *next;
>> +Arg arg = (Arg) { .i = term.scr };
>> +

Re: [hackers] [st] st-scrollback update 1/2

2018-03-11 Thread Hiltjo Posthuma
On Sun, Mar 11, 2018 at 03:40:39AM -0400, Gary Allen Vollink wrote:
> I took a few hours to get st-scrollback and st-scrollback-mouse working
> again after the 9 March 2018 patches. I did NOT update
> st-scrollback-mouse-altscreen.
> 
> Following, st-scrollback-20180311-c5ba9c0.diff
> 
> I hope this is helpful to someone.
> 
> Sincerely,
> Gary Allen Vollink
> 
> 
> 
> 
> diff -U 3 a/config.def.h b/config.def.h
> --- a/config.def.h    2018-03-10 17:55:12.445254900 -0500
> +++ b/config.def.h    2018-03-10 23:55:54.468236300 -0500
> @@ -178,6 +178,8 @@
>  { TERMMOD,  XK_Y,   selpaste,   {.i =  0} },
>  { TERMMOD,  XK_Num_Lock,    numlock,    {.i =  0} },
>  { TERMMOD,  XK_I,   iso14755,   {.i =  0} },
> +    { ShiftMask,    XK_Page_Up, kscrollup,  {.i = -1} },
> +    { ShiftMask,    XK_Page_Down,   kscrolldown,    {.i = -1} },
>  };
> 
>  /*
> diff -U 3 a/st.c b/st.c
> --- a/st.c    2018-03-10 17:55:12.449266800 -0500
> +++ b/st.c    2018-03-11 00:36:36.437966200 -0500
> @@ -121,6 +121,9 @@
>  int col;  /* nb col */
>  Line *line;   /* screen */
>  Line *alt;    /* alternate screen */
> +    Line hist[HISTSIZE]; /* history buffer */
> +    int histi;    /* history index */
> +    int scr;  /* scroll back */
>  int *dirty;   /* dirtyness of lines */
>  TCursor c;    /* cursor */
>  int ocx;  /* old cursor col */
> @@ -188,8 +191,8 @@
>  static void tputtab(int);
>  static void tputc(Rune);
>  static void treset(void);
> -static void tscrollup(int, int);
> -static void tscrolldown(int, int);
> +static void tscrollup(int, int, int);
> +static void tscrolldown(int, int, int);
>  static void tsetattr(int *, int);
>  static void tsetchar(Rune, Glyph *, int, int);
>  static void tsetdirt(int, int);
> @@ -431,10 +434,10 @@
>  {
>  int i = term.col;
> 
> -    if (term.line[y][i - 1].mode & ATTR_WRAP)
> +    if (TLINE(y)[i - 1].mode & ATTR_WRAP)
>      return i;
> 
> -    while (i > 0 && term.line[y][i - 1].u == ' ')
> +    while (i > 0 && TLINE(y)[i - 1].u == ' ')
>      --i;
> 
>  return i;
> @@ -543,7 +546,7 @@
>       * Snap around if the word wraps around at the end or
>       * beginning of a line.
>       */
> -        prevgp = [*y][*x];
> +        prevgp = (*y)[*x];
>      prevdelim = ISDELIM(prevgp->u);
>      for (;;) {
>          newx = *x + direction;
> @@ -558,14 +561,14 @@
>                  yt = *y, xt = *x;
>              else
>                  yt = newy, xt = newx;
> -                if (!(term.line[yt][xt].mode & ATTR_WRAP))
> +                if (!(TLINE(yt)[xt].mode & ATTR_WRAP))
>                  break;
>          }
> 
>          if (newx >= tlinelen(newy))
>              break;
> 
> -            gp = [newy][newx];
> +            gp = (newy)[newx];
>          delim = ISDELIM(gp->u);
>          if (!(gp->mode & ATTR_WDUMMY) && (delim != prevdelim
>                  || (delim && gp->u != prevgp->u)))
> @@ -586,14 +589,14 @@
>      *x = (direction < 0) ? 0 : term.col - 1;
>      if (direction < 0) {
>          for (; *y > 0; *y += direction) {
> -                if (!(term.line[*y-1][term.col-1].mode
> +                if (!(TLINE(*y-1)[term.col-1].mode
>                      & ATTR_WRAP)) {
>                  break;
>              }
>          }
>      } else if (direction > 0) {
>          for (; *y < term.row-1; *y += direction) {
> -                if (!(term.line[*y][term.col-1].mode
> +                if (!(TLINE(*y)[term.col-1].mode
>                      & ATTR_WRAP)) {
>                  break;
>              }
> @@ -624,13 +627,13 @@
>      }
> 
>      if (sel.type == SEL_RECTANGULAR) {
> -            gp = [y][sel.nb.x];
> +            gp = (y)[sel.nb.x];
>          lastx = sel.ne.x;
>      } else {
> -            gp = [y][sel.nb.y == y ? sel.nb.x : 0];
> +            gp = (y)[sel.nb.y == y ? sel.nb.x : 0];
>          lastx = (sel.ne.y == y) ? sel.ne.x : term.col-1;
>      }
> -        last = [y][MIN(lastx, linelen-1)];
> +        last = (y)[MIN(lastx, linelen-1)];
>      while (last >= gp && last->u == ' ')
>          --last;
> 
> @@ -836,6 +839,9 @@
>  if (buflen > 0)
>      memmove(buf, buf + written, buflen);
> 
> +    if (term.scr > 0 && term.scr < HISTSIZE-1)
> +        term.scr++;
> +
>  return ret;
>  }
> 
> @@ -843,6 +849,9 @@
>  ttywrite(const char *s, size_t n, int may_echo)
>  {
>  const char *next;
> +    Arg arg = (Arg) { .i = term.scr };
> +
> +    kscrolldown();
> 
>  if (may_echo && IS_SET(MODE_ECHO))
>      twrite(s, n, 1);
> @@ -1054,13 +1063,54 @@
>  }
> 
>  void
> -tscrolldown(int orig, int n)
> +kscrolldown(const Arg* a)
> +{
> +    int n = a->i;
> +
> +    if (n < 0)
> +        n = term.row + n;
> +
> +    if (n > term.scr)
> +        n = term.scr;
>