Skip to content

Whitespace color support #66

@joric

Description

@joric

These patches are OPTIONAL, I don't currently use them because I use 8-bit color for my schemes. But if you use RGB you may notice that whitespace color is "inverted" so it makes sense for RGB.

Whitespace color is buggy in 1.14.15 (uses inverted def:Text color, RGB-BGR), so I've added whitespace color definition (adds def:Whitespace support in hrd schemes). It behaves well both with RGB and console colors but needs patching 2 repositories (Colorer-library and FarColorer) so it's somewhat complicated to merge.

Before (white dots all over the place):

image

After (actually usable):

image

Selection color is a global setting (Options-Colors-Editor), Far doesn't support transparent background at the moment:

image

I strongly vote against hardcoding whitespace as visible on selection only because I like to see if code has bad/mixed indentation right away. There should be 3 options: always visible, visible only on selection, and completely hidden. I.e as in sublime:

// Set to "none" to turn off drawing white space, "selection" to draw only the
// white space within the selection, and "all" to draw all white space
"draw_white_space": "selection",

Far Manager already has it in the UI, it allows three options [_] [?] [x] but it's apparently not implemented.

Using patched colorer you may specify the same background/foreground for the whitespace to appear on selection only. I am not sure about using "transparent" region ("default") from lib/default.hrc, looks like it's not supposed to be customizable.

Patches

Patches below add whitespace (def:Whitespace) color support to HRC schemes. It works both for console and RGB schemes.

You just use a color in hrd, like:

  • <assign name="def:Whitespace" fore="#75715e" back="#272822"/> RGB
  • <assign name="def:Whitespace" fore="#6" back="#8"/> console

Colorer-library uses commit 587599f as in 1.14.15, FarColorer is the latest master (I used e6089fd).

colorer.patch

diff --git a/src/colorer/editor/BaseEditor.cpp b/src/colorer/editor/BaseEditor.cpp
index 4474038..67d19a5 100644
--- a/src/colorer/editor/BaseEditor.cpp
+++ b/src/colorer/editor/BaseEditor.cpp
@@ -47,7 +47,7 @@ BaseEditor::BaseEditor(ParserFactory* parserFactory_, LineSource* lineSource_)
 
   setRegionCompact(regionCompact);
 
-  rd_def_Text = rd_def_HorzCross = rd_def_VertCross = nullptr;
+  rd_def_Text = rd_def_HorzCross = rd_def_VertCross = rd_def_Whitespace = nullptr;
 }
 
 BaseEditor::~BaseEditor()
@@ -103,11 +103,12 @@ void BaseEditor::remapLRS(bool recreate)
   lrSupport->setRegionMapper(regionMapper);
   lrSupport->setSpecialRegion(def_Special);
   invalidLine = 0;
-  rd_def_Text = rd_def_HorzCross = rd_def_VertCross = nullptr;
+  rd_def_Text = rd_def_HorzCross = rd_def_VertCross = rd_def_Whitespace = nullptr;
   if (regionMapper != nullptr) {
     rd_def_Text = regionMapper->getRegionDefine("def:Text");
     rd_def_HorzCross = regionMapper->getRegionDefine("def:HorzCross");
     rd_def_VertCross = regionMapper->getRegionDefine("def:VertCross");
+    rd_def_Whitespace = regionMapper->getRegionDefine("def:Whitespace");
   }
 }
 
diff --git a/src/colorer/editor/BaseEditor.h b/src/colorer/editor/BaseEditor.h
index bd6789e..b34c534 100644
--- a/src/colorer/editor/BaseEditor.h
+++ b/src/colorer/editor/BaseEditor.h
@@ -231,7 +231,7 @@ class BaseEditor : public RegionHandler
   const Region* def_PairEnd;
 
   /** Basic HRC region mapping */
-  const RegionDefine *rd_def_Text, *rd_def_HorzCross, *rd_def_VertCross;
+  const RegionDefine *rd_def_Text, *rd_def_HorzCross, *rd_def_VertCross, *rd_def_Whitespace;
 
   void startParsing(size_t lno) override;
   void endParsing(size_t lno) override;

FarColorer.patch

diff --git a/src/FarEditor.cpp b/src/FarEditor.cpp
index ce7ad6d..718488f 100644
--- a/src/FarEditor.cpp
+++ b/src/FarEditor.cpp
@@ -190,6 +190,7 @@ void FarEditor::setRegionMapper(RegionMapper* rs)
   rdBackground = StyledRegion::cast(baseEditor->rd_def_Text);
   horzCrossColor = convert(StyledRegion::cast(baseEditor->rd_def_HorzCross));
   vertCrossColor = convert(StyledRegion::cast(baseEditor->rd_def_VertCross));
+  whitespaceColor = convert(StyledRegion::cast(baseEditor->rd_def_Whitespace));
 
   if (!horzCrossColor.BackgroundColor && !horzCrossColor.ForegroundColor) {
     horzCrossColor.ForegroundColor = 0xE;
@@ -197,6 +198,9 @@ void FarEditor::setRegionMapper(RegionMapper* rs)
   if (!vertCrossColor.BackgroundColor && !vertCrossColor.ForegroundColor) {
     vertCrossColor.ForegroundColor = 0xE;
   }
+  if (!whitespaceColor.BackgroundColor && !whitespaceColor.ForegroundColor) {
+    whitespaceColor.ForegroundColor = 0xE;
+  }
 }
 
 void FarEditor::matchPair()
@@ -645,8 +649,10 @@ int FarEditor::editorEvent(intptr_t event, void* param)
           }
 
           if (whitespace) {
-            col1.ForegroundColor = rdBackground->fore;
+            col1.ForegroundColor = whitespaceColor.ForegroundColor;
+            col1.BackgroundColor = whitespaceColor.BackgroundColor;
           }
+
           // horizontal cross
           if (lno == ei.CurLine && showHorizontalCross) {
             if (crossZOrder != 0 && !whitespace) {
diff --git a/src/FarEditor.h b/src/FarEditor.h
index a2f1aac..58e00a9 100644
--- a/src/FarEditor.h
+++ b/src/FarEditor.h
@@ -132,6 +132,7 @@ class FarEditor : public LineSource
   int crossZOrder = 0;
   FarColor horzCrossColor{};
   FarColor vertCrossColor{};
+  FarColor whitespaceColor{};
 
   bool drawPairs = true;
   bool drawSyntax = true;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions