commit 0741d2520dd7ac9e197dc9b177e8740190b2200b
parent 3c7c824bdc08052239285b0028885fb610d36d41
Author: Sathya Pramodh <94102031+sathya-pramodh@users.noreply.github.com>
Date: Fri, 2 May 2025 18:36:55 +0530
feat(messages): hl-StderrMsg, hl-StdoutMsg #33429
Problem:
stderr messages from executing ":!cmd" show up with
highlight hl-ErrorMsg. But some shell utilites use stderr for debug
logging, progress updates, etc.
Solution:
Highlight shell command outputs hl-StderrMsg and hl-StdoutMsg.
Diffstat:
9 files changed, 22 insertions(+), 12 deletions(-)
diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt
@@ -5205,6 +5205,10 @@ EndOfBuffer Filler lines (~) after the last line in the buffer.
TermCursor Cursor in a focused terminal.
*hl-ErrorMsg*
ErrorMsg Error messages on the command line.
+ *hl-StderrMsg*
+StderrMsg Messages in stderr from shell commands.
+ *hl-StdoutMsg*
+StdoutMsg Messages in stdout from shell commands.
*hl-WinSeparator*
WinSeparator Separators between window splits.
*hl-Folded*
diff --git a/src/nvim/highlight.h b/src/nvim/highlight.h
@@ -18,6 +18,8 @@ EXTERN const char *hlf_names[] INIT( = {
[HLF_AT] = "NonText",
[HLF_D] = "Directory",
[HLF_E] = "ErrorMsg",
+ [HLF_SE] = "StderrMsg",
+ [HLF_SO] = "StdoutMsg",
[HLF_I] = "IncSearch",
[HLF_L] = "Search",
[HLF_LC] = "CurSearch",
diff --git a/src/nvim/highlight_defs.h b/src/nvim/highlight_defs.h
@@ -130,6 +130,8 @@ typedef enum {
HLF_BFOOTER, ///< Float Border Footer
HLF_TS, ///< status line for terminal window
HLF_TSNC, ///< status line for non-current terminal window
+ HLF_SE, ///< stderr messages (from shell)
+ HLF_SO, ///< stdout messages (from shell)
HLF_COUNT, ///< MUST be the last one
} hlf_T;
diff --git a/src/nvim/highlight_group.c b/src/nvim/highlight_group.c
@@ -180,6 +180,8 @@ static const char *highlight_init_both[] = {
"default link Substitute Search",
"default link StatusLineTerm StatusLine",
"default link StatusLineTermNC StatusLineNC",
+ "default link StderrMsg ErrorMsg",
+ "default link StdoutMsg NONE",
"default link TabLine StatusLineNC",
"default link TabLineFill TabLine",
"default link VertSplit WinSeparator",
diff --git a/src/nvim/os/shell.c b/src/nvim/os/shell.c
@@ -1104,7 +1104,7 @@ static void out_data_append_to_screen(const char *output, size_t *count, int fd,
msg_ext_set_kind(fd == STDERR_FILENO ? "shell_err" : "shell_out");
while (p < end) {
if (*p == '\n' || *p == '\r' || *p == TAB || *p == BELL) {
- msg_putchar_hl((uint8_t)(*p), fd == STDERR_FILENO ? HLF_E : 0);
+ msg_putchar_hl((uint8_t)(*p), fd == STDERR_FILENO ? HLF_SE : HLF_SO);
p++;
} else {
// Note: this is not 100% precise:
@@ -1120,7 +1120,7 @@ static void out_data_append_to_screen(const char *output, size_t *count, int fd,
goto end;
}
- msg_outtrans_len(p, i, fd == STDERR_FILENO ? HLF_E : 0, false);
+ msg_outtrans_len(p, i, fd == STDERR_FILENO ? HLF_SE : HLF_SO, false);
p += i;
}
}
diff --git a/test/functional/ui/cmdline_spec.lua b/test/functional/ui/cmdline_spec.lua
@@ -858,7 +858,7 @@ local function test_cmdline(linegrid)
cmdline = {
{
content = { { '' } },
- hl_id = 243,
+ hl_id = 245,
pos = 0,
prompt = 'Prompt:',
},
diff --git a/test/functional/ui/cursor_spec.lua b/test/functional/ui/cursor_spec.lua
@@ -262,7 +262,7 @@ describe('ui/cursor', function()
m.attr = { background = Screen.colors.DarkGray }
end
if m.id_lm then
- m.id_lm = 73
+ m.id_lm = 75
m.attr_lm = {}
end
end
diff --git a/test/functional/ui/messages_spec.lua b/test/functional/ui/messages_spec.lua
@@ -229,11 +229,11 @@ describe('ui/ext_messages', function()
{
content = {
{ '\n@character ' },
- { 'xxx', 26, 156 },
+ { 'xxx', 26, 158 },
{ ' ' },
{ 'links to', 18, 5 },
{ ' Character\n@character.special ' },
- { 'xxx', 16, 157 },
+ { 'xxx', 16, 159 },
{ ' ' },
{ 'links to', 18, 5 },
{ ' SpecialChar' },
@@ -300,7 +300,7 @@ describe('ui/ext_messages', function()
cmdline = { { abort = false } },
messages = {
{
- content = { { 'Error', 9, 6 }, { 'Message', 16, 100 } },
+ content = { { 'Error', 9, 6 }, { 'Message', 16, 102 } },
history = true,
kind = 'echoerr',
},
@@ -471,7 +471,7 @@ describe('ui/ext_messages', function()
kind = 'shell_out',
},
{
- content = { { ('stderr%s\n'):format(t.is_os('win') and '\r' or ''), 9, 6 } },
+ content = { { ('stderr%s\n'):format(t.is_os('win') and '\r' or ''), 9, 71 } },
history = false,
kind = 'shell_err',
},
diff --git a/test/functional/ui/output_spec.lua b/test/functional/ui/output_spec.lua
@@ -203,10 +203,10 @@ describe('shell command :!', function()
{1:~ }|
{3: }|
:!cat test/functional/fixtures/shell_data.txt |
- {18:^@^A^B^C^D^E^F^H} |
- {18:^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_} |
- ö 한글 {18:<a5><c3>} |
- t {18:<ff>} |
+ ^@^A^B^C^D^E^F^H |
+ ^N^O^P^Q^R^S^T^U^V^W^X^Y^Z^[^\^]^^^_ |
+ ö 한글 <a5><c3> |
+ t <ff> |
|
{6:Press ENTER or type command to continue}^ |
]],