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.17 1999/06/04 21:26:29 hubbe Exp $ + // $Id: Readline.pike,v 1.18 1999/06/06 09:05:48 mirar 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:739:    void forward_word()    {    _readline->setcursorpos(forward_find_word());    }       void backward_word()    {    _readline->setcursorpos(backward_find_word());    }    -  void delete_word() +  void kill_word()    { -  _readline->delete(_readline->getcursorpos(), forward_find_word()); +  _readline->kill(_readline->getcursorpos(), forward_find_word());    }    -  void backward_delete_word() +  void backward_kill_word()    {    int sp = backward_find_word();    int ep = _readline->getcursorpos();    if((ep - sp) == 0)    sp--; -  _readline->delete(sp, ep); +  _readline->kill(sp, ep);    }       void kill_line()    { -  _readline->delete(_readline->getcursorpos(), strlen(_readline->gettext())); +  _readline->kill(_readline->getcursorpos(), strlen(_readline->gettext()));    }       void kill_whole_line()    { -  _readline->delete(0, strlen(_readline->gettext())); +  _readline->kill(0, strlen(_readline->gettext()));    }    -  +  void yank() +  { +  _readline->setmark(_readline->getcursorpos()); +  _readline->insert(_readline->kill_ring_yank(),_readline->getcursorpos()); +  } +  +  void kill_ring_save() +  { +  _readline->add_to_kill_ring(_readline->region()); +  } +  +  void kill_region() +  { +  _readline->kill(@_readline->pointmark()); +  } +  +  void set_mark() +  { +  _readline->setmark(_readline->getcursorpos()); +  } +  +  void swap_mark_and_point() +  { +  int p=_readline->getcursorpos(); +  _readline->setcursorpos(_readline->getmark()); +  _readline->setmark(p); +  } +     void redisplay()    {    _readline->redisplay(0);    }       void clear_screen()    {    _readline->redisplay(1);    }   
pike.git/lib/modules/Stdio.pmod/Readline.pike:784:    ({ "^[[A", up_history }),    ({ "^[[B", down_history }),    ({ "^[[C", forward_char }),    ({ "^[[D", backward_char }),    ({ "^[C", capitalize_word }),    ({ "^[c", capitalize_word }),    ({ "^[U", upcase_word }),    ({ "^[u", upcase_word }),    ({ "^[L", downcase_word }),    ({ "^[l", downcase_word }), -  ({ "^[D", delete_word }), -  ({ "^[^H", backward_delete_word }), -  ({ "^[^?", backward_delete_word }), -  ({ "^[d", delete_word }), +  ({ "^[D", kill_word }), +  ({ "^[^H", backward_kill_word }), +  ({ "^[^?", backward_kill_word }), +  ({ "^[d", kill_word }),    ({ "^[F", forward_word }),    ({ "^[B", backward_word }),    ({ "^[f", forward_word }),    ({ "^[b", backward_word }), -  +  ({ "^[w", kill_ring_save }), +  ({ "^[W", kill_ring_save }), +  ({ "^0", set_mark }),    ({ "^A", beginning_of_line }),    ({ "^B", backward_char }),    ({ "^D", delete_char_or_eof }),    ({ "^E", end_of_line }),    ({ "^F", forward_char }),    ({ "^H", backward_delete_char }),    ({ "^J", newline }),    ({ "^K", kill_line }),    ({ "^L", clear_screen }),    ({ "^M", newline }),    ({ "^N", down_history }),    ({ "^P", up_history }),    ({ "^R", redisplay }),    ({ "^T", transpose_chars }),    ({ "^U", kill_whole_line }),    ({ "^V", quoted_insert }), -  +  ({ "^W", kill_region }), +  ({ "^Y", yank }),    ({ "^?", backward_delete_char }),    ({ "\\!ku", up_history }),    ({ "\\!kd", down_history }),    ({ "\\!kr", forward_char }),    ({ "\\!kl", backward_char }), -  +  ({ "^X^X", swap_mark_and_point }),    });       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);
pike.git/lib/modules/Stdio.pmod/Readline.pike:907:      }         static private object(OutputController) output_controller;   static private object(InputController) input_controller;   static private string prompt="";   static private string text="", readtext;   static private function(string:void) newline_func;   static private int cursorpos = 0; + static private int mark = 0;   static private object(History) historyobj = 0;   static private int hide = 0;    -  + static private array(string) kill_ring=({}); + static private int kill_ring_size=30; +    object(OutputController) get_output_controller()   {    return output_controller;   }      object(InputController) get_input_controller()   {    return input_controller;   }   
pike.git/lib/modules/Stdio.pmod/Readline.pike:982:    cursorpos = p;    }    else if (p>cursorpos)    {    output_controller->move_forward(text[cursorpos..p-1]);    cursorpos = p;    }    return cursorpos;   }    + int setmark(int p) + { +  if (p<0) +  p = 0; +  if (p>strlen(text)) +  p = strlen(text); +  mark=p; + } +  + int getmark() + { +  return mark; + } +    void insert(string s, int p)   {    if (p<0)    p = 0;    if (p>strlen(text))    p = strlen(text);    setcursorpos(p);    output_controller->write(s,0,0,hide);    cursorpos += strlen(s);    string rest = text[p..];    if (strlen(rest))    {    output_controller->write(rest,0,0,hide);    output_controller->move_backward(rest);    }    text = text[..p-1]+s+rest; -  +  +  if (mark>p) mark+=strlen(s);   }      void delete(int p1, int p2)   {    if (p1<0)    p1 = 0;    if (p2>strlen(text))    p2 = strlen(text);    setcursorpos(p1);    if (p1>=p2)    return;    output_controller->write(text[p2..],0,0,hide);    output_controller->erase(text[p1..p2-1]);    text = text[..p1-1]+text[p2..]; -  +  +  if (mark>p2) mark-=(p2-p1); +  else if (mark>p1) mark=p1; +     cursorpos = strlen(text);    setcursorpos(p1);   }    -  + array(int) pointmark() // returns point and mark in numeric order + { +  int p1,p2; +  p1=getcursorpos(),p2=getmark(); +  if (p1>p2) return ({p2,p1}); +  return ({p1,p2}); + } +  + string region(int ... args) /* p1, p2 or point-mark */ + { +  int p1,p2; +  if (sizeof(args)) [p1,p2]=args; +  else [p1,p2]=pointmark(); +  return text[p1..p2-1]; + } +  + void kill(int p1, int p2) + { +  if (p1<0) +  p1 = 0; +  if (p2>strlen(text)) +  p2 = strlen(text); +  if (p1>=p2) +  return; +  add_to_kill_ring(text[p1..p2-1]); +  delete(p1,p2); + } +  + void add_to_kill_ring(string s) + { +  kill_ring+=({s}); +  if (sizeof(kill_ring)>kill_ring_size) kill_ring=kill_ring[1..]; + } +  + string kill_ring_yank() + { +  if (!sizeof(kill_ring)) return ""; +  return kill_ring[-1]; + } +    void history(int n)   {    if(historyobj) {    string h = historyobj->history(n, text);    delete(0, strlen(text)+strlen(prompt));    insert(h, 0);    }   }      void delta_history(int d)