jpb@icdoc.UUCP (Jonathan Bowen) (04/18/85)
This program helps control the VDU display from the shell. It uses the library `Curses' available under Berkeley Unix. To create `curse.1' (manual entry), `curse.c' (source) and `curse' (executable program) in the current directory, run the following shell script: ---------------------- cut here ----------------------- cat >curse.1 <<'--EOF--' .TH CURSE 1 "20 February 1985" .UC 4 .SH NAME curse \- screen functions .SH SYNOPSIS .B curse [ option ] [ text ] ... .SH DESCRIPTION This command gives the user a method of updating the screen from the shell. The options are two letter variable names from .I curses.h as detailed in Appendix A of .I "Screen Updating and Cursor Movement Optimization: A Library Package". All the .I char* type variables are included. Some commonly used options are: .TP 6 .B -cd Clear to end of Display. .TP 6 .B -ce Clear to End of line. .TP 6 .B -cl CLear screen. This is exactly like the .I clear command. .TP 6 .B -cm Cursor Motion. This takes the next two numerical arguments on the command line to be the .I x and .I y coordinates of the desired position of the cursor from the .I home position .I (0,0) at the top lefthand corner of the screen. .TP 6 .B -ho HOme cursor. This moves the cursor to the top lefthand corner of the screen. This is equivalent to .I -cm 0 0. .TP 6 .B -ll Last Line. This moves the cursor to the bottom lefthand corner of the screen. This is equivalent to .I -cm 0 23 on a standard 24 line screen. .TP 6 .B -se Standout End (may leave space). .TP 6 .B -so Stand Out begin (may leave space). This normally produces reverse video but depends on the terminal\'s capabilities. .TP 6 .B -ue Underline Ending sequence. .TP 6 .B -us Underline Starting sequence. .TP 6 .B -xx Prints all allowable options. .PP The options may be given in upper or lower case. Letters after the first two characters are ignored (e.g. .B -clear may be used instead of .B -cl ). Any arguments not starting with a `-' are treated as text and are printed at the current cursor position in the current style (e.g. standout mode). For example, to print a message in standout mode at the center of a standard 80 by 24 character screen and leave the cursor at the bottom of the screen, the following sequence could be used: .PP .ti+8n curse -cl -cm 34 11 -so \'BSD4.2 Unix\' -se -ll .SH SEE ALSO .I "Screen Updating and Cursor Movement Optimization: A Library Package," Ken Arnold, .br clear(1), curses(3x), termcap(5) .SH AUTHOR Jonathan Bowen, PRG, Oxford, England .SH BUGS Some options will only work if the corresponding entry in .I termcap has been set for the terminal in use (e.g. standout mode). Cursor motion may not work on some terminals. --EOF-- cat >curse.c <<'--EOF--' #include <curses.h> main(argc, argv) int argc; char *argv[]; { char c1, c2, *s; int x, y; if (--argc <= 0) { fprintf(stderr,"Usage: curse -xx ...\n"); exit(0); } initscr(); while (--argc >= 0) { *++argv; if ((*argv)[0] == '-') { c1 = (*argv)[1]; if ((c1 >= 'A') && (c1 <= 'Z')) c1 = c1+'a'-'A'; c2 = (*argv)[2]; if ((c2 >= 'A') && (c2 <= 'Z')) c2 = c2+'a'-'A'; if ((c1 == 'x') && (c2 == 'x')) { printf("Legal options are:\n"); printf("al,bc,bt,cd,ce,cl,cm,dc,dl,dm,do,ed,ei,ho\n"); printf("ic,im,ip,ll,ma,nd,pc,se,sf,so,sr,ta,te,ti\n"); printf("uc,ue,ul,us,vb,ve,vs\n"); } else if ((c1 == 'a') && (c2 == 'l')) printf("%s",AL); else if ((c1 == 'b') && (c2 == 'c')) printf("%s",BC); else if ((c1 == 'b') && (c2 == 't')) printf("%s",BT); else if ((c1 == 'c') && (c2 == 'd')) printf("%s",CD); else if ((c1 == 'c') && (c2 == 'e')) printf("%s",CE); else if ((c1 == 'c') && (c2 == 'l')) printf("%s",CL); else if ((c1 == 'c') && (c2 == 'm')) { if ((argc -= 2) < 0) { fprintf(stderr,"Usage: curse -cm X Y\n"); exit(0); } x = (char)atoi(*++argv); y = (char)atoi(*++argv); move(x,y); } else if ((c1 == 'd') && (c2 == 'c')) printf("%s",DC); else if ((c1 == 'd') && (c2 == 'l')) printf("%s",DL); else if ((c1 == 'd') && (c2 == 'm')) printf("%s",DM); else if ((c1 == 'd') && (c2 == 'o')) printf("%s",DO); else if ((c1 == 'e') && (c2 == 'd')) printf("%s",ED); else if ((c1 == 'e') && (c2 == 'i')) printf("%s",EI); else if ((c1 == 'h') && (c2 == 'o')) { if (*HO != '\0') printf("%s",HO); else move(0,0); } else if ((c1 == 'i') && (c2 == 'c')) printf("%s",IC); else if ((c1 == 'i') && (c2 == 'm')) printf("%s",IM); else if ((c1 == 'i') && (c2 == 'p')) printf("%s",IP); else if ((c1 == 'l') && (c2 == 'l')) { if (*LL != '\0') printf("%s",LL); else move(0,23); } else if ((c1 == 'm') && (c2 == 'a')) printf("%s",MA); else if ((c1 == 'n') && (c2 == 'd')) printf("%s",ND); else if ((c1 == 'p') && (c2 == 'c')) printf("%s",PC); else if ((c1 == 's') && (c2 == 'e')) printf("%s",SE); else if ((c1 == 's') && (c2 == 'f')) printf("%s",SF); else if ((c1 == 's') && (c2 == 'o')) printf("%s",SO); else if ((c1 == 's') && (c2 == 'r')) printf("%s",SR); else if ((c1 == 't') && (c2 == 'a')) printf("%s",TA); else if ((c1 == 't') && (c2 == 'e')) printf("%s",TE); else if ((c1 == 't') && (c2 == 'i')) printf("%s",TI); else if ((c1 == 'u') && (c2 == 'c')) printf("%s",UC); else if ((c1 == 'u') && (c2 == 'e')) printf("%s",UE); else if ((c1 == 'u') && (c2 == 'l')) printf("%s",UL); else if ((c1 == 'u') && (c2 == 's')) printf("%s",US); else if ((c1 == 'v') && (c2 == 'b')) printf("%s",VB); else if ((c1 == 'v') && (c2 == 'e')) printf("%s",VE); else if ((c1 == 'v') && (c2 == 's')) printf("%s",VS); else fprintf(stderr,"curse: unknown option %s\n",*argv); } else for (s = argv[0]; *s != '\0'; s++) putchar(*s); } endwin(); } move(x,y) int x, y; { char n, *s; int i = 0, rev = 0; for (s = CM; *s != '\0'; s++) { if (*s != '%') putchar(*s); else { switch (i) { case 0: n = (rev?x:y); break; case 1: n = (rev?y:x); break; default: n = '\0'; } switch(*++s) { case 'd': printf("%d",n); i++; break; case '2': printf("%2d",n); i++; break; case '3': printf("%3d",n); i++; break; case '+': n += (int)*++s; case '.': printf("%c",(char)n); i++; break; case '>': if (n > (int)*++s) n+=(int)*++s; else *++s; break; case 'i': x++; y++; break; case 'n': x ^= 0140; y ^= 0140; break; case 'B': x = (16*(x/10))+(x%10); y = (16*(y/10))+(y%10); break; case 'D': x = (x-2*(x%16)); y = (y-2*(y%16)); case 'r': rev++; break; default: *--s; case '%': break; } } } } --EOF-- cc curse.c -o curse -lcurses -ltermlib --------------------- end of shell script -------------------- -- Jonathan Bowen Programming Research Group Oxford University Computing Laboratory 8-11 Keble Road Oxford OX1 3QD England Tel +44-865-54141 ext 299 Mail: bowen@xxvd or bowen@ox.prgv or bowen@50250300 (JANET) Arpa: bowen%ox.prgv@ucl-cs
silvert@dalcs.UUCP (Bill Silvert) (04/25/85)
This is a very useful program, but while it works fine on fairly dumb terminals, I have a problem with my 4-page Concept -- curse calls initscr, which redefines the window and sends the ti and vi strings. This is OK if I want to run cm, but if I only want to set so/se for a message or something like that the result appears on the wrong window. Does anyone know how to run curse without sending the ti and vi strings when they are not needed? (I am not an expert on curses, and the manual entry doesn't offer me much help!). -- Bill Silvert Marine Ecology Lab. Dartmouth, NS dalcs!biomel!bill