Opened 20 months ago

Last modified 20 months ago

#18330 new bug

Terminal: Line feed violates ANSI color attributes

Reported by: LekKit Owned by: jackburton
Priority: normal Milestone: Unscheduled
Component: Applications/Terminal Version: R1/beta5
Keywords: Cc:
Blocked By: Blocking:
Platform: All

Description

Basically, if \n is used when ANSI color attribute is applied, it should not fill the rest of the line with that color. Haiku Terminal does this, however, and this subtly breaks some of the TUI applications rendering.

On a compliant terminal, \n should introduce a new line at the bottom of the screen instead.

Example with htop:

https://i.ibb.co/ryh1mTr/photo-2023-03-30-09-06-59.jpg

How it should render:

https://i.ibb.co/FwyQ0ns/photo-2023-03-30-08-35-52.jpg

Reproducible with

$ printf "\n\x1b[41mLine is partially red\nWhole row is red\x1b[0m\n\n"

The output should speak for itself: On a compliant terminal, the first row should reset to default color when the line ends, and the next one will be completely filled with red color. With Haiku Terminal though, the opposite happens.

https://i.ibb.co/MNqYCFX/photo-2023-03-30-09-29-32.jpg

https://i.ibb.co/PZbJpsK/photo-2023-03-30-09-29-43.jpg

Change History (8)

comment:1 by pulkomandy, 20 months ago

Keywords: terminal ansi linefeed vt htop removed

comment:2 by jessicah, 20 months ago

The "whole row is red" makes zero sense to me, as the attributes are reset _before_ the newline.

Saying that, I have found where the problem is occurring: https://github.com/haiku/haiku/blob/master/src/apps/terminal/TermView.cpp#L1370-L1397, in particular:

if (attr.IsBackSet())
    rgb_back = attr.BackgroundColor(fTextBuffer->Palette());

Overall, it's taking the attributes of the previous character, or the current line, which I think is erroneous behaviour. But I need to investigate the "whole row is red" behaviour with other terminal implementations before committing to a fix.

Also, can I get a copy of the htop binary used? Should be small enough to attach to this ticket.

in reply to:  2 comment:3 by X512, 20 months ago

Replying to jessicah:

Also, can I get a copy of the htop binary used? Should be small enough to attach to this ticket.

According to screenshot, it is probably Linux binary inside headless RISC-V virtual machine.

comment:4 by pulkomandy, 20 months ago

The behavior of Haiku's terminal seems logical to me. Could very well be htop trying to workaround a bug due to the wrong TERM value being set or an out-of tync termcap/terminfo database?

comment:5 by jessicah, 20 months ago

Terminals I've tested thus far, the first line is always only the text portion has the red background. For the second line, behaviour varies within the same terminal. It's honestly kind of bizarre, but generally it's only the text that's red, sometimes it's the whole line, but perhaps after it's gotten itself confused. So I'll address the first-line issue, as that definitely seems wrong. For a whole line, should be using the erase line commands, e.g. \x1b[0K, so using that for testing my fix :-)

in reply to:  4 comment:6 by LekKit, 20 months ago

Replying to pulkomandy:

The behavior of Haiku's terminal seems logical to me. Could very well be htop trying to workaround a bug due to the wrong TERM value being set or an out-of tync termcap/terminfo database?

I tried TERM=xterm, TERM=xterm-256color, TERM=linux. No difference.

The termcap/terminfo inside the guest is up to date.

Reproducer script exactly captures what it is doing, I've already dumped what htop outputs when this misrendering occurs.

in reply to:  5 comment:7 by LekKit, 20 months ago

Replying to jessicah:

For the second line, behaviour varies within the same terminal.

Sometimes the shell erases last line, etc. I am specifically injecting a bunch of \n therefore.

Anyways htop only cares about the "first line" apparently and I'm not forcing you to mimic "second line" behavior if it is non-standard or undefined behavior. Sorry for any confusion caused.

Version 0, edited 20 months ago by LekKit (next)

comment:8 by jessicah, 20 months ago

No, it's fine, I've installed xterm to observe its behaviour, and then going from there. I just haven't found a good way to get BCE to behave correctly in all circumstances yet.

Note: See TracTickets for help on using tickets.