How to write a script that uses GPM instead of xclip?

Using applications, configuring, problems
Post Reply
Message
Author
compo
Posts: 4
Joined: Mon 28 Nov 2011, 22:51
Contact:

How to write a script that uses GPM instead of xclip?

#1 Post by compo »

I need to write a script employing GPM for no X environment. What command / string should be put into this script to do by GPM the same as by "xclip -i"?

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#2 Post by npierce »

Although, in this world, anything is possible, some things are just not as possible as others. :)

One would think, in this open source world, where there are usually multiple utilities for doing just about anything, that finding an equivalent to xclip for use in the Linux text console would be a simple matter. But I know of no such animal.

Here is one possible reason for the lack of such a utility:

The selection buffer for the Linux text console is handled by the kernel. To access it, a program would talk to the kernel with the TIOCL_SETSEL type of the TIOCLINUX I/O request, which calls the set_selection() function within the kernel.

That's not hard to do, but the fly in the ointment is that it sets the buffer by grabbing text directly from the screen. There is no type of I/O request that says "here is a string; please stuff it into the selection buffer."

So, the kernel supports the needs of GPM just fine, but wasn't designed to support what you would like to do.

Of course, anything is possible.

You could patch your kernel. But then your program would not be portable to systems other than your own -- unless you provided patches for all of your users, or convinced Linus that the world needs your patch in the kernel. :)

You could temporarily borrow some screen real estate, echo your string to that area (using an ANSI escape sequence or an ncurses function), send a request to the kernel to put that part of the screen in the selection buffer, then erase your string from the screen. That could certainly work, but it is a bit of a crazy kludge.

Possibly the best thing to do would be to try to find some way, if possible, to reach your ultimate goal without the need of using the selection buffer.

Good luck.

compo
Posts: 4
Joined: Mon 28 Nov 2011, 22:51
Contact:

#3 Post by compo »

That is sad to hear. I am not that determined to go that deep. My intention was rather modest:

There is a text-based web browser, ELinks. It is possible there to pass a URI to an external application. When it is under X, you access a clipboard by, for example, xclip, but what about a no X environment? I thought if GPM can copy and paste text selections, then it has a clipboard or use a clipboard of others, then the content of this clipboard may be read and made available to the next command-line command to handle it.

If it comes to patching the kernel, then it is too much at the moment.

Thanks indeed for your explanation.

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#4 Post by npierce »

compo,

You may want to take a look at screen, a window manager for the text console that has its own clipboard for moving text between the programs running in its different windows. This might be just what you need.

In fact, it looks like elinks is designed to talk to screen's clipboard.

I've tried it out, and it worked for me after taking care of one problem. By default the Ctrl-Insert key is mapped to the "copy-clipboard" action. But on my PC, elinks could not distinguish between Insert and Ctrl-Insert. So I remapped the action to y by creating a /root/.elinks/elinks.conf file with one line:

Code: Select all

bind "main" "y" = "copy-clipboard"
After fixing that, copy and paste worked well using the following steps:

1. Run screen.
2. Dismiss the welcome message.
3. Run elinks.
4. Move to the link that you want.
5. Press the key that you have bound to "copy-clipboard" (in my case y).
6. Press Ctrl-a then c to create a new window.
7. Type the name of the program that you want to open the URI, followed by pressing Ctrl-a then ] to paste the URI on the command line.

You may move back and forth between windows with Ctrl-a then 0 or 1. Or you may simply use Ctrl-a Ctrl-a to toggle back and forth.

If you want to save the clipboard to a file, from either window you can press Ctrl-a then >. To load the clipboard from the file, press Ctrl-a then <. The default file name is /tmp/screen-exchange, but that can be changed at any time.

For more details see: http://www.gnu.org/software/screen/manual/screen.html

Screen can be downloaded from the wary5 repository: screen-4.0.3-w5c.pet (I know that .pet works on Racy 5.2.2, but don't know about other Puppies.)

Anyway, I hope there is something here that you can make use of when writing your script.

compo
Posts: 4
Joined: Mon 28 Nov 2011, 22:51
Contact:

#5 Post by compo »

I know about Screen. It is pretty interesting. But I was into a more pure case. Screen even if being a text mode thing is a window manager. And that is not a case hard enough.

Thanks anyway for your details on Screen. Text-mode "computeering" is an interesting experience, which may also be productive for some real work even today.

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#6 Post by npierce »

You're welcome.

Yes. As the years go by, I need to spend more and more time in X, but I still feel most at home working in a pure black screen with big white characters. :)

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#7 Post by npierce »

compo wrote:What command / string should be put into this script to do by GPM the same as by "xclip -i"?
You could try the attached utility and use "lclip -i".

In input mode (option -i) lclip works in the Linux text console similarly to xclip in X, except that it doesn't handle multiple files. (The other options of xclip aren't supported.)

Keep in mind that it has the same limitations as gpm, including the inability to include control codes other than newline, and a size limited by what can be displayed on one screen. Neither of those limitations should be a problem when doing things like grabbing URIs from elinks.

The lclip utility also requires write access to /dev/console and read & write access to /dev/vcs0 & /dev/vcsa0. That won't be a problem in Puppy, running as root.

Some Puppies don't have /dev/vcs0, so you may get this error when you first try it:
Error opening /dev/vcs0: No such file or directory
If so, just run this command to create /dev/vcs0:

Code: Select all

mknod -m 644 /dev/vcs0 c 7 0
Attachments
lclip.gz
Utility for setting the Linux console selection buffer
(4.44 KiB) Downloaded 268 times

Post Reply