Unexpected behavior with colored background, wrapping, scroll, and partial lines #4463
-
While writing a program that uses background colors, I noticed a strange behavior in ghostty, where partial lines have an unexpected background color (screencap below). It looks like the following circumstances are necessary:
When these are met, the rest of the partial line has the same background color as the text that wrapped. I'm not familiar with the standards for this; perhaps this is intentional? Minimized test case: const std = @import("std");
pub fn main() !void {
const stdout_file = std.io.getStdOut().writer();
var bw = std.io.bufferedWriter(stdout_file);
const stdout = bw.writer();
// get terminal window size
var wsz: std.os.linux.winsize = undefined;
_ = std.os.linux.ioctl(1, std.os.linux.T.IOCGWINSZ, @intFromPtr(&wsz));
// reset cursor with CSI 0m and print an initial dot
try stdout.writeAll("\x1b[0m.");
for (0..1) |_| {
// write additional $COLUMNS-2 dots
try stdout.writeByteNTimes('.', wsz.ws_col - 2);
// write 2 dots with black on bright red
// this will wrap and put the 2nd one on the next line
// then reset cursor again
try stdout.writeAll("\x1b[30;101m..\x1b[0m");
}
try stdout.writeAll(".\n\n");
try bw.flush();
} Save above as Results of the above in ghostty (in unaffected terminals it displays like the top lines, every time): |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
A simpler test case: printf '\e[999C\e[30;101m..\e[0m.\n' |
Beta Was this translation helpful? Give feedback.
-
I haven't verified this again recently, but I believe in I know 100% this is true within scroll regions and for operations like delete lines or insert lines or erase characters and so on. I'm not 100% sure if this applies to scrollback generating lines. In our case, we follow xterm's lead, so let me verify with xterm. |
Beta Was this translation helpful? Give feedback.
-
Understandable, thanks for checking. This feels weird in xterm too (since it only occurs with scrollback), but I get that ghostty wants to match it. |
Beta Was this translation helpful? Give feedback.
Verified with xterm, this is intended behavior.