23 #include <sys/ioctl.h>
31 const char* term = getenv(
"TERM");
38 setvbuf(stdout, NULL, _IONBF, 0);
39 console_ = GetStdHandle(STD_OUTPUT_HANDLE);
40 CONSOLE_SCREEN_BUFFER_INFO csbi;
47 CONSOLE_SCREEN_BUFFER_INFO csbi;
48 GetConsoleScreenBufferInfo(console_, &csbi);
55 csbi.dwCursorPosition.X = 0;
56 SetConsoleCursorPosition(console_, csbi.dwCursorPosition);
63 size_t width =
static_cast<size_t>(csbi.dwSize.X) - 1;
68 GetConsoleScreenBufferInfo(console_, &csbi);
69 COORD buf_size = { csbi.dwSize.X, 1 };
70 COORD zero_zero = { 0, 0 };
72 csbi.dwCursorPosition.X, csbi.dwCursorPosition.Y,
73 static_cast<SHORT
>(csbi.dwCursorPosition.X + csbi.dwSize.X - 1),
74 csbi.dwCursorPosition.Y
76 CHAR_INFO* char_data =
new CHAR_INFO[csbi.dwSize.X];
77 memset(char_data, 0,
sizeof(CHAR_INFO) * csbi.dwSize.X);
78 for (
int i = 0; i < csbi.dwSize.X; ++i) {
79 char_data[i].Char.AsciiChar =
' ';
80 char_data[i].Attributes = csbi.wAttributes;
82 for (
size_t i = 0; i < to_print.size(); ++i)
83 char_data[i].Char.AsciiChar = to_print[i];
84 WriteConsoleOutput(console_, char_data, buf_size, zero_zero, &target);
90 if ((ioctl(0, TIOCGWINSZ, &size) == 0) && size.ws_col) {
93 printf(
"%s", to_print.c_str());
100 printf(
"%s\n", to_print.c_str());
107 printf(
"%s", to_print.c_str());
bool have_blank_line_
Whether the caret is at the beginning of a blank line.
void PrintOnNewLine(const string &to_print)
Prints a string on a new line, not overprinting previous output.
void Print(string to_print, LineType type)
Overprints the current line.
bool smart_terminal_
Whether we can do fancy terminal control codes.
string ElideMiddle(const string &str, size_t width)
Elide the given string str with '...' in the middle if the length exceeds width.