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

version» Context lines:

pike.git/lib/modules/Stdio.pmod/Readline.pike:1:   #pike __REAL_VERSION__      //!   //! @fixme   //! Ought to have support for charset conversion.   class OutputController   { -  protected private .File outfd; -  protected private .Terminfo.Termcap term; -  protected private int xpos = 0, columns = 0; -  protected private mapping oldattrs = 0; +  private .File outfd; +  private .Terminfo.Termcap term; +  private int xpos = 0, columns = 0; +  private mapping oldattrs = 0;      #define BLINK 1   #define BOLD 2   #define DIM 4   #define REVERSE 8   #define ITALIC 16   #define STANDOUT 32   #define UNDERLINE 64    -  protected private int selected_attributes = 0, needed_attributes = 0; -  protected private int active_attributes = 0; +  private int selected_attributes = 0, needed_attributes = 0; +  private int active_attributes = 0;       protected int low_attribute_mask(array(string) atts)    {    return `|(@rows(([    "blink":BLINK,    "bold":BOLD,    "dim":DIM,    "reverse":REVERSE,    "italic":ITALIC,    "standout":STANDOUT,
pike.git/lib/modules/Stdio.pmod/Readline.pike:117:    //!    void enable()    {    if(term->put("cr") && term->put("do"))    catch { outfd->tcsetattr((["OPOST":0])); };    else    catch { outfd->tcsetattr((["OPOST":1,"ONLCR":1,"OCRNL":0,"OLCUC":0,    "OFILL":1,"OFDEL":0,"ONLRET":0,"ONOCR":0]));};    }    -  protected void destroy() +  protected void _destruct()    {    disable();    }       //! Check and return the terminal width.    //!    //! @note    //! In Pike 7.4 and earlier this function returned @expr{void@}.    //!    //! @seealso
pike.git/lib/modules/Stdio.pmod/Readline.pike:430:    catch { oldattrs = outfd->tcgetattr(); };    check_columns();    }   }      //!   //! @fixme   //! Ought to have support for charset conversion.   class InputController   { -  protected private object infd, term; -  protected private int enabled = -1; -  protected private function(:int) close_callback = 0; -  protected private string prefix=""; -  protected private mapping(int:function|mapping(string:function)) bindings=([]); -  protected private function grab_binding = 0; -  protected private mapping oldattrs = 0; +  private object infd, term; +  private int enabled = -1; +  private function(:int) close_callback = 0; +  private string prefix=""; +  private mapping(int:function|mapping(string:function)) bindings=([]); +  private function grab_binding = 0; +  private mapping oldattrs = 0;       int dumb=0;    -  protected void destroy() +  protected void _destruct()    {    catch{ infd->set_blocking(); };    if(dumb)    return;    catch{ infd->tcsetattr((["ECHO":1,"ICANON":1])); };    catch{ if(oldattrs) infd->tcsetattr((["ECHO":0,"ICANON":0,"VEOF":0,    "VEOL":0,"VLNEXT":0])&oldattrs); };    }    -  protected private string process_input(string s) +  private string process_input(string s)    {    int i;       for (i=0; i<sizeof(s); i++)    {    if (!enabled)    return s[i..];    function|mapping(string:function) b = grab_binding || bindings[s[i]];    grab_binding = 0;    if (!b)
pike.git/lib/modules/Stdio.pmod/Readline.pike:487:    {    i += ml-1;    b[m](m);    }    } else    b(s[i..i]);    }    return "";    }    -  protected private void read_cb(mixed _, string s) +  private void read_cb(mixed _, string s)    {    if (!s || s=="")    return;    if (sizeof(prefix))    {    s = prefix+s;    prefix = "";    }    prefix = process_input(s);    }    -  protected private void close_cb() +  private void close_cb()    {    if (close_callback && close_callback())    return;    destruct(this);    }    -  protected private int set_enabled(int e) +  private int set_enabled(int e)    {    if (e != enabled)    {    enabled = e;    if (enabled)    {    string oldprefix = prefix;    prefix = "";    prefix = process_input(oldprefix);    if ((!infd->set_read_callback || !infd->set_close_callback) &&
pike.git/lib/modules/Stdio.pmod/Readline.pike:805:    }    catch { infd->tcsetattr((["ECHO":0,"ICANON":0,"VMIN":1,"VTIME":0,    "VLNEXT":0])); };    }      }      //!   class DefaultEditKeys   { -  protected private multiset word_break_chars = -  mkmultiset("\t \n\r/*?_-.[]~&;\!#$%^(){}<>\"'`"/""); +  private multiset word_break_chars = +  mkmultiset("\t \n\r/*?_-.[]~&;!#$%^(){}<>\"'`"/"");    protected object _readline;       //!    void self_insert_command(string str)    {    _readline->insert(str, _readline->getcursorpos());    }       //!    void quoted_insert()
pike.git/lib/modules/Stdio.pmod/Readline.pike:1159:    {    _readline = readline;    set_default_bindings();    }      }      //!   class History   { -  protected private array(string) historylist; -  protected private mapping(int:string) historykeep=([]); -  protected private int minhistory, maxhistory, historynum; +  private array(string) historylist; +  private mapping(int:string) historykeep=([]); +  private int minhistory, maxhistory, historynum;       //!    string encode()    {    return historylist*"\n";    }       //!    int get_history_num()    {
pike.git/lib/modules/Stdio.pmod/Readline.pike:1223:    if(sizeof(historylist)>1 && historylist[-2]==historylist[-1])    historylist = historylist[..<1];    }       //!    void set_max_history(int maxhist)    {    maxhistory = maxhist;    }    +  //! Pop the last string off the history, discarding it. +  //! If text is provided, will only pop that string. +  //! Returns 1 if a string was removed, 0 if not. +  int(0..1) pop(string|void text) +  { +  if (sizeof(historylist) < 2) return 0; //Not enough to pop +  if (text && historylist[-2] != text) return 0; //Wrong string +  historylist = historylist[..<2] + ({historylist[-1]}); +  return 1; +  } +     //!    void create(int maxhist, void|array(string) hist)    {    historylist = hist || ({ "" });    minhistory = historynum = 0;    maxhistory = maxhist;    }   }       - protected private OutputController output_controller; - protected private InputController input_controller; - protected private string prompt=""; - protected private array(string) prompt_attrs=0; - protected private string text="", readtext; - protected private function(string:void) newline_func; - protected private int cursorpos = 0; - protected private int mark = 0; - /*static private */ History historyobj = 0; - protected private int hide = 0; + private OutputController output_controller; + private InputController input_controller; + private string prompt=""; + private array(string) prompt_attrs=0; + private string text="", readtext; + private function(string:void) newline_func; + private int cursorpos = 0; + private int mark = 0; + /* private */ History historyobj = 0; + private int hide = 0;    - protected private array(string) kill_ring=({}); - protected private int kill_ring_size=30; + private array(string) kill_ring=({}); + private int kill_ring_size=30;      //! get current output control object   //! @returns   //! Terminal output controller object   OutputController get_output_controller()   {    return output_controller;   }      //! get current input control object
pike.git/lib/modules/Stdio.pmod/Readline.pike:1498:    output_controller->write(prompt);    if(prompt_attrs)    output_controller->turn_off(@prompt_attrs);    }    output_controller->write(text,0,hide);    }    cursorpos = sizeof(text);    setcursorpos(p);   }    - protected private void initline() + private void initline()   {    text = "";    cursorpos = 0;    if (historyobj)    historyobj->initline();   }      //! @fixme   //! Document this function   string newline()
pike.git/lib/modules/Stdio.pmod/Readline.pike:1574:   }      //! @fixme   //! Document this function   void list_completions(array(string) c)   {    message(sprintf("%-*#s",output_controller->get_number_of_columns(),    c*"\n"));   }    - protected private void read_newline(string s) + private void read_newline(string s)   {    input_controller->disable();    readtext = s;   }      //! @fixme   //! Document this function   void set_nonblocking(function f)   {    int p=cursorpos;
pike.git/lib/modules/Stdio.pmod/Readline.pike:1685:    historyobj = History(hist);   }      //! @fixme   //! Document this function   History get_history()   {    return historyobj;   }    - protected void destroy() + protected void _destruct()   {    if(input_controller)    destruct(input_controller);    if(output_controller)    destruct(output_controller);   }      //! Creates a Readline object, that takes input from @[infd] and has output   //! on @[outfd].   //!
pike.git/lib/modules/Stdio.pmod/Readline.pike:1711:   //!   //! @param outfd   //! Defaults to @[infd], unless @[infd] is 0, in which case   //! @[outfd] defaults to @[Stdio.stdout].   //!   //! @param outterm   //! Defaults to @[interm].   void create(object|void infd, object|string|void interm,    object|void outfd, object|string|void outterm)   { -  atexit(destroy); +  atexit(_destruct);    output_controller = OutputController(outfd || infd, outterm || interm);    input_controller = InputController(infd, interm);    DefaultEditKeys(this);   }