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.11 1999/04/12 02:23:12 hubbe Exp $ + // $Id: Readline.pike,v 1.12 1999/04/25 08:29:28 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 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);    }    +  array find_word_to_manipulate() +  { +  int p = _readline->getcursorpos(); +  int ep; +  string line = _readline->gettext(); +  while(word_break_chars[ line[p..p] ] && p < strlen(line)) +  p++; +  if(p >= strlen(line)) { +  _readline->setcursorpos(p); +  return ({ 0, 0 }); +  } +  ep = forward_find_word(); +  _readline->delete(p, ep); +  return ({ line[p..ep-1], p }); +  } +  +  void capitalize_word() +  { +  [string word, string pos]= find_word_to_manipulate(); +  if(word) +  _readline->insert(String.capitalize(lower_case(word)), pos); +  } +  +  void upper_case_word() +  { +  [string word, string pos]= find_word_to_manipulate(); +  if(word) +  _readline->insert(upper_case(word), pos); +  } +  +  void lower_case_word() +  { +  [string word, string pos]= find_word_to_manipulate(); +  if(word) +  _readline->insert(lower_case(word), pos); +  } +     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; +  int p = _readline->getcursorpos()-1;    string line = _readline->gettext();    if(p >= strlen(line)) p = strlen(line) - 1; -  for(; p >= 0; p--) { +  while(word_break_chars[ line[p..p] ] && p >= 0) +  // find first "non break char" +  p--; +  for(;p >= 0; p--)    if(word_break_chars[ line[p..p] ]) { -  if(n) break; -  } else n = 1; +  p++; // We want to be one char before the break char. +  break;    }    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()    { -  int sp = backward_find_word() + 1; +  int sp = backward_find_word();    int ep = _readline->getcursorpos();    if((ep - sp) == 0)    sp--;    _readline->delete(sp, ep);    }       void kill_line()    {    _readline->delete(_readline->getcursorpos(), strlen(_readline->gettext()));    }
pike.git/lib/modules/Stdio.pmod/Readline.pike:705:    ({ "^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 }), +  ({ "^[C", capitalize_word }), +  ({ "^[c", capitalize_word }), +  ({ "^[U", upper_case_word }), +  ({ "^[u", upper_case_word }), +  ({ "^[L", lower_case_word }), +  ({ "^[l", lower_case_word }),    ({ "^[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 }),    });