Output bold text to console in C (on Mac - Xcode)

对着背影说爱祢 提交于 2020-01-07 02:23:11

问题


Lately I've been experimenting with coding basic programs in C using Xcode, and I've found myself looking for ways to italicize text or make it bold or coloured. Despite the numerous similar posts on SO, there hasn't been one to prove helpful to my situation, however I've found many examples for this in C++ (if that means anything). Perhaps it's not possible to format text in C using Xcode?

Particularly, I've read about using ANSI escape coding, but when I use this code: printf("\033[32;1mTest"), I end up with this as output: [32;1mTest. I believe this is because ANSI escape coding is not intended to be used on MacOS (just Linux).

Specifically, I'm looking for a way to output formatted text to the console using printf or some other method that prints text to the console, on a Mac. (Is this even possible?...)

Feel free to ask for any additional information as needed.


回答1:


The default internal console for XCode is not a terminal, so it doesn't interpret escape codes. As a result you don't get to see the effects of bold/color changes.

On XCode 8, there is an option to edit the scheme to get the program to run in a terminal. Click on the pop-down to the right of the stop button, and select 'Edit Scheme…'

Once you pop up the 'edit scheme' screen, choose options, then select run in terminal.

If you're just trying to get it to run from a terminal; you can launch terminal separately, then drag and drop the binary from the 'Products' section of the project navigator into the terminal (it will print out the full path to the binary in the terminal, and you can run it from there).

Colored emojis do display properly on the console; it's just that it doesn't respect color escape codes.



来源:https://stackoverflow.com/questions/40752107/output-bold-text-to-console-in-c-on-mac-xcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!