Something similar to web's document.visibilityState to detect when the terminal pane/window comes or goes out of focus, this could be helpful to run some side effects for which we need to know if user is actively looking at the TUI or not, for example, to send OS native notifications if user is out of focus or refetch some data when user comes back to the TUI.
Potential solution: maybe it can be detected using the FocusIn/FocusOut events emitted by most modern terminals