How to create linux tui like this one on the picture - linux

Could someone share how can i create tui like this one with input boxex and search ?
What do i need?

Normally programmers use a ready to use library like ncurses.
You can also do it by hand if you really have to much time. To get for example the border lines of a dialog window you have to take a look at the current code page your terminal is emulating, for example: Code Page 850. As you can see, you will find single and double line boarders and also crossings and so on. Now you have to move your cursor to a given position, print that char from the code page and ... lots of work. Moving cursors itself can also be done by simple chars from your emulated terminal by using escape codes.
As said: Instead of doing it all by hand, simply use a lib like ncurses.

You can use some python libraries like pyTermTk or textual, there is wide selection of
libraries to choose from.

Related

Python Inquirer Module: Remove Choices When Done (Using Curses)

NOTE: Although I give a lot of info on Inquirer, I'm pretty sure that most of it won't apply (just being safe). For my actual question about curses, its at the bottom.
I'm using the Inquirer module in Python 3 to allow the user to select a value from a list. I run this:
import inquirer
choice = inquirer.prompt([inquirer.List("size",message="Which size do you need?",choices=["Large", "Medium", "Small"])
And I'm given this:
[?] What size do you need?: Medium
Large
> Medium
Small
And using the up and down keys, I can change my selection, and hit enter to choose, after which the "choice" variable contains the value I selected. The issue is: Once the selection is done, the choices still show. I want to delete them when done. I'm currently using ANSI Escape Codes to delete the choices from onscreen when done, where x is the number of choices:
import sys
for i in range (x+1):
sys.stdout.write('\x1b[1A')
sys.stdout.write('\x1b[2K')
Which leaves the printed text as:
[?] What size do you need?: Medium
The issue is, ANSI escape codes aren't universal. I want to use a solution that works on all terminals, preferably curses, but curses isn't very friendly to new users, so I was wondering if anyone knew how to use curses to "delete x lines above current position". Thanks!
curses, as such, would erase the whole display (which is probably not what you want). A low-level terminfo/termcap approach might seem promising, but while ECMA-48 does define a sequence (ED, with parameter 1) which erases above the current position, there is no predefined terminfo/termcap capability which corresponds to this. All that you will find there is the capability for erasing to the end of the screen, or erasing the whole screen.
"ANSI sequences" is an obsolete term. Referring to ECMA-48, you could do
sys.stdout.write('\x1b[1J')
after moving the cursor to the last location you would like to erase.

What exactly does "printw" do? (Ncurses)

Could someone please tell me what exactly does printw do? I tried looking for information but just could not find anything.
5 seconds on Google revealed some nice documentation.
printw() class: Print formatted output similar to printf()
and
6.3.1. printw() and mvprintw
These two functions work much like printf(). mvprintw() can be used to move
the cursor to a position and then print. If you want to move the cursor first
and then print using printw() function, use move() first and then use printw()
though I see no point why one should avoid using mvprintw(), you have the
flexibility to manipulate.
Source - NCURSES-Programming-HOWTO
Type man printw (I suppose you are not programming with Windows).

Go to beginning of output command created - shortcut

I can scroll trough bash output using shift+pgup/pgdown.
But lets say, some command outputted lot of text, I have to pageup few times to go to beginning of output of this command.
Can I just simply do this by some shortcut? Something that simply allows me to scroll between previous commands (not history!), seeing their output.
You could try piping the output into less:
someCommand | less
less will allow you to search and scroll through the output text pretty easily.
once in less you can just type % to jump back to the top of the page. Essentially that means jump to 0% of the page. There are also a bunch of extra commands on the page I linked to above.
Another option is to use screen and use backward search (beware: read the Overview first, especially the part about the C-a prefix) to e.g. search for some specific characters in your prompt (like your username).
The scroll back history in Unix shells is a shell specific functionality, meaning that it is up to the specific shell (xterm, rxvt, text console, etc) to handle it. The functionality you request would require the shell to identify the individual program runs, to know where to scroll to. Scanning text is not technically hard per se, but as prompts and command display can differ due to user settings it can be hard to make it work generally good. Some communication between the shell and the terminal could make it better.
There sure are some nice fancy terminal programs doing things like this, to for example show syntax help when writing commands, but for your case I agree with previous answer, that piping commands to less is a good way to isolate the output. It might be a bit cumbersome first, as it requires you to think about it first, and not just go back in history, but if you learn the shell better and learn to use the command history it will probably work fine. I recommend you to, if you haven't already. What I mean is ctrl-r etc. More described for example here:
http://www.catonmat.net/blog/the-definitive-guide-to-bash-command-line-history/

how can I extract text contents from GUI apps in linux?

I want to extract text contents from GUI apps,here are 2 examples::
example 1:
Suppose I opened firefox, and input url : www.google.com
how can I extract the string "www.google.com" from firefox using my own app ?
example 2:
open calculator(using gcalctool),then input 1+1
How can I extract the string "1+1" of calculator from my own program?
in brief ,what I want is to find out whether there is a way to extract the text contents from any widget of an GUI application
Thanks
I don't think there's a generic way to do this, at least not a very elegant one.
Some inelegant ideas:
You might be able to modify the X window system or even some toolkit framework to extract what is being displayed in specific window elements as text.
You could take a screenshot and use an OCR library to convert the pixels back into text for the interesting areas.
You could recompile the apps of interest to add some kind of mechanism for asking them questions.
You could use something like xtest to inject events highlighting the region of interest and copying it to the clipboard.
I believe firefox and gcalctool are for examples only and you just want to know in general how to pass output of one application to other application.
There are many ways to do that on Linux, like:
piping
application1 | application2
btw here is the Firefox command line manual if you want to start firefox on Ubuntu with a URL. eg:
firefox "$url"
where $url is a variable whose value can be www.mozilla.org
That sounds difficult. Supposing you're running X11, you can very easily grab a window picture ( see "man xwd"); however there is no easy way to get to the text unless it's selected and therefore copied to the clipboard.
Alternatively, if you only want to capture user input, this is quite easy to do, too, by activation the X11 record extension: put this in your /etc/X11/xorg.conf:
Section "Module"
Load "record"
#Load other modules you need ...
EndSection
though it may prove difficult to use too, see example code for Xorg/X11 record extension fails

Tools for displaying text, powerpoint style, in linux

I have a problem where I need a way to display a repeating series of "images" on a computer monitor. Specifically, given a series of text files, I'd like a way to display the contents of said files on a screen in a way much like a powerpoint would.
My current thoughts are to find some tool that will take in a text file of some format, and then output an image which contains the text from the file. Then I'd put it in a directory and have some Slideshow program continuously go between the images in that directory. It's a very hacky solution, obviously.
So, does anyone know of tools that would do such a thing? Or is there a better way to do this? I've looked into the library libgd2, but it doesn't seem to support text-wrapping for images, which is something I'd need.
Thanks!
MagicPoint is a tool for displaying presentations. Presentations are written in a simple plain text file format, much like HTML.
You could easily generate the MagicPoint file automatically and then run it and display the presentation. You can also generate HTML, PS oder PDF from the presentation and display that.
Are you looking for powerpoint equivalent for linux? Openoffice??
have you tried some magic scripting with TeX?
a chain like
tex file | dvi2ps | ps2jpg > output
and define some TeX-Macros?
Showoff's pretty cool. It uses Markdown-formatted slides to create a simple little Sinatra app that you run (with showoff serve), and then view in a browser.
Docutils. See http://docutils.sourceforge.net/docs/user/slide-shows.html
The text syntax is reStructuredText
another idea:
text2gif
To complement the suggestions given by others, if you were going to write a program to do this, it would probably be more efficient to just render the text to the screen directly, rather than converting it to images first. It could probably be done using a canvas or text box component in a full-screen window on whatever window manager you are using (e.g. KDE or Gnome).
I give presentations with Opera's #media projection CSS support. On http://talks.webconverger.com/ you can find a template and an example which you can load in Opera's full screen mode and start sliding through.
So besides writing in a familiar language HTML, it's dead easy to share the slides and even get your audience to look at the slides as you're going through them.
If you are looking for something more flashy, there are tools on the Web to generate animations and what not, and again you would simply use a full screen browser to play it back to your audience.

Resources