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.
This commit is contained in:
Sathya Pramodh
2025-05-02 18:36:55 +05:30
committed by GitHub
parent 3c7c824bdc
commit 0741d2520d
9 changed files with 22 additions and 12 deletions

View File

@ -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*

View File

@ -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",

View File

@ -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;

View File

@ -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",

View File

@ -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;
}
}

View File

@ -858,7 +858,7 @@ local function test_cmdline(linegrid)
cmdline = {
{
content = { { '' } },
hl_id = 243,
hl_id = 245,
pos = 0,
prompt = 'Prompt:',
},

View File

@ -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

View File

@ -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',
},

View File

@ -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}^ |
]],