Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: parse ConEmu OSC9;1 #4327

Merged
merged 4 commits into from
Jan 5, 2025
Merged

Conversation

dmehala
Copy link
Collaborator

@dmehala dmehala commented Jan 1, 2025

Description

This PR implements support for the ConEmu OSC9;1 escape sequence.

Based on my understanding of ConEmu's source code:

  • The default timeout is set to 100 milliseconds if no value is specified.
  • The timeout value is clamped to a maximum of 10000 milliseconds.

#3125

@@ -158,6 +158,9 @@ pub const Command = union(enum) {
/// End a hyperlink (OSC 8)
hyperlink_end: void,

/// Sleep (OSC 9;1) in ms
sleep: u16,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered using the Duration type but this would introduce a dependency on Config. Would that be an issue?

Copy link
Collaborator

@jcollie jcollie Jan 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that the Duration type is necessary here, unless there's a need to display it with units or parse it from a string with units. You might consider scaling it to nanoseconds and using a u64 since that's what Zig tends to use for that sort of thing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the duration is in the ConEmu spec as ms I'm fine keeping this as u16 and documenting it (as @dmehala already has) as a millisecond unit.

},

.conemu_sleep_value => switch (c) {
'0'...'9' => {},
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could construct the number directly here, but I thought it would be safer to handle potential overflow correctly by using std.fmt.parseUnsigned.

Copy link
Collaborator

@jcollie jcollie Jan 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parseUnsigned allows _ as in 1_000_000 is a valid Zig number so I always feel a little icky when using it to parse data, but since you don't allow _ it shouldn't be a problem.

Comment on lines 1179 to 1181
v.* = @min(num, 10000);
} else |_| {
v.* = 10000;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need to replicate ConEmu's behaviour here.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's ConEmu's behavior? We should either replicate ConEmu's behavior or document the differences.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, looks like we match ConEmu's behavior. Please be careful linking to code though as we can't use GPL code since we are MIT. ConEmu is BSD 3 clause so I think that's OK (IANAL).

try testing.expect(cmd == .sleep);
try testing.expectEqual(10000, cmd.sleep);
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should test invalid codes as well, perhaps parameters that contain something other than digits.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in c98d207

- Add test with invalid value.
- Fix inspector compilation.
Comment on lines 1721 to 1732
test "OSC: conemu sleep invalid input" {
const testing = std.testing;

var p: Parser = .{};

const input = "9;1;foo";
for (input) |ch| p.next(ch);

const cmd = p.end('\x1b');

try testing.expect(cmd == null);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to myself: well that should default to 100 to fully match conemu's behaviou

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 9d9fa60

- Default to 100 if the value can't be parsed as an integer or
  is missing entirely.
@dmehala
Copy link
Collaborator Author

dmehala commented Jan 2, 2025

Alright, I think the logic matches ConEmu's now.

@dmehala dmehala requested a review from mitchellh January 5, 2025 20:39
@mitchellh
Copy link
Contributor

Please rebase. I can't merge :)

@mitchellh mitchellh merged commit 143c01e into ghostty-org:main Jan 5, 2025
24 checks passed
@github-actions github-actions bot added this to the 1.0.2 milestone Jan 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants