linux clipboard read/write in C - linux

I done lots of googling but I am still unsure on how to proceed.
What's the most common way of reading/write to the clipboard under Linux? I want both support for Gnome & KDE desktops.
Updated: do I take there isn't an easy solution and one must "aggregate" together multiple sources (gnome, kde) in order to craft a solution?

Maybe you can look at xclip and see how they have done it.
It provides an interface to X
selections ("the clipboard") from the
command line. It can read data from
standard in or a file and place it in
an X selection for pasting into other
X applications. xclip can also print
an X selection to standard out, which
can then be redirected to a file or
another program.

I might be shooting myself in the foot, but this could give you a hint on how to do the clipboard for kde, not sure about Gnome myself but try it, the script is in python and demonstrates how to get/set stuff on the clipboard, via using dcop and klipper, it is on this site here.
Hope this helps,
Best regards,
Tom.

Related

How to read text from clipboard?

Is that possible to read text from clipboard on Linux udner X?
I select some text in a browser (Firefox for example) then click Edit->Copy.
Now I need this text in my application. I am using plain XLib. No GTK, no QT.
I do not want to use external apps like xsel. I studiet xsel source code, DAMN it is over 1000 lines. In Windows I am used to GetCLipboardTextW() one function call. That's all I need. Why is this so sophisticated? I have read this already:
http://www.sbin.org/doc/Xlib/chapt_12.html
And some more, I know there are many kinds of clipboards in X, selections, cut buffers etc. It does not help! Give me some code that compiles and works. No external libraries please no sudo apt-get install something, no "Are you using KDE(GNOME/whatever)?".
xclip is just 600 lines of code, but much of it seems to be due to processing command line options, reading input files, etc. Looking at main and doOut the core of what it does seems to be:
XOpenDisplay(...)
XCreateSimpleWindow(...)
XSelectInput(...)
XFetchBuffer(...) or xcout(...)
XCloseDisplay(...)

Ubuntu terminal in windows ? Can anyone explain the 'col' command in plain English for me?

Next week I am getting an exam on using basic commands and shell scripting using terminal in Ubuntu. Please help me out with two quick questions:
-Does a practice environment for the Ubuntu terminal exist? I don't want to dual boot with Linux, so I want to find somewhere I could practice using some basic terminal commands as Cygwin seems to be quite different from the ubuntu terminal.
-What does the col command in Linux do? The manual page is here: Link, but I find that hard to understand, and since it doesn't work in Cygwin, it's hard to interpret! Also, why would one use man piped to col -b -x?
Thank you very much and sorry for the probably silly questions!
You can use the Ubuntu LiveCD boot (boots up an Ubuntu system without actually installing it) and experiment with the Ubuntu terminal shell. Its actually the same CD as the standard Ubuntu installtion CD... you just chose "Try Ubuntu" instead of "Install Ubuntu" once it boots up:
https://help.ubuntu.com/community/LiveCD
col is program to filter out reverse-linefeeds (i.e. the backspace character) from text input. In the olden days of line printers, a common method to achieve boldface print was to print a character, then print a backspace character, then print the character again. This would make the printer strike the character twice in the same place. Some programs would emit text files formatted in this way (man is one such program)-- but if you then tried to display that text file to your terminal screen, you might end up seeing something like this: "here is b^Hbo^Hol^Hld^Hd text".
col -b simply filters text input to strip out those extra backspace and double-strike characters. The -x option converts tab characters to space characters, which might be useful if the output was formatted for a device with a particular tab width, but then displayed on a different device.
man pages often have the backspace/double-strike text embedded in them, so man piped into col was often useful.
Nowadays, most terminal emulators actually know how to handle the backspace/double-strike, so col doesn't get used as much.
Far better (easier to use, install, maintain, etc.) than Cygwin, and perhaps less resource-using than a virtual machine, is http://andlinux.org . That will give you a shell on your Windows desktop, and you can play with the col command to better understand it.
Win-bash is essentially the same shell as linux, but on windows. You can use this to experiment outside Linux but I'm not sure how effective it is.
Other options are virtual machines, and if you don't mind a reboot, you can install ubuntu with wubi which means it can be deleted from windows' add/remove programs when you are done with it. (Or just use the live disc)
Col has very limited use for most people, it only affects programs that write lines asynchronously as opposed to line by line...

Make a Linux "GUI" in the command line

How to make a Linux program in the Command Line Interface who display a nice user interface?
For example when I use "wget" to download a file from internet, I can see the download advancement in the Command Line Interface. How can I do that?
ncurses is a popular option, there are APIs for lots of programming languages.
Take a look at curses. It is a library for text based UI.
You can get a basic interface by using \r to go to the beginning of the current line.
Slightly more advanced is ncurses.
The next step up is Newt.
If you want to do a GUI for Bash scripts or to wrap around other command line utilities, you can use dialog (man page).
Here two great dialog tutorial to get you started :
Dialog: An Introductory Tutorial
Improve Bash Shell Scripts Using Dialog.
If you only need a progress bar, this can be done directly with a simple print (that prints the bar), followed by the carriage return character (ANSI character #13), which puts you back at the beginning of the line. The line can then be later updated by printing over it.
For more complicated needs, ncurses is indeed the standard way to go.
I wouldn't call wget's progress report as a 'nice gui', but anyway, the classic library for building graphical interfaces without X Windows is Linux and UNIX systems is ncurses.
Recently a C# version of ncurses has been started, check out details here
If you're using Mono, you could use MonoCurses
Try curses, it is a well documented API for text based UI.Also, there is so much open source projects that are using curses for you see and learn
wget does not really have a GUI, all I see is stuff that you can already achieve using stdout and echos (e.g. printf() or std::cout)
Anyways, for simple dialog boxes of the MessageBox kind, but not limited to that, also have a look at dialog
http://linux.die.net/man/1/dialog
http://hightek.org/dialog/
You can just use ANSI escape codes. A simple example in bash
echo -e "\033[H\033[2J \033[20;20H \033[4mThis is a underlined line.\033[0m"
One should mention FTXUI. Functional Terminal (X) User interface: A simple C++ library for terminal-based user interfaces!
Cross-Platform
Support for UTF8 and fullwidth chars (→ 测试)
No dependencies
etc

Tool to create UI for Linux (Gnome) shell scripts

I'm writing a bunch of Linux shell scripts with complex selections. For now I use zenity for prompts. I'd rather use something where I can show more than one UI element at a time and query it in a script (e.g. a list and some checkboxed and a file picker and an entry field.
What are my options?
I believe GTKDialog comes with extended gtk-ified versions of the popular curses based dialog utility for shell scripts.
I'm not sure if it will serve the complexity of your needs, however. In any event, its a place to start.
You're going to have to move up to something more capable. PyGTK with Glade is fairly powerful, and Python is easy enough to pick up.
autoglade could also be of help to give your scripts of commands a graphical user interface, in many cases with no additional programming.
Some docs and tutorials can be found here.
zenity 3 now has a option to create a form with multiple elements. See the following bug report
https://bugzilla.gnome.org/show_bug.cgi?id=412493
Yad is a fork of Zenity that adds almost as much functionality as Gtkdialog. Mostly backward compatible too.

Replace in multiple files - graphical tool for Linux

It needs to be graphical. No sed, awk, grep, perl, whatever. I know how to use those and I do use them now, but I need to cherry-pick each replace in 300+ files.
I want a tool where I can:
type a search string
type a replace string
select a directory and file extension
and it would recursively go into each file in that directory and its sub-directories, open it and scroll to the place where search string is and offer two options:
replace (and find next)
find next
Nothing more. Reg.exp. support is a plus, but not required.
SOLVED: Regexxer is exactly what I needed. In case someone needs it on Slackware, here's what you need to download and how to compile it (choosing correct version of each dependency can be a PITA)
I think regexxer is exactly what you're looking for:
Regexxer
regexxer is a nifty GUI search/replace tool featuring Perl-style regular
expressions. If you need project-wide substitution and you’re tired of
hacking sed command lines together, then you should definitely give it a try.
See also the screenshot, looks a lot like what you're describing:
Emacs + dired + query-replace-regexp
For complete recipe follow this link (it's rather long, covering all possible alternatives),
jEdit does exactly what you need. It is written in Java and works well in Linux, Windows and OS X (probably other operating systems also).
Lately Kate (if you use KDE) can do it, but in a very tricky way. Go to "Edit>Search in Files", and choose the folder within which your files exist.
The trick is that only after the search results appear, you will find a text box and a button called "Replace checked". This button will do what you want.
I use gVim for this task all the time. I open up all the files at once, then use the commands to perform a subsitution on each file, asking for confirmation. Generally I use < 20 files, so I open them as tabs and use this:
:tabdo %s/foo/bar/gc
gVim works fine on Windows :) My coworkers often use Textpad to do this same thing, but I'd say gVim is much more efficient at it.
If you are a KDE user there's also kfilereplace.

Resources