-
Notifications
You must be signed in to change notification settings - Fork 3
Add some AnsiConsole extensions and string manipulation. Support throwing CliCommandAbortException while constructing commands #77
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
6304c49
Add `WriteLines` and `MarkupLines` extensions to `IAnsiConsole` and i…
darthsharp ba16d67
Extend `IAnsiConsole` methods to support params for line collections,…
darthsharp 6d2f9c5
Refactor exception handling in `DefaultCliHost` to centralize `CliCom…
darthsharp 308b1fd
Enhance exception handling in `DefaultCliHost` to handle base excepti…
darthsharp ecbc625
Refactor `DefaultCliHost` to extract `FindAbortException` method for …
darthsharp 7f29276
Remove unused `[PublicAPI]` annotations in `AnsiConsoleExtensions` fo…
darthsharp bc1bcb0
Update `WriteLines` and `MarkupLines` extensions to use `params strin…
darthsharp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,21 @@ | ||
| using CreativeCoders.Cli.Core; | ||
| using CreativeCoders.SysConsole.Core; | ||
| using JetBrains.Annotations; | ||
| using Spectre.Console; | ||
|
|
||
| namespace CliHostSampleApp; | ||
|
|
||
| [UsedImplicitly] | ||
| [CliCommand([DemoCommandGroup.Name, "do"] | ||
| , AlternativeCommands = ["demo1"])] | ||
| public class DemoCliCommand : ICliCommand | ||
| public class DemoCliCommand(IAnsiConsole ansiConsole) : ICliCommand | ||
| { | ||
| public Task<CommandResult> ExecuteAsync() | ||
| { | ||
| Console.WriteLine("Hello World from cli command !"); | ||
|
|
||
| ansiConsole.WriteLines("Test", 1234.ToString()); | ||
|
|
||
| return Task.FromResult(new CommandResult()); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
source/SysConsole/CreativeCoders.SysConsole.Core/AnsiConsoleStringExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using JetBrains.Annotations; | ||
| using Spectre.Console; | ||
|
|
||
| namespace CreativeCoders.SysConsole.Core; | ||
|
|
||
| [ExcludeFromCodeCoverage] | ||
| [PublicAPI] | ||
| public static class AnsiConsoleStringExtensions | ||
| { | ||
| public static string ToErrorMarkup(this string text) | ||
| { | ||
| return $"[red]{text}[/]"; | ||
| } | ||
|
|
||
| public static string ToSuccessMarkup(this string text) | ||
| { | ||
| return $"[green]{text}[/]"; | ||
| } | ||
|
|
||
| public static string ToWarningMarkup(this string text) | ||
| { | ||
| return $"[yellow]{text}[/]"; | ||
| } | ||
|
|
||
| public static string ToInfoMarkup(this string text) | ||
| { | ||
| return $"[blue]{text}[/]"; | ||
| } | ||
|
|
||
| public static string ToWhiteMarkup(this string text) | ||
| { | ||
| return $"[white]{text}[/]"; | ||
| } | ||
|
|
||
| public static string ToBoldMarkup(this string text) | ||
| { | ||
| return $"[bold]{text}[/]"; | ||
| } | ||
|
|
||
| public static string ToItalicMarkup(this string text) | ||
| { | ||
| return $"[italic]{text}[/]"; | ||
| } | ||
|
|
||
| public static string ToUnderlineMarkup(this string text) | ||
| { | ||
| return $"[underline]{text}[/]"; | ||
| } | ||
|
|
||
| public static string ToStrikethroughMarkup(this string text) | ||
| { | ||
| return $"[strikethrough]{text}[/]"; | ||
| } | ||
|
|
||
| public static string ToLinkMarkup(this string text, string url = "") | ||
| { | ||
| return string.IsNullOrWhiteSpace(url) | ||
| ? $"[link]{text}[/]" | ||
| : $"[link={url}]{text}[/]"; | ||
|
darthsharp marked this conversation as resolved.
|
||
| } | ||
|
|
||
| public static string ToEscapedMarkup(this string text) | ||
| { | ||
| return Markup.Escape(text); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.