3 Replies
      Latest reply on Oct 15, 2019 3:19 AM by eskimo
      RD2019 Level 1 Level 1 (0 points)

        I need to print texts in various colors, with a  program in C under Xcode 10.3 and OSX 10.14.6

        With

             printf(" Black,  \033[31m Red ");

        what is printed is all black, and is

             Black, [31m Red.

        The same with "033" replaced by "e"

        Any solution?

        Help much appreciated

        • Re: Getting colors with printf, C, Xcode, MacOs ?
          eskimo Apple Staff Apple Staff (12,285 points)

          Are you running your tool from Xcode?  Or in Terminal?  Xcode’s console does not support ANSI escape codes, so this is not expected to work there.  It does, however, work just fine in Terminal.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"

            • Re: Getting colors with printf, C, Xcode, MacOs ?
              RD2019 Level 1 Level 1 (0 points)

              Thanks.

              As said, I use Xcode.

              Not familiar with running C with Terminal under Macos => I will look at it.

                • Re: Getting colors with printf, C, Xcode, MacOs ?
                  eskimo Apple Staff Apple Staff (12,285 points)

                  As said, I use Xcode.

                  Indeed, but there’s a difference between using Xcode to build your tool and using Xcode to run it.

                  Not familiar with running C with Terminal

                  You can still build the tool with Xcode, you just have to run it from Terminal.  You’ll probably want to disable your colour generation when run from Xcode, so you get colours when deploying to Terminal but don’t see this noise when you’re debugging with Xcode.

                  Share and Enjoy

                  Quinn “The Eskimo!”
                  Apple Developer Relations, Developer Technical Support, Core OS/Hardware
                  let myEmail = "eskimo" + "1" + "@apple.com"