Skip to content

Commit

Permalink
Support OSC 133 escape sequences for shell integration.
Browse files Browse the repository at this point in the history
Closes #91.
  • Loading branch information
alexrp committed Dec 31, 2023
1 parent 2cb84d5 commit 77c2b0d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/core/Text/Control/ControlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,37 @@ public ControlBuilder CloseHyperlink()
return Print(OSC).Print("8;;").Print(ST);
}

public ControlBuilder BeginShellPrompt()
{
return Print(OSC).Print("133;A").Print(ST);
}

public ControlBuilder EndShellPrompt()
{
return Print(OSC).Print("133;B").Print(ST);
}

public ControlBuilder BeginShellExecution()
{
return Print(OSC).Print("133;C").Print(ST);
}

public ControlBuilder EndShellExecution(int? code = null)
{
_ = Print(OSC).Print("133;D");

if (code is { } c)
{
var codeSpan = (stackalloc char[StackBufferSize]);

_ = c.TryFormat(codeSpan, out var codeLen, provider: _culture);

_ = Print(";").Print(codeSpan[..codeLen]);
}

return Print(ST);
}

public ControlBuilder SaveScreenshot(ScreenshotFormat format = ScreenshotFormat.Html)
{
Check.Enum(format);
Expand Down
20 changes: 20 additions & 0 deletions src/core/Text/Control/ControlSequences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,26 @@ public static string CloseHyperlink()
return Create(static cb => cb.CloseHyperlink());
}

public static string BeginShellPrompt()
{
return Create(static cb => cb.BeginShellPrompt());
}

public static string EndShellPrompt()
{
return Create(static cb => cb.EndShellPrompt());
}

public static string BeginShellExecution()
{
return Create(static cb => cb.BeginShellExecution());
}

public static string EndShellExecution(int? code = null)
{
return Create(static (cb, code) => cb.EndShellExecution(code), code);
}

public static string SaveScreenshot(ScreenshotFormat format = ScreenshotFormat.Html)
{
return Create(static (cb, format) => cb.SaveScreenshot(format), format);
Expand Down

0 comments on commit 77c2b0d

Please sign in to comment.