mirror of
https://github.com/ghostty-org/ghostty.git
synced 2025-07-16 08:46:08 +03:00
terminal: add easy debug mode for stream debugging
This commit is contained in:
@ -16,6 +16,14 @@ const MouseShape = @import("mouse_shape.zig").MouseShape;
|
|||||||
|
|
||||||
const log = std.log.scoped(.stream);
|
const log = std.log.scoped(.stream);
|
||||||
|
|
||||||
|
/// Flip this to true when you want verbose debug output for
|
||||||
|
/// debugging terminal stream issues. In addition to louder
|
||||||
|
/// output this will also disable the SIMD optimizations in
|
||||||
|
/// order to make it easier to see every byte. So if you're
|
||||||
|
/// debugging an issue in the SIMD code then you'll need to
|
||||||
|
/// do something else.
|
||||||
|
const debug = false;
|
||||||
|
|
||||||
/// 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
|
||||||
@ -48,6 +56,12 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
|
|
||||||
/// Process a string of characters.
|
/// Process a string of characters.
|
||||||
pub fn nextSlice(self: *Self, input: []const u8) !void {
|
pub fn nextSlice(self: *Self, input: []const u8) !void {
|
||||||
|
// Debug mode disables the SIMD optimizations
|
||||||
|
if (comptime debug) {
|
||||||
|
for (input) |c| try self.next(c);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// This is the maximum number of codepoints we can decode
|
// This is the maximum number of codepoints we can decode
|
||||||
// at one time for this function call. This is somewhat arbitrary
|
// at one time for this function call. This is somewhat arbitrary
|
||||||
// so if someone can demonstrate a better number then we can switch.
|
// so if someone can demonstrate a better number then we can switch.
|
||||||
@ -261,10 +275,7 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
const actions = self.parser.next(c);
|
const actions = self.parser.next(c);
|
||||||
for (actions) |action_opt| {
|
for (actions) |action_opt| {
|
||||||
const action = action_opt orelse continue;
|
const action = action_opt orelse continue;
|
||||||
|
if (comptime debug) log.info("action: {}", .{action});
|
||||||
// if (action != .print) {
|
|
||||||
// log.info("action: {}", .{action});
|
|
||||||
// }
|
|
||||||
|
|
||||||
// If this handler handles everything manually then we do nothing
|
// If this handler handles everything manually then we do nothing
|
||||||
// if it can be processed.
|
// if it can be processed.
|
||||||
@ -317,7 +328,7 @@ pub fn Stream(comptime Handler: type) type {
|
|||||||
|
|
||||||
pub fn execute(self: *Self, c: u8) !void {
|
pub fn execute(self: *Self, c: u8) !void {
|
||||||
const c0: ansi.C0 = @enumFromInt(c);
|
const c0: ansi.C0 = @enumFromInt(c);
|
||||||
// log.info("execute: {}", .{c0});
|
if (comptime debug) log.info("execute: {}", .{c0});
|
||||||
switch (c0) {
|
switch (c0) {
|
||||||
// We ignore SOH/STX: https://github.com/microsoft/terminal/issues/10786
|
// We ignore SOH/STX: https://github.com/microsoft/terminal/issues/10786
|
||||||
.NUL, .SOH, .STX => {},
|
.NUL, .SOH, .STX => {},
|
||||||
|
Reference in New Issue
Block a user