粗体字通过C ++写的语句(Bold text through C++ write statemen

2019-09-03 18:13发布

我正在通过telnet字典服务器上,我想它在这个格式返回它:

  **word** (wordType): wordDef wordDef wordDef wordDef
wordDef wordDef wordDef.

现在,我输出使用的代码:

write( my_socket, ("%s", word.data()    ), word.length()    ); // Bold this
write( my_socket, ("%s", theRest.data() ), theRest.length() );

所以我想这第一线被加粗。

编辑

对不起,我忘了提,这是一个命令行。

Answer 1:

请考虑使用像使用VT100转义序列 。 因为你的服务器是基于Telnet的用户可能拥有支持各种终端模式的客户端。

例如,如果你想打开粗体VT100终端你会输出

ESC[1m

其中,“ESC”就是人品值0x1b。 切换回正常的格式输出

ESC[0m

要在应用程序中使用这个,你可以从你的问题下面的示例行更改。

std::string str = "Hello!"
write( my_socket, "\x1b[1m", 4); // Turn on bold formatting
write( my_socket, str.c_str(), str.size()); // output string
write( my_socket, "\x1b[0m", 4); // Turn all formatting off

还有其他的终端模式,如VT52,VT220,等等。你可能要考虑使用ncurses的 ,虽然它可能是一个有点沉重,如果你需要的是简单的开/关大胆。



文章来源: Bold text through C++ write statement