Skip to content

Commit

Permalink
Remove generic Print methods on ControlBuilder.
Browse files Browse the repository at this point in the history
This is an API intended for high-performance scenarios where allocations should
be avoided. These methods ran contrary to that.

Part of #193.
  • Loading branch information
alexrp committed Aug 21, 2024
1 parent 4a02a48 commit 5f1bd4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
3 changes: 1 addition & 2 deletions src/core/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ Vezel.Cathode.Text.Control.ControlBuilder.PopTitle() -> Vezel.Cathode.Text.Contr
Vezel.Cathode.Text.Control.ControlBuilder.Print(scoped ref Vezel.Cathode.Text.Control.ControlBuilder.PrintInterpolatedStringHandler handler) -> Vezel.Cathode.Text.Control.ControlBuilder!
Vezel.Cathode.Text.Control.ControlBuilder.Print(scoped System.ReadOnlySpan<char> value) -> Vezel.Cathode.Text.Control.ControlBuilder!
Vezel.Cathode.Text.Control.ControlBuilder.Print(System.IFormatProvider? provider, scoped ref Vezel.Cathode.Text.Control.ControlBuilder.PrintInterpolatedStringHandler handler) -> Vezel.Cathode.Text.Control.ControlBuilder!
Vezel.Cathode.Text.Control.ControlBuilder.Print<T>(T value) -> Vezel.Cathode.Text.Control.ControlBuilder!
Vezel.Cathode.Text.Control.ControlBuilder.PrintInterpolatedStringHandler
Vezel.Cathode.Text.Control.ControlBuilder.PrintInterpolatedStringHandler.AppendFormatted(object? value, string? format = null) -> void
Vezel.Cathode.Text.Control.ControlBuilder.PrintInterpolatedStringHandler.AppendFormatted(scoped System.ReadOnlySpan<char> value) -> void
Expand All @@ -427,8 +426,8 @@ Vezel.Cathode.Text.Control.ControlBuilder.PrintInterpolatedStringHandler.PrintIn
Vezel.Cathode.Text.Control.ControlBuilder.PrintInterpolatedStringHandler.PrintInterpolatedStringHandler(int literalLength, int formattedCount, Vezel.Cathode.Text.Control.ControlBuilder! builder, System.IFormatProvider? provider = null) -> void
Vezel.Cathode.Text.Control.ControlBuilder.PrintLine() -> Vezel.Cathode.Text.Control.ControlBuilder!
Vezel.Cathode.Text.Control.ControlBuilder.PrintLine(scoped ref Vezel.Cathode.Text.Control.ControlBuilder.PrintInterpolatedStringHandler handler) -> Vezel.Cathode.Text.Control.ControlBuilder!
Vezel.Cathode.Text.Control.ControlBuilder.PrintLine(scoped System.ReadOnlySpan<char> value) -> Vezel.Cathode.Text.Control.ControlBuilder!
Vezel.Cathode.Text.Control.ControlBuilder.PrintLine(System.IFormatProvider? provider, scoped ref Vezel.Cathode.Text.Control.ControlBuilder.PrintInterpolatedStringHandler handler) -> Vezel.Cathode.Text.Control.ControlBuilder!
Vezel.Cathode.Text.Control.ControlBuilder.PrintLine<T>(T value) -> Vezel.Cathode.Text.Control.ControlBuilder!
Vezel.Cathode.Text.Control.ControlBuilder.ProtectedClearLine(Vezel.Cathode.Text.Control.ClearMode mode = Vezel.Cathode.Text.Control.ClearMode.Full) -> Vezel.Cathode.Text.Control.ControlBuilder!
Vezel.Cathode.Text.Control.ControlBuilder.ProtectedClearScreen(Vezel.Cathode.Text.Control.ClearMode mode = Vezel.Cathode.Text.Control.ClearMode.Full) -> Vezel.Cathode.Text.Control.ControlBuilder!
Vezel.Cathode.Text.Control.ControlBuilder.PushTitle() -> Vezel.Cathode.Text.Control.ControlBuilder!
Expand Down
25 changes: 10 additions & 15 deletions src/core/Text/Control/ControlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,6 @@ public ControlBuilder Print(scoped ReadOnlySpan<char> value)
return this;
}

public ControlBuilder Print<T>(T value)
{
return Print((value?.ToString()).AsSpan());
}

[SuppressMessage("", "IDE0060")]
public ControlBuilder Print(
[InterpolatedStringHandlerArgument("")] scoped ref PrintInterpolatedStringHandler handler)
Expand All @@ -172,14 +167,14 @@ public ControlBuilder Print(
return this;
}

public ControlBuilder PrintLine()
public ControlBuilder PrintLine(scoped ReadOnlySpan<char> value)
{
return Print(Environment.NewLine);
return Print(value).PrintLine();
}

public ControlBuilder PrintLine<T>(T value)
public ControlBuilder PrintLine()
{
return Print(value).PrintLine();
return Print(Environment.NewLine);
}

[SuppressMessage("", "IDE0060")]
Expand Down Expand Up @@ -323,7 +318,7 @@ public ControlBuilder SetKeypadMode(KeypadMode mode)

var ch = (char)mode;

return Print(ESC).Print(new(in ch));
return Print([ESC]).Print(new(in ch));
}

public ControlBuilder SetKeyboardLevel(KeyboardLevel level)
Expand Down Expand Up @@ -579,12 +574,12 @@ public ControlBuilder MoveCursorRight(int count)

public ControlBuilder SaveCursorState()
{
return Print(ESC).Print("7");
return Print([ESC]).Print("7");
}

public ControlBuilder RestoreCursorState()
{
return Print(ESC).Print("8");
return Print([ESC]).Print("8");
}

public ControlBuilder SetForegroundColor(Color color)
Expand Down Expand Up @@ -700,7 +695,7 @@ public ControlBuilder OpenHyperlink(Uri uri, scoped ReadOnlySpan<char> id = defa
if (!id.IsEmpty)
_ = Print("id=").Print(id);

return Print(";").Print(uri).Print(ST);
return Print(";").Print(uri.ToString()).Print(ST);
}

public ControlBuilder CloseHyperlink()
Expand All @@ -713,7 +708,7 @@ public ControlBuilder SetWorkingDirectory(Uri uri)
Check.Null(uri);
Check.Argument(uri.Scheme == Uri.UriSchemeFile, uri);

return Print(OSC).Print("7").Print(uri).Print(ST);
return Print(OSC).Print("7").Print(uri.ToString()).Print(ST);
}

public ControlBuilder SetWorkingDirectory(scoped ReadOnlySpan<char> path)
Expand Down Expand Up @@ -799,7 +794,7 @@ public ControlBuilder SoftReset()

public ControlBuilder FullReset()
{
return Print(ESC).Print("c");
return Print([ESC]).Print("c");
}

public override string ToString()
Expand Down
2 changes: 1 addition & 1 deletion src/extensions/Logging/TerminalLoggerWriters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Decorator Decorate(byte r, byte g, byte b)
_ = builder.Print("][");

using (_ = Decorate(0, 155, 155))
_ = builder.Print(message.EventId);
_ = builder.Print(message.EventId.ToString());

_ = builder.Print("] ");

Expand Down

0 comments on commit 5f1bd4a

Please sign in to comment.