; ANSI/VT100 allows regions to be partially typed-over (eg curses menus).
; So wait commands watching the raw stream see the edits, not the revised lines.
I like to do sanity checks before sending keystrokes, so this was irritating. It's why I gave up writing an automated client in C. I nearly rigged RealTerm with AutoHotKey.
Luckily TeraTerm provides terminal emulation and slightly-kludgy screencap on top of some other features that made my life easier.
; waitForScreen and strOnScreen
; Waits for a short string, pauses half a second, flushes the
; recv buffer, then scans the visible screen for a string in context.
With these subroutines, you can delay until a menu choice is available, stall a little to let painting settle down, and then confirm the choice is in a context you were expecting. For example, when I traverse menus on a ProCurve switch I've got, the names of choices in submenus are written over the earlier menu's names. But the numbers next to the choices are left on the screen from before. So I have to do a screen dump to check that the choice I want has the number I'm about to send.
This screen dump doesn't touch a file, and it handles a corner case when the string you're looking for is partly in one 255-char buffer and partly in another.
The switch normally starts out blank and unresponsive except for pressing enter twice. So I know to abort if I send an arrow key and the screen's no longer blank.
Example waitForScreen Usage:
Example isScreenBlank Usage: