home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / bsd / curses / doc / intro.3 < prev    next >
Encoding:
Text File  |  1991-04-17  |  6.7 KB  |  231 lines

  1. .\" Copyright (c) 1980 The Regents of the University of California.
  2. .\" All rights reserved.
  3. .\"
  4. .\" Redistribution and use in source and binary forms, with or without
  5. .\" modification, are permitted provided that the following conditions
  6. .\" are met:
  7. .\" 1. Redistributions of source code must retain the above copyright
  8. .\"    notice, this list of conditions and the following disclaimer.
  9. .\" 2. Redistributions in binary form must reproduce the above copyright
  10. .\"    notice, this list of conditions and the following disclaimer in the
  11. .\"    documentation and/or other materials provided with the distribution.
  12. .\" 3. All advertising materials mentioning features or use of this software
  13. .\"    must display the following acknowledgement:
  14. .\"    This product includes software developed by the University of
  15. .\"    California, Berkeley and its contributors.
  16. .\" 4. Neither the name of the University nor the names of its contributors
  17. .\"    may be used to endorse or promote products derived from this software
  18. .\"    without specific prior written permission.
  19. .\"
  20. .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  21. .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  24. .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. .\" SUCH DAMAGE.
  31. .\"
  32. .\"    @(#)intro.3    6.3 (Berkeley) 4/17/91
  33. .\"
  34. .sh 1 Usage
  35. .pp
  36. This is a description of how to actually use the screen package.
  37. In it, we assume all updating, reading, etc.
  38. is applied to
  39. .Vn stdscr .
  40. All instructions will work on any window,
  41. with changing the function name and parameters as mentioned above.
  42. .sh 2 "Starting up"
  43. .pp
  44. In order to use the screen package,
  45. the routines must know about terminal characteristics,
  46. and the space for
  47. .Vn curscr
  48. and
  49. .Vn stdscr
  50. must be allocated.
  51. These functions are performed by
  52. .Fn initscr .
  53. Since it must allocate space for the windows,
  54. it can overflow core when attempting to do so.
  55. On this rather rare occasion,
  56. .Fn initscr
  57. returns ERR.
  58. .Fn initscr
  59. must
  60. .bi always
  61. be called before any of the routines which affect windows are used.
  62. If it is not,
  63. the program will core dump as soon as either
  64. .Vn curscr
  65. or
  66. .Vn stdscr
  67. are referenced.
  68. However, it is usually best to wait to call it
  69. until after you are sure you will need it,
  70. like after checking for startup errors.
  71. Terminal status changing routines
  72. like
  73. .Fn nl
  74. and
  75. .Fn cbreak
  76. should be called after
  77. .Fn initscr .
  78. .pp
  79. Now that the screen windows have been allocated,
  80. you can set them up for the run.
  81. If you want to, say, allow the window to scroll,
  82. use
  83. .Fn scrollok .
  84. If you want the cursor to be left after the last change, use
  85. .Fn leaveok .
  86. If this isn't done,
  87. .Fn refresh
  88. will move the cursor to the window's current \*y after updating it.
  89. New windows of your own can be created, too, by using the functions
  90. .Fn newwin
  91. and
  92. .Fn subwin .
  93. .Fn delwin
  94. will allow you to get rid of old windows.
  95. If you wish to change the official size of the terminal by hand,
  96. just set the variables
  97. .Vn LINES
  98. and
  99. .Vn COLS
  100. to be what you want,
  101. and then call
  102. .Fn initscr .
  103. This is best done before,
  104. but can be done either before or after,
  105. the first call to
  106. .Fn initscr ,
  107. as it will always delete any existing
  108. .Vn stdscr
  109. and/or
  110. .Vn curscr
  111. before creating new ones.
  112. .pp
  113. .sh 2 "The Nitty-Gritty"
  114. .sh 3 Output
  115. .pp
  116. Now that we have set things up,
  117. we will want to actually update the terminal.
  118. The basic functions
  119. used to change what will go on a window are
  120. .Fn addch
  121. and
  122. .Fn move .
  123. .Fn addch
  124. adds a character at the current \*y,
  125. returning ERR if it would cause the window to illegally scroll,
  126. .i i.e. ,
  127. printing a character in the lower right-hand corner
  128. of a terminal which automatically scrolls
  129. if scrolling is not allowed.
  130. .Fn move
  131. changes the current \*y to whatever you want them to be.
  132. It returns ERR if you try to move off the window when scrolling is not allowed.
  133. As mentioned above, you can combine the two into
  134. .Fn mvaddch
  135. to do both things in one fell swoop.
  136. .pp
  137. The other output functions,
  138. such as
  139. .Fn addstr
  140. and
  141. .Fn printw ,
  142. all call
  143. .Fn addch
  144. to add characters to the window.
  145. .pp
  146. After you have put on the window what you want there,
  147. when you want the portion of the terminal covered by the window
  148. to be made to look like it,
  149. you must call
  150. .Fn refresh .
  151. In order to optimize finding changes,
  152. .Fn refresh
  153. assumes that any part of the window not changed
  154. since the last
  155. .Fn refresh
  156. of that window has not been changed on the terminal,
  157. .i i.e. ,
  158. that you have not refreshed a portion of the terminal
  159. with an overlapping window.
  160. If this is not the case,
  161. the routines
  162. .Fn touchwin ,
  163. .Fn touchline ,
  164. and
  165. .Fn touchoverlap
  166. are provided to make it look like a desired part of window has been changed,
  167. thus forcing
  168. .Fn refresh
  169. check that whole subsection of the terminal for changes.
  170. .pp
  171. If you call
  172. .Fn wrefresh
  173. with
  174. .Vn curscr ,
  175. it will make the screen look like
  176. .Vn curscr
  177. thinks it looks like.
  178. This is useful for implementing a command
  179. which would redraw the screen in case it get messed up.
  180. .sh 3 Input
  181. .pp
  182. Input is essentially a mirror image of output.
  183. The complementary function to
  184. .Fn addch
  185. is
  186. .Fn getch
  187. which,
  188. if echo is set,
  189. will call
  190. .Fn addch
  191. to echo the character.
  192. Since the screen package needs to know what is on the terminal at all times,
  193. if characters are to be echoed,
  194. the tty must be in raw or cbreak mode.
  195. If it is not,
  196. .Fn getch
  197. sets it to be cbreak,
  198. and then reads in the character.
  199. .sh 3 Miscellaneous
  200. .pp
  201. All sorts of fun functions exists for maintaining and changing information
  202. about the windows.
  203. For the most part,
  204. the descriptions in section 5.4. should suffice.
  205. .sh 2 "Finishing up"
  206. .pp
  207. In order to do certain optimizations,
  208. and,
  209. on some terminals,
  210. to work at all,
  211. some things must be done
  212. before the screen routines start up.
  213. These functions are performed in
  214. .Fn getttmode
  215. and
  216. .Fn setterm ,
  217. which are called by
  218. .Fn initscr .
  219. In order to clean up after the routines,
  220. the routine
  221. .Fn endwin
  222. is provided.
  223. It restores tty modes to what they were
  224. when
  225. .Fn initscr
  226. was first called.
  227. Thus,
  228. anytime after the call to initscr,
  229. .Fn endwin
  230. should be called before exiting.
  231.