old-www/HOWTO/NCURSES-Programming-HOWTO/misc.html

337 lines
7.4 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML
><HEAD
><TITLE
>Miscellaneous features</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.7"><LINK
REL="HOME"
TITLE=" NCURSES Programming HOWTO "
HREF="index.html"><LINK
REL="PREVIOUS"
TITLE="Screen Manipulation"
HREF="screen.html"><LINK
REL="NEXT"
TITLE=" Other libraries "
HREF="otherlib.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>NCURSES Programming HOWTO</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="screen.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
></TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="otherlib.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="MISC"
></A
>14. Miscellaneous features</H1
><P
>Now you know enough features to write a good curses program, with all bells and
whistles. There are some miscellaneous functions which are useful in various
cases. Let's go headlong into some of those.</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="CURSSET"
></A
>14.1. curs_set()</H2
><P
>This function can be used to make the cursor invisible. The parameter to this
function should be </P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
> 0 : invisible or
1 : normal or
2 : very visible.</PRE
></FONT
></TD
></TR
></TABLE
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="TEMPLEAVE"
></A
>14.2. Temporarily Leaving Curses mode</H2
><P
>Some times you may want to get back to cooked mode (normal line buffering mode)
temporarily. In such a case you will first need to save the tty modes with a
call to <TT
CLASS="LITERAL"
>def_prog_mode()</TT
> and then call
<TT
CLASS="LITERAL"
>endwin()</TT
> to end the curses mode. This will
leave you in the original tty mode. To get back to curses once you are done,
call <TT
CLASS="LITERAL"
>reset_prog_mode() </TT
>. This function returns
the tty to the state stored by <TT
CLASS="LITERAL"
>def_prog_mode()</TT
>. Then do refresh(), and you are back to the curses mode. Here
is an example showing the sequence of things to be done.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="BTELE"
></A
><P
><B
>Example 12. Temporarily Leaving Curses Mode </B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
><SPAN
CLASS="INLINEMEDIAOBJECT"
>#include &#60;ncurses.h&#62;
int main()
{
initscr(); /* Start curses mode */
printw("Hello World !!!\n"); /* Print Hello World */
refresh(); /* Print it on to the real screen */
def_prog_mode(); /* Save the tty modes */
endwin(); /* End curses mode temporarily */
system("/bin/sh"); /* Do whatever you like in cooked mode */
reset_prog_mode(); /* Return to the previous tty mode*/
/* stored by def_prog_mode() */
refresh(); /* Do refresh() to restore the */
/* Screen contents */
printw("Another String\n"); /* Back to curses use the full */
refresh(); /* capabilities of curses */
endwin(); /* End curses mode */
return 0;
}</SPAN
></PRE
></FONT
></TD
></TR
></TABLE
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="ACSVARS"
></A
>14.3. ACS_ variables</H2
><P
>If you have ever programmed in DOS, you know about those nifty characters in
extended character set. They are printable only on some terminals. NCURSES
functions like <TT
CLASS="LITERAL"
>box()</TT
> use these characters. All
these variables start with ACS meaning alternative character set. You might have
noticed me using these characters in some of the programs above. Here's an example
showing all the characters.</P
><DIV
CLASS="EXAMPLE"
><A
NAME="BACSVARS"
></A
><P
><B
>Example 13. ACS Variables Example </B
></P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><FONT
COLOR="#000000"
><PRE
CLASS="PROGRAMLISTING"
><SPAN
CLASS="INLINEMEDIAOBJECT"
>#include &#60;ncurses.h&#62;
int main()
{
initscr();
printw("Upper left corner "); addch(ACS_ULCORNER); printw("\n");
printw("Lower left corner "); addch(ACS_LLCORNER); printw("\n");
printw("Lower right corner "); addch(ACS_LRCORNER); printw("\n");
printw("Tee pointing right "); addch(ACS_LTEE); printw("\n");
printw("Tee pointing left "); addch(ACS_RTEE); printw("\n");
printw("Tee pointing up "); addch(ACS_BTEE); printw("\n");
printw("Tee pointing down "); addch(ACS_TTEE); printw("\n");
printw("Horizontal line "); addch(ACS_HLINE); printw("\n");
printw("Vertical line "); addch(ACS_VLINE); printw("\n");
printw("Large Plus or cross over "); addch(ACS_PLUS); printw("\n");
printw("Scan Line 1 "); addch(ACS_S1); printw("\n");
printw("Scan Line 3 "); addch(ACS_S3); printw("\n");
printw("Scan Line 7 "); addch(ACS_S7); printw("\n");
printw("Scan Line 9 "); addch(ACS_S9); printw("\n");
printw("Diamond "); addch(ACS_DIAMOND); printw("\n");
printw("Checker board (stipple) "); addch(ACS_CKBOARD); printw("\n");
printw("Degree Symbol "); addch(ACS_DEGREE); printw("\n");
printw("Plus/Minus Symbol "); addch(ACS_PLMINUS); printw("\n");
printw("Bullet "); addch(ACS_BULLET); printw("\n");
printw("Arrow Pointing Left "); addch(ACS_LARROW); printw("\n");
printw("Arrow Pointing Right "); addch(ACS_RARROW); printw("\n");
printw("Arrow Pointing Down "); addch(ACS_DARROW); printw("\n");
printw("Arrow Pointing Up "); addch(ACS_UARROW); printw("\n");
printw("Board of squares "); addch(ACS_BOARD); printw("\n");
printw("Lantern Symbol "); addch(ACS_LANTERN); printw("\n");
printw("Solid Square Block "); addch(ACS_BLOCK); printw("\n");
printw("Less/Equal sign "); addch(ACS_LEQUAL); printw("\n");
printw("Greater/Equal sign "); addch(ACS_GEQUAL); printw("\n");
printw("Pi "); addch(ACS_PI); printw("\n");
printw("Not equal "); addch(ACS_NEQUAL); printw("\n");
printw("UK pound sign "); addch(ACS_STERLING); printw("\n");
refresh();
getch();
endwin();
return 0;
}</SPAN
></PRE
></FONT
></TD
></TR
></TABLE
></DIV
></DIV
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
SUMMARY="Footer navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="screen.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
ACCESSKEY="H"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="otherlib.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Screen Manipulation</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
>&nbsp;</TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Other libraries</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>