Read screen character from terminal
Asked Answered
F

1

8

As far I researched, terminfo/termcap and ioctl don't allow to query character at (x,y) position on terminal's screen. This is rather unexpected, because:

  • one can read e.g. screen dimensions from terminal (e.g. tput co, tput li),
  • one can read input from terminal

– the two mean that communication with terminal is bidirectional. Is there really no way to query a character at given position, like with *inch*, *in_wch* curses functions (which work only for curses windows)?

Forge answered 29/8, 2016 at 12:23 Comment(0)
S
3

That's expected (not "unexpected"):

  • tput gives values from a combination of the terminal database (fixed) and the operating system (changeable), but does not ask the terminal.
  • reading from the terminal is by an input stream from the device (what terminals are designed to do).

Some (not all) terminals support an escape sequence which asks the terminal where the cursor is. The resize program uses that to obtain the screensize. But keep in mind that it is known to be terminal-dependent, as mentioned in the manual page:

-s [rows columns]
This option indicates that Sun console escape sequences will be used instead of the VT100-style xterm escape codes.

Very few terminals support an escape sequence which will simply read characters from the screen. Not everyone likes the notion of a program that can read their screen — perhaps without their knowledge.

Sweptwing answered 30/8, 2016 at 0:0 Comment(3)
I'm interested to know which terminal type(s) support reading characters from the screen buffer.Inherent
two cents: It makes determining the current state of the terminal impossible. This was a common function with stand-alone terminals, the uses were to readback fields entered by the user, and restoring the previous contents of the screen (like vi does). There is another function for the latter, but it does not work in the same way.Interlanguage
@Inherent any windows conhost supports reading output characters. it also supports getting character encoding.Hydrolyse

© 2022 - 2024 — McMap. All rights reserved.