home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / emx / bsd / curses / doc / intro.4 < prev    next >
Encoding:
Text File  |  1991-04-17  |  7.2 KB  |  250 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.4    6.3 (Berkeley) 4/17/91
  33. .\"
  34. .sh 1 "Cursor Motion Optimization: Standing Alone"
  35. .pp
  36. It is possible to use the cursor optimization functions of this screen package
  37. without the overhead and additional size of the screen updating functions.
  38. The screen updating functions are designed for uses
  39. where parts of the screen are changed,
  40. but the overall image remains the same.
  41. This includes such programs as
  42. .b rogue
  43. and
  44. .b vi \**.
  45. .(f
  46. \**
  47. .b rogue
  48. actually uses these functions,
  49. .b vi
  50. does not.
  51. .)f
  52. Certain other programs
  53. will find it difficult to use these functions in this manner
  54. without considerable unnecessary program overhead.
  55. For such applications,
  56. such as some
  57. .q "\fIcrt hacks\fR\|" \**
  58. .(f
  59. \**
  60. Graphics programs designed to run on character-oriented terminals.
  61. I could name many,
  62. but they come and go,
  63. so the list would be quickly out of date.
  64. Recently, there have been programs such as
  65. .b rain ,
  66. .b rocket ,
  67. and
  68. .b gun .
  69. .)f
  70. and optimizing
  71. .b more (1)-type
  72. programs,
  73. all that is needed is the motion optimizations.
  74. This, therefore, is a description
  75. of what some of what goes on at the lower levels of this screen package.
  76. The descriptions assume a certain amount of familiarity
  77. with programming problems and some finer points of C.
  78. None of it is terribly difficult,
  79. but you should be forewarned.
  80. .sh 2 "Terminal Information"
  81. .pp
  82. In order to use a terminal's
  83. features to the best of a program's abilities,
  84. it must first know what they are\**.
  85. .(f
  86. \**
  87. If this comes as any surprise to you,
  88. there's this tower in Paris they're thinking of junking
  89. that I can let you have for a song.
  90. .)f
  91. The \*(tc \*(db describes these,
  92. but a certain amount of decoding is necessary,
  93. and there are, of course,
  94. both efficient and inefficient ways of reading them in.
  95. The algorithm that the uses is taken from
  96. .b vi
  97. and is hideously efficient.
  98. It reads them
  99. in a tight loop
  100. into a set of variables
  101. whose names are two uppercase letters with some mnemonic value.
  102. For example,
  103. .Vn HO
  104. is a string which moves the cursor to the "home" position\**.
  105. .(f
  106. \**
  107. These names are identical to those variables
  108. used in the
  109. .b termcap (5)
  110. \*(db to describe each capability.
  111. See Appendix A for a complete list of those read,
  112. and the
  113. .b termcap (5)
  114. manual page
  115. for a full description.
  116. .)f
  117. As there are two types of variables involving ttys,
  118. there are two routines.
  119. The first,
  120. .Fn gettmode ,
  121. sets some variables based upon the tty modes accessed by
  122. .b gtty (2)
  123. and
  124. .b stty (2) .
  125. The second,
  126. .Fn setterm ,
  127. a larger task by reading in the descriptions from the \*(tc \*(db.
  128. This is the way these routines are used by
  129. .Fn initscr :
  130. .(b
  131. .(l I
  132. \*fif\fP (isatty(0)) {
  133.        gettmode();
  134.        \*fif\fP ((sp=getenv("TERM")) != NULL)
  135.                setterm(sp);
  136.     \*felse\fP
  137.            setterm(Def\*_term);
  138. }
  139. \*felse\fP
  140.        setterm(Def\*_term);
  141. \*_puts(TI);
  142. \*_puts(VS);
  143. .)l
  144. .)b
  145. .pp
  146. .Fn isatty
  147. checks to see if file descriptor 0 is a terminal\**.
  148. .(f
  149. \**
  150. .Fn isatty
  151. is defined in the default C library function routines.
  152. It does a
  153. .b gtty (2)
  154. on the descriptor and checks the return value.
  155. .)f
  156. If it is,
  157. .Fn gettmode
  158. sets the terminal description modes from a
  159. .b gtty (2) .
  160. .Fn getenv
  161. is then called to get the name of the terminal,
  162. and that value (if there is one) is passed to
  163. .Fn setterm ,
  164. which reads in the variables from \*(tc
  165. associated with that terminal.
  166. .Fn getenv "" (
  167. returns a pointer to a string containing the name of the terminal,
  168. which we save in the character pointer
  169. .Vn sp .)
  170. If
  171. .Fn isatty
  172. returns false,
  173. the default terminal
  174. .Vn Def\*_term
  175. is used.
  176. The
  177. .Vn TI
  178. and
  179. .Vn VS
  180. sequences initialize the terminal
  181. .Fn \*_puts "" (
  182. is a macro which uses
  183. .Fn tputs
  184. (see
  185. .b termcap (3))
  186. and
  187. .Fn \*_putchar ""
  188. to put out a string).
  189. .Fn endwin
  190. undoes these things.
  191. .sh 2 "Movement Optimizations, or, Getting Over Yonder"
  192. .pp
  193. Now that we have all this useful information,
  194. it would be nice to do something with it\**.
  195. .(f
  196. \**
  197. Actually,
  198. it
  199. .i can
  200. be emotionally fulfilling just to get the information.
  201. This is usually only true, however,
  202. if you have the social life of a kumquat.
  203. .)f
  204. The most difficult thing to do properly is motion optimization.
  205. When you consider how many different features various terminals have
  206. (tabs, backtabs, non-destructive space, home sequences, absolute tabs, .....)
  207. you can see that deciding how to get from here to there
  208. can be a decidedly non-trivial task.
  209. The editor
  210. .b vi
  211. uses many of these features,
  212. and the routines it uses to do this take up many pages of code.
  213. Fortunately, I was able to liberate them with the author's permission,
  214. and use them here.
  215. .pp
  216. After using
  217. .Fn gettmode
  218. and
  219. .Fn setterm
  220. to get the terminal descriptions,
  221. the function
  222. .Fn mvcur
  223. deals with this task.
  224. It usage is simple:
  225. you simply tell it where you are now and where you want to go.
  226. For example
  227. .(l
  228. mvcur(0\*,0\*,LINES/2\*,COLS/2)
  229. .)l
  230. .lp
  231. would move the cursor from the home position (0\*,0)
  232. to the middle of the screen.
  233. If you wish to force absolute addressing,
  234. you can use the function
  235. .Fn tgoto
  236. from the
  237. .b termlib (7)
  238. routines,
  239. or you can tell
  240. .Fn mvcur
  241. that you are impossibly far away,
  242. like Cleveland.
  243. For example,
  244. to absolutely address the lower left hand corner of the screen
  245. from anywhere
  246. just claim that you are in the upper right hand corner:
  247. .(l
  248. mvcur(0\*,COLS\-1\*,LINES\-1\*,0)
  249. .)l
  250.