aboutsummaryrefslogtreecommitdiff
path: root/sys/tty/ttygoto.x
diff options
context:
space:
mode:
authorJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
committerJoseph Hunkeler <jhunkeler@gmail.com>2015-07-08 20:46:52 -0400
commitfa080de7afc95aa1c19a6e6fc0e0708ced2eadc4 (patch)
treebdda434976bc09c864f2e4fa6f16ba1952b1e555 /sys/tty/ttygoto.x
downloadiraf-linux-fa080de7afc95aa1c19a6e6fc0e0708ced2eadc4.tar.gz
Initial commit
Diffstat (limited to 'sys/tty/ttygoto.x')
-rw-r--r--sys/tty/ttygoto.x78
1 files changed, 78 insertions, 0 deletions
diff --git a/sys/tty/ttygoto.x b/sys/tty/ttygoto.x
new file mode 100644
index 00000000..d8896125
--- /dev/null
+++ b/sys/tty/ttygoto.x
@@ -0,0 +1,78 @@
+# Copyright(c) 1986 Association of Universities for Research in Astronomy Inc.
+
+include <chars.h>
+include "tty.h"
+
+# TTYGOTO -- Position the cursor to the given absolute screen coordinates.
+# We do not require any knowledge of the current screen position; many programs
+# will wish to do cursor positioning at a lower level to take advantage of
+# knowledge of the current position.
+
+procedure ttygoto (fd, tty, col, line)
+
+int fd # output stream
+pointer tty # termcap descriptor
+int col # destination column
+int line # destination line
+
+pointer sp, cm_in, cm_out
+int coords[2], nchars, i
+int ttygets(), ttysubi()
+errchk salloc, ttygets, ttyputs, ttywrite
+
+begin
+ call smark (sp)
+ call salloc (cm_in, SZ_CTRLSTR, TY_CHAR)
+ call salloc (cm_out, SZ_LINE, TY_CHAR)
+
+ # Use the cursor motion control string to position cursor, if the
+ # terminal has such a capability. Otherwise try to use primitive
+ # motion commands.
+
+ if (ttygets (tty, "cm", Memc[cm_in], SZ_CTRLSTR) > 0) {
+ # Coordinates are ordered line,col in the termcap entry,
+ # whereas our args are ordered col,line (e.g., x,y). Store
+ # in "coords" in the termcap order.
+
+ coords[1] = line
+ coords[2] = col
+ nchars = ttysubi (Memc[cm_in], Memc[cm_out], SZ_LINE, coords, 2)
+
+ # Output cursor motion control string to file.
+ call ttywrite (fd, tty, Memc[cm_out], nchars, 1)
+
+ # If unable to position to the exact coordinates, use primitive
+ # motion commands to step the rest of the way in. Do not abort
+ # if unable to do so.
+
+ if (coords[2] > 0) {
+ # Presumably we do not have to step in very often, so we do
+ # nothing special to buffer the backspace control sequence.
+ # Most terminals recognize BS in any case.
+
+ if (T_BSOK(tty) == YES) {
+ Memc[cm_out] = BS
+ Memc[cm_out+1] = EOS
+ } else if (ttygets (tty, "bc", Memc[cm_out], SZ_CTRLSTR) == 0)
+ Memc[cm_out] = EOS
+
+ for (i=coords[2]; i > 0; i=i-1)
+ call ttyputs (fd, tty, Memc[cm_out], 1)
+ }
+
+ # Now adjust vertical position if necessary.
+ if (coords[1] > 0) {
+ if (ttygets (tty, "up", Memc[cm_out], SZ_CTRLSTR) > 0)
+ for (i=coords[1]; i > 0; i=i-1)
+ call ttyputs (fd, tty, Memc[cm_out], 1)
+ }
+
+ } else {
+ # Terminal has no nifty cursor addressing capability; add code here
+ # to position cursor by generating a sequence of more primitive
+ # codes. Not going to bother with this for now.
+ ;
+ }
+
+ call sfree (sp)
+end