Mumpster
http://mumpster.org/

Determining terminal dimensions in GT.M
http://mumpster.org/viewtopic.php?f=13&t=8
Page 1 of 1

Author:  jollis [ Thu Nov 04, 2010 9:35 pm ]
Post subject:  Determining terminal dimensions in GT.M

Hello all,

I am wondering if anyone can point me in the right direction...
I'm looking to be able to determine the number of rows and
columns in the terminal connected to $PRINCIPAL in GT.M.
Specifically, I would like for my code to be able to respond to
an xterm/rxvt/etc. window being resized.

The approach I'm currently taking is below (the PDOC
stuff is for a texinfo documentation generator I've built):

Code:
;;PDOC
;;SUMMARY Get terminal height in lines
;;DEFFNC
TRMLINES()
;;PDOC/
 Q $ZTRNLNM("LINES")

;;PDOC
;;SUMMARY Get terminal width in columns
;;DEFFNC
TRMCOLS()
;;PDOC/
 Q $ZTRNLNM("COLUMNS")


However, the LINES and COLUMNS environment variables don't
seem to be updated when the terminal window resizes.

Any ideas?

Thanks much,

Author:  toad [ Fri Nov 05, 2010 10:01 am ]
Post subject:  Re: Determining terminal dimensions in GT.M

The MUMPS standard is silent on the issue of maximum screen height and width, which is the standard's terse way of saying it imposes no limits. By the same token, though, it doesn't help standardize how the current range is set or adjusted, which means that's vendor specific. This is a question we'll need to answer vendor by vendor. I don't know any of the answers off the top of my head, so let's explore the manuals and post what we find.

Author:  dlw [ Sat Nov 06, 2010 11:00 am ]
Post subject:  Re: Determining terminal dimensions in GT.M

John, LINES and COLUMNS are shell variables, not environment variables. They don't get exported to child processes. That's why your code won't work that way.

You can use tput and put the output into a temporary file, and then open it and read the answer into a variable for use in your code. The easiest thing to do is to leverage the kernel API for returning the output of shell commands in your mumps code. Here is your code reworked with my example:

Code:
;;PDOC
;;SUMMARY Get terminal height in lines
;;DEFFNC
TRMLINES()
;;PDOC/
Q $$RETURN^%ZOSV("tput lines")

;;PDOC
;;SUMMARY Get terminal width in columns
;;DEFFNC
TRMCOLS()
;;PDOC/
Q $$RETURN^%ZOSV("tput cols")


I hope this helps you John. :)

Author:  jollis [ Sat Nov 06, 2010 6:11 pm ]
Post subject:  Re: Determining terminal dimensions in GT.M

Works great! Thanks much!

Author:  ldl [ Mon Nov 08, 2010 5:13 pm ]
Post subject:  Re: Determining terminal dimensions in GT.M

Another option you can use in a newer (don't recall which) version of GT.M:

GTM>o "tput":(SHELL="/bin/sh":COMMAND="tput lines":READONLY)::"PIPE"

GTM>u "tput" r lines c "tput" u 0 w lines
24
GTM>

Confirmed to work on Linux and AIX.

BUT for VISTA systems, David's approach is far superior!

Author:  whitten [ Tue Nov 23, 2010 10:59 am ]
Post subject:  Re: Determining terminal dimensions in GT.M

It would probably be useful to at least mention the $KEY and $DEVICE special variables in this thread, since they are the "Standard" way of getting information about the current I/O device.

The 1995 standard mentions the X3.64 Controlmnemonics in Annex G (informative) on the web here:

http://71.174.62.16/Demo/AnnoStd?Frame= ... ition=1995

The note about the effect on $KEY and $DEVICE on that website might be useful, especially as it interacts with the /DSR controlmnemonic. (it basically gives you information about the current $X and $Y position, not the maximum values )

Best Regards,
David Whitten

Page 1 of 1 All times are UTC - 8 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/