control font and character set in console using visual studio c++ - c++

Every time I run debugger debugging console shows it's "prefered" font "lucida console" instead of "console" ... and always ignores diacritics from any european language characters over 0x7f are considered graphics or so...
So I ask How to select Font used in Console, type and size.
I ask too, what header file or instruction should I use to have
std::cout << "... ácido propiónico como fungicida ... y sus sales de amoníaco ... " be written with teese special á ó í or others like ñ Ç deustche dzet ...
Sorry maybe those questions need to be asked elsewhere ... I would be pleased to learn where and how ...
thanks

SetCurrentConsoleFontEx would be my starting point.
Note the font selection is by index, and these are defined in the registry:
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
Note: the names needs to be a sequence of "0" and the value is the font name.
But you would be better off just setting the console properties for that Window: they are retained per executable: open the system menu of the console window and modify its properties.

Related

Strikethrough text in ncurses

I am developing a terminal TUI application for myself using the ncurses library. (Running on Linux)
I cannot seem to find much info regarding the use of a "strikethrough/strikeout" text attribute when adding a string to a ncurses window using addstr and friends.
The only information I've found online was on this site:
https://midnight-commander.org/ticket/3264
Ncurses will not add [strikethrough text] because the bitfield is already fully packed.
I was wondering if there are any workarounds to this, or any official way to do this.
Any help would be appreciated.
Thanks.
ncurses has 16 bits allocated for video-attributes. SVr4 curses used 8; XOpen Curses added 7. Those 15 are defined for X/Open Curses compatibility.
Referring to the X/Open Curses documentation, there are two sets of definitions:
A_ALTCHARSET Alternate character set
A_BLINK Blinking
A_BOLD Extra bright or bold
A_DIM Half bright
A_INVIS Invisible
A_PROTECT Protected
A_REVERSE Reverse video
A_STANDOUT Best highlighting mode of the terminal
A_UNDERLINE Underlining
and
WA_ALTCHARSET Alternate character set
WA_BLINK Blinking
WA_BOLD Extra bright or bold
WA_DIM Half bright
WA_HORIZONTAL Horizontal highlight
WA_INVIS Invisible
WA_LEFT Left highlight
WA_LOW Low highlight
WA_PROTECT Protected
WA_REVERSE Reverse video
WA_RIGHT Right highlight
WA_STANDOUT Best highlighting mode of the terminal
WA_TOP Top highlight
WA_UNDERLINE Underlining
WA_VERTICAL Vertical highlight
depending on whether the bits are stored in a attr_t or a chtype (X/Open and SVr4 respectively). In ncurses, those are the same (see the manual page), so that it does not matter if one refers to A_BOLD or WA_BOLD (Solaris xpg4 curses does store those differently).
Discounting the A_ vs WA_, the two lists are different. The newer ones from X/Open Curses are rarely used. Since ncurses doesn't know what it looks like on the screen, someone could add the corresponding terminfo capability to a terminal description and ncurses would handle it.
The terminfo manual page mentions these:
The XSI Curses standard added these hardcopy capabilities. They were
used in some post-4.1 versions of System V curses, e.g., Solaris 2.5
and IRIX 6.x. Except for YI, the ncurses termcap names for them are
invented. According to the XSI Curses standard, they have no termcap
names. If your compiled terminfo entries use these, they may not be
binary-compatible with System V terminfo entries after SVr4.1; beware!
(Explaining how to modify a terminal description can be found in thousands of webpages, and is off-topic for this forum).
Possible attributes in ncurses are:
A_NORMAL Normal display (no highlight)
A_STANDOUT Best highlighting mode of the terminal.
A_UNDERLINE Underlining
A_REVERSE Reverse video
A_BLINK Blinking
A_DIM Half bright
A_BOLD Extra bright or bold
A_PROTECT Protected mode
A_INVIS Invisible or blank mode
A_ALTCHARSET Alternate character set
A_CHARTEXT Bit−mask to extract a character
COLOR_PAIR(n) Color−pair number n
Functions like attron(), attroff(), attrset() may be used to work with attributes,
Strikethrough is not and will not be available.
If you know your terminal and want your software to be able to to work just on such an terminal type AND the terminal supports strikethrough, then you can use control characters or escape sequences to activate such a funcionality.
You can use Unicode for that:
(I know it's an old question, but I had a similar issue, and this is the top result for "curses strikethrough" on Google, so this answer might be helpful to someone.)
I made it work using Python, but the strategy should work in any language:
import curses
def strike(text: str) -> str:
# See <https://stackoverflow.com/a/25244576/4039050>
return "\u0336".join(text) + "\u0336"
def main(stdscr):
message = "The quick brown fox jumps over the lazy dog."
stdscr.addstr(strike(message))
stdscr.refresh()
stdscr.getch()
if __name__ == "__main__":
curses.wrapper(main)

Is it possible to print Bengali language with C in console?

Is it possible to print Bengali Language with C in console? If it can be done, how can I do it?
I tried:
wprintf (L"Character: %lc %lc \n", L'ঈ', 2440);
This does not work. It just shows an unknown symbol. What is the best formula for working with UTF-8 format data in console? If it is possible with C++, I want to know that.
To use a language & display it is very much an OS dependent task and below are few generic possible ways to do it.
On linux :
Set Locale,
In your case it should be : setlocale(LC_ALL, 'bn_IN.utf8');
Refer : (http://www.linuxquestions.org/questions/linux-newbie-8/displaying-hindi-in-linux-command-prompt-terminal-4175448642/)
Download appropriate font & install in your system.
Check your : cd /usr/share/fonts/ for the font.
edit your .bashrc file and add your font like this:
export LANG=bn_IN.UTF-8
(Side effect your whole os may start using this font if it supports).
On Windows :
Necessary criteria for fonts to be available in a command window
How to print a unicode string to console?
Refer
Note : Your Terminal must support Unicode for any of this to work.

how to use of unicode fonts in Verifone VX675

I have a problem to write Arabic text on VeriFone vx675 pay pose model.
i trying this codes line:
int ret=set_font("Tahoma.ttf");
if (ret!=0)
{
printf("con : %d, err: %s\n",ret,strerror(errno));
}
display_at(0,0,"سلام", NO_CLEAR);
but device show an error as
Invalid Argument
could anyone say to me how i should to resolve this problem. or how i can write Unicode Arabic text in Vx675 Model.
Thanks in Advance
Disclaimer: I have not worked with the Vx675 before, nor have I tried to use an Arabic font, but I think this will work...
You can't use .ttf fonts on the VeriFone terminals. Instead, you need to use VeriFone's "Font Generation Tool" to convert a .ttf to either a .vft or .fon file.
Start "Font Generation Tool". If you installed the DTK, then it should be in your start menu under "VeriFone"
Go to the "Font" menu item and select "Convert Font".
Select "Windows Unicode Font"
Select "Arabic" as the "Custom Unicode Fonts" choice. Set whatever other styles you want.
Click through the rest of the wizard and save the font file somewhere.
Download that new font file to your terminal with the rest of your program (this is typically the step I forget to do on my first run)
When you do your "display_at" function, I'm noting that you are using the Arabic character(s) directly. I have no experience with this as to whether or not it will work, but one thing you can try if it isn't working is to use printf with numerical offsets. I don't think you'll want to do that in the long-run, but it can help you get started:
printf("%c%c%c%c%c%c%c%c", 0, 1, 2, 3, 4, 5, 6, 7);

Error message "error: stray '\302' in program"

I'm using Code::Blocks on Ubuntu 10.10 (Maverick Meerkat). I have connected a Mac keyboard and set the keyboard settings to "Swiss German Mac". Now whenever I write an equals sign, followed by a space (something like width = 100) I get the error message: stray '\302' in program.
I know this error means that there is a non-standard character in the text file.
When I delete the space character, the program compiles just fine. So that means Code::Blocks adds some sort of special character. But I can't see why this happens. What is the reason?
What character does '\302' stand for?
[UPDATE]
I got a little further investigating the problem. I get this stray when I use the combo Shift + Space. Now that I know it doesn't happen that often any more. But it's still rather annoying especially when writing code... Is there a way to turn off this combo in X11?
[SOLVED]
Thanks to Useless's answer, I was able to solve the "issue". It's more of a feature actually. Shift + space created a spacenolinebreak by default. So by changing the xmodmap with
xmodmap -e "keycode 65 = space space space space space space"
this behavior was overridden and everything works fine now.
Since you're sure it's caused by hitting Shift + Space, you can check what X itself is doing by. First, run xev from the command line, hit Shift + Space and check the output. For example, I see:
$ xev
KeyPress event, serial 29, synthetic NO, window 0x2000001,
root 0x3a, subw 0x0, time 4114211795, (-576,-249), root:(414,593),
state 0x0, keycode 50 (keysym 0xffe1, Shift_L), same_screen YES,
XLookupString gives 0 bytes:
XmbLookupString gives 0 bytes:
XFilterEvent returns: False
KeyPress event, serial 29, synthetic NO, window 0x2000001,
root 0x3a, subw 0x0, time 4114213059, (-576,-249), root:(414,593),
state 0x1, keycode 65 (keysym 0x20, space), same_screen YES,
XLookupString gives 1 bytes: (20) " "
XmbLookupString gives 1 bytes: (20) " "
XFilterEvent returns: False
...
Then, run xmodmap -pk and look up the keycode (space should be 65 as above, but check your xev output).
If you see something like
65 0x0020 (space)
Then X isn't doing this. On the other hand, if I pick a character key which is modified by shift, I see something like this:
58 0x006d (m) 0x004d (M)
If you have two or more keysyms for your keycode, X is the culprit. In that case, something like xmodmap -e 'keycode 65 space' should work.
\302 stands for the octal representation of byte value the compiler encountered. It translates to 11000010 in binary, which makes me think it's the start of a two byte UTF-8 sequence. Then this sequence must be:
11000010 10??????
Which encodes the binary Unicode point 10??????, which can be anything from U+80 to U+BF.
Several characters starting from U+80 are special spaces and breaks which usually are not shown inside a text editor.
Probably it's not your editor, but Xorg, that emits these characters due to your keyboard settings. Try switching to a generic US keyboard and test if the problems persists.
'\302' is C notation for the octal number 3028, which equals C216 and 19410. So it's not ASCII.
Which character it maps to depends on the encoding. In Latin-1, it's the  character, for instance.
I have seen this type of issue when copying and pasting from web pages or other electronic documents. The common culprits would be invalid quotes like ` instead of ', or something alike. Try to use the compiler error to guide you into where in the file the error might be.
That sounds like some kind of encoding issue. I haven't used Code::Blocks for years, so I am not sure if it allows you to pick different encodings.
How about opening your code file with gedit and saving it as UTF-8, and then try again? But it sounds rather strange that you get such an issue using space characters.
I've seen this problem in my Linux box with a Finnish keyboard.
It also happens with Emacs, etc. I don't have a good solution for it, but I guess reports about the fact that it happens elsewhere are also useful...
If you open your file in Emacs and set-buffer-file-coding-system to something like "unix" or some ASCII variety, then when you try to save, it'll warn you that the buffer contains unrepresentable characters and points you to them so you can fix them.
I had the same issue by modified a US ASCII example file.
So I convert it in UTF-8, here are GNU/Linux command:
iconv -c -t us-ascii -f utf-8 source_file -o dest_file
And then add my modifications… no more errors!
To verify initial encoding, use
file -i source_file
I should add a non-ASCII character to allow iconv do the job!!??
I decided to move the file from a MAC book to a Linux box and used email with my icloud.com address. When I opened the transferred file the errors had gone and the file now compiles !

C code changes terminal text color; how can I restore defaults? Linux

I have a C file running on Linux. It prints some lines in red (failures) and some in green (passes). As you might expect, it uses escape codes in the printf statements as follows:
#define BLACK "\033[22;30m"
#define GREEN "\033[22;31m"
printf(GREEN "this will show up green" BLACK "\n");
If the BLACK at the end wasn't there, the terminal text will continue to be green for everything. In case you didn't catch it, that's fine for a terminal window with a non-black background, but otherwise you'll end up with black-on-black. Not good! Running the program has this problem, as does capturing the output in a text file and then viewing the file with "more" or "less".
Is there a code to restore defaults instead of specifying a color at the end of the printf statement? This needs to be in C, but I would be interested in reading about other approaches.
I updated my macros as follows (note 31 is for red):
#define RESET_COLOR "\e[m"
#define MAKE_GREEN "\e[32m"
printf(MAKE_GREEN "this will show up green" RESET_COLOR "\n");
I found the following links helpful in understanding how these codes work:
http://www.phwinfo.com/forum/comp-unix-shell/450861-bash-shell-escapes-not-working-via-putty-ssh.html explains what these escape sequences do, and to use ncurses if portability is needed.
http://www.linuxselfhelp.com/howtos/Bash-Prompt/Bash-Prompt-HOWTO-6.html
ANSI codes shows even more escape sequences; It is useful to get the big picture
Try using:
#define RESETCOLOR "\033[0m"
That should reset it to the defaults.
More about these terminal codes can be found in ANSI escape code.
"\033[0m"
See ANSI escape code.
Type reset in the terminal.
There is a binary found in Linux and OS X called reset.