项目作者: fbdtemme

项目描述 :
A library for ecma-48 control sequences.
高级语言: C++
项目地址: git://github.com/fbdtemme/termcontrol.git
创建时间: 2020-08-08T14:31:59Z
项目社区:https://github.com/fbdtemme/termcontrol

开源协议:

下载


termcontrol

build

A small C++20 library for ANSI control sequences and terminal bits.

Examples

All examples assume namespace tc = termcontrol for brevity.

Generate or print escape codes.

  1. // Generate a control sequence as std::string
  2. std::string erase_page_after = tc::format<tc::def::erase_in_page>(tc::erase_in_page_mode::after);
  3. // Directly print a control sequence to an output stream or output iterator.
  4. tc::format_to<tc::def::erase_in_page>(std::cout, tc::erase_in_page_mode::after);
  5. // Parameters that are specific to a control sequence can be printed without needing to
  6. // specify the control_sequence_definition by using operator<<
  7. std::cout << tc::erase_in_page_mode::after;
  8. // Make cursor invisible
  9. std::cout << tc::def::reset_mode(tc::dec_mode::cursor_visible);

Create compile time control sequences.

  1. constexpr auto move_up_10 = tc::control_sequence<tc::def::cursor_up>(10);
  2. constexpr auto erase_page_after = tc::control_sequence<tc::def::erase_in_page>(tc::erase_in_page_mode::after);

Format styled text.

  1. // underlined with red foregroung
  2. text_style style = em(tc::emphasis::underline) | fg(tc::terminal_color::red);
  3. std::cout << style << "ANSI" << text_style::reset();
  4. // equivalent command without temporaries.
  5. tc::format_to(std::cout, em(tc::emphasis::underline) | fg(tc::terminal_color::red, "Test");

Colors can be specified with predefined color schemes css_color,
x11_color and pwc_color, or as rgb values.

  1. auto style1 = fg(tc::css_color::lightslategray);
  2. auto style2 = fg(tc::x11_color::light_goldenrod_yellow);
  3. auto style3 = fg(tc::pwc_color::light_brown);
  4. auto style4 = fg(tc::rgb(250,250,250))