Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Whitespace color support #66

Open
joric opened this issue May 29, 2022 · 2 comments
Open

Whitespace color support #66

joric opened this issue May 29, 2022 · 2 comments

Comments

@joric
Copy link

joric commented May 29, 2022

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;
@joric joric closed this as completed Apr 8, 2023
@ctapmex
Copy link
Member

ctapmex commented Feb 17, 2024

для изучения
https://forum.farmanager.com/viewtopic.php?p=170695#p170695

@ctapmex ctapmex reopened this Feb 17, 2024
@joric
Copy link
Author

joric commented Apr 30, 2024

As it was reopened, just wanted to say that I actually use this patch in 16-color mode, because the text color is too bright. See how it looks in 16 colors here https://github.com/joric/monokai.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants