zsh-users
 help / color / mirror / code / Atom feed
* Is there a way of getting current xterm buffer?
@ 2023-09-13  7:48 Sebastian Gniazdowski
  2023-09-13  9:16 ` Roman Perepelitsa
  2023-09-13 15:14 ` Grant Taylor
  0 siblings, 2 replies; 12+ messages in thread
From: Sebastian Gniazdowski @ 2023-09-13  7:48 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 469 bytes --]

Hi,
I would like to implement a from-screen-words completion. For this, I need
the current screen text. People have already used tmux for this, however I
don't use it. Is there a way to somehow read screen-text/ I've have had
hopes for it when reading xtermctl and promptnl (this function reads cursor
position, so I've thought that maybe it could read the character at given
position…), but no success at the end.

-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 829 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Is there a way of getting current xterm buffer?
  2023-09-13  7:48 Is there a way of getting current xterm buffer? Sebastian Gniazdowski
@ 2023-09-13  9:16 ` Roman Perepelitsa
  2023-09-13 14:35   ` A. Wik
  2023-09-13 15:14 ` Grant Taylor
  1 sibling, 1 reply; 12+ messages in thread
From: Roman Perepelitsa @ 2023-09-13  9:16 UTC (permalink / raw)
  To: Sebastian Gniazdowski; +Cc: Zsh Users

On Wed, Sep 13, 2023 at 9:48 AM Sebastian Gniazdowski
<sgniazdowski@gmail.com> wrote:
>
> Hi,
> I would like to implement a from-screen-words completion. For this,
> I need the current screen text. People have already used tmux for
> this, however I don't use it. Is there a way to somehow read
> screen-text/ I've have had hopes for it when reading xtermctl and
> promptnl (this function reads cursor position, so I've thought that
> maybe it could read the character at given position…), but no
> success at the end.

In general, terminals don't have this capability. The only terminal I
know that does is tmux. This isn't really a zsh question.

Roman.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Is there a way of getting current xterm buffer?
  2023-09-13  9:16 ` Roman Perepelitsa
@ 2023-09-13 14:35   ` A. Wik
  0 siblings, 0 replies; 12+ messages in thread
From: A. Wik @ 2023-09-13 14:35 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Sebastian Gniazdowski, Zsh Users

On Wed, 13 Sept 2023 at 09:16, Roman Perepelitsa
<roman.perepelitsa@gmail.com> wrote:
>
> On Wed, Sep 13, 2023 at 9:48 AM Sebastian Gniazdowski
> <sgniazdowski@gmail.com> wrote:
> >
> > Hi,
> > I would like to implement a from-screen-words completion. For this,
> > I need the current screen text. People have already used tmux for
> > this, however I don't use it. Is there a way to somehow read
> > screen-text/ I've have had hopes for it when reading xtermctl and
> > promptnl (this function reads cursor position, so I've thought that
> > maybe it could read the character at given position…), but no
> > success at the end.
>
> In general, terminals don't have this capability. The only terminal I
> know that does is tmux. This isn't really a zsh question.
>
> Roman.
>

I think by looking into the termcap, terminfo, curses, and/or ncurses
libraries, you could find out about the capabilities of different
terminal types.  Note that I'm no expert on this, I come from a DOS
background, where you'd typically read/write directly to the video
memory.

-Albert.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Is there a way of getting current xterm buffer?
  2023-09-13  7:48 Is there a way of getting current xterm buffer? Sebastian Gniazdowski
  2023-09-13  9:16 ` Roman Perepelitsa
@ 2023-09-13 15:14 ` Grant Taylor
  2023-09-13 15:18   ` Roman Perepelitsa
  1 sibling, 1 reply; 12+ messages in thread
From: Grant Taylor @ 2023-09-13 15:14 UTC (permalink / raw)
  To: zsh-users

Pre-Script:  As others have said, this probably isn't a Zsh question.

On 9/13/23 2:48 AM, Sebastian Gniazdowski wrote:
> Hi,

Hi,

> Is there a way to somehow read screen-text

I'm not aware of one.

But my ignorance doesn't preclude it from existing.

> I've have had hopes for it when reading xtermctl and promptnl (this 
> function reads cursor position, so I've thought that maybe it could 
> read the character at given position…), but no success at the end.

I'd suggest skimming / reading the XTerm Control Sequences page.

Link - ctlseqs(ms) - XTerm Control Sequences
  - https://www.invisible-island.net/xterm/ctlseqs/ctlseqs.html

N.B. the ctlseqs page is the most complete that I've found for XTerm -- 
which makes sense given the source.  The only other thing beyond that is 
to delve into the manuals for various other terminals.

XTerm should implement everything on it's ctlseqs page.

I've found that most of the control sequences that XTerm and fancier DEC 
terminals support aren't even a glimmer in the eye of most terminal 
emulator programmers.

Finally, I find the idea of allowing programs to read existing text on 
the screen to be a potential security violation.



-- 
Grant. . . .
unix || die



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Is there a way of getting current xterm buffer?
  2023-09-13 15:14 ` Grant Taylor
@ 2023-09-13 15:18   ` Roman Perepelitsa
  2023-09-13 16:01     ` Oliver Kiddle
  0 siblings, 1 reply; 12+ messages in thread
From: Roman Perepelitsa @ 2023-09-13 15:18 UTC (permalink / raw)
  To: Grant Taylor; +Cc: zsh-users

On Wed, Sep 13, 2023 at 5:16 PM Grant Taylor <gtaylor@tnetconsulting.net> wrote:
>
> I'd suggest skimming / reading the XTerm Control Sequences page.

xterm does not have this capability and neither do any of the most
popular 10 terminals. The only exception among popular terminals is
tmux. I don't know of any other terminal with this capability but if
it exists it's not a popular one.

Roman.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Is there a way of getting current xterm buffer?
  2023-09-13 15:18   ` Roman Perepelitsa
@ 2023-09-13 16:01     ` Oliver Kiddle
  2023-09-13 16:10       ` Roman Perepelitsa
  2023-09-13 18:59       ` Grant Taylor
  0 siblings, 2 replies; 12+ messages in thread
From: Oliver Kiddle @ 2023-09-13 16:01 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Grant Taylor, zsh-users

Roman Perepelitsa wrote:
> xterm does not have this capability and neither do any of the most
> popular 10 terminals. The only exception among popular terminals is
> tmux. I don't know of any other terminal with this capability but if
> it exists it's not a popular one.

Within limits, it's possible with rxvt-unicode. The escape sequence
\e[0i is equivalent to pressing Shift-Print_Screen which is for
sending the scrollback buffer to a printer. To actually capture the
output you need to send it to a file instead of a printer which is
configured from .Xresources, e.g. as
  Rxvt.print-pipe: umask 077;cat >/tmp/XXX
Same basic concept may work with other terminals but the data is
being dumped to a file rather than sent down the tty line. So given
ssh connections or permission changes the zsh completion widget at
the other end won't be able to read it.

And I'd agree with Grant that the entire concept is questionable
from a security perspective. Many terminals removed even the feature
for retrieving the title bar text.

Aside from tmux, screen also has the feature with screen -X hardcopy

Oliver


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Is there a way of getting current xterm buffer?
  2023-09-13 16:01     ` Oliver Kiddle
@ 2023-09-13 16:10       ` Roman Perepelitsa
  2023-09-13 18:59       ` Grant Taylor
  1 sibling, 0 replies; 12+ messages in thread
From: Roman Perepelitsa @ 2023-09-13 16:10 UTC (permalink / raw)
  To: Oliver Kiddle; +Cc: Grant Taylor, zsh-users

On Wed, Sep 13, 2023 at 6:01 PM Oliver Kiddle <opk@zsh.org> wrote:
>
> Roman Perepelitsa wrote:
> > xterm does not have this capability and neither do any of the most
> > popular 10 terminals. The only exception among popular terminals is
> > tmux. I don't know of any other terminal with this capability but if
> > it exists it's not a popular one.
>
> Within limits, it's possible with rxvt-unicode. The escape sequence
> \e[0i is equivalent to pressing Shift-Print_Screen which is for
> sending the scrollback buffer to a printer. To actually capture the
> output you need to send it to a file instead of a printer which is
> configured from .Xresources, e.g. as
>   Rxvt.print-pipe: umask 077;cat >/tmp/XXX
> Same basic concept may work with other terminals but the data is
> being dumped to a file rather than sent down the tty line. So given
> ssh connections or permission changes the zsh completion widget at
> the other end won't be able to read it.
>
> And I'd agree with Grant that the entire concept is questionable
> from a security perspective. Many terminals removed even the feature
> for retrieving the title bar text.
>
> Aside from tmux, screen also has the feature with screen -X hardcopy

I stand corrected. Thanks, Oliver.

Now that you mentioned it, I remember `screen hardcopy` but it's news
to me that rxvt-unicode also has something of this sort.

Roman.

P.S.

zsh4humans has an option to wrap the TTY in order to implement two
capabilities: save screen and restore screen. The TTY wrapping is
supposed to be transparent but the abstraction is a bit leaky. The
capability to save and restore screen allows one to implement a pop up
window. zsh4humans uses it to display the completion menu above the
prompt line. This in turn allows it to keep prompt at the bottom at
all times without it jumping around. For the sake of consistency,
there is also an option to put prompt at the bottom when zsh is
starting so that it's always in the same location.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Is there a way of getting current xterm buffer?
  2023-09-13 16:01     ` Oliver Kiddle
  2023-09-13 16:10       ` Roman Perepelitsa
@ 2023-09-13 18:59       ` Grant Taylor
  2023-09-19 22:21         ` Sebastian Gniazdowski
  1 sibling, 1 reply; 12+ messages in thread
From: Grant Taylor @ 2023-09-13 18:59 UTC (permalink / raw)
  To: zsh-users

On 9/13/23 11:01 AM, Oliver Kiddle wrote:
> Within limits, it's possible with rxvt-unicode.

I may be wrong, or have misunderstood what the OP is wanting to do.  But 
I disagree.

> The escape sequence \e[0i is equivalent to pressing Shift-Print_Screen 
> which is for sending the scrollback buffer to a printer. To actually 
> capture the output you need to send it to a file instead of a printer 
> which is configured from .Xresources, e.g. as
> 
>    Rxvt.print-pipe: umask 077;cat >/tmp/XXX

XTerm supports DEC's "Media Copy" feature.

> Same basic concept may work with other terminals but the data is 
> being dumped to a file rather than sent down the tty line. So given 
> ssh connections or permission changes the zsh completion widget at 
> the other end won't be able to read it.

My understanding is that the OP wanted the data to go back to the host 
sending the control sequences, not a local file / printer.  Ergo why I 
say that rxvt's feature you're talking about and XTerm's Media Copy 
feature won't do what I understand the OP to want to do.

My understanding is that the OP wanted the host to be able to scrape the 
screen so that it could intelligently modify something on the screen, 
ostensibly something like command completion or such such handy behavior.

> And I'd agree with Grant that the entire concept is questionable from 
> a security perspective. Many terminals removed even the feature for 
> retrieving the title bar text.

I'm okay with the idea of having the terminal switch it's output to a 
local AUXiliary port -- ostensibly connected to a printer -- redirect 
/future/ output to said AUX port & printer.  At least until the terminal 
is directed to start sending things to the screen again.

> Aside from tmux, screen also has the feature with screen -X hardcopy

Sending existing screen contents back to the host is considerably 
different than sending new content to an alternate location.



-- 
Grant. . . .
unix || die


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Is there a way of getting current xterm buffer?
  2023-09-13 18:59       ` Grant Taylor
@ 2023-09-19 22:21         ` Sebastian Gniazdowski
  2023-09-20  3:05           ` Grant Taylor
  0 siblings, 1 reply; 12+ messages in thread
From: Sebastian Gniazdowski @ 2023-09-19 22:21 UTC (permalink / raw)
  To: Grant Taylor; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 2440 bytes --]

It fine to save the screen copy to a file, I can read it via $(<file). Does
xterm can save the screen to a file, via the "media-copy" control seq that
you've mentioned? Is there some example available of how to use it?

On Wed, 13 Sept 2023 at 14:01, Grant Taylor <gtaylor@tnetconsulting.net>
wrote:

> On 9/13/23 11:01 AM, Oliver Kiddle wrote:
> > Within limits, it's possible with rxvt-unicode.
>
> I may be wrong, or have misunderstood what the OP is wanting to do.  But
> I disagree.
>
> > The escape sequence \e[0i is equivalent to pressing Shift-Print_Screen
> > which is for sending the scrollback buffer to a printer. To actually
> > capture the output you need to send it to a file instead of a printer
> > which is configured from .Xresources, e.g. as
> >
> >    Rxvt.print-pipe: umask 077;cat >/tmp/XXX
>
> XTerm supports DEC's "Media Copy" feature.
>
> > Same basic concept may work with other terminals but the data is
> > being dumped to a file rather than sent down the tty line. So given
> > ssh connections or permission changes the zsh completion widget at
> > the other end won't be able to read it.
>
> My understanding is that the OP wanted the data to go back to the host
> sending the control sequences, not a local file / printer.  Ergo why I
> say that rxvt's feature you're talking about and XTerm's Media Copy
> feature won't do what I understand the OP to want to do.
>
> My understanding is that the OP wanted the host to be able to scrape the
> screen so that it could intelligently modify something on the screen,
> ostensibly something like command completion or such such handy behavior.
>
> > And I'd agree with Grant that the entire concept is questionable from
> > a security perspective. Many terminals removed even the feature for
> > retrieving the title bar text.
>
> I'm okay with the idea of having the terminal switch it's output to a
> local AUXiliary port -- ostensibly connected to a printer -- redirect
> /future/ output to said AUX port & printer.  At least until the terminal
> is directed to start sending things to the screen again.
>
> > Aside from tmux, screen also has the feature with screen -X hardcopy
>
> Sending existing screen contents back to the host is considerably
> different than sending new content to an alternate location.
>
>
>
> --
> Grant. . . .
> unix || die
>
>

-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 3214 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Is there a way of getting current xterm buffer?
  2023-09-19 22:21         ` Sebastian Gniazdowski
@ 2023-09-20  3:05           ` Grant Taylor
  2023-09-20 12:28             ` Sebastian Gniazdowski
  0 siblings, 1 reply; 12+ messages in thread
From: Grant Taylor @ 2023-09-20  3:05 UTC (permalink / raw)
  To: zsh-users

On 9/19/23 5:21 PM, Sebastian Gniazdowski wrote:
> It fine to save the screen copy to a file, I can read it via $(<file).

Fair enough.

> Does xterm can save the screen to a file, via the "media-copy" control 
> seq that you've mentioned?

XTerm can be configured to save content sent via media copy to a file.

N.B. media copy doesn't capture the screen to a file.  Rather media copy 
causes XTerm to take subsequent data and send it to the file.

You set media copy on, send data to -- ostensibly -- print to media, and 
then set media copy off to return the terminal to normal operations.

> Is there some example available of how to use it?

I've got things somewhere.

Hand typing this between terminals for $REASONS.

--8<--
#!/bin/bash
# Media Copy On
echo -n "^[[5i"
cat -
# Media Copy Off
echo -n "^[[4i"
-->8--

^[ is a stand in for the escape character.

This is the standard Control Sequence Introducer (CSI). Escape followed 
by an open square bracket.

I use this with something like the following:

    % uname -a | mediacopy

That causes uname's STDOUT to go into the mediacopy script's STDIN which 
gets wrapped with the CSI 5 i or CSI 4 i.

I have the following configured in my ~/.Xdefaults:

--8<--
XTerm.vt100.printerCommand: /path/to/XTerm.vt100.printerCommand.sh
-->8--

My XTerm.vt100.printerCommand.sh is fairly simple.

--8<--
#!/bin/bash
cat - > `date +/path/to/destination.d/XTerm-printout-%Y%m%d-%H%M%S.txt`
-->8--

Remember to use xrdb et al. to load the updated ~/.Xdefaults file.  Or 
otherwise get the XTerm.vt100.printerCommand setting into X11.



-- 
Grant. . . .
unix || die



^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Is there a way of getting current xterm buffer?
  2023-09-20  3:05           ` Grant Taylor
@ 2023-09-20 12:28             ` Sebastian Gniazdowski
  2023-09-21 18:05               ` Grant Taylor
  0 siblings, 1 reply; 12+ messages in thread
From: Sebastian Gniazdowski @ 2023-09-20 12:28 UTC (permalink / raw)
  To: Grant Taylor; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 2138 bytes --]

Thanks. For completing screen-words, I would it seems need something
different – so that the screen contents gets saved to the file in
background, causing no visual or other effects for the user. Is this
possible?

On Tue, 19 Sept 2023 at 22:06, Grant Taylor <gtaylor@tnetconsulting.net>
wrote:

> On 9/19/23 5:21 PM, Sebastian Gniazdowski wrote:
> > It fine to save the screen copy to a file, I can read it via $(<file).
>
> Fair enough.
>
> > Does xterm can save the screen to a file, via the "media-copy" control
> > seq that you've mentioned?
>
> XTerm can be configured to save content sent via media copy to a file.
>
> N.B. media copy doesn't capture the screen to a file.  Rather media copy
> causes XTerm to take subsequent data and send it to the file.
>
> You set media copy on, send data to -- ostensibly -- print to media, and
> then set media copy off to return the terminal to normal operations.
>
> > Is there some example available of how to use it?
>
> I've got things somewhere.
>
> Hand typing this between terminals for $REASONS.
>
> --8<--
> #!/bin/bash
> # Media Copy On
> echo -n "^[[5i"
> cat -
> # Media Copy Off
> echo -n "^[[4i"
> -->8--
>
> ^[ is a stand in for the escape character.
>
> This is the standard Control Sequence Introducer (CSI). Escape followed
> by an open square bracket.
>
> I use this with something like the following:
>
>     % uname -a | mediacopy
>
> That causes uname's STDOUT to go into the mediacopy script's STDIN which
> gets wrapped with the CSI 5 i or CSI 4 i.
>
> I have the following configured in my ~/.Xdefaults:
>
> --8<--
> XTerm.vt100.printerCommand: /path/to/XTerm.vt100.printerCommand.sh
> -->8--
>
> My XTerm.vt100.printerCommand.sh is fairly simple.
>
> --8<--
> #!/bin/bash
> cat - > `date +/path/to/destination.d/XTerm-printout-%Y%m%d-%H%M%S.txt`
> -->8--
>
> Remember to use xrdb et al. to load the updated ~/.Xdefaults file.  Or
> otherwise get the XTerm.vt100.printerCommand setting into X11.
>
>
>
> --
> Grant. . . .
> unix || die
>
>
>

-- 
Best regards,
Sebastian Gniazdowski

[-- Attachment #2: Type: text/html, Size: 3088 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: Is there a way of getting current xterm buffer?
  2023-09-20 12:28             ` Sebastian Gniazdowski
@ 2023-09-21 18:05               ` Grant Taylor
  0 siblings, 0 replies; 12+ messages in thread
From: Grant Taylor @ 2023-09-21 18:05 UTC (permalink / raw)
  To: zsh-users

On 9/20/23 7:28 AM, Sebastian Gniazdowski wrote:
> Thanks. For completing screen-words, I would it seems need something 
> different – so that the screen contents gets saved to the file in 
> background, causing no visual or other effects for the user. Is this 
> possible?

XTerm does have the ability to capture / print the screen to a file in 
HTML or SVG (?) formats.  However I'm not aware of a way to have the 
data stream initiate this.  As far as I know it's purely client side 
initiated and manual.



-- 
Grant. . . .
unix || die



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-09-21 18:07 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-13  7:48 Is there a way of getting current xterm buffer? Sebastian Gniazdowski
2023-09-13  9:16 ` Roman Perepelitsa
2023-09-13 14:35   ` A. Wik
2023-09-13 15:14 ` Grant Taylor
2023-09-13 15:18   ` Roman Perepelitsa
2023-09-13 16:01     ` Oliver Kiddle
2023-09-13 16:10       ` Roman Perepelitsa
2023-09-13 18:59       ` Grant Taylor
2023-09-19 22:21         ` Sebastian Gniazdowski
2023-09-20  3:05           ` Grant Taylor
2023-09-20 12:28             ` Sebastian Gniazdowski
2023-09-21 18:05               ` Grant Taylor

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).