Hi,

I am very new to rxvt, but I already tried to hack it a little bit to
customize it. The code is quite readable, so I decided to jump in an
try to had a "search" function. What I want to achieve is that by
selecting some text and pressing a key (CTRL-h for example), rxvt will
search back in the window and the saved lines the selected text. If you
have done a command with a long output, you can easily scroll back to the
begining by selecting your shell prompt and searching backwards for it.
(For the history, this is a functionnality I used to enjoy a long time
ago on apollo workstations).

Now I started to program this in a very dirty way, but I already achieve
the following: I added a call for a function search_selection when CTRL-h
is pressed. This function search back correctly the current selection, but
I have problem with the final steps: selecting and displaying (by doing a
scrolling if needed) the found string.

The code is added below. I am struggling with the call to selection_start.
If the found string is visible in the window, the selection is done one
row higher. And if the found string is in the saved lines, it doesn't work
at all.


Can somebody guide me to achieve the final steps?


Many thanks in advance,


Thierry






/* ------------------------------------------------------------------------- */
/*
 * search a selection
 * EXT: button 1 or 3 release
 */
/* EXTPROTO */
void
search_selection(int direction)
{
  int i, r, row, col, nrows, row_offset, len, found ;
  text_t *t;

  found = 0;

  if ( selection.op != SELECTION_DONE
      || selection.beg.row != selection.end.row )
    return;

  col = max(selection.beg.col-1, 0);
  row = selection.beg.row ;
  len = strlen(selection.text);
  if ( selection.beg.col == 0 )
    {
      if ( row == 0 ) return;
      row--;
      col = TermWin.ncol - 1 - len;
    }
  else
    col = max(selection.beg.col-1, 0);


  nrows = TermWin.nrow + TermWin.nscrolled;
  row_offset = TermWin.saveLines - TermWin.nscrolled;

  for (r = row + TermWin.nscrolled;
       r >= 0 && !found;
       r--, col = TermWin.ncol - 1 - len )
    {
      t = screen.text[r + row_offset];

      for ( i = col; i >= 0; i-- )
        {
          if ( strncmp( selection.text, t+i, len ) == 0  )
            {
              found = 1;
              break;
            }
        }

    }

 if (found)
   {
     fprintf(stderr, "found %d %d\n", r, i ); /* debug statement */
     selection_start_colrow( i, r - TermWin.nscrolled );
     selection_extend_colrow( i+len, r - TermWin.nscrolled, 0, 1, 0 );
   }

}

Reply via email to