MCPcopy Create free account
hub / github.com/duckdb/duckdb / PrintText

Method PrintText

tools/shell/shell_highlight.cpp:76–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74}
75
76void ShellHighlight::PrintText(const string &text, PrintOutput output, PrintColor color, PrintIntensity intensity) {
77 if ((color == PrintColor::STANDARD && intensity == PrintIntensity::STANDARD) || !IsEnabled()) {
78 // no highlighting - print directly
79 state.Print(output, text);
80 return;
81 }
82#ifdef _WIN32
83 HANDLE out = GetStdHandle(output == PrintOutput::STDOUT ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
84 bool use_terminal_codes = false;
85 DWORD mode = 0;
86 if (GetConsoleMode(out, &mode)) {
87 if (mode & ENABLE_VIRTUAL_TERMINAL_PROCESSING) {
88 // terminal codes are supported - use them!
89 use_terminal_codes = true;
90 }
91 }
92 if (!use_terminal_codes) {
93 // terminal codes are not supported - use standard 4-bit colors
94 CONSOLE_SCREEN_BUFFER_INFO defaultScreenInfo;
95 GetConsoleScreenBufferInfo(out, &defaultScreenInfo);
96 WORD wAttributes = 0;
97
98 switch (intensity) {
99 case PrintIntensity::BOLD:
100 case PrintIntensity::BOLD_UNDERLINE:
101 wAttributes |= FOREGROUND_INTENSITY;
102 break;
103 default:
104 break;
105 }
106 switch (color) {
107 case PrintColor::RED:
108 wAttributes |= FOREGROUND_RED;
109 break;
110 case PrintColor::GREEN:
111 wAttributes |= FOREGROUND_GREEN;
112 break;
113 case PrintColor::BLUE:
114 wAttributes |= FOREGROUND_BLUE;
115 break;
116 case PrintColor::YELLOW:
117 wAttributes |= FOREGROUND_RED | FOREGROUND_GREEN;
118 break;
119 case PrintColor::GRAY:
120 wAttributes |= FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE;
121 break;
122 case PrintColor::MAGENTA:
123 wAttributes |= FOREGROUND_BLUE | FOREGROUND_RED;
124 break;
125 case PrintColor::CYAN:
126 wAttributes |= FOREGROUND_BLUE | FOREGROUND_GREEN;
127 break;
128 case PrintColor::WHITE:
129 wAttributes |= FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
130 break;
131 default:
132 break;
133 }

Callers 11

RenderLineMethod · 0.45
RenderLineDisplayFunction · 0.45
RenderTableMetadataMethod · 0.45
ShowHelpFunction · 0.45
SetStartupTextFunction · 0.45
DisplayColorsFunction · 0.45
PrintHelpMethod · 0.45
ProcessInputMethod · 0.45
RunShellFunction · 0.45
PrintUsageMethod · 0.45
PrintPromptMethod · 0.45

Calls 2

PrintMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected