Print the key of the current entry and the CMake version on the status bar. Designed for a width of 80 chars.
| 365 | // Print the key of the current entry and the CMake version |
| 366 | // on the status bar. Designed for a width of 80 chars. |
| 367 | void cmCursesMainForm::UpdateStatusBar(cm::optional<std::string> message) |
| 368 | { |
| 369 | int x; |
| 370 | int y; |
| 371 | getmaxyx(stdscr, y, x); |
| 372 | // If window size is too small, display error and return |
| 373 | if (x < cmCursesMainForm::MIN_WIDTH || x < this->InitialWidth || |
| 374 | y < cmCursesMainForm::MIN_HEIGHT) { |
| 375 | clear(); |
| 376 | move(0, 0); |
| 377 | char fmt[] = "Window is too small. A size of at least %dx%d is required."; |
| 378 | printw(fmt, |
| 379 | (cmCursesMainForm::MIN_WIDTH < this->InitialWidth |
| 380 | ? this->InitialWidth |
| 381 | : cmCursesMainForm::MIN_WIDTH), |
| 382 | cmCursesMainForm::MIN_HEIGHT); |
| 383 | touchwin(stdscr); |
| 384 | wrefresh(stdscr); |
| 385 | return; |
| 386 | } |
| 387 | |
| 388 | // Find the current label index |
| 389 | // Field are grouped by 3, the label should be 2 less than the current index |
| 390 | using size_type = decltype(this->Fields)::size_type; |
| 391 | size_type currentLabelIndex = field_index(current_field(this->Form)) - 2; |
| 392 | |
| 393 | // Use the status message if any, otherwise join the key and help string |
| 394 | std::string bar; |
| 395 | if (message) { |
| 396 | bar = *message; |
| 397 | } else { |
| 398 | // Get the key of the current entry |
| 399 | cmCursesWidget* labelWidget = reinterpret_cast<cmCursesWidget*>( |
| 400 | field_userptr(this->Fields[currentLabelIndex])); |
| 401 | std::string labelValue = labelWidget->GetValue(); |
| 402 | bar = labelValue + ": "; |
| 403 | |
| 404 | // Get the help string of the current entry |
| 405 | // and add it to the help string |
| 406 | auto* cmakeState = this->CMakeInstance->GetState(); |
| 407 | cmValue existingValue = cmakeState->GetCacheEntryValue(labelValue); |
| 408 | if (existingValue) { |
| 409 | cmValue help = |
| 410 | cmakeState->GetCacheEntryProperty(labelValue, "HELPSTRING"); |
| 411 | if (help) { |
| 412 | bar += *help; |
| 413 | } |
| 414 | } |
| 415 | } |
| 416 | // Pad with spaces to erase any previous text, |
| 417 | // or truncate as necessary to fit the screen |
| 418 | bar.resize(x, ' '); |
| 419 | move(y - 5, 0); |
| 420 | attron(A_STANDOUT); |
| 421 | char fmt_s[] = "%s"; |
| 422 | printw(fmt_s, bar.c_str()); |
| 423 | attroff(A_STANDOUT); |
| 424 |
no test coverage detected