mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 00:36:07 +03:00
terminal2: better blank line handling
This commit is contained in:
@ -885,11 +885,16 @@ pub fn selectionString(
|
|||||||
|
|
||||||
const cells = cells_ptr[start_x..end_x];
|
const cells = cells_ptr[start_x..end_x];
|
||||||
for (cells) |*cell| {
|
for (cells) |*cell| {
|
||||||
if (!cell.hasText()) continue;
|
// Skip wide spacers
|
||||||
|
switch (cell.wide) {
|
||||||
|
.narrow, .wide => {},
|
||||||
|
.spacer_head, .spacer_tail => continue,
|
||||||
|
}
|
||||||
|
|
||||||
var buf: [4]u8 = undefined;
|
var buf: [4]u8 = undefined;
|
||||||
{
|
{
|
||||||
const char = if (cell.content.codepoint > 0) cell.content.codepoint else ' ';
|
const raw: u21 = if (cell.hasText()) cell.content.codepoint else 0;
|
||||||
|
const char = if (raw > 0) raw else ' ';
|
||||||
const encode_len = try std.unicode.utf8Encode(char, &buf);
|
const encode_len = try std.unicode.utf8Encode(char, &buf);
|
||||||
try strbuilder.appendSlice(buf[0..encode_len]);
|
try strbuilder.appendSlice(buf[0..encode_len]);
|
||||||
}
|
}
|
||||||
@ -931,8 +936,11 @@ pub fn selectionString(
|
|||||||
try strbuilder.append('\n');
|
try strbuilder.append('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove our trailing newline again
|
// Remove all trailing newlines
|
||||||
if (strbuilder.items.len > 0) strbuilder.items.len -= 1;
|
for (0..strbuilder.items.len) |_| {
|
||||||
|
if (strbuilder.items[strbuilder.items.len - 1] != '\n') break;
|
||||||
|
strbuilder.items.len -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get our final string
|
// Get our final string
|
||||||
@ -5221,7 +5229,7 @@ test "Screen: selectionString trim empty line" {
|
|||||||
|
|
||||||
var s = try init(alloc, 5, 5, 0);
|
var s = try init(alloc, 5, 5, 0);
|
||||||
defer s.deinit();
|
defer s.deinit();
|
||||||
const str = "1AB \n \n2EFGH\n3IJKL";
|
const str = "1AB \n\n2EFGH\n3IJKL";
|
||||||
try s.testWriteString(str);
|
try s.testWriteString(str);
|
||||||
|
|
||||||
const sel = Selection.init(
|
const sel = Selection.init(
|
||||||
@ -5462,38 +5470,38 @@ test "Screen: selectionString, rectangle, w/EOL" {
|
|||||||
try testing.expectEqualStrings(expected, contents);
|
try testing.expectEqualStrings(expected, contents);
|
||||||
}
|
}
|
||||||
|
|
||||||
// test "Screen: selectionString, rectangle, more complex w/breaks" {
|
test "Screen: selectionString, rectangle, more complex w/breaks" {
|
||||||
// const testing = std.testing;
|
const testing = std.testing;
|
||||||
// const alloc = testing.allocator;
|
const alloc = testing.allocator;
|
||||||
//
|
|
||||||
// var s = try init(alloc, 30, 8, 0);
|
var s = try init(alloc, 30, 8, 0);
|
||||||
// defer s.deinit();
|
defer s.deinit();
|
||||||
// const str =
|
const str =
|
||||||
// \\Lorem ipsum dolor
|
\\Lorem ipsum dolor
|
||||||
// \\sit amet, consectetur
|
\\sit amet, consectetur
|
||||||
// \\adipiscing elit, sed do
|
\\adipiscing elit, sed do
|
||||||
// \\eiusmod tempor incididunt
|
\\eiusmod tempor incididunt
|
||||||
// \\ut labore et dolore
|
\\ut labore et dolore
|
||||||
// \\
|
\\
|
||||||
// \\magna aliqua. Ut enim
|
\\magna aliqua. Ut enim
|
||||||
// \\ad minim veniam, quis
|
\\ad minim veniam, quis
|
||||||
// ;
|
;
|
||||||
// const sel = Selection.init(
|
const sel = Selection.init(
|
||||||
// s.pages.pin(.{ .screen = .{ .x = 11, .y = 2 } }).?,
|
s.pages.pin(.{ .screen = .{ .x = 11, .y = 2 } }).?,
|
||||||
// s.pages.pin(.{ .screen = .{ .x = 26, .y = 7 } }).?,
|
s.pages.pin(.{ .screen = .{ .x = 26, .y = 7 } }).?,
|
||||||
// true,
|
true,
|
||||||
// );
|
);
|
||||||
// const expected =
|
const expected =
|
||||||
// \\elit, sed do
|
\\elit, sed do
|
||||||
// \\por incididunt
|
\\por incididunt
|
||||||
// \\t dolore
|
\\t dolore
|
||||||
// \\
|
\\
|
||||||
// \\a. Ut enim
|
\\a. Ut enim
|
||||||
// \\niam, quis
|
\\niam, quis
|
||||||
// ;
|
;
|
||||||
// try s.testWriteString(str);
|
try s.testWriteString(str);
|
||||||
//
|
|
||||||
// const contents = try s.selectionString(alloc, sel, true);
|
const contents = try s.selectionString(alloc, sel, true);
|
||||||
// defer alloc.free(contents);
|
defer alloc.free(contents);
|
||||||
// try testing.expectEqualStrings(expected, contents);
|
try testing.expectEqualStrings(expected, contents);
|
||||||
// }
|
}
|
||||||
|
Reference in New Issue
Block a user