In Glk, what happens to the cursor when text grid windows resize?

Section 3.5.4 of the Glk specification document describes “text grid windows”, which store an “output cursor position”. Consider the following 16x4 text grid window, where the cursor (represented by _) is at (13, 1):

+----------------+
|This is a text w|
|indow...     _  |
|                |
|                |
+----------------+

The window is resized to 8x4:

+--------+
|This is |
|indow...|    _  <- (13, 1) is now out of bounds!
|        |
|        |
+--------+

What happens to the cursor? The specification doesn’t seem to say, and I can come up with a few different plausible ideas:

  • It moves to (0, 2), the beginning of the next line
  • It moves to (5, 2), which is where it would be if it started at (0, 1) and 13 characters were printed
  • It moves to (5, 3), which is where it would be if it started at (0, 0) and 16+13=29 characters were printed
  • It is reset to (0, 0)
  • It goes “off the screen”, silencing all further output until it’s put back in bounds with a glk_window_move_cursor() or glk_window_clear() call
2 Likes

Good question. My guess is that the last option, that it goes off the screen, would be the most consistent, though it’s highly possible implementations do something else instead.

The official answer is “the spec doesn’t say, therefore don’t rely on the cursor position staying the same after a resize input event.” (Or, really, any input event.)

What I remember implementing (RemGlk, Quixe) is that it goes off-screen. But the interpreter checks it back on-screen the next time text is printed, using the “wrap to beginning of the next line” rule. If there aren’t enough lines, further output is silenced.

However, I may be remembering this wrong, and I haven’t looked at what other implementations do.

2 Likes