Python curses draw nvim-style gui cursor vertical bar - curses

How to draw the cursor as a vertical bar with python curses library?

You need to do this:
https://stackoverflow.com/a/17100535/9590859
There's no API in curses library for raw control sequences, just run:
def run_control_sequence(sequence):
os.write(sys.stdout.fileno(), bytes(sequence, 'utf-8'))
run_control_sequence('\x1b[\x36 q')
This solution is terminal dependent. The above control sequence is for xterm.

Related

how to restore default characteristics of terminal in fpc program (+ crt library)?

Default terminal characteristics (on Linux mint) are: black background and grey font. After launching fpc program with TextColor(Red) and TextBackground(White) and quit out of a program, terminal still has red font and white background.
The goal is to find a solution which will restore default characteristics (black background and grey font) of terminal.
thanks for your attention
The easiest solution is to set the text background and text color back to black/grey programatically, using TextColor and TextBackground before end.
the solution is not pretty nice, but worked (from here: https://wiki.freepascal.org/Executing_External_Programs#TProcess).
you should paste the code to the relevant places in a program:
uses
process;
var
reset_process: TProcess;
begin
reset_process := TProcess.Create(nil);
reset_process.Executable := 'reset';
reset_process.Options := reset_process.Options + [poWaitOnExit];
reset_process.Execute;
reset_process.Free
end.

Ruby curses: how to get pure white

I'm having a hard time trying to get a pure white (background) and black (foreground) text with ruby and curses.
With this code
Curses.init_pair(1,COLOR_BLACK,COLOR_WHITE)
Curses.attron(Curses.color_pair(1))
Curses.stdscr.addstr str
Curses.attroff(Curses.color_pair(1))
I get black text on a grayish background (the bottom three lines in
screenshot)
What could I be doing wrong? I tried switching from iterm2 to mac terminal
still the same.
Most of the terminals which implement "ANSI color" use a more intense foreground color when told to render bold. But there is no corresponding workaround for the background.
However, the majority of these also implement SGR 39 and SGR 49, which reset the foreground and background to its "default" colors. Using that would get your original terminal background (which is likely what you want). That is a feature of ncurses called use_default_colors, which I see is available in ruby.
Using that feature, your example would
call the Curses.use_default_colors method,
not bother (for example) to create a color pair, since the default pair 0 would draw using the terminal's default colors.
other color pairs (1 through the maximum number of pairs) would work just like regular curses.
The example given uses color pair 1. If you were using the default-colors extension, you could initialize Curses with the use_default_colors method. Then, using the default color pair 0, you would see on most terminals the original terminal colors. This method is from the underlying ncurses library irregardless of whether the Ruby package is called "curses" or "ncurses".
Color pair 0 is special (see manpage). It cannot be set to specific colors by your application. As an extension, ncurses provides a way to alter this in a useful way.

How does htop display work?

I want to write a program that displays its output in the shell like htop does, as opposed to just running the program and using the watch command. I have looked through the htop source code and am still a little lost. Is there a output beyond tty in the shell that is used, or are all the htop panels custom and opening an output like that is not a native task for a shell like bash?
Thanks.
htop author here. What you're looking for is the NCurses library.
With NCurses, you can implement a full-screen textmode application in C.
It provides a set of primitives for "drawing" on the terminal: ie, move() to go to a X-Y coordinate on the screen, functions to change colors, to erase part of the screen, etc. It also provides some high-level constructs such as "windows" through which you can scroll parts of the screen separately, but in htop I don't use that and implement my scrollable panels drawing them "by hand" using the lower-level primitives.

How can i get light green ansi code and get bigger font for ruby?

printf "\033[1;32;40mGreen text on black background.\033[0m\n"
That is the green, but how can i get light green or other variation of color?
http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html , are only those color available for gnome-terminal as escape code?
Also how can i get bigger font with ruby?
using the "1" as the first parameter, as you are doing already, that's as "light" a green as you're going to get. this guy's webpage might be helpful: http://www.linuxfocus.org/English/May2004/article335.shtml
testing on urxvt:
[added later] there is a DEC extension for double-sized characters: Printing double-size characters with Ncurses but urxvt doesn't support it, I don't know about Gnome terminal.
With an offset of 90 you can create bright/high contrast colors.
See here for a reference. Wikipedia mentions the bright color range, but doesn't really explain how to use them (if I haven't missed it).
If you combine it with the bold style you can create 4 variations of a color.
Example:
It's a matter of the terminal support. The ansi codes that you list are interpreted by the terminal emulator and those codes are the only available colours (it comes from the days before windows and when 16 colours caused a stir).
If you need more you could consider using a graphical interface to your ruby app such as tk.
You can use an RGB escape code:
printf "\033[38;2;r;g;bmText\033[0m"
or, for background colour:
printf "\033[48;2;r;g;bmText\033[0m"
Just replace r, g, and b with the desired RGB value.

How do I enable more than 8-bit colors in Terminal.app?

In the Vim and Emacs terminal apps, the color schemes look horrid. How do I enable the colors to be as vibrant as the GUI version (or more than 8 colors for that matter)?
Should I just give up, and move over to their respective GUI applications? And if so, which?
You can't have more colors in the terminal, because there are only ANSI codes for 8 colors (16 if you count bold/light). If you want to customize the colors, you can use the TerminalColours plugin from http://ciaranwal.sh/2007/11/01/customising-colours-in-leopard-terminal
Personally, I prefer to use the so-called Carbon Emacs on my Mac. There are several builds available; Google is your friend. I get mine from http://www.porkrind.org/emacs/
You are possibly being inhibited by the fact you are running in a VT100/WhateverItsCalled compatible terminal and it just doesn't have more than about 16 foreground and 16 background colours. If it did, the lovely library "CaCa" ( ColourAsciiColourArt ) would be much more pleasing to watch than it is.
If you want more colours, you simply have to use more modern technology, and this generally means using X ( unless your loving pain and want to use directfb/framebuffer/svgalib ).
For vim, there is GVim ( GTK+Vim ). Emacs GUI version however displeases me much, but I'm not an emacs user.
Aquamacs and MacVim
Sounds like you want MacVim

Resources