mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 08:16:13 +03:00
terminal/new: some missing APIs
This commit is contained in:
@ -61,6 +61,11 @@ pub const Cursor = struct {
|
|||||||
x: size.CellCountInt,
|
x: size.CellCountInt,
|
||||||
y: size.CellCountInt,
|
y: size.CellCountInt,
|
||||||
|
|
||||||
|
/// The visual style of the cursor. This defaults to block because
|
||||||
|
/// it has to default to something, but users of this struct are
|
||||||
|
/// encouraged to set their own default.
|
||||||
|
cursor_style: CursorStyle = .block,
|
||||||
|
|
||||||
/// The "last column flag (LCF)" as its called. If this is set then the
|
/// The "last column flag (LCF)" as its called. If this is set then the
|
||||||
/// next character print will force a soft-wrap.
|
/// next character print will force a soft-wrap.
|
||||||
pending_wrap: bool = false,
|
pending_wrap: bool = false,
|
||||||
@ -87,6 +92,11 @@ pub const Cursor = struct {
|
|||||||
page_cell: *pagepkg.Cell,
|
page_cell: *pagepkg.Cell,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// The visual style of the cursor. Whether or not it blinks
|
||||||
|
/// is determined by mode 12 (modes.zig). This mode is synchronized
|
||||||
|
/// with CSI q, the same as xterm.
|
||||||
|
pub const CursorStyle = enum { bar, block, underline };
|
||||||
|
|
||||||
/// Saved cursor state.
|
/// Saved cursor state.
|
||||||
pub const SavedCursor = struct {
|
pub const SavedCursor = struct {
|
||||||
x: size.CellCountInt,
|
x: size.CellCountInt,
|
||||||
@ -445,6 +455,11 @@ pub fn scrollClear(self: *Screen) !void {
|
|||||||
self.kitty_images.dirty = true;
|
self.kitty_images.dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns true if the viewport is scrolled to the bottom of the screen.
|
||||||
|
pub fn viewportIsBottom(self: Screen) bool {
|
||||||
|
return self.pages.viewport == .active;
|
||||||
|
}
|
||||||
|
|
||||||
/// Erase the region specified by tl and br, inclusive. This will physically
|
/// Erase the region specified by tl and br, inclusive. This will physically
|
||||||
/// erase the rows meaning the memory will be reclaimed (if the underlying
|
/// erase the rows meaning the memory will be reclaimed (if the underlying
|
||||||
/// page is empty) and other rows will be shifted up.
|
/// page is empty) and other rows will be shifted up.
|
||||||
@ -808,6 +823,22 @@ pub fn manualStyleUpdate(self: *Screen) !void {
|
|||||||
self.cursor.style_ref = &md.ref;
|
self.cursor.style_ref = &md.ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the raw text associated with a selection. This will unwrap
|
||||||
|
/// soft-wrapped edges. The returned slice is owned by the caller and allocated
|
||||||
|
/// using alloc, not the allocator associated with the screen (unless they match).
|
||||||
|
pub fn selectionString(
|
||||||
|
self: *Screen,
|
||||||
|
alloc: Allocator,
|
||||||
|
sel: Selection,
|
||||||
|
trim: bool,
|
||||||
|
) ![:0]const u8 {
|
||||||
|
_ = self;
|
||||||
|
_ = alloc;
|
||||||
|
_ = sel;
|
||||||
|
_ = trim;
|
||||||
|
@panic("TODO");
|
||||||
|
}
|
||||||
|
|
||||||
/// 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.
|
||||||
|
@ -1885,6 +1885,21 @@ pub fn decaln(self: *Terminal) !void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Execute a kitty graphics command. The buf is used to populate with
|
||||||
|
/// the response that should be sent as an APC sequence. The response will
|
||||||
|
/// be a full, valid APC sequence.
|
||||||
|
///
|
||||||
|
/// If an error occurs, the caller should response to the pty that a
|
||||||
|
/// an error occurred otherwise the behavior of the graphics protocol is
|
||||||
|
/// undefined.
|
||||||
|
pub fn kittyGraphics(
|
||||||
|
self: *Terminal,
|
||||||
|
alloc: Allocator,
|
||||||
|
cmd: *kitty.graphics.Command,
|
||||||
|
) ?kitty.graphics.Response {
|
||||||
|
return kitty.graphics.execute(alloc, self, cmd);
|
||||||
|
}
|
||||||
|
|
||||||
/// Set a style attribute.
|
/// Set a style attribute.
|
||||||
pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void {
|
pub fn setAttribute(self: *Terminal, attr: sgr.Attribute) !void {
|
||||||
try self.screen.setAttribute(attr);
|
try self.screen.setAttribute(attr);
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
|
|
||||||
pub const page = @import("page.zig");
|
pub const page = @import("page.zig");
|
||||||
|
pub const point = @import("point.zig");
|
||||||
pub const PageList = @import("PageList.zig");
|
pub const PageList = @import("PageList.zig");
|
||||||
pub const Terminal = @import("Terminal.zig");
|
pub const Terminal = @import("Terminal.zig");
|
||||||
|
pub const Screen = @import("Screen.zig");
|
||||||
pub const Page = page.Page;
|
pub const Page = page.Page;
|
||||||
|
|
||||||
test {
|
test {
|
||||||
@ -11,9 +13,6 @@ test {
|
|||||||
// todo: make top-level imports
|
// todo: make top-level imports
|
||||||
_ = @import("bitmap_allocator.zig");
|
_ = @import("bitmap_allocator.zig");
|
||||||
_ = @import("hash_map.zig");
|
_ = @import("hash_map.zig");
|
||||||
_ = @import("page.zig");
|
|
||||||
_ = @import("Screen.zig");
|
|
||||||
_ = @import("point.zig");
|
|
||||||
_ = @import("size.zig");
|
_ = @import("size.zig");
|
||||||
_ = @import("style.zig");
|
_ = @import("style.zig");
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@ const std = @import("std");
|
|||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const assert = std.debug.assert;
|
const assert = std.debug.assert;
|
||||||
|
|
||||||
/// The possible reference locations for a point. When someone says
|
/// The possible reference locations for a point. When someone says "(42, 80)" in the context of a terminal, that could mean multiple
|
||||||
/// "(42, 80)" in the context of a terminal, that could mean multiple
|
|
||||||
/// things: it is in the current visible viewport? the current active
|
/// things: it is in the current visible viewport? the current active
|
||||||
/// area of the screen where the cursor is? the entire scrollback history?
|
/// area of the screen where the cursor is? the entire scrollback history?
|
||||||
/// etc. This tag is used to differentiate those cases.
|
/// etc. This tag is used to differentiate those cases.
|
||||||
@ -69,3 +68,24 @@ pub const Point = union(Tag) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// A point in the terminal that is always in the viewport area.
|
||||||
|
pub const Viewport = struct {
|
||||||
|
x: usize = 0,
|
||||||
|
y: usize = 0,
|
||||||
|
|
||||||
|
pub fn eql(self: Viewport, other: Viewport) bool {
|
||||||
|
return self.x == other.x and self.y == other.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
const TerminalScreen = @import("Screen.zig");
|
||||||
|
pub fn toScreen(_: Viewport, _: *const TerminalScreen) Screen {
|
||||||
|
@panic("TODO");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/// A point in the terminal that is in relation to the entire screen.
|
||||||
|
pub const Screen = struct {
|
||||||
|
x: usize = 0,
|
||||||
|
y: usize = 0,
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user