pike.git / lib / modules / Stdio.pmod / Readline.pike

version» Context lines:

pike.git/lib/modules/Stdio.pmod/Readline.pike:1: - // $Id: Readline.pike,v 1.8 1999/03/23 20:48:36 marcus Exp $ + // $Id: Readline.pike,v 1.9 1999/04/02 09:57:59 neotron Exp $      class OutputController   {    static private object outfd, term;    static private int xpos = 0, columns = 0;    static private mapping oldattrs = 0;       void disable()    {    catch{
pike.git/lib/modules/Stdio.pmod/Readline.pike:538:    disable();    catch { oldattrs = infd->tcgetattr(); };    catch { infd->tcsetattr((["ECHO":0,"ICANON":0,"VMIN":1,"VTIME":0,    "VLNEXT":0])); };    }      }      class DefaultEditKeys   { -  +  static private multiset word_break_chars = mkmultiset("\t \n\r/*?_-.[]~&;\!#$%^(){}<>"/"");    static object _readline;       void self_insert_command(string str)    {    _readline->insert(str, _readline->getcursorpos());    }       void quoted_insert()    {    _readline->get_input_controller()->grabnextkey(self_insert_command);
pike.git/lib/modules/Stdio.pmod/Readline.pike:611:    void transpose_chars()    {    int p = _readline->getcursorpos();    if (p<0 || p>=strlen(_readline->gettext()))    return;    string c = _readline->gettext()[p-1..p];    _readline->delete(p-1, p+1);    _readline->insert(reverse(c), p-1);    }    +  int forward_find_word() +  { +  int p, n; +  string line = _readline->gettext(); +  for(p = _readline->getcursorpos(); p < sizeof(line); p++) { +  if(word_break_chars[ line[p..p] ]) { +  if(n) break; +  } else n = 1; +  } +  return p; +  } +  +  int backward_find_word() +  { +  int p = _readline->getcursorpos() , n; +  string line = _readline->gettext(); +  if(p >= strlen(line)) p = strlen(line) - 1; +  for(; p >= 0; p--) { +  if(word_break_chars[ line[p..p] ]) { +  if(n) break; +  } else n = 1; +  } +  return p; +  } +  +  void forward_word() +  { +  _readline->setcursorpos(forward_find_word()); +  } +  +  void backward_word() +  { +  _readline->setcursorpos(backward_find_word()); +  } +  +  void forward_delete_word() +  { +  _readline->delete(_readline->getcursorpos(), forward_find_word()); +  } +  void backward_delete_word() +  { +  _readline->delete(backward_find_word()+1, _readline->getcursorpos()); +  } +     void kill_line()    {    _readline->delete(_readline->getcursorpos(), strlen(_readline->gettext()));    }       void kill_whole_line()    {    _readline->delete(0, strlen(_readline->gettext()));    }   
pike.git/lib/modules/Stdio.pmod/Readline.pike:656:    ({ "^N", down_history }),    ({ "^P", up_history }),    ({ "^R", redisplay }),    ({ "^T", transpose_chars }),    ({ "^U", kill_whole_line }),    ({ "^V", quoted_insert }),    ({ "^?", backward_delete_char }),    ({ "\\!ku", up_history }),    ({ "\\!kd", down_history }),    ({ "\\!kr", forward_char }), -  ({ "\\!kl", backward_char }) +  ({ "\\!kl", backward_char }), +  ({ "^[D", forward_delete_word }), +  ({ "^[^H", backward_delete_word }), +  ({ "^[^?", backward_delete_word }), +  ({ "^[d", forward_delete_word }), +  ({ "^[F", forward_word }), +  ({ "^[B", backward_word }), +  ({ "^[f", forward_word }), +  ({ "^[b", backward_word }),    });       static void set_default_bindings()    {    object ic = _readline->get_input_controller();    ic->nullbindings();    for(int i=' '; i<'\177'; i++)    ic->bindstr(sprintf("%c", i), self_insert_command);    for(int i='\240'; i<='\377'; i++)    ic->bindstr(sprintf("%c", i), self_insert_command);