Forum

Can I create custom...
 
Notifications
Clear all

Can I create custom filters for copy-paste?

0 Posts
2 Users
0 Reactions
330 Views
(@stefgott)
New Member
Joined: 6 years ago
Posts: 1
Topic starter  

Greetings!

I've been using AbsoluteTelnet for just over a year now. I love it. Just absolutely love it. So much better than PuTTY. Worth every penny. Thank you, Mr Pence!

[u]Summary of Question (TLDR):[/u]

I'd love to be able to run whatever I've copied from the terminal screen through a text-manipulating program of my own before depositing it into the MS Windows system clipboard.

OR, equivalently

I'd love to configure AbsoluteTelnet to execute a program of my own immediately any and every copy operation it performs.

Is this possible?

[u]Details of Question:[/u]

I'm a programmer. Oh, don't roll your eyes -- I'm not trying to impress anyone, here: I assume that most users of AbsoluteTelnet are some flavor of programmer, right?

So, anyway, I'm a programmer - [u]like you (probably)[/u] - and as most of my time is spent working in a linux shell or in an editor (it is emacs, and yes that becomes relevant later), I find I prefer to ssh from my laptop to connect to my linux work hosts, whereupon I connect to persistent /usr/bin/screen sessions. The alternative (at my workplace) is to run VNC X servers on the linux work host and connect to it via a VNC viewer on my laptop - but I find that sometimes the network delays are so bad that I sit and impatiently watch update rectangles being drawn. I find that ssh connections require far less traffic, so congestion impacts me less. AbsoluteTelnet FTW!

I do internal tools support at my workplace. Other engineers and programmers are my internal "customers", and I often need to cut-and-paste multiple lines of text from a shell session or a file into an email (or other communication). When emacs is controlling the terminal, and I'm displaying text which is wider than the screen, I usually have emacs wrap (rather than truncate) the lines. When I use AbsTel's copy-paste to copy a paragraph of text, these line wraps appear as newline characters in the copied text. So then I have to go over my pasted text to delete the unwanted newlines and rejoin the lines to form my original text.

This behavior is not a bug, I know. I'm assuming that my editor (emacs) is drawing each line up to the right-hand margin, and then explicitly moving the cursor to the start of next line to draw the next one.
A full-screen editor wants to control where the cursor goes, right? Presumably it is using the codes specified in the termcap specs (which I've set to xterm-256color). So there is no way the terminal emulator (AbsoluteTelnet) could know that the next line is an unbroken continuation of the previous one. Note - when I used XVNC (instead of ssh and /usr/bin/screen), this wasn't an issue because, when copying from the emacs X-windows GUI, the editor placed the text into the X-server's cut buffer, which XVNC then transferred to the VNC viewer's clipboard on my laptop, and I could then paste directly into my MS Windows email without having to fixup any newlines).

Interestingly, I have discovered the following workaround when dealing with shell sessions with long lines: It turns out that /usr/bin/screen lets you scroll upward to view things that have been scrolled off the top. It is called "copy mode", because that mode also lets you navigate the cursor and mark two places in the text history, and copy all the text between the marks into the "screen-exchange" file. If I enter this mode, then scroll upward a couple pages, and then downward a few pages, I find that using AbsoluteTelnet's copy-paste on the freshly-revealed-by-scrolling-down text does not insert newlines at the line breaks. Why? Because (and I'm guessing here) when scrolling down, the /usr/bin/screen program simply sends the text to the terminal without tracking where the cursor is, relying on the terminal's built-in cursor movement. Hence, AbsoluteTelnet knows that such lines are simply continuations (because it knows it did not receive cursor movement codes within that text - which is not the case when I'm display text from my editor).

Okay, that works for shell sessions, but most of my copy-pasting is done from programs and log files (especially log files). If there is a file snippet (from a program or a log file, which I usually view in my editor) with long lines, I will copy that fragment to a new file, then /bin/cat the file to the screen from the shell and use the above workaround to capture it without the extra newlines -- rather than try to copy-paste it from my editor's display and rejoin the broken lines manually.

But that's annoying, and it interrupts my train of thought. So, here's an idea:

If AbsoluteTelnet could be configured to run a program of mine immediately after it deposits text into the system clipboard, I could write a program (python, perl, whatever) which reads the system clipboard, alters the text as desired, and then writes the alteration back to the clipboard.

In my case, my editor (when writing to a terminal) places a backslash (\) in the right hand margin of lines where they wrap to the next line. So, my text mutating program would read the system clipboard, delete any backslash-newline pairs in the text, and write it back to the clipboard.

With that customization in place, I could copy stuff from my editor display into emails without missing a beat. Just mark terminal region with mouse, Ctrl-C, click in email to place cursor, Ctrl-V. That would be amazing! (it's funny how excited we can get over tiny victories)

Now, while explaining all this in excruciating detail I realized that even without any sort of configurable AbsoluteTelnet hook, I could solve this by simply mapping a windows shortcut key (e.g. Ctrl-Alt-C) to my clipboard mutating program, and it is almost as good. Then the sequence becomes mark terminal region with mouse, Ctrl-C, Alt-Ctrl-C, click in email to place cursor, Ctrl-V.

Okay, that's not so bad. Maybe I don't need a custom filter for copy-paste after all.

But, wow, I spent all this time writing out the request, I hate to let it go to waste.

What to do, what to do...

Aw, why not, I'll just send it. 🙂

-stefan


   
ReplyQuote
(@bpence)
Member Admin
Joined: 1 year ago
Posts: 1375
 

Stefan, you definitely win the award for longest post ever to this form. SO, thanks for that.

There's always more than one way to skin a cat. I'm glad you found a solution.

Brian


   
ReplyQuote
Share: