Thread: ANSI Coloring not working

  1. #16
    Registered User
    Join Date
    Nov 2015
    Posts
    72
    It seems that the TCC shell parses escape color sequences but not through stdio for some reason. The only problem with the pipe is that the output isn't shown until the execution is finished, so no terminal interaction is allowed such as with scanf();, getchar(), cin >> etc. I tried looking into PDCurses but it is 32-bit which doesn't work with 64-bit applications.

  2. #17
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    This fork of PDCurses is supposed to work for 64-bit applications, if you compile it yourself. (I don't use Windows myself at all, though.)

    For portable development work, you could always set up a virtual machine with an image of some flavour of Linux or *BSD. There are ready-made images you can download (for Mint or Ubuntu for example), and the virtual machine "players" are free, too (for example, VirtualBox).

  3. #18
    Registered User
    Join Date
    Nov 2015
    Posts
    72
    I have downloaded that package but I can only see 32-bit make files. Do you have any idea as to how to build it to be compatible with 64-bit applications?

    Edit: Btw, I saw the following entry on their site:

    "Note also that "Win32a" is an unfortunate misnomer; it uses the Win32 API, but can be compiled and run in 64 bits. It may need to be renamed."

    but I'm not sure as to what compiler options to use to ensure that it gets 64 bit.
    Last edited by bot; 11-10-2015 at 10:22 AM.

  4. #19
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Are you targeting 64-bit, or are you using a 64-bit OS to make 32-bit applications? Windows can still use 32-bit applications, so you may be fine building a 32-bit version in any event.

    Visual Studio is preferred for windows-related targets, but compiling is easiest with non-free tools like Visual Studio Professional. When I last checked, the free version of their compiler didn't target 64-bit. In case that changed, the actual instructions would be here.

  5. #20
    Registered User
    Join Date
    Nov 2015
    Posts
    72
    I prefer the prompt for now, it feels more lightweight and transparent that way.

    Edit: The .mak file builds for 64 bit applications by default; there is a flag that is set to /MACHINE:x64 in the file.

    But I'm not sure how to install this into the VC include path. I copied all .lib files to the main /lib dir and created a 'curses' directory in the main 'include' path. While '#include <curses.h>' works, I'm unable to call any functions within that header. Th compile complains that e.g. printw() is undefined.
    Last edited by bot; 11-10-2015 at 12:00 PM.

  6. #21
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    >> I'm on a Windows 7 x64 environment with a UTF-8 encoded command line prompt.
    There is no such thing.

    Just use the Win32 API like vim does: https://github.com/vim/vim/blob/mast..._win32.c#L5291

    If you want to understand why printf() doesn't act like a "binary write" when using a [real] console: Non-English characters with cout

    Note that when using TCC shell, your program's output is likely being redirected into TCC - and so the behavior can be different from a real/OS console.

    gg

  7. #22
    Registered User
    Join Date
    Nov 2015
    Posts
    72
    Thanks for your replies. While I have not solved the issue with escape codes or got 'ncurses' library to work with my visualC compiler, I have solved it by using an implementation that is similar to Vim by:

    1. including windows.h
    2. Using
    Code:
    hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute(hStdOut, color);
    to change the text color
    and
    Code:
    int getColors() const
    {
       CONSOLE_SCREEN_BUFFER_INFO csbi;
       GetConsoleScreenBufferInfo(hStdOut, &csbi);
       return csbi.wAttributes;
    }
    to get the system color.

    Still, I'd very much prefer to change the colors with some in-text labels. The text gets a little easier to comprehend in the source and its faster to type...

    I don't really understand peoples' complaints that Escape codes are 'invisible' or whatevs. Escape codes are pretty easy to understand and I've been using them for ages by now.

    Perhaps I should try to write an ANSI interface that interprets ANSI codes in text and translates them into calls to SetConsoleTextAttribute() et al for Windows and something else for GNU/Linux. But perhaps ANSI works fine in Linux? I've seen demos somewhere of 256 ANSI colors in the terminal.

  8. #23
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Quote Originally Posted by bot View Post
    Perhaps I should try to write an ANSI interface that interprets ANSI codes in text and translates them into calls to SetConsoleTextAttribute() et al for Windows
    Doesn't ConEmu do just that? Again, I do not use Windows, but the ConEmu site seems to describe the functionality you'd need.

    Quote Originally Posted by bot View Post
    and something else for GNU/Linux.
    No need. ANSI escape codes work fine in Linux (and in Mac OS X command prompt, in *BSDs, and in old Unix systems). Windows is just the odd one out, that's all. (It used to support the ANSI color codes, via a driver, but..)

    The Wikipedia ANSI escape code page is very useful; just note that in practice, CSI refers to "\033[". That is, ASCII code 27 = 0x1B (in hexadecimal) = 033 (in octal) = ESC control character, followed by ASCII code 91 = 0x5B = 0133 = [ .)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pre-ANSI to ANSI - Unix to Linux
    By petterk in forum C Programming
    Replies: 12
    Last Post: 04-20-2015, 07:56 AM
  2. Coloring My Text
    By bjl in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2008, 07:37 PM
  3. ANSI - working with directories
    By sean345 in forum C Programming
    Replies: 1
    Last Post: 06-01-2002, 04:43 PM
  4. Coloring Buttons
    By Okiesmokie in forum Windows Programming
    Replies: 5
    Last Post: 03-17-2002, 07:00 AM
  5. What is the Difference between ANSI C and non-ANSI C ?
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 11-24-2001, 06:55 AM