Browse Source

ccmake: Show the cursor only when in text editing mode

Additionally, stretch the current row highlight to cover the whole
left column.

Fixes: #4025
Nikita Nemkin 8 months ago
parent
commit
fa96d1b42d

+ 3 - 3
Source/CursesDialog/cmCursesCacheEntryComposite.cxx

@@ -29,7 +29,7 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
 {
   this->Label =
     cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key);
-  this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " ");
+  this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(3, 1, 1, 1, "   ");
   this->Entry =
     cm::make_unique<cmCursesStringWidget>(this->EntryWidth, 1, 1, 1);
 }
@@ -44,9 +44,9 @@ cmCursesCacheEntryComposite::cmCursesCacheEntryComposite(
   this->Label =
     cm::make_unique<cmCursesLabelWidget>(this->LabelWidth, 1, 1, 1, key);
   if (isNew) {
-    this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, "*");
+    this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(3, 1, 1, 1, " * ");
   } else {
-    this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(1, 1, 1, 1, " ");
+    this->IsNewLabel = cm::make_unique<cmCursesLabelWidget>(3, 1, 1, 1, "   ");
   }
 
   cmValue value = state->GetCacheEntryValue(key);

+ 17 - 5
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<cmCursesCacheEntryComposite> 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<std::string> 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);

+ 2 - 0
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

+ 10 - 4
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();

+ 1 - 1
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; }
 
   /**