将粗体文本输出到C控制台(在Mac上-Xcode) [英] Output bold text to console in C (on Mac - Xcode)

查看:136
本文介绍了将粗体文本输出到C控制台(在Mac上-Xcode)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在尝试使用 Xcode C 中编码基本程序,并且我发现自己正在寻找使文本变为斜体或使其变为粗体或彩色的方法.尽管有很多关于SO的类似文章,但是还没有人证明对我的情况有所帮助,但是我在C ++中找到了很多这样的示例(如果有任何意义的话).也许不可能使用Xcode在C语言中格式化文本?

尤其是,我已经阅读了有关使用ANSI转义编码的信息,但是当我使用以下代码:printf("\033[32;1mTest")时,最终将其作为输出:[32;1mTest.我相信这是因为ANSI转义编码不打算在MacOS(仅Linux)上使用.

具体地说,我正在寻找一种方法,可以在 Mac 上使用printf或其他将文本打印到控制台的方法输出到控制台. (甚至有可能吗?...)

随时根据需要询问其他信息.

解决方案

XCode的默认内部控制台不是终端,因此它不解释转义码.结果,您看不到粗体/颜色更改的效果.

在XCode 8上,有一个选项可以编辑方案以使程序在终端中运行.单击停止按钮右侧的弹出窗口,然后选择编辑方案..."

弹出编辑方案"屏幕后,选择options,然后选择在终端中运行".

如果您只是想让它从终端运行;您可以单独启动终端,然后将二进制文件从项目导航器的产品"部分拖放到终端中(它将在终端中打印出二进制文件的完整路径,您可以从那里运行它.)/p>

彩色表情符号确实可以在控制台上正确显示;只是因为它不遵守颜色转义代码.

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.

解决方案

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.

这篇关于将粗体文本输出到C控制台(在Mac上-Xcode)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆