1

I wrote a program in C using Code Blocks for Linux. As you can see below, it has a lot of "graphic parts" that are not directly compatible with Windows (such as unicode characters and colored texts). I was wondering if there's a quick way or a workaround to make this program display correctly on a Windows machine without having to rewrite the code.

#define INRED "\033[1;31m"
#define INGREEN "\033[1;32m"
#define INYELLOW "\033[1;33m"
#define INBLUE "\033[1;34m"
#define INWHITE "\033[1;37m"
#define INRESETCOLOR "\033[0m"
#define ERRORCOLOR "\033[1;31m\a"
#define WINCOLOR "\033[5;1;39m"    

#define BLOCK "\u2B24"
#define BLACKMATCH "\u25A0 "
#define WHITEMATCH "\u25A1 "

#define RBLOCK INRED BLOCK INRESETCOLOR "  "
#define GBLOCK INGREEN BLOCK INRESETCOLOR "  "
#define BBLOCK INBLUE BLOCK INRESETCOLOR "  "
#define YBLOCK INYELLOW BLOCK INRESETCOLOR "  "

#define PROMPT printf("\n> ");
#define CLEARSCR printf("\033[H\033[J");

EDIT: Here's there's a solution to the problem with the ANSI escape sequences How to make win32 console recognize ANSI/VT100 escape sequences? but not to the wrong display of Unicode characters.

  • 3
    Yeah, this is not Unicode but rather ANSI escape sequences. – 500 - Internal Server Error Nov 20 '18 at 11:03
  • 1
    `#define BLOCK "\u2B24"` it's both. – melpomene Nov 20 '18 at 11:04
  • There are other "consoles" or terminal programs that can display Unicode and VT100 sequences fine. Perhaps find and use one of them for your program? – Some programmer dude Nov 20 '18 at 11:04
  • Thanks guys, I've found a solution for the ANSI escape sequences here: https://stackoverflow.com/questions/16755142/how-to-make-win32-console-recognize-ansi-vt100-escape-sequences#comment92954461_16799175 but the Unicode characters are still not correctly displayed. – astral_flight_adapter Nov 20 '18 at 11:20
  • 1
    Your question was closed without an answer to how to print Unicode. I was in the middle of writing one. So, one solution is [here](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode?view=vs-2017). Another that might work is to declare the strings as `u8"\u2B24"`, open the command window as `cmd /u`, type `chcp 65001`, set the font to Lucida Console (or another monospace Unicode font, such as DejaVu Sans Mono), and then print the UTF-8. – Davislor Nov 20 '18 at 12:20
  • @Davislor I voted to close initially, but voted to reopen once it was edited. We'll see if we can get a few more votes to reopen it so you can post an answer proper. – HostileFork says dont trust SE Nov 20 '18 at 12:23
  • 1
    @Davislor: that's the problem with two questions-in-one. Half of it was a duplicate of this, the other half a duplicate of [another question](https://stackoverflow.com/q/44224081/2564301). – Jongware Nov 20 '18 at 12:24
  • I guess they can just look up my answer to that one! Thanks for digging it up. – Davislor Nov 20 '18 at 12:30
  • Well, one addendum: the MS implementation of `printf()` and `wprintf()` has a non-standard non-portable`%S` format specifier that might be useful for printing UTF-8. – Davislor Nov 20 '18 at 12:38

0 Answers0