| 192 | } |
| 193 | |
| 194 | void ShellProgressBarDisplay::PrintProgressInternal(int32_t percentage, double estimated_remaining_seconds, |
| 195 | bool is_finished) { |
| 196 | auto terminal_width = Printer::TerminalWidth(); |
| 197 | string result; |
| 198 | if (previous_terminal_width.IsValid() && terminal_width < previous_terminal_width.GetIndex()) { |
| 199 | // terminal size got smaller - need to erase more lines |
| 200 | idx_t line_count = (previous_terminal_width.GetIndex() + terminal_width - 1) / terminal_width; |
| 201 | D_ASSERT(line_count > 1); |
| 202 | |
| 203 | for (idx_t i = 1; i < line_count; i++) { |
| 204 | // go up + clear line until we reach the first line again |
| 205 | result += "\r\x1b[0K\x1b[1A"; |
| 206 | } |
| 207 | } |
| 208 | // clear the current line |
| 209 | result += "\r\x1b[0K"; |
| 210 | previous_terminal_width = terminal_width; |
| 211 | if (!is_finished) { |
| 212 | auto &state = ShellState::Get(); |
| 213 | try { |
| 214 | state.progress_bar->percentage = percentage; |
| 215 | state.progress_bar->estimated_remaining_seconds = estimated_remaining_seconds; |
| 216 | result += state.progress_bar->GenerateProgressBar(state, terminal_width); |
| 217 | } catch (std::exception &ex) { |
| 218 | ErrorData error(ex); |
| 219 | result += error.Message(); |
| 220 | } |
| 221 | state.progress_bar->connection.reset(); |
| 222 | } |
| 223 | Printer::RawPrint(OutputStream::STREAM_STDOUT, result); |
| 224 | } |
| 225 | |
| 226 | } // namespace duckdb_shell |
nothing calls this directly
no test coverage detected