Bold text through C++ write statement

懵懂的女人 提交于 2019-12-01 12:21:04

Consider using using something like VT100 escape sequences. Since your server is telnet based the user is likely to have a client that supports various terminal modes.

For instance if you wanted to turn on bold for a VT100 terminal you would output

ESC[1m

where "ESC" is the character value 0x1b. To switch back to normal formatting output

ESC[0m

To use this in your application you can change the example lines from your question to the following.

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

There other terminal modes such as VT52, VT220, etc. You might want to look into using ncurses although it might be a bit heavy if all you need is simple bold on/off.

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