mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-15 00:06:09 +03:00
stylistic nitpicks
This commit is contained in:
@ -714,17 +714,22 @@ pub fn handleMessage(self: *Surface, msg: Message) !void {
|
|||||||
},
|
},
|
||||||
|
|
||||||
.report_title => |style| {
|
.report_title => |style| {
|
||||||
const title: ?[:0]const u8 = if (@hasDecl(apprt.runtime.Surface, "getTitle"))
|
const title: ?[:0]const u8 = title: {
|
||||||
self.rt_surface.getTitle()
|
if (!@hasDecl(apprt.runtime.Surface, "getTitle")) break :title null;
|
||||||
else
|
break :title self.rt_surface.getTitle();
|
||||||
// If the apprt does not implement getTitle, report a
|
|
||||||
// blank title.
|
|
||||||
"";
|
|
||||||
|
|
||||||
const data = switch (style) {
|
|
||||||
.csi_21_t => try std.fmt.allocPrint(self.alloc, "\x1b]l{s}\x1b\\", .{title orelse ""}),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const data = switch (style) {
|
||||||
|
.csi_21_t => try std.fmt.allocPrint(
|
||||||
|
self.alloc,
|
||||||
|
"\x1b]l{s}\x1b\\",
|
||||||
|
.{title orelse ""},
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
|
// We always use an allocating message because we don't know
|
||||||
|
// the length of the title and this isn't a performance critical
|
||||||
|
// path.
|
||||||
self.io.queueMessage(.{
|
self.io.queueMessage(.{
|
||||||
.write_alloc = .{
|
.write_alloc = .{
|
||||||
.alloc = self.alloc,
|
.alloc = self.alloc,
|
||||||
|
@ -63,6 +63,8 @@ pub const Message = union(enum) {
|
|||||||
|
|
||||||
pub const ReportTitleStyle = enum {
|
pub const ReportTitleStyle = enum {
|
||||||
csi_21_t,
|
csi_21_t,
|
||||||
|
|
||||||
|
// This enum is a placeholder for future title styles.
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// Modes for the ED CSI command.
|
/// Modes for the ED CSI command.
|
||||||
pub const EraseDisplay = enum(u8) {
|
pub const EraseDisplay = enum(u8) {
|
||||||
below = 0,
|
below = 0,
|
||||||
above = 1,
|
above = 1,
|
||||||
@ -10,7 +10,7 @@ pub const EraseDisplay = enum(u8) {
|
|||||||
scroll_complete = 22,
|
scroll_complete = 22,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Modes for the EL CSI command.
|
/// Modes for the EL CSI command.
|
||||||
pub const EraseLine = enum(u8) {
|
pub const EraseLine = enum(u8) {
|
||||||
right = 0,
|
right = 0,
|
||||||
left = 1,
|
left = 1,
|
||||||
@ -22,7 +22,7 @@ pub const EraseLine = enum(u8) {
|
|||||||
_,
|
_,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Modes for the TBC (tab clear) command.
|
/// Modes for the TBC (tab clear) command.
|
||||||
pub const TabClear = enum(u8) {
|
pub const TabClear = enum(u8) {
|
||||||
current = 0,
|
current = 0,
|
||||||
all = 3,
|
all = 3,
|
||||||
@ -31,3 +31,12 @@ pub const TabClear = enum(u8) {
|
|||||||
// user-generated.
|
// user-generated.
|
||||||
_,
|
_,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Style formats for terminal size reports.
|
||||||
|
pub const SizeReportStyle = enum {
|
||||||
|
// XTWINOPS
|
||||||
|
csi_14_t,
|
||||||
|
csi_16_t,
|
||||||
|
csi_18_t,
|
||||||
|
csi_21_t,
|
||||||
|
};
|
||||||
|
@ -3,7 +3,7 @@ const builtin = @import("builtin");
|
|||||||
pub usingnamespace @import("sanitize.zig");
|
pub usingnamespace @import("sanitize.zig");
|
||||||
|
|
||||||
const charsets = @import("charsets.zig");
|
const charsets = @import("charsets.zig");
|
||||||
pub const stream = @import("stream.zig");
|
const stream = @import("stream.zig");
|
||||||
const ansi = @import("ansi.zig");
|
const ansi = @import("ansi.zig");
|
||||||
const csi = @import("csi.zig");
|
const csi = @import("csi.zig");
|
||||||
const hyperlink = @import("hyperlink.zig");
|
const hyperlink = @import("hyperlink.zig");
|
||||||
@ -38,6 +38,7 @@ pub const Pin = PageList.Pin;
|
|||||||
pub const Screen = @import("Screen.zig");
|
pub const Screen = @import("Screen.zig");
|
||||||
pub const ScreenType = Terminal.ScreenType;
|
pub const ScreenType = Terminal.ScreenType;
|
||||||
pub const Selection = @import("Selection.zig");
|
pub const Selection = @import("Selection.zig");
|
||||||
|
pub const SizeReportStyle = csi.SizeReportStyle;
|
||||||
pub const StringMap = @import("StringMap.zig");
|
pub const StringMap = @import("StringMap.zig");
|
||||||
pub const Style = style.Style;
|
pub const Style = style.Style;
|
||||||
pub const Terminal = @import("Terminal.zig");
|
pub const Terminal = @import("Terminal.zig");
|
||||||
|
@ -24,13 +24,6 @@ const log = std.log.scoped(.stream);
|
|||||||
/// do something else.
|
/// do something else.
|
||||||
const debug = false;
|
const debug = false;
|
||||||
|
|
||||||
pub const ReportStyle = enum {
|
|
||||||
csi_14_t,
|
|
||||||
csi_16_t,
|
|
||||||
csi_18_t,
|
|
||||||
csi_21_t,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// Returns a type that can process a stream of tty control characters.
|
/// Returns a type that can process a stream of tty control characters.
|
||||||
/// This will call various callback functions on type T. Type T only has to
|
/// This will call various callback functions on type T. Type T only has to
|
||||||
/// implement the callbacks it cares about; any unimplemented callbacks will
|
/// implement the callbacks it cares about; any unimplemented callbacks will
|
||||||
@ -1123,8 +1116,8 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
switch (input.params[0]) {
|
switch (input.params[0]) {
|
||||||
14 => if (input.params.len == 1) {
|
14 => if (input.params.len == 1) {
|
||||||
// report the text area size in pixels
|
// report the text area size in pixels
|
||||||
if (@hasDecl(T, "sendReport")) {
|
if (@hasDecl(T, "sendSizeReport")) {
|
||||||
self.handler.sendReport(.csi_14_t);
|
self.handler.sendSizeReport(.csi_14_t);
|
||||||
} else log.warn(
|
} else log.warn(
|
||||||
"ignoring unimplemented CSI 14 t",
|
"ignoring unimplemented CSI 14 t",
|
||||||
.{},
|
.{},
|
||||||
@ -1135,8 +1128,8 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
),
|
),
|
||||||
16 => if (input.params.len == 1) {
|
16 => if (input.params.len == 1) {
|
||||||
// report cell size in pixels
|
// report cell size in pixels
|
||||||
if (@hasDecl(T, "sendReport")) {
|
if (@hasDecl(T, "sendSizeReport")) {
|
||||||
self.handler.sendReport(.csi_16_t);
|
self.handler.sendSizeReport(.csi_16_t);
|
||||||
} else log.warn(
|
} else log.warn(
|
||||||
"ignoring unimplemented CSI 16 t",
|
"ignoring unimplemented CSI 16 t",
|
||||||
.{},
|
.{},
|
||||||
@ -1147,8 +1140,8 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
),
|
),
|
||||||
18 => if (input.params.len == 1) {
|
18 => if (input.params.len == 1) {
|
||||||
// report screen size in characters
|
// report screen size in characters
|
||||||
if (@hasDecl(T, "sendReport")) {
|
if (@hasDecl(T, "sendSizeReport")) {
|
||||||
self.handler.sendReport(.csi_18_t);
|
self.handler.sendSizeReport(.csi_18_t);
|
||||||
} else log.warn(
|
} else log.warn(
|
||||||
"ignoring unimplemented CSI 18 t",
|
"ignoring unimplemented CSI 18 t",
|
||||||
.{},
|
.{},
|
||||||
@ -1159,8 +1152,8 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
),
|
),
|
||||||
21 => if (input.params.len == 1) {
|
21 => if (input.params.len == 1) {
|
||||||
// report window title
|
// report window title
|
||||||
if (@hasDecl(T, "sendReport")) {
|
if (@hasDecl(T, "sendSizeReport")) {
|
||||||
self.handler.sendReport(.csi_21_t);
|
self.handler.sendSizeReport(.csi_21_t);
|
||||||
} else log.warn(
|
} else log.warn(
|
||||||
"ignoring unimplemented CSI 21 t",
|
"ignoring unimplemented CSI 21 t",
|
||||||
.{},
|
.{},
|
||||||
@ -2126,9 +2119,9 @@ test "stream: csi param too long" {
|
|||||||
|
|
||||||
test "stream: send report with CSI t" {
|
test "stream: send report with CSI t" {
|
||||||
const H = struct {
|
const H = struct {
|
||||||
style: ?ReportStyle = null,
|
style: ?csi.SizeReportStyle = null,
|
||||||
|
|
||||||
pub fn sendReport(self: *@This(), style: ReportStyle) void {
|
pub fn sendSizeReport(self: *@This(), style: csi.SizeReportStyle) void {
|
||||||
self.style = style;
|
self.style = style;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -2136,23 +2129,23 @@ test "stream: send report with CSI t" {
|
|||||||
var s: Stream(H) = .{ .handler = .{} };
|
var s: Stream(H) = .{ .handler = .{} };
|
||||||
|
|
||||||
try s.nextSlice("\x1b[14t");
|
try s.nextSlice("\x1b[14t");
|
||||||
try testing.expectEqual(ReportStyle.csi_14_t, s.handler.style);
|
try testing.expectEqual(csi.SizeReportStyle.csi_14_t, s.handler.style);
|
||||||
|
|
||||||
try s.nextSlice("\x1b[16t");
|
try s.nextSlice("\x1b[16t");
|
||||||
try testing.expectEqual(ReportStyle.csi_16_t, s.handler.style);
|
try testing.expectEqual(csi.SizeReportStyle.csi_16_t, s.handler.style);
|
||||||
|
|
||||||
try s.nextSlice("\x1b[18t");
|
try s.nextSlice("\x1b[18t");
|
||||||
try testing.expectEqual(ReportStyle.csi_18_t, s.handler.style);
|
try testing.expectEqual(csi.SizeReportStyle.csi_18_t, s.handler.style);
|
||||||
|
|
||||||
try s.nextSlice("\x1b[21t");
|
try s.nextSlice("\x1b[21t");
|
||||||
try testing.expectEqual(ReportStyle.csi_21_t, s.handler.style);
|
try testing.expectEqual(csi.SizeReportStyle.csi_21_t, s.handler.style);
|
||||||
}
|
}
|
||||||
|
|
||||||
test "stream: invalid CSI t" {
|
test "stream: invalid CSI t" {
|
||||||
const H = struct {
|
const H = struct {
|
||||||
style: ?ReportStyle = null,
|
style: ?csi.SizeReportStyle = null,
|
||||||
|
|
||||||
pub fn sendReport(self: *@This(), style: ReportStyle) void {
|
pub fn sendSizeReport(self: *@This(), style: csi.SizeReportStyle) void {
|
||||||
self.style = style;
|
self.style = style;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1261,7 +1261,7 @@ pub const StreamHandler = struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Send a report to the pty.
|
/// Send a report to the pty.
|
||||||
pub fn sendReport(self: *StreamHandler, style: terminal.stream.ReportStyle) void {
|
pub fn sendSizeReport(self: *StreamHandler, style: terminal.SizeReportStyle) void {
|
||||||
switch (style) {
|
switch (style) {
|
||||||
.csi_14_t => self.messageWriter(.{ .size_report = .csi_14_t }),
|
.csi_14_t => self.messageWriter(.{ .size_report = .csi_14_t }),
|
||||||
.csi_16_t => self.messageWriter(.{ .size_report = .csi_16_t }),
|
.csi_16_t => self.messageWriter(.{ .size_report = .csi_16_t }),
|
||||||
|
Reference in New Issue
Block a user