curses/0000755000602200060220000000000010344253427013504 5ustar frigautfrigaut00000000000000curses/check.i0000644000602200060220000000375110344253167014742 0ustar frigautfrigaut00000000000000plug_dir,"."; require,"curses.i"; require,"util_fr.i"; require,"random.i"; func testloop(void) { kbdinit; cerase; cprintw,"%s"," Press 'q' to end, space to pause"; tic(3); niter = 3000; fromzen = 0.f; tozen = 50.f; zen = span(fromzen,tozen,niter); nc = cgetcols(); for (i=1;i<=niter;i++) { r = string(&char(kbd(0))); if (r=="q") break; if (r==" ") { // pause cbeep; cmvprintw,0,0,"%s"," Press any key to resume"; cclrtoeol; crefresh; r=string(&char(kbd(1))); cmvprintw,0,0,"%s"," Press 'q' to end, space to pause"; crefresh; } line = 1; cmvprintw,line,0,"%s",swrite(format="Elevation: %.2f -> %.2f -> %.2f",fromzen, zen(i),tozen); cclrtoeol; line++; for (n=1;n<=2;n++) { line++; cmvprintw,line,0,"%s",swrite(format="%-17s tip=%+7.2f'', tilt=%+7.2f''", "Mechanism",random_n(1)(1),random_n(1)(1)); cclrtoeol; } progressbar,i,niter,15,counter=3,line=1; ccurs_set,0; ccurs_move,0,0; crefresh; } kbdend; } func enterstr(void) { kbdinit; cerase; cecho; s= array(" ",1024)(sum); cprintw,"%s","Enter some string: "; cgetstr,s; kbdend; print,"You entered "+s; pause,1000; } func testatom(void) { cinitscr; ccbreak; cnoecho; cnonl; cintrflush,1; ckeypad,1; cnodelay,0; nl = cgetlines(); cmvprintw,nl-1,0,"%s","Hit a key to start"; // ccurs_move,0,0; r = cgetch(); cendwin; return string(&char(r)); } func testscroll(void) // the scroll does not produce the desired effect. // i must have forgotten something or not understood // the nature of "scrollok" { cinitscr; cerase; cclear; ccbreak; cscrollok,1; cidlok,1; text = rdfile("check-plug.i"); for (i=1;i<=numberof(text);i++) { cprintw,"%s\n",text(i); } cprintw,"%s","\nhit a key when ready"; cnodelay,0; r = cgetch(); cendwin; } testatom; //testscroll; enterstr; //countdown,3; testloop; write,"Tests successful" curses/curses.c0000644000602200060220000000244110344162264015153 0ustar frigautfrigaut00000000000000#include #include void kbdinit() { initscr(); cbreak(); noecho(); nonl(); intrflush(stdscr, TRUE); keypad(stdscr, TRUE); } int kbd(int wait) { int kb; if (!wait) nodelay(stdscr, TRUE); else nodelay(stdscr, FALSE); kb = getch(); nodelay(stdscr, FALSE); return kb; } void kbdend() { endwin(); } int getlines() {return LINES; } int getcols() {return COLS; } int ynodelay(int condition) { if (condition) nodelay(stdscr, TRUE); else nodelay(stdscr, FALSE); } int ynotimeout(int condition) { if (condition) notimeout(stdscr, TRUE); else notimeout(stdscr, FALSE); } int ykeypad(int condition) { if (condition) keypad(stdscr, TRUE); else keypad(stdscr, FALSE); } int ymeta(int condition) { if (condition) meta(stdscr, TRUE); else meta(stdscr, FALSE); } int yintrflush(int condition) { if (condition) intrflush(stdscr, TRUE); else intrflush(stdscr, FALSE); } int yscrollok(int condition) { if (condition) scrollok(stdscr, TRUE); else scrollok(stdscr, FALSE); } int yleaveok(int condition) { if (condition) leaveok(stdscr, TRUE); else leaveok(stdscr, FALSE); } int yclearok(int condition) { if (condition) clearok(stdscr, TRUE); else clearok(stdscr, FALSE); } int yidlok(int condition) { if (condition) idlok(stdscr, TRUE); else idlok(stdscr, FALSE); } curses/curses.i0000644000602200060220000001327710344162264015172 0ustar frigautfrigaut00000000000000/* 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; } curses/curses.info0000644000602200060220000000170210344253340015657 0ustar frigautfrigaut00000000000000Package: curses Kind: plugin Version: 0.1 Revision: 1 Description: Wrapper for the curses library License: GPL Maintainer: Francois Rigaut OS: Depends: yorick(>=1.6.02), yutils(>=1.1) Source: http://www.maumae.net/yorick/packages/%o/tarballs/curses-%v-%o.tgz Source-MD5: Source-Directory: contrib/curses DocFiles: README TODO VERSION NEWS LEGAL doc/README:README.doc doc/FILE_FORMATS doc/*.doc doc/*.pdf doc/*.ps doc/*.tex Homepage: http://www.maumae.net/yorick/doc/plugins.php DescDetail: << Wrapper for the curses library. Allow fine control of the cursor and output in a terminal session. << DescUsage: << See contrib/curses/check.i for a test suite. Type "yorick -i check.i" (in this directory) in a terminal to run it. << DescPort: << This package will compile Yorick only on MacOSX 10.3.4 or later, because of a bug in the system math library libm (part of /usr/lib/LibSystem.dylib) in earlier versions of MacOSX 10.3. << curses/Makefile0000644000602200060220000000712010344162313015135 0ustar frigautfrigaut00000000000000Y_MAKEDIR=/Users/frigaut/yorick-2.1/Darwin-Power_Macintosh Y_EXE=/Users/frigaut/yorick-2.1/Darwin-Power_Macintosh/bin/yorick Y_EXE_PKGS= Y_EXE_HOME=/Users/frigaut/yorick-2.1/Darwin-Power_Macintosh Y_EXE_SITE=/Users/frigaut/yorick-2.1 # ----------------------------------------------------- optimization flags COPT=$(COPT_DEFAULT) TGT=$(DEFAULT_TGT) # ------------------------------------------------ macros for this package PKG_NAME=curses PKG_I=curses.i OBJS=curses.o # change to give the executable a name other than yorick PKG_EXENAME=yorick # PKG_DEPLIBS=-Lsomedir -lsomelib for dependencies of this package PKG_DEPLIBS=-lcurses # set compiler or loader (rare) flags specific to this package PKG_CFLAGS= PKG_LDFLAGS= # list of additional package names you want in PKG_EXENAME # (typically Y_EXE_PKGS should be first here) EXTRA_PKGS=$(Y_EXE_PKGS) # list of additional files for clean PKG_CLEAN= # autoload file for this package, if any PKG_I_START= # -------------------------------- standard targets and rules (in Makepkg) # set macros Makepkg uses in target and dependency names # DLL_TARGETS, LIB_TARGETS, EXE_TARGETS # are any additional targets (defined below) prerequisite to # the plugin library, archive library, and executable, respectively PKG_I_DEPS=$(PKG_I) include $(Y_MAKEDIR)/Make.cfg include $(Y_MAKEDIR)/Makepkg include $(Y_MAKEDIR)/Make$(TGT) # override macros Makepkg sets for rules and other macros # Y_HOME and Y_SITE in Make.cfg may not be correct (e.g.- relocatable) Y_HOME=$(Y_EXE_HOME) Y_SITE=$(Y_EXE_SITE) # reduce chance of yorick-1.5 corrupting this Makefile MAKE_TEMPLATE = protect-against-1.5 # ------------------------------------- targets and rules for this package # simple example: #myfunc.o: myapi.h # more complex example (also consider using PKG_CFLAGS above): #myfunc.o: myapi.h myfunc.c # $(CC) $(CPPFLAGS) $(CFLAGS) -DMY_SWITCH -o $@ -c myfunc.c # -------------------------------------------------------- end of Makefile # for the binary package production: PKG_DEPLIBS_STATIC=-lm -lcurses PKG_OS = macosx # or linux or windows PKG_VERSION = 0.1 binaries: $(MAKE) $(LD_DLL) -o $@ $(OBJS) ywrap.o $(PKG_DEPLIBS_STATIC) $(DLL_DEF) mv binaries $(PKG_NAME).so package: $(MAKE) binaries mkdir -p binaries/$(PKG_NAME)/dist/y_home/lib mkdir -p binaries/$(PKG_NAME)/dist/y_home/i-start mkdir -p binaries/$(PKG_NAME)/dist/y_site/i0 cp -p *.i binaries/$(PKG_NAME)/dist/y_site/i0/ cp -p check.i binaries/$(PKG_NAME)/. rm binaries/$(PKG_NAME)/dist/y_site/i0/check.i if test -n "$(PKG_I_START)"; then rm binaries/$(PKG_NAME)/dist/y_site/i0/$(PKG_I_START); fi cp -p $(PKG_NAME).so binaries/$(PKG_NAME)/dist/y_home/lib/ if test -n "$(PKG_I_START)"; then cp -p $(PKG_I_START) binaries/$(PKG_NAME)/dist/y_home/i-start/; fi cat $(PKG_NAME).info | sed -e 's/OS:/OS: $(PKG_OS)/' > tmp.info mv tmp.info binaries/$(PKG_NAME)/$(PKG_NAME).info cd binaries; tar zcvf $(PKG_NAME)-$(PKG_VERSION)-$(PKG_OS).tgz $(PKG_NAME) distrib: if test -f "binaries/$(PKG_NAME)-$(PKG_VERSION)-$(PKG_OS).tgz" ; then ncftpput -f /Users/frigaut/.ncftp/maumae www/yorick/packages/$(PKG_OS)/tarballs/ binaries/$(PKG_NAME)-$(PKG_VERSION)-$(PKG_OS).tgz; fi if test -f "binaries/$(PKG_NAME)/$(PKG_NAME).info" ; then ncftpput -f /Users/frigaut/.ncftp/maumae www/yorick/packages/$(PKG_OS)/info/ binaries/$(PKG_NAME)/$(PKG_NAME).info; fi make clean cd ..; tar --exclude binaries --exclude .svn -zcvf $(PKG_NAME)-$(PKG_VERSION)-src.tgz $(PKG_NAME); ncftpput -f /Users/frigaut/.ncftp/maumae www/yorick/packages/src/ $(PKG_NAME)-$(PKG_VERSION)-src.tgz # -------------------------------------------------------- end of Makefile curses/README0000644000602200060220000000074510344162264014370 0ustar frigautfrigaut00000000000000curses plugin for Yorick: F.Rigaut, Nov2004. see file curses.i for more details. 1. Content: This plugin includes wrapping function for the curses library. 2. Installation: see installation instructions in Makefile. Basically, you will need a C compiler and make/gnumake. You need yorick in your executable path. yorick -batch make.i make make check make install The install puts curses.i in Y_SITE/i, the curses.so library in Y_HOME/lib. 3. History: Nov2004: creation, v0.1