1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
/* curses Yorick plugin, version 0.1
* Francois Rigaut, nov2004
* last revision/addition: 2004Nov30
*
* Copyright (c) 2003, Francois RIGAUT (frigaut@maumae.net)
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details (to receive a copy of the GNU
* General Public License, write to the Free Software Foundation, Inc., 675
* Mass Ave, Cambridge, MA 02139, USA).
*/
func curses{}
/* DOCUMENT curses package
The curses plugin wraps some of the curses routine, hopefully enough
of them to do something useful in a one terminal environment (i.e.
I did not wrap multi-terminal curses control routines like newterm).
Curses allow control of the screen and keyboard in a unbuffered way.
you can position and write string wherever you want, without or with
scroll, and you can monitor keyboard events. This can be useful to
report results of large computations without the rapid screen scrolling
and/or steer simulations as they go.
You can see examples of use in the check-plug.i file or in the
"progressbar" or "countdown" routines below.
NOTE: This routine uses the "curses" library. Thus, it will work
on Linux and maxosx machines (and probably unix) but *NOT* on windows
machine (unless curses has been ported to windows, which I am ignorant
of).
Also, curses may not have all the term files. In particular, I have
noticed that it doesn't like to be ran in an emacs terminal/environment.
SEE ALSO:
*/
if (strmatch(get_env("TERM"),"emacs")) \
error,"curses will not work in an emacs environement";
plug_in, "curses";
extern kbdinit;
/* PROTOTYPE
void kbdinit(void)
*/
extern kbd;
/* PROTOTYPE
int kbd(int wait)
*/
extern kbdend;
/* PROTOTYPE
void kbdend(void)
*/
extern cgetch;
/* PROTOTYPE
int getch(void)
*/
extern cinitscr;
/* PROTOTYPE
int initscr(void)
*/
extern cendwin;
/* PROTOTYPE
int endwin(void)
*/
extern cisendwin;
/* PROTOTYPE
int isendwin(void)
*/
extern ccbreak;
/* PROTOTYPE
int cbreak(void)
*/
extern cnocbreak;
/* PROTOTYPE
int nocbreak(void)
*/
extern chalfdelay;
/* PROTOTYPE
int halfdelay(int tenths)
*/
extern craw;
/* PROTOTYPE
int raw(void)
*/
extern cnoraw;
/* PROTOTYPE
int noraw(void)
*/
extern ctimeout;
/* PROTOTYPE
void timeout(int delay)
*/
extern cnl;
/* PROTOTYPE
int nl(void)
*/
extern cnonl;
/* PROTOTYPE
int nonl(void)
*/
extern cprintw;
/* PROTOTYPE
int printw(string fmt, string str)
*/
extern cmvprintw;
/* PROTOTYPE
int mvprintw(int y, int x, string fmt, string str)
*/
extern crefresh;
/* PROTOTYPE
int refresh(void)
*/
extern caddch;
/* PROTOTYPE
int addch(char ch)
*/
extern cmvaddch;
/* PROTOTYPE
int mvaddch(int y, int x, char ch)
*/
extern cerase;
/* PROTOTYPE
int erase(void)
*/
extern cclear;
/* PROTOTYPE
int clear(void)
*/
extern cclrtobot;
/* PROTOTYPE
int clrtobot(void)
*/
extern cclrtoeol;
/* PROTOTYPE
int clrtoeol(void)
*/
extern cbkgdset;
/* PROTOTYPE
int bkgdset(char ch)
*/
extern cgetlines;
/* PROTOTYPE
int getlines(void)
*/
extern cgetcols;
/* PROTOTYPE
int getcols(void)
*/
extern ccurs_set;
/* PROTOTYPE
int curs_set(int visibility)
*/
extern ccurs_move;
/* PROTOTYPE
int move(int y, int x)
*/
extern cbeep;
/* PROTOTYPE
int beep(void)
*/
extern cflash;
/* PROTOTYPE
int flash(void)
*/
extern cecho;
/* PROTOTYPE
int echo(void)
*/
extern cnoecho;
/* PROTOTYPE
int noecho(void)
*/
extern cgetstr;
/* PROTOTYPE
int getstr(string str);
*/
extern cmvgetstr;
/* PROTOTYPE
int mvgetstr(int y, int x, string str);
*/
extern cnodelay;
/* PROTOTYPE
int ynodelay(int condition)
*/
extern cnotimeout;
/* PROTOTYPE
int ynotimeout(int condition)
*/
extern ckeypad;
/* PROTOTYPE
int ykeypad(int condition)
*/
extern cmeta;
/* PROTOTYPE
int ymeta(int condition)
*/
extern cintrflush;
/* PROTOTYPE
int yintrflush(int condition)
*/
extern cscrollok;
/* PROTOTYPE
int yscrollok(int condition)
*/
extern cleaveok;
/* PROTOTYPE
int yleaveok(int condition)
*/
extern cclearok;
/* PROTOTYPE
int yclearok(int condition)
*/
extern cidlok;
/* PROTOTYPE
int yidlok(int condition)
*/
func countdown(sec,interval)
/* DOCUMENT func countdown(sec,interval)
sec: number of seconds to coundown
interval: time to pause between refresh, in ms
SEE ALSO:
*/
{
if (!interval) interval=10;
kbdinit;
cerase;
tic;
while ((elapsed=tac()) < sec) {
el = round(elapsed);
cmvprintw,0,0,"[%-"+swrite(format="%s",sec)+"s]",((el==0)?"":array("*",el)(sum));
cmvprintw,0,sec+3,"Time remaining: %s sec",swrite(format="%.3f",sec-elapsed);
cclrtobot;
crefresh;
pause,interval;
}
kbdend;
}
func progressbar(current,outof,nstars,counter=,line=)
/* DOCUMENT print out a progress bar in the terminal using curse
no init necessary. Just do a tic(counter) at the start of the loop.
term has to be in curse mode.
SEE ALSO:
*/
{
if (!counter) counter=1;
if (line==[]) line=0;
nc = cgetcols();
el = round(current*1./outof*nstars);
cmvprintw,line,nc-nstars-2,"[%-"+swrite(format="%d",nstars)+"s]",
((el==0)?"":array("*",el)(sum));
elapsed = tac(counter);
left = elapsed*(outof-current)/(current+1e-6);
cmvprintw,line+1,nc-nstars-2,"%s s left ",swrite(format="%.3f",left);
cmvprintw,line+2,nc-nstars-2,"%s",swrite(format="%d/%d",current,outof);
cclrtoeol;
}
|