From fa96d1b42d9d74fcd0565eef435e1a308eb2a6e6 Mon Sep 17 00:00:00 2001 From: Nikita Nemkin Date: Tue, 11 Mar 2025 15:58:16 +0500 Subject: [PATCH] ccmake: Show the cursor only when in text editing mode Additionally, stretch the current row highlight to cover the whole left column. Fixes: #4025 --- .../cmCursesCacheEntryComposite.cxx | 6 ++--- Source/CursesDialog/cmCursesMainForm.cxx | 22 ++++++++++++++----- Source/CursesDialog/cmCursesMainForm.h | 2 ++ Source/CursesDialog/cmCursesStringWidget.cxx | 14 ++++++++---- Source/CursesDialog/cmCursesStringWidget.h | 2 +- 5 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx index 557d32c2ee..056982177a 100644 --- a/Source/CursesDialog/cmCursesCacheEntryComposite.cxx +++ b/Source/CursesDialog/cmCursesCacheEntryComposite.cxx @@ -29,7 +29,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( { this->Label = cm::make_unique(this->LabelWidth, 1, 1, 1, key); - this->IsNewLabel = cm::make_unique(1, 1, 1, 1, " "); + this->IsNewLabel = cm::make_unique(3, 1, 1, 1, " "); this->Entry = cm::make_unique(this->EntryWidth, 1, 1, 1); } @@ -44,9 +44,9 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite( this->Label = cm::make_unique(this->LabelWidth, 1, 1, 1, key); if (isNew) { - this->IsNewLabel = cm::make_unique(1, 1, 1, 1, "*"); + this->IsNewLabel = cm::make_unique(3, 1, 1, 1, " * "); } else { - this->IsNewLabel = cm::make_unique(1, 1, 1, 1, " "); + this->IsNewLabel = cm::make_unique(3, 1, 1, 1, " "); } cmValue value = state->GetCacheEntryValue(key); diff --git a/Source/CursesDialog/cmCursesMainForm.cxx b/Source/CursesDialog/cmCursesMainForm.cxx index cd42fb2d9b..7b223dc21a 100644 --- a/Source/CursesDialog/cmCursesMainForm.cxx +++ b/Source/CursesDialog/cmCursesMainForm.cxx @@ -72,6 +72,9 @@ bool cmCursesMainForm::LookForCacheEntry(std::string const& key) // Create new cmCursesCacheEntryComposite entries from the cache void cmCursesMainForm::InitializeUI() { + // Hide the cursor by default + curs_set(0); + // Create a vector of cmCursesCacheEntryComposite's // which contain labels, entries and new entry markers std::vector newEntries; @@ -271,7 +274,7 @@ void cmCursesMainForm::Render(int left, int top, int width, int height) this->NumberOfPages++; } entry.Label->Move(left, top + row - 1, isNewPage); - entry.IsNewLabel->Move(left + 32, top + row - 1, false); + entry.IsNewLabel->Move(left + 30, top + row - 1, false); entry.Entry->Move(left + 33, top + row - 1, false); entry.Entry->SetPage(this->NumberOfPages); i++; @@ -424,8 +427,11 @@ void cmCursesMainForm::UpdateStatusBar(cm::optional message) // Fields are grouped by 3, the first one being the label // so start at 0 and move up by 3 avoiding the last null entry for (size_type index = 0; index < this->Fields.size() - 1; index += 3) { - bool currentLabel = index == currentLabelIndex; - set_field_fore(this->Fields[index], currentLabel ? A_STANDOUT : A_NORMAL); + int attr = (index == currentLabelIndex) ? A_STANDOUT : A_NORMAL; + set_field_fore(this->Fields[index], attr); + set_field_back(this->Fields[index], attr); + set_field_fore(this->Fields[index + 1], attr); + set_field_back(this->Fields[index + 1], attr); } // Display CMake version under the status bar @@ -658,6 +664,12 @@ void cmCursesMainForm::FixValue(cmStateEnums::CacheEntryType type, } } +void cmCursesMainForm::SetSearchMode(bool enable) +{ + this->SearchMode = enable; + curs_set(enable); +} + void cmCursesMainForm::HandleInput() { int x = 0; @@ -710,7 +722,7 @@ void cmCursesMainForm::HandleInput() if (this->SearchMode) { if (key == 10 || key == KEY_ENTER) { - this->SearchMode = false; + this->SetSearchMode(false); if (!this->SearchString.empty()) { this->JumpToCacheEntry(this->SearchString.c_str()); this->OldSearchString = this->SearchString; @@ -865,7 +877,7 @@ void cmCursesMainForm::HandleInput() CurrentForm = this; this->Render(1, 1, x, y); } else if (key == '/') { - this->SearchMode = true; + this->SetSearchMode(true); this->UpdateStatusBar("Search"); this->PrintKeys(1); touchwin(stdscr); diff --git a/Source/CursesDialog/cmCursesMainForm.h b/Source/CursesDialog/cmCursesMainForm.h index d92b6c25f1..d7695b7d41 100644 --- a/Source/CursesDialog/cmCursesMainForm.h +++ b/Source/CursesDialog/cmCursesMainForm.h @@ -63,6 +63,8 @@ public: MAX_WIDTH = 512 }; + void SetSearchMode(bool enable); + /** * This method should normally be called only by the form. The only * exception is during a resize. The optional argument specifies the diff --git a/Source/CursesDialog/cmCursesStringWidget.cxx b/Source/CursesDialog/cmCursesStringWidget.cxx index d472236469..eb801ca826 100644 --- a/Source/CursesDialog/cmCursesStringWidget.cxx +++ b/Source/CursesDialog/cmCursesStringWidget.cxx @@ -32,6 +32,12 @@ cmCursesStringWidget::cmCursesStringWidget(int width, int height, int left, field_opts_off(this->Field, O_STATIC); } +void cmCursesStringWidget::SetInEdit(bool inedit) +{ + this->InEdit = inedit; + curs_set(inedit); +} + void cmCursesStringWidget::OnTab(cmCursesMainForm* /*unused*/, WINDOW* /*unused*/) { @@ -42,7 +48,7 @@ void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW* /*unused*/) { if (this->InEdit) { cmCursesForm::LogMessage("String widget leaving edit."); - this->InEdit = false; + this->SetInEdit(false); fm->PrintKeys(); this->OriginalString.clear(); // trick to force forms to update the field buffer @@ -52,7 +58,7 @@ void cmCursesStringWidget::OnReturn(cmCursesMainForm* fm, WINDOW* /*unused*/) this->Done = true; } else { cmCursesForm::LogMessage("String widget entering edit."); - this->InEdit = true; + this->SetInEdit(true); fm->PrintKeys(); this->OriginalString = field_buffer(this->Field, 0); } @@ -114,7 +120,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, } else if (key == KEY_DOWN || key == ctrl('n') || key == KEY_UP || key == ctrl('p') || key == KEY_NPAGE || key == ctrl('d') || key == KEY_PPAGE || key == ctrl('u')) { - this->InEdit = false; + this->SetInEdit(false); this->OriginalString.clear(); // trick to force forms to update the field buffer form_driver(form, REQ_NEXT_FIELD); @@ -124,7 +130,7 @@ bool cmCursesStringWidget::HandleInput(int& key, cmCursesMainForm* fm, // esc else if (key == 27) { if (this->InEdit) { - this->InEdit = false; + this->SetInEdit(false); fm->PrintKeys(); this->SetString(this->OriginalString); this->OriginalString.clear(); diff --git a/Source/CursesDialog/cmCursesStringWidget.h b/Source/CursesDialog/cmCursesStringWidget.h index 6d94369c30..e0ee89709b 100644 --- a/Source/CursesDialog/cmCursesStringWidget.h +++ b/Source/CursesDialog/cmCursesStringWidget.h @@ -40,7 +40,7 @@ public: * Set/Get InEdit flag. Can be used to tell the widget to leave * edit mode (in case of a resize for example). */ - void SetInEdit(bool inedit) { this->InEdit = inedit; } + void SetInEdit(bool inedit); bool GetInEdit() { return this->InEdit; } /**