Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Tue 16 Oct 2018, 10:10
All times are UTC - 4
 Forum index » House Training » Users ( For the regulars )
How to write a script that uses GPM instead of xclip?
Moderators: Flash, Ian, JohnMurga
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [7 Posts]  
Author Message
compo

Joined: 28 Nov 2011
Posts: 4

PostPosted: Fri 10 Aug 2012, 06:12    Post subject:  How to write a script that uses GPM instead of xclip?
Subject description: GPM instead of xclip in a no X environment
 

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"?
Back to top
View user's profile Send private message Visit poster's website 
npierce

Joined: 28 Dec 2009
Posts: 858

PostPosted: Sat 11 Aug 2012, 10:14    Post subject:  

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

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. Smile

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.
Back to top
View user's profile Send private message 
compo

Joined: 28 Nov 2011
Posts: 4

PostPosted: Sat 11 Aug 2012, 12:24    Post subject:  

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.
Back to top
View user's profile Send private message Visit poster's website 
npierce

Joined: 28 Dec 2009
Posts: 858

PostPosted: Sat 11 Aug 2012, 21:29    Post subject:  

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:
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.
Back to top
View user's profile Send private message 
compo

Joined: 28 Nov 2011
Posts: 4

PostPosted: Tue 21 Aug 2012, 17:18    Post subject:  

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.
Back to top
View user's profile Send private message Visit poster's website 
npierce

Joined: 28 Dec 2009
Posts: 858

PostPosted: Wed 22 Aug 2012, 22:58    Post subject:  

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. Smile
Back to top
View user's profile Send private message 
npierce

Joined: 28 Dec 2009
Posts: 858

PostPosted: Fri 07 Sep 2012, 10:27    Post subject:  

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:
Quote:
Error opening /dev/vcs0: No such file or directory

If so, just run this command to create /dev/vcs0:
Code:
mknod -m 644 /dev/vcs0 c 7 0
lclip.gz
Description  Utility for setting the Linux console selection buffer
gz

 Download 
Filename  lclip.gz 
Filesize  4.44 KB 
Downloaded  207 Time(s) 
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [7 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » House Training » Users ( For the regulars )
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0594s ][ Queries: 13 (0.0181s) ][ GZIP on ]