Re: Extend functionality of printf (Add colours)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bill Reid

    Re: Extend functionality of printf (Add colours)


    Tomás Ó hÉilidhe <toe@lavabit.co mwrote in message news:391f429b-4cb8-4762-80bf-511a1dc5eeab@a2 9g2000pra.googl egroups.com...
    >
    Firstly... before the guns go off... I realise that the C Standard
    doesn't mention anything about the existence of colour, which is why
    I'm writing a small little cross-platform library for setting the
    console text colour.
    Just curious...have you ever heard of something called "conio.h"
    and functions like "cprintf()" ? Definitely NOT a C "standard" library,
    just wondering if you've heard of it, you might want to check it out
    for possible linking/defines on "some" platforms...

    ---
    William Ernest Reid

  • =?ISO-8859-1?Q?Tom=E1s_=D3_h=C9ilidhe?=

    #2
    Re: Extend functionality of printf (Add colours)

    On Nov 10, 9:38 pm, "Bill Reid" <hormelf...@hap pyhealthy.netwr ote:
    Just curious...have you ever heard of something called "conio.h"
    There's an easier way. For instance on Linux, you can do:

    printf("\033[37mHello!");

    They call them escape sequences or something like that.

    I've already got the code written and working for Linux, and now I'm
    writing it for Windows. I had thought that under Windows I might be
    able to do:

    printf("$e[37mHello!");

    but I tried it just there and it didn't work (as far as I know it
    worked in DOS). I know under Windows there's a Win32 API function
    called "SetConsoleText Attribute", but I was hoping the above would
    work because I'm not too keen on explicitly linking with gdi32.lib,
    nor am I keen on including the whore of a file that is <windows.h>.
    Anyone know another way of changing the console text colour in
    Windows?

    Just as an aside, I'm also writing a cross-platform library for
    dealing with raw sockets. I pretty much have it simplified to four
    functions:

    OpenRawsock
    SendEthernetFra me
    RecvEthernetFra me
    CloseRawsock

    So far I have it working for Linux and Windows (The Linux version used
    Berkeley Sockets and the Windows version uses pcap because WinSock no
    longer allows raw sockets). Anyone who's interested can e-mail me.

    Comment

    • Richard Tobin

      #3
      Re: Extend functionality of printf (Add colours)

      In article <1d64875b-f365-4cb9-b983-2e27ac853e72@b3 1g2000prb.googl egroups.com>,
      Tomás Ó hÉilidhe <toe@lavabit.co mwrote:
      >There's an easier way. For instance on Linux, you can do:
      >
      >printf("\033[37mHello!");
      >
      >They call them escape sequences or something like that.
      This isn't a specifically Linux feature. It's a feature of the
      terminal emulator (or real terminal) that you're using. Xterm (in
      "VT" mode) uses ANSI escape sequences, which are what you're
      describing.

      -- Richard
      --
      Please remember to mention me / in tapes you leave behind.

      Comment

      • Keith Thompson

        #4
        Re: Extend functionality of printf (Add colours)

        richard@cogsci. ed.ac.uk (Richard Tobin) writes:
        In article
        <1d64875b-f365-4cb9-b983-2e27ac853e72@b3 1g2000prb.googl egroups.com>,
        Tomás Ó hÉilidhe <toe@lavabit.co mwrote:
        >
        >>There's an easier way. For instance on Linux, you can do:
        >>
        >>printf("\03 3[37mHello!");
        >>
        >>They call them escape sequences or something like that.
        >
        This isn't a specifically Linux feature. It's a feature of the
        terminal emulator (or real terminal) that you're using. Xterm (in
        "VT" mode) uses ANSI escape sequences, which are what you're
        describing.
        Note that "ANSI" here refers to the ANSI standard that describes the
        behavior of VT100-compatible display terminals (including emulators);
        it's completely separate from the ANSI (and/or ISO) C standard.

        --
        Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
        Nokia
        "We must do something. This is something. Therefore, we must do this."
        -- Antony Jay and Jonathan Lynn, "Yes Minister"

        Comment

        Working...