Commit 93b66735 authored by Sylvain Joubert's avatar Sylvain Joubert
Browse files

ccmake: Use type-based colors to display cache values

The colors are based on the entry type (or value for booleans),
paths and filepaths sharing the same color.
parent dbd14eca
ccmake-colored-values
---------------------
* :manual:`ccmake(1)` now displays cache values using colors
based on the entry type if the terminal supports color.
...@@ -5,6 +5,7 @@ add_executable(ccmake ...@@ -5,6 +5,7 @@ add_executable(ccmake
ccmake.cxx ccmake.cxx
cmCursesBoolWidget.cxx cmCursesBoolWidget.cxx
cmCursesCacheEntryComposite.cxx cmCursesCacheEntryComposite.cxx
cmCursesColor.cxx
cmCursesDummyWidget.cxx cmCursesDummyWidget.cxx
cmCursesFilePathWidget.cxx cmCursesFilePathWidget.cxx
cmCursesForm.cxx cmCursesForm.cxx
...@@ -17,21 +18,41 @@ add_executable(ccmake ...@@ -17,21 +18,41 @@ add_executable(ccmake
cmCursesWidget.cxx cmCursesWidget.cxx
) )
target_include_directories(ccmake PRIVATE ${CURSES_INCLUDE_PATH}) target_include_directories(ccmake PRIVATE ${CURSES_INCLUDE_PATH})
set(CMAKE_REQUIRED_INCLUDES ${CURSES_INCLUDE_PATH})
target_link_libraries(ccmake CMakeLib) target_link_libraries(ccmake CMakeLib)
if(CMAKE_USE_SYSTEM_FORM) if(CMAKE_USE_SYSTEM_FORM)
find_path(CURSES_FORM_INCLUDE_DIR NAMES form.h HINTS ${CURSES_INCLUDE_PATH} ${CURSES_INCLUDE_PATH}/ncurses) find_path(CURSES_FORM_INCLUDE_DIR NAMES form.h HINTS ${CURSES_INCLUDE_PATH} ${CURSES_INCLUDE_PATH}/ncurses)
if(CURSES_FORM_INCLUDE_DIR) if(CURSES_FORM_INCLUDE_DIR)
target_include_directories(ccmake PRIVATE ${CURSES_FORM_INCLUDE_DIR}) target_include_directories(ccmake PRIVATE ${CURSES_FORM_INCLUDE_DIR})
list(APPEND CMAKE_REQUIRED_INCLUDES ${CURSES_FORM_INCLUDE_DIR})
endif() endif()
target_link_libraries(ccmake target_link_libraries(ccmake
${CURSES_FORM_LIBRARY} ${CURSES_FORM_LIBRARY}
${CURSES_LIBRARY} ${CURSES_LIBRARY}
) )
set(CMAKE_REQUIRED_LIBRARIES
${CURSES_FORM_LIBRARY}
${CURSES_LIBRARY}
)
if(CURSES_EXTRA_LIBRARY) if(CURSES_EXTRA_LIBRARY)
target_link_libraries(ccmake ${CURSES_EXTRA_LIBRARY}) target_link_libraries(ccmake ${CURSES_EXTRA_LIBRARY})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CURSES_EXTRA_LIBRARY})
endif() endif()
else() else()
target_link_libraries(ccmake cmForm) target_link_libraries(ccmake cmForm)
get_target_property(cmFormIncludeDirs cmForm INTERFACE_INCLUDE_DIRECTORIES)
list(APPEND CMAKE_REQUIRED_INCLUDES ${cmFormIncludeDirs})
get_target_property(cmFormLibraries cmForm INTERFACE_LINK_LIBRARIES)
set(CMAKE_REQUIRED_LIBRARIES ${cmFormLibraries})
endif()
include(CheckSymbolExists)
check_symbol_exists(use_default_colors
"form.h"
HAVE_CURSES_USE_DEFAULT_COLORS)
if(HAVE_CURSES_USE_DEFAULT_COLORS)
set_source_files_properties(cmCursesColor.cxx
PROPERTIES COMPILE_DEFINITIONS HAVE_CURSES_USE_DEFAULT_COLORS)
endif() endif()
if(CMake_JOB_POOL_LINK_BIN) if(CMake_JOB_POOL_LINK_BIN)
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "cmsys/Encoding.hxx" #include "cmsys/Encoding.hxx"
#include "cmCursesColor.h"
#include "cmCursesForm.h" #include "cmCursesForm.h"
#include "cmCursesMainForm.h" #include "cmCursesMainForm.h"
#include "cmCursesStandardIncludes.h" #include "cmCursesStandardIncludes.h"
...@@ -126,6 +127,7 @@ int main(int argc, char const* const* argv) ...@@ -126,6 +127,7 @@ int main(int argc, char const* const* argv)
noecho(); /* Echo off */ noecho(); /* Echo off */
cbreak(); /* nl- or cr not needed */ cbreak(); /* nl- or cr not needed */
keypad(stdscr, true); /* Use key symbols as KEY_DOWN */ keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
cmCursesColor::InitColors();
signal(SIGWINCH, onsig); signal(SIGWINCH, onsig);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <string> #include <string>
#include "cmCursesColor.h"
#include "cmCursesWidget.h" #include "cmCursesWidget.h"
#include "cmStateTypes.h" #include "cmStateTypes.h"
...@@ -12,8 +13,10 @@ cmCursesBoolWidget::cmCursesBoolWidget(int width, int height, int left, ...@@ -12,8 +13,10 @@ cmCursesBoolWidget::cmCursesBoolWidget(int width, int height, int left,
: cmCursesWidget(width, height, left, top) : cmCursesWidget(width, height, left, top)
{ {
this->Type = cmStateEnums::BOOL; this->Type = cmStateEnums::BOOL;
set_field_fore(this->Field, A_NORMAL); if (!cmCursesColor::HasColors()) {
set_field_back(this->Field, A_STANDOUT); set_field_fore(this->Field, A_NORMAL);
set_field_back(this->Field, A_STANDOUT);
}
field_opts_off(this->Field, O_STATIC); field_opts_off(this->Field, O_STATIC);
this->SetValueAsBool(false); this->SetValueAsBool(false);
} }
...@@ -42,8 +45,16 @@ void cmCursesBoolWidget::SetValueAsBool(bool value) ...@@ -42,8 +45,16 @@ void cmCursesBoolWidget::SetValueAsBool(bool value)
{ {
if (value) { if (value) {
this->SetValue("ON"); this->SetValue("ON");
if (cmCursesColor::HasColors()) {
set_field_fore(this->Field, COLOR_PAIR(cmCursesColor::BoolOn));
set_field_back(this->Field, COLOR_PAIR(cmCursesColor::BoolOn));
}
} else { } else {
this->SetValue("OFF"); this->SetValue("OFF");
if (cmCursesColor::HasColors()) {
set_field_fore(this->Field, COLOR_PAIR(cmCursesColor::BoolOff));
set_field_back(this->Field, COLOR_PAIR(cmCursesColor::BoolOff));
}
} }
} }
......
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCursesColor.h"
#include "cmCursesStandardIncludes.h"
bool cmCursesColor::HasColors()
{
#ifdef HAVE_CURSES_USE_DEFAULT_COLORS
return has_colors();
#else
return false;
#endif
}
void cmCursesColor::InitColors()
{
#ifdef HAVE_CURSES_USE_DEFAULT_COLORS
if (HasColors()) {
start_color();
use_default_colors();
init_pair(cmCursesColor::BoolOff, COLOR_RED, -1);
init_pair(cmCursesColor::BoolOn, COLOR_GREEN, -1);
init_pair(cmCursesColor::String, COLOR_BLUE, -1);
init_pair(cmCursesColor::Path, COLOR_YELLOW, -1);
init_pair(cmCursesColor::Options, COLOR_MAGENTA, -1);
}
#endif
}
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#ifndef cmCursesColor_h
#define cmCursesColor_h
class cmCursesColor
{
public:
enum Color
{
// Default color is pair 0
BoolOff = 1,
BoolOn,
String,
Path,
Options
};
static bool HasColors();
static void InitColors();
};
#endif // cmCursesColor_h
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmCursesOptionsWidget.h" #include "cmCursesOptionsWidget.h"
#include "cmCursesColor.h"
#include "cmCursesWidget.h" #include "cmCursesWidget.h"
#include "cmStateTypes.h" #include "cmStateTypes.h"
...@@ -15,8 +16,13 @@ cmCursesOptionsWidget::cmCursesOptionsWidget(int width, int height, int left, ...@@ -15,8 +16,13 @@ cmCursesOptionsWidget::cmCursesOptionsWidget(int width, int height, int left,
// there is no option type, and string type causes ccmake to cast // there is no option type, and string type causes ccmake to cast
// the widget into a string widget at some point. BOOL is safe for // the widget into a string widget at some point. BOOL is safe for
// now. // now.
set_field_fore(this->Field, A_NORMAL); if (cmCursesColor::HasColors()) {
set_field_back(this->Field, A_STANDOUT); set_field_fore(this->Field, COLOR_PAIR(cmCursesColor::Options));
set_field_back(this->Field, COLOR_PAIR(cmCursesColor::Options));
} else {
set_field_fore(this->Field, A_NORMAL);
set_field_back(this->Field, A_STANDOUT);
}
field_opts_off(this->Field, O_STATIC); field_opts_off(this->Field, O_STATIC);
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <vector> #include <vector>
#include "cmCursesColor.h"
#include "cmCursesMainForm.h" #include "cmCursesMainForm.h"
#include "cmCursesStringWidget.h" #include "cmCursesStringWidget.h"
#include "cmStateTypes.h" #include "cmStateTypes.h"
...@@ -16,6 +17,13 @@ cmCursesPathWidget::cmCursesPathWidget(int width, int height, int left, ...@@ -16,6 +17,13 @@ cmCursesPathWidget::cmCursesPathWidget(int width, int height, int left,
this->Type = cmStateEnums::PATH; this->Type = cmStateEnums::PATH;
this->Cycle = false; this->Cycle = false;
this->CurrentIndex = 0; this->CurrentIndex = 0;
if (cmCursesColor::HasColors()) {
set_field_fore(this->Field, COLOR_PAIR(cmCursesColor::Path));
set_field_back(this->Field, COLOR_PAIR(cmCursesColor::Path));
} else {
set_field_fore(this->Field, A_NORMAL);
set_field_back(this->Field, A_STANDOUT);
}
} }
void cmCursesPathWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW* w) void cmCursesPathWidget::OnType(int& key, cmCursesMainForm* fm, WINDOW* w)
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <cstdio> #include <cstdio>
#include "cmCursesColor.h"
#include "cmCursesForm.h" #include "cmCursesForm.h"
#include "cmCursesMainForm.h" #include "cmCursesMainForm.h"
#include "cmCursesStandardIncludes.h" #include "cmCursesStandardIncludes.h"
...@@ -21,8 +22,13 @@ cmCursesStringWidget::cmCursesStringWidget(int width, int height, int left, ...@@ -21,8 +22,13 @@ cmCursesStringWidget::cmCursesStringWidget(int width, int height, int left,
{ {
this->InEdit = false; this->InEdit = false;
this->Type = cmStateEnums::STRING; this->Type = cmStateEnums::STRING;
set_field_fore(this->Field, A_NORMAL); if (cmCursesColor::HasColors()) {
set_field_back(this->Field, A_STANDOUT); set_field_fore(this->Field, COLOR_PAIR(cmCursesColor::String));
set_field_back(this->Field, COLOR_PAIR(cmCursesColor::String));
} else {
set_field_fore(this->Field, A_NORMAL);
set_field_back(this->Field, A_STANDOUT);
}
field_opts_off(this->Field, O_STATIC); field_opts_off(this->Field, O_STATIC);
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment