mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-25 13:16:11 +03:00
terminal: dumpString options
This commit is contained in:
@ -2309,7 +2309,7 @@ pub fn pageIterator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get the top-left of the screen for the given tag.
|
/// Get the top-left of the screen for the given tag.
|
||||||
fn getTopLeft(self: *const PageList, tag: point.Tag) Pin {
|
pub fn getTopLeft(self: *const PageList, tag: point.Tag) Pin {
|
||||||
return switch (tag) {
|
return switch (tag) {
|
||||||
// The full screen or history is always just the first page.
|
// The full screen or history is always just the first page.
|
||||||
.screen, .history => .{ .page = self.pages.first.? },
|
.screen, .history => .{ .page = self.pages.first.? },
|
||||||
@ -2343,7 +2343,7 @@ fn getTopLeft(self: *const PageList, tag: point.Tag) Pin {
|
|||||||
/// Returns the bottom right of the screen for the given tag. This can
|
/// Returns the bottom right of the screen for the given tag. This can
|
||||||
/// return null because it is possible that a tag is not in the screen
|
/// return null because it is possible that a tag is not in the screen
|
||||||
/// (e.g. history does not yet exist).
|
/// (e.g. history does not yet exist).
|
||||||
fn getBottomRight(self: *const PageList, tag: point.Tag) ?Pin {
|
pub fn getBottomRight(self: *const PageList, tag: point.Tag) ?Pin {
|
||||||
return switch (tag) {
|
return switch (tag) {
|
||||||
.screen, .active => last: {
|
.screen, .active => last: {
|
||||||
const page = self.pages.last.?;
|
const page = self.pages.last.?;
|
||||||
|
@ -1667,17 +1667,28 @@ pub fn promptPath(
|
|||||||
return .{ .x = to_x - from_x, .y = to_y - from_y };
|
return .{ .x = to_x - from_x, .y = to_y - from_y };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub const DumpString = struct {
|
||||||
|
/// The start and end points of the dump, both inclusive. The x will
|
||||||
|
/// be ignored and the full row will always be dumped.
|
||||||
|
tl: Pin,
|
||||||
|
br: ?Pin = null,
|
||||||
|
|
||||||
|
/// If true, this will unwrap soft-wrapped lines. If false, this will
|
||||||
|
/// dump the screen as it is visually seen in a rendered window.
|
||||||
|
unwrap: bool = true,
|
||||||
|
};
|
||||||
|
|
||||||
/// Dump the screen to a string. The writer given should be buffered;
|
/// Dump the screen to a string. The writer given should be buffered;
|
||||||
/// this function does not attempt to efficiently write and generally writes
|
/// this function does not attempt to efficiently write and generally writes
|
||||||
/// one byte at a time.
|
/// one byte at a time.
|
||||||
pub fn dumpString(
|
pub fn dumpString(
|
||||||
self: *const Screen,
|
self: *const Screen,
|
||||||
writer: anytype,
|
writer: anytype,
|
||||||
tl: point.Point,
|
opts: DumpString,
|
||||||
) !void {
|
) !void {
|
||||||
var blank_rows: usize = 0;
|
var blank_rows: usize = 0;
|
||||||
|
|
||||||
var iter = self.pages.rowIterator(.right_down, tl, null);
|
var iter = opts.tl.rowIterator(.right_down, opts.br);
|
||||||
while (iter.next()) |row_offset| {
|
while (iter.next()) |row_offset| {
|
||||||
const rac = row_offset.rowAndCell();
|
const rac = row_offset.rowAndCell();
|
||||||
const cells = cells: {
|
const cells = cells: {
|
||||||
@ -1736,6 +1747,8 @@ pub fn dumpString(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// You should use dumpString, this is a restricted version mostly for
|
||||||
|
/// legacy and convenience reasons for unit tests.
|
||||||
pub fn dumpStringAlloc(
|
pub fn dumpStringAlloc(
|
||||||
self: *const Screen,
|
self: *const Screen,
|
||||||
alloc: Allocator,
|
alloc: Allocator,
|
||||||
@ -1743,7 +1756,13 @@ pub fn dumpStringAlloc(
|
|||||||
) ![]const u8 {
|
) ![]const u8 {
|
||||||
var builder = std.ArrayList(u8).init(alloc);
|
var builder = std.ArrayList(u8).init(alloc);
|
||||||
defer builder.deinit();
|
defer builder.deinit();
|
||||||
try self.dumpString(builder.writer(), tl);
|
|
||||||
|
try self.dumpString(builder.writer(), .{
|
||||||
|
.tl = self.pages.getTopLeft(tl),
|
||||||
|
.br = self.pages.getBottomRight(tl) orelse return error.UnknownPoint,
|
||||||
|
.unwrap = false,
|
||||||
|
});
|
||||||
|
|
||||||
return try builder.toOwnedSlice();
|
return try builder.toOwnedSlice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user