C - How to change font size in Ncurses? - c

Is there anyway? I cant seem to find any function that does this. I tried googling this but could not find anything.

I do not believe it is possible. The terminal is not for such things. It is meant for displaying text in sometimes varying colors. If you want to change the font size, you would need to open a window and draw to it (That might not actually be the correct term. Graphics aren't my forte). If this is what you want to do, I suggest looking into sdl. It is fairly simple to set up and is easy (IMO) to use. And because I know stackoverflow doesn't like flamewars, I am by no means saying it is the best. Im sure there are plenty of alternatives that are just as good. I just have not used them

If the text is being displayed in an xterm then it can be changed.
Edit .Xresources and add (probably at the top):
xterm*font: *-fixed-*-*-*-20-*
xterm*geometry: 80x24+5+5
This specifies a font size of 20 with a 80x24 charactor xterminal window located in the upper left of the display (widthxheight+xoffset+yoffset)
I was unable to use a font larger than 20. I start the application from a terminal window with the command line below on Ubuntu 14.04 with XFCE GUI.
xterm -e my_c_app

Well, it can be done if you are running on Windows command windows. I did that.
Ncurses will use your console windows settings: colors, size and typeface.
This works, but it is a somewhat basic mode of use. If needed you can even change the character attributes by program, before initializing ncurses terminal.
I tried with monospaced typefaces without any problems, tried even with proportional typefaces. It works also, but here visual quality is lesser due to the "entangling" of some characters, because ncurses keeps spacing in monospace mode.
I didn't try (yet) to change the character mode "in flight", but believe that this is possible. But i think that you can use only one mode/size for a time, that is: you cannot mix typefaces / sizes at the same screen.

There's no way with ncurses, but certain terminals support changing fonts. For xterm, for example:
$ echo -e '\x1b]50;-misc-fixed-medium-r-normal--20-200-75-75-c-100-iso10646-1\a'
XTerm Control Sequences
Change Terminal Font Size with C++

Related

GTK 4 and applications icons : how to include an application icon in a portable way?

I have difficulties to understand the icon system in GTK 4 (I work in C language).
In GTK 2 and 3 that was easy to instruct the OS about the icon to use for displaying the apps.
In GTK 4 the set_icon functions have been removed which let us with the theming system.
I understand that, by default, gtk want us to follow the Freedesktop Icon Theme Specification and so to put the icons during the installation in directories like /usr/local/share/icons/hicolor/ and setting it in the application via function like gtk_window_set_default_icon_name or gtk_window_set_icon_name. But I didn't really manage to make this system work.
Moreover, it remains obscure to me what happens on other systems that are not gnome-based like Windows (or even KDE desktop)...
So, well, I have a few questions that stem from theses previous points :
How the system work on other OS or DE that do not follow the Freedesktop Icon Theme Specification ?
Is this possible to have a very short working example that illustrates how to use, in GTK4, a new application icons that, for example, was just copied in /usr/local/share/icons/hicolor/
And my real question for my use case : is this still possible, by one way or another, to include applications icons in the binary or in the binary directory to have a simple portable application which do not need installations and work on every system ?
(edit : edited to include nielsdg precision)
Ok, I have found a (partial) answer to my second question and third question, sort of.
In fact, it's pretty simple, but I made a few mistakes.
You simply have to have a directory with this structure exactly (I made a mistake in the structure) :
my_ressource_directory/hicolor/apps/48x48/my-icon.png
my_ressource_directory/hicolor/apps/256x256/my-icon.png
my_ressource_directory/hicolor/apps/512x512/my-icon.png
Only the 48x48 size is necessary, there are a lot of other sizes which seems to be : 8x8 16x16 22x22 24x24 32x32 36x36 42x42 44x44 48x48 64x64 72x72 96x96 128x128 150x150 192x192 256x256 310x310 512x512 and "scalable".
I don't know in which context the system use all of them and I don't know if personalised size is possible.
I equally don't know in which context the svg icons in scalable can be used by the system...
In the code, then, you simply have to include a thing like that :
icon_theme = gtk_icon_theme_get_for_display (gdk_display_get_default ());
gtk_icon_theme_add_search_path(icon_theme,path_to_my_ressource_directory);
if(gtk_icon_theme_has_icon(icon_theme,"my-icon")!=1)
{
// manage error
}
gtk_window_set_default_icon_name("my-icon"); // default icon for all windows if nothing is set explicitly if I understand well.
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Your app");
gtk_window_set_icon_name(GTK_WINDOW (window),"my-icon"); // set explicitly the icon for the min window
And tadaaa; it works :) .
Please also notice that some post seems to say that the call to gtk-update-icon-cache is important to make the system works. This command creates a "icon-theme.cache" file in the directory that is used by GTK to accelerate the opening/processing of icons.
In practice I can't say if this is efficient or really used by GTK but after checking, even without the icon-theme.cache it works. So the call of this command seems not to be mandatory.
That said, it cost nothing to call the command in the Makefile. The exact command is :
gtk-update-icon-cache -f -t my_ressource_directory/
EDIT
The solution is incomplete because the resulting icon is fuzzy in certain context. See this question : Why GTK4 seems to use only 48x48 icons for displaying minimized application in all context?
And the answer, to have the full solution.
Works fine for me (under FedoraCore 35). Needed to have custom icon shown when running exampleapp1 (A trivial application) of GTK 4 doc. https://docs.gtk.org/gtk4/getting_started.html

ACS characters not working in putty even with export NCURSES_NO_UTF8_ACS=1

I am developing an ncurses application myself in C. The problem is that putty displays alternative character set characters like ACS_VLINE as letters. My locale is
LANG=en_US.UTF-8
and I have set
export NCURSES_NO_UTF8_ACS=1
I have also set putty to UTF-8 and tried different fonts. The characters display fine on the tty on the actual machine so I think the issue is with putty. I have also tried linking ncursesw instead of ncurses.
It is a combination of things. The recommended TERM for PuTTY is "putty", but due to inertia, most people use "xterm". The line-drawing support in the xterm terminal description is different from PuTTY's assumptions because xterm supports luit, which has some limitations with the way the alternate character set is managed (see Debian Bug report #254316:
ncurses-base: workaround for screen's handling of register sgr0 isn't quite right).
If you use infocmp to compare, you may see these lines which deal with the alternate character set:
acsc: '``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~', '``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~'.
enacs: NULL, '\E(B\E)0'.
rmacs: '\E(B', '^O'.
smacs: '\E(0', '^N'.
VT100s can have two character sets "designated", referred to as G0 and G1:
The "xterm" line-drawing works by changing the designation of G0 between the ASCII and line-drawing characters,
the "putty" line-drawing works by designating ASCII in G0 and line-drawing in G1 and switching between the two with the shift-in/shift-out control characters.
Although both are VT100-compatible, the xterm scheme does not work with PuTTY. Because of the tie-in with luit, the normal terminal description for xterm will not change (unless it proves possible to modify luit to solve the problem for its users), so a workaround is needed for users of PuTTY:
use a different terminal description as recommended, e.g., TERM=putty. PuTTY's settings dialog lets you set environment variables to pass to the remote machine.
This has the drawback that some systems do not have the full ncurses terminal database installed, due to "size" (it is 6.8Mb on my local machine). Also, TERM may not be on the list of allowed ssh environment variables.
you can compile your own terminfo entry with ncurses' tic, e.g.,
cat >foo <<"EOF"
xterm|my terminfo entry,
enacs=\E(B\E)0,
rmacs=^O,
smacs=^N,
use=xterm-new,
EOF
tic foo
use GNU screen. It does its own fixes, and happens to compensate for PuTTY's problems.
Further reading
SCS – Select Character Set (VT100 manual)
4.4 Character Set Selection (SCS) (VT220 manual)
The terminfo database is big—do I need all of that? (ncurses FAQ)
Putty: login, execute command/change environment variable, and do NOT close the session
I want to make some additions. I faced same issue: many ncurses-based tools like dialog, menuconfig and nconfig from Linux kenrel sources, even mc is broken when built with ncurses (although mc is built using Slang on many OSes and not affected).
Here is what happened
ncurses uses smacs record from terminfo to switch to "alternative charset" and then it uses acsc to draw boxes. It sends a which is box-drawing character in alternative charset (ACS).
This is VT100 graphics.
Some terminal emulators nowadays do not support ACS when in UTF-8 because apps have ability to send real box-drawing codepoints.
There is unofficial capability U8 (capital U!) in terminfo that tells ncurses: "Instead of ACS use real box-drawing codepoints."
I have this capability infocmp -x xterm-utf and for putty aswell, but not for xterm.
As you can read in ncurses(3) (https://invisible-island.net/ncurses/man/ncurses.3x.html), ncurses is aware of Linux console and GNU screen (and tmux, which also uses screen as TERM) and always behave like if U8 were set.
For other terminals that do not support ACS when in UTF, you can set NCURSES_NO_UTF8_ACS.
Unfortunatelly, ncurses is not aware of putty.
There is also luit that may convert ACS to Unicode points.
So, here is what we can do to run ncurses + putty in UTF-8:
Use terminal with U8#1 capability. This one is set for putty (btw, I suggest to use putty-256color instead). You can create your own entry with U8#1 and colors#256 and compile it with tic -x. Be carefull that mouse may not work on terminals that do not start with xterm (see mouseinterval(3), BUGS section). This is why I do not use putty terminal. I suggest to copy xterm-utf8, add colors#256, compile and stay with it: it works perfectly with putty, mouse and utf8.
You can set NCURSES_NO_UTF8_ACS in your profile.
You can run screen or tmux: it will set TERM to screen and fix ncurses
You can run luit: it will do all convertions for you.
Since putty 0.71 you can ask putty to support ACS drawings even in UTF-8

How can output be directed to specific coordinates in the linux terminal?

To be more specific, I am looking for an equivalent to the Windows API function: WriteConsoleOutputCharacter. I know this style of direct output is possible, as I have seen the behaviour used before in the time that I have used Linux. However, I am still a baby when it comes to Linux specific C libraries, and have not been able to ascertain any clues as to where I may find such functionality. Any assistance would be appreciated.
Check out ncurses library.
It allows you to create some text-based UI in terminal. It is more than you asked, but if you need more than only this one function it may be best option for you.
You can use the ANSI control sequence
Say, following will print 'ddd' string 3 lines above the prompt in bash
echo -e "\e[3Addd"
This line will put a clock in right upper conner of a terminal (from commandlinefu.com)
while sleep 1;do tput sc;tput cup 0 $(($(tput cols)-29));date;tput rc;done

Motif programming and UTF-8

I'm new to Motif programming and I want to use UTF-8 encoding.
I've tried XtSetLanguageProc (NULL, NULL, NULL); but when I read a file in Motif (editor text-like in 6A volume motif programming), I've got problems with accented characters.
I had to use setlocale()?
thanks!
With Motif, you have to switch to the correct font for the languages that you are using. There is currently no single UTF-8 font that has full support for all languages.
If there is more to your problem you might want to ask it on MotifZone http://www.motifzone.com/forum/unicode-support since Motif is not a commonly used toolkit anymore.
As Michael said, you need a font that supports Unicode. The ones with most broad support are Iso10646 fonts. Assuming Linux with X11, launch xfontsel to find them. Select iso10646 from the rgstry drop-down menu. Then fmly menu will list available fonts with that encoding. Some are very limited, but
-*-fixed-medium-*-*-*-18-*-*-*-*-*-iso10646-*
is a good choice that comes with the X11 installation.
Then, you need either to set that font as a fallback in your Motif program or supply the resource via command-line
xmprogram -xrm '*fontList: -*-fixed-medium-*-*-*-18-*-*-*-*-*-iso10646-*'
If all worked right, there will be no problems with accented characters anymore.
For a font supporting even more glyphs, consider GNU Unifont.

Bolding text in console output

For extra credit, the professor wants us to use bolding and/or underlining to text output in the current project.
The example he gave was b\bb o\bo l\bl d\bd is displayed as b o l d
Following that example, I marked up SPACE as
printf("\033[7mS\bSP\bPA\bAC\bCE\E- move forward one page\033[0m");
I'm also implementing reverse video by enclosing strings within \033[7m and \033[0m fields. The reverse video inverts the colors of the line appropriately, but doesn't seem to be affecting the bolding, since both strings with and without the reverse video are not bolding.
Could it be the standard shell used in Ubuntu 10.10 that is at fault?
I agree about using curses, but given your starting point ....
I think you want to use the 'bright' feature of VT100 for the bold, ESC[1m
You can probably find better doc on VT100 codes, but using this page I found the codes. ANSI/VT100 Escape Codes
I hope this helps.
Unless you're just trying to be masochistic, try using curses (or ncurses) instead.
// warning: Going from distant memory here...
curs_attron(A_INVERSE); // maybe A_REVERSE? I don't remember for sure.
curs_addstr("SPACE - move forward one page");
curs_attroff(A_INVERSE);

Resources