aligrudi / neatvi

A small vi/ex editor for editing bidirectional UTF-8 text

Home Page:http://litcave.rudi.ir/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Keep status line background white when nohl is set

lobre opened this issue · comments

When you have syntax highlighting disabled with set nohl, it is really hard to distinguish the separation between splits, because the statusline background (which is white by default) is removed.

I understand that setting set nohl means removing colors, but I would argue that keeping at least this white background on the statusline would give a better experience.

Thank you this is cleaner in terms of separation.

However, not sure how I feel about this because while the background is white (as desired), the line foreground is still "colored". Seeing the code and the change you made, I am not sure it is as trivial as I thought.

But ideally, when I set nohl, I would like to avoid "colors". So I was thinking that without hl, the background would keep white (to continue having this clean separation), but the foreground would stay all-black.

Do you know if this is easily doable without too much refactoring?

Thank you again, your small vi editor is really interesting in terms of codebase and outcome. It is a pleasure to hack around! Great project to get inspired.

You may edit conf.h for that. See the "---" and "-ex" patterns in highlights array.

Yeah, I saw that and understand overall that neatvi was meant to be hacked directly in the source code. And this is nice in some way to have such a simple codebase so that this is possible.

However, in the long run, I am not sure I am in favor of maintaining my fork or patches of neatvi. I see neatvi is already packaged here and there (for instance in Alpine apk). And I just enjoy using tools are they are, without having to clone and rebuild my tools when possible.

So while I understand that it is doable (and in a simple way), I think I will prefer staying with the default experience even if it means I have some small personal inconsistencies. And it is also why I am trying to get a grasp of neatvi and try to bring feedback so that I can hopefully contribute to having it evolve into a good enough default xp.

And this is also why I am not really into syntax highlighting. For each new language, this will require tweaking. And to me, the burden of creating and maintaining it is not worth it. I prefer to disable it and learn to not bother not having it. I guess it pays in the long run.

I saw in other issues also the resistance to creating a configuration file. This is great also in some way. It keeps the soft simple and encourages hacking. But same, if I could avoid having to rebuild and just drop a small configuration file in my dotfiles, I see this as a good tradeoff.

Anyway, to come back to the issue, I still find it weird that even saying: I set nohl so I don't want syntax highlighting, I still have this status line highlighted (ツ)_/¯

When I do have colors enabled (set hl), the statusline background (which is white) is very close to the foreground of ex commands.

image

While when I do (^g), the filename is colored with darker variants, so it is fine.

image

I know colors can be changed in conf.h, but I think the default color for this foreground might not be ideal, especially because I use a terminal palette which is pretty standard (close to default 16 ansi colors). So I guess I might not be the only one having the pb.

image

Yes, it is way better with this patch. Does this patch work both for light and dark terminal themes?

It's not as pretty as the first patch.

image

I cannot read what is in the unfocused (bottom one) status line. Also, the grey is not as "pretty", and I am not a fan of this yellow for the command line.

I would personally prefer not to change the color of the statusline whether is it focused or not (same as in nvi). It keeps the colors simple.

Something like the following.

diff --git a/conf.h b/conf.h
index 7b73252..2289db3 100644
--- a/conf.h
+++ b/conf.h
@@ -34,8 +34,8 @@ static struct highlight {
        /* status bar */
        {"---", {SYN_BGMK(7) | 8 | SYN_BD, 4, 1}, "^(\".*\").*(\\[[wr]\\]).*$"},
        {"---", {SYN_BGMK(7) | 8 | SYN_BD, 4, 4}, "^(\".*\").*=.*(L[0-9]+) +(C[0-9]+).*$"},
-       {"---", {SYN_BGMK(8) | 0 | SYN_BD, 4, 4}, "^(\".*\").*-.*(L[0-9]+) +(C[0-9]+).*$"},
-       {"---", {SYN_BGMK(7) | SYN_BD}, ".*$\n?"},
+       {"---", {SYN_BGMK(7) | 8 | SYN_BD, 4, 4}, "^(\".*\").*-.*(L[0-9]+) +(C[0-9]+).*$"},
+       {"---", {SYN_BGMK(7) | 8 | SYN_BD}, ".*$\n?"},
        /* ex mode */
        {"-ex", {SYN_BGMK(7) | SYN_BD}, ":.*$\n?"},
        {"-ex", {SYN_BGMK(7) | SYN_BD}, "\\[.*$\n?"},

What do you think?

Also, now when the statusline is empty, it stays with white background. It is odd.

image

Do you think there can be a way to keep it the same color as the background when nothing it printed on that line? So that it becomes (as before):

image

If not possible, I think I would prefer anyway to have the current filename always printed on that line instead of a blank white space. Like the patch you proposed in another issue (even if it might require more rendering).

diff --git a/vi.c b/vi.c
index f1f51d2..1d332cf 100644
--- a/vi.c
+++ b/vi.c
@@ -1278,7 +1278,6 @@ static void vi(void)
                int otop = xtop;
                int oleft = xleft;
                int orow = xrow;
-               char *opath = ex_path();        /* do not dereference; to detect buffer changes */
                int mv, n;
                term_cmd(&n);
                vi_arg2 = 0;
@@ -1640,7 +1639,7 @@ static void vi(void)
                        if (msg[0])
                                strcpy(vi_msg, msg);
                }
-               if (!vi_msg[0] && (w_cnt > 1 || opath != ex_path()))
+               if (!vi_msg[0])
                        vc_status();
                if (mod || xleft != oleft) {
                        vi_drawagain(xcol, mod == 2 && xleft == oleft && xrow == orow);

image

I disabled bold text entirely and same issue.

And for the empty white statusline, I changed my colors for 7 and 15 to completely other colors (purple and brown), and the statusline seems to stay empty with a purple background (so it seems to be painted with color7).

image

It is still weird. Though, going down the route of choosing only 8 colors can be nice as the default so that even people with few colors would have a good native xp.

I am trying to come up with a patch that could make sense, but I realize that I don't manage to find the "background color". When I use 0, it uses the terminal foreground color, but I do not find a way to either choose the terminal background color, or not use any color at all.

Do you know if there is a way to do this?

Thanks for explaining this. There is still something that I don't get though.

I will use this back script as reference to show the 16 ansi colors. On top of that, there is also the default background, default foreground, or the possibility to apply reverse. But I am not talking about that here. Just the first 16 ansi colors.

$ cat ./colors.sh 
#!/bin/bash

for i in {0..15}; do
    printf "\e[38;5;${i}mColor %02d\e[0m\t" $i
    printf "\e[48;5;${i}m   \e[0m\n"
done

See the result in my terminal.

image

And I would like to have a statusline that is white, using color 7, and using the black which is color 0 (we don't see it clearly on my screenshot as my color 0 is lighter but close to the background). But it seems it does not apply this black as foreground. Instead, it uses the default foreground of the terminal.

...
{"---", {SYN_BGMK(7) | 0}, ".*$\n?"}
...

Do you know why? Is there a way to apply color 0 as the foreground of my statusline?

Thank you. I need to think more about this, but I feel that neatvi it trying to do too much in terms of colors for the statusline. The out of the box xp for me is not good (at least with my colors). See with latest version how it looks like for both single and dual windows.

When I open neatvi, I do have:

image

Then, if I do ^D:

image

Then if I split:

image

I do have a rather normal dark terminal palette more or less following base ANSI colors. Either I see an empty bar that visually takes space, or I have two windows and I cannot realize which one is the current pane between the black or white panel.

I think colors should be really minimal so that the default experience is super simple, and then if people want to do fancy stuff, they can opt-in as they can modify conf.h. And it should work both for dark and light terminal colors, and be clean whatever the value of set hl/set nohl.

As an example, take nvi which follows this principle of having simple defaults. Only black and white are used, and in a consistent and ergonomic manner.

When I open it, I do have:

image

If I type a command:

image

If I scroll (^D), it stays as the first screenshot, keeping the ruler in the middle and the command mode at the bottom right (in nvi, the ruler can be disabled in config so avoids having to re-render it when disabled I guess).

Now if I split in 2 windows, it needs a way to show the user that there are two panes, and so reverses the background and foreground:

image

You can clearly see which pane is active (as it contains the full bar):

image

And here is what happens if I try to enter a command while in dual-window mode:

image

And here are a few screenshots with a light terminal theme. The colors reverse and one can still understand what happens easily.

Normal:

image

Command:

image

Two windows:

image

Two windows with command:

image

What do you think about it?

Thanks for the guidance. Your first solution is not that bad. But I think removing the background color when the statusline is empty makes it prettier.

diff --git a/conf.h b/conf.h                                                                                                                               │*** use it for notes or open a file buffer with the :edit command ***
index 1f8fe0d..d5534f3 100644                                                                                                                              │~
--- a/conf.h                                                                                                                                               │~
+++ b/conf.h                                                                                                                                               │~
@@ -47,10 +47,10 @@ static struct highlight {                                                                                                              │~
        int end;                /* the group ending this pattern */                                                                                        │~
 } highlights[] = {                                                                                                                                        │~
        /* status bar */                                                                                                                                   │~
-       {"---", {SYN_BGMK(0) | 7 | SYN_BD, 3, 1}, "^(\".*\").*(\\[[wr]\\]).*$"},                                                                           │~
-       {"---", {SYN_BGMK(0) | 7 | SYN_BD, 3, 5, 7}, "^(\".*\").*=.*(L[0-9]+) +(C[0-9]+).*$"},                                                             │~
-       {"---", {SYN_BGMK(7) | 6}, "^(\".*\").*-.*(L[0-9]+) +(C[0-9]+).*$"},                                                                               │~
-       {"---", {SYN_BGMK(0) | 3 | SYN_BD}, ".*$\n?"},                                                                                                     │~
+       {"---", {SYN_BGMK(0) | 7 | SYN_BD, 3, 1}, "^(\".*\").*(\\[[wr]\\]).*$"}, // single window                                                          │~
+       {"---", {SYN_BGMK(0) | 7 | SYN_BD, 3, 5, 7}, "^(\".*\").*=.*(L[0-9]+) +(C[0-9]+).*$"}, // split active                                             │~
+       {"---", {SYN_BGMK(0) | 7}, "^(\".*\").*-.*(L[0-9]+) +(C[0-9]+).*$"}, // split inactive                                                             │~
+       {"---", {7}, ".*$\n?"}, // single window split                                                                                                     │~
        /* ex mode */                                                                                                                                      │~
        {"-ex", {SYN_BGMK(0) | 7 | SYN_BD}, ":.*$\n?"},                                                                                                    │~
        {"-ex", {SYN_BGMK(0) | 7 | SYN_BD}, "\\[.*$\n?"},

Also, I do prefer when bold is used sparingly, so I think that commands should not be bold.

This patch looks better to me as the native xp is improved already.

The last problem I see is that there is no possibility to remove this white background when set nohl is defined, and when the statusline is empty (for single window). Not sure what can be done here...

image

I think I can use the last line instead of adding one more (sorry my last post was a broken patch):

diff --git a/conf.h b/conf.h
index 1f8fe0d..6b40a02 100644
--- a/conf.h
+++ b/conf.h
@@ -49,8 +49,8 @@ static struct highlight {
 	/* status bar */
 	{"---", {SYN_BGMK(0) | 7 | SYN_BD, 3, 1}, "^(\".*\").*(\\[[wr]\\]).*$"},
 	{"---", {SYN_BGMK(0) | 7 | SYN_BD, 3, 5, 7}, "^(\".*\").*=.*(L[0-9]+) +(C[0-9]+).*$"},
-	{"---", {SYN_BGMK(7) | 6}, "^(\".*\").*-.*(L[0-9]+) +(C[0-9]+).*$"},
-	{"---", {SYN_BGMK(0) | 3 | SYN_BD}, ".*$\n?"},
+	{"---", {SYN_BGMK(0) | 7}, "^(\".*\").*-.*(L[0-9]+) +(C[0-9]+).*$"},
+	{"---", {0}, ".*$\n?"},
 	/* ex mode */
 	{"-ex", {SYN_BGMK(0) | 7 | SYN_BD}, ":.*$\n?"},
 	{"-ex", {SYN_BGMK(0) | 7 | SYN_BD}, "\\[.*$\n?"},

So {"---", {0}, ".*$\n?"}, matches and allows removing the background when the window is scrolled.

To me, this patch makes neatvi consistent. Not sure how it reacts for you, but I also tested with a light theme and it also seems fine.

For set nohl, since this commit, the reverse is hard coded, so it seems there is nothing I can do to put the same color as the background when scrolled. Do you have an idea?

I am not sure I prefer cyan (6) over green (2). Green is fine with me.

Here is a patch that I quite like.

diff --git a/conf.h b/conf.h
index 6dec2d0..1128ae5 100644
--- a/conf.h
+++ b/conf.h
@@ -49,8 +49,8 @@ static struct highlight {
        /* status bar */
        {"---", {SYN_BGMK(0) | 7 | SYN_BD, 2, 1}, "^(\".*\").*(\\[[wr]\\]).*$"},
        {"---", {SYN_BGMK(0) | 7 | SYN_BD, 2, 5, 7}, "^(\".*\").*=.*(L[0-9]+) +(C[0-9]+).*$"},
-       {"---", {SYN_BGMK(0) | 7}, "^(\".*\").*-.*(L[0-9]+) +(C[0-9]+).*$"},
-       {"---", {SYN_BGMK(0) | 2 | SYN_BD}, ".*$"},
+       {"---", {SYN_BGMK(0) | 7, 2, 5, 7}, "^(\".*\").*-.*(L[0-9]+) +(C[0-9]+).*$"},
+       {"---", {SYN_BGMK(0) | 7}, ".*$"},
        /* ex mode */
        {"-ex", {SYN_BGMK(0) | 7 | SYN_BD}, ":.*$"},
        {"-ex", {SYN_BGMK(0) | 7 | SYN_BD}, "\\[.*$"},
diff --git a/vi.c b/vi.c
index e1ddb2a..c0a205a 100644
--- a/vi.c
+++ b/vi.c
@@ -1640,7 +1640,7 @@ static void vi(void)
                        if (msg[0])
                                strcpy(vi_msg, msg);
                }
-               if (!vi_msg[0] && (w_cnt > 1 || opath != ex_path()))
+               if (!vi_msg[0] && (w_cnt > 1 || opath != ex_path() || !xhl))
                        vc_status();
                if (mod || xleft != oleft) {
                        vi_drawagain(xcol, mod == 2 && xleft == oleft && xrow == orow);

It does multiple things:

  1. It uses the same colors for active and inactive status lines, and the active one is just bold. I think that defining a primary element over a secondary does not need a change of both thickness and color. It is too distracting to the eye, and I checked with other vi-likes, including neovim, and they only change one parameter to differentiate.
  2. It removes bold for the command prompt. I still find it weird to type my user commands in bold (maybe you don't share the same feeling).
  3. It refreshes the status line more often when nohl is set. I think it can be a good middle ground to avoid this white empty line (which is to me visually drawing attention to empty information).

What do you think?

Since the last few commits, the current state is satisfying to me.

As a reminder, when set nohl is enabled, the statusline will be in reverse color mode. And otherwise, the statusline has enough foreground/background contrast. We also clearly differentiate which split is active. And the used colors are ANSI 0-7 to work on almost all terminal emulators. Also, has the ruler option has been added, we don't want any custom background color of this statusline when it is empty. It means the code is more consistent as there is no need to have a custom behavior here.

@aligrudi, do you have anything else to add, or should I close this issue?