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.33 2000/04/06 09:06:22 hubbe Exp $ + // $Id: Readline.pike,v 1.34 2000/08/29 13:16:55 noring Exp $      class OutputController   {    static private object outfd, term;    static private int xpos = 0, columns = 0;    static private mapping oldattrs = 0;      #define BLINK 1   #define BOLD 2   #define DIM 4
pike.git/lib/modules/Stdio.pmod/Readline.pike:1074:    minhistory = historynum = 0;    maxhistory = maxhist;    }      }         static private object(OutputController) output_controller;   static private object(InputController) input_controller;   static private string prompt=""; + static private array(string) prompt_attrs=0;   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;   
pike.git/lib/modules/Stdio.pmod/Readline.pike:1099:   object(InputController) get_input_controller()   {    return input_controller;   }      string get_prompt()   {    return prompt;   }    - string set_prompt(string newp) + string set_prompt(string newp, array(string)|void newattrs)   {    string oldp = prompt; -  if(newp!=prompt) +  if(newp!=prompt || !equal(prompt_attrs, newattrs))    {    if(newline_func)    {   // werror("\nNew prompt!!! %O\n",newline_func);    int p=cursorpos;    setcursorpos(0);    output_controller->bol();    output_controller->clear(1);    prompt = newp; -  +  prompt_attrs = newattrs && copy_value(newattrs);    cursorpos=strlen(text);    redisplay(0, 1);    cursorpos=p;    }else{    prompt = newp; -  +  prompt_attrs = newattrs && copy_value(newattrs);    }    }    return oldp;   }      void set_echo(int onoff)   {    hide=!onoff;   }   
pike.git/lib/modules/Stdio.pmod/Readline.pike:1283:    if(clear)    output_controller->clear();    else if(!nobackup) {    setcursorpos(0);    output_controller->bol();    output_controller->clear(1);    }    output_controller->check_columns();       if(!input_controller->dumb) { -  if(newline_func == read_newline) +  if(newline_func == read_newline) { +  if(prompt_attrs) +  output_controller->turn_on(@prompt_attrs);    output_controller->write(prompt); -  +  if(prompt_attrs) +  output_controller->turn_off(@prompt_attrs); +  }    output_controller->write(text,0,hide);    }    cursorpos = sizeof(text);    setcursorpos(p);   }      static private void initline()   {    text = "";    cursorpos = 0;
pike.git/lib/modules/Stdio.pmod/Readline.pike:1386:    input_controller->disable();    output_controller->disable();    }   }      void set_blocking()   {    set_nonblocking(0);   }    - string edit(string data, string|void local_prompt) + string edit(string data, string|void local_prompt, array(string)|void attrs)   {    if(data && strlen(data) && input_controller->dumb)    { -  string ret=edit("", (local_prompt || get_prompt()) +" ["+data+"] "); +  string ret=edit("", (local_prompt || get_prompt()) +" ["+data+"] ", attrs);    return (!ret || !strlen(ret))?data:ret;    }    string old_prompt; -  +  array(string) old_attrs;       if(newline_func == read_newline)    return 0;       if(local_prompt)    {    old_prompt = get_prompt(); -  set_prompt(local_prompt); +  old_attrs = prompt_attrs; +  set_prompt(local_prompt, attrs);    }       function oldnl = newline_func; -  +  if(attrs) +  output_controller->turn_on(@attrs);    output_controller->write(local_prompt||prompt); -  +  if(attrs) +  output_controller->turn_off(@attrs);    initline();    newline_func = read_newline;    readtext = "";    output_controller->enable();    insert(data, 0);    int res = input_controller->run_blocking();          set_nonblocking(oldnl);       if(local_prompt) -  set_prompt(old_prompt); +  set_prompt(old_prompt, old_attrs);       return (res>=0 || sizeof(readtext)) && readtext;   }    - string read(string|void prompt) + string read(string|void prompt, array(string)|void attrs)   { -  return edit("", prompt); +  return edit("", prompt, attrs);   }      void enable_history(array(string)|object(History)|int hist)   {    if (objectp(hist))    historyobj = hist;    else if(arrayp(hist))    historyobj = History(512,hist);    else if(!hist)    historyobj = 0;