Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,15 @@
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (console)",
"name": "Argument Parsing",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/examples/Args/bin/Debug/net8.0/Args.dll",
"args": ["a", "--bar", "a", "a"],
"args": ["argument", "-ab", "-c"],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "externalTerminal",
"console": "integratedTerminal",
"preLaunchTask": "build Argument parsing Example",
}



]
}
25 changes: 12 additions & 13 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "dotnet",
"task": "build",
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": [],
"label": "build"
},
]
"version": "2.0.0",
"tasks": [
{
"label": "build Argument parsing Example",
"command": "dotnet",
"type": "process",
"args": [
"build",
"${workspaceFolder}/examples/Args/Args.csproj"
],
}
]
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ It also supports logging.
- [Colors](https://github.com/dedouwe26/Terminal/tree/main/examples/Colors/Program.cs) (colors and text decoration)
- [Keypresses](https://github.com/dedouwe26/Terminal/tree/main/examples/Keypresses/Program.cs) (waiting for keypress, reading keypresses)
- [Logging](https://github.com/dedouwe26/Terminal/tree/main/examples/Logging/Program.cs) (also with sub-loggers.)
- [Window](https://github.com/dedouwe26/Terminal/tree/main/examples/Window/Program.cs) (Creates a terminal window, Only works in GUI mode)
- [Assertions](https://github.com/dedouwe26/Terminal/tree/main/examples/Assertion/Program.cs) (one-liners)
- [Argument parsing](https://github.com/dedouwe26/Terminal/tree/main/examples/Args/Program.cs)
- [Window](https://github.com/dedouwe26/Terminal/tree/main/examples/Window/Program.cs) (doesn't work)
7 changes: 7 additions & 0 deletions Terminal.sln
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Window", "examples\Window\W
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Args", "examples\Args\Args.csproj", "{3F6DC96D-963F-443B-8ABC-FE5B07F3B72D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Assertion", "examples\Assertion\Assertion.csproj", "{87F6A6F3-7365-4DA5-8A9B-46F7B24327DD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -50,12 +52,17 @@ Global
{3F6DC96D-963F-443B-8ABC-FE5B07F3B72D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3F6DC96D-963F-443B-8ABC-FE5B07F3B72D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3F6DC96D-963F-443B-8ABC-FE5B07F3B72D}.Release|Any CPU.Build.0 = Release|Any CPU
{87F6A6F3-7365-4DA5-8A9B-46F7B24327DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87F6A6F3-7365-4DA5-8A9B-46F7B24327DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87F6A6F3-7365-4DA5-8A9B-46F7B24327DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{87F6A6F3-7365-4DA5-8A9B-46F7B24327DD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{70C53AE0-A9EB-4551-807A-B4D31599C92E} = {5363993F-0762-4307-9658-82BF54A21CB6}
{B58A49BE-9B1F-43C7-8648-928D9EF292A0} = {5363993F-0762-4307-9658-82BF54A21CB6}
{61D6E9FD-4FDA-4386-AF0A-B54DB90E8210} = {5363993F-0762-4307-9658-82BF54A21CB6}
{1C553047-F904-48E8-A84D-7273D71C79DD} = {5363993F-0762-4307-9658-82BF54A21CB6}
{3F6DC96D-963F-443B-8ABC-FE5B07F3B72D} = {5363993F-0762-4307-9658-82BF54A21CB6}
{87F6A6F3-7365-4DA5-8A9B-46F7B24327DD} = {5363993F-0762-4307-9658-82BF54A21CB6}
EndGlobalSection
EndGlobal
6 changes: 3 additions & 3 deletions Terminal/ANSI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ namespace OxDED.Terminal;
/// </summary>
public static class ANSI {
/// <summary>
/// (1B)
/// (0x1B)
/// </summary>
public const string ESC = "\x1B";
/// <summary>
/// CSI
/// CSI (ESC + [)
/// </summary>
public const string CSI = ESC+"[";

Expand All @@ -24,7 +24,7 @@ public static class ANSI {
/// <summary>
/// Will return as CSI{row};{column}R <para/>
/// Where CSI is CSI,
/// {row} is the row,
/// {row} is the row and
/// {column} is the column.
/// </summary>
public const string RequestCursorPosition = CSI+"6n";
Expand Down
147 changes: 11 additions & 136 deletions Terminal/Arguments/Argument.cs
Original file line number Diff line number Diff line change
@@ -1,147 +1,22 @@
using static OxDED.Terminal.Arguments.ArgumentFormatter;

namespace OxDED.Terminal.Arguments;

/// <summary>
/// Represents an optional argument (-f, --foo).
/// Represents a parsed option.
/// </summary>
public class Argument : ICloneable, IEquatable<Argument> {
/// <summary>
/// The keys of this argument (f, foo).
/// </summary>
public string[] keys;
/// <summary>
/// The parameters of this argument.
/// </summary>
public ArgumentParameter[] parameters;
/// <summary>
/// The description of this argument.
/// </summary>
public string? description = null;
/// <summary>
/// Creates an argument.
/// </summary>
/// <param name="key">The key of this argument.</param>
/// <param name="description">The description of this argument (optional).</param>
/// <param name="parameters">The parameters of this argument (default: empty).</param>
public Argument(string key, string? description = null, IEnumerable<ArgumentParameter>? parameters = null) {
keys = [key];
this.description = description;
this.parameters = parameters == null ? [] : [.. parameters];
}
public class Argument {
/// <summary>
/// Creates an argument.
/// The format of this argument.
/// </summary>
/// <param name="keys">The keys of this argument.</param>
/// <param name="description">The description of this argument (optional).</param>
/// <param name="parameters">The parameters of this argument (default: empty).</param>
public Argument(IEnumerable<string> keys, string? description = null, IEnumerable<ArgumentParameter>? parameters = null) {
this.keys = [.. keys];
this.description = description;
this.parameters = parameters == null ? [] : [.. parameters];
}
/// <summary>
/// Sets the key of this argument.
/// </summary>
/// <param name="key">The new key.</param>
/// <returns>This argument.</returns>
public Argument Key(string key) {
keys = [key];
return this;
}
public readonly ArgumentFormat Format;
/// <summary>
/// Sets the keys of this argument.
/// The content of this argument.
/// </summary>
/// <param name="keys">The new keys.</param>
/// <returns>This argument.</returns>
public Argument Keys(IEnumerable<string> keys) {
this.keys = [.. keys];
return this;
}
/// <summary>
/// Sets the description of this argument.
/// </summary>
/// <param name="description">The new description.</param>
/// <returns>This argument.</returns>
public Argument Description(string? description) {
this.description = description;
return this;
}
/// <summary>
/// Sets the parameters of this argument.
/// </summary>
/// <param name="parameters">The new parameters.</param>
/// <returns>This argument.</returns>
public Argument Parameters(IEnumerable<ArgumentParameter> parameters) {
this.parameters = [.. parameters];
return this;
}
/// <summary>
/// Adds a parameter to this argument.
/// </summary>
/// <param name="parameter">The parameter to add.</param>
/// <returns>This argument.</returns>
public Argument AddParameter(ArgumentParameter parameter) {
parameters = [.. parameters, parameter];
return this;
}
/// <summary>
/// If this argument's parameters have values (should be yes).
/// </summary>
public bool HasValue { get => parameters.All((ArgumentParameter parameter) => parameter.HasValue); }
public readonly string Content;

///
public static bool operator ==(Argument? left, Argument? right) {
if (left is null && right is null) {
return true;
} else if (left is null) {
return false;
}
return left.Equals(right);
}
///
public static bool operator !=(Argument? left, Argument? right) {
return !(left == right);
}
/// <inheritdoc/>
/// <remarks>
/// Checks if the that color is identical to this one.
/// </remarks>
public bool Equals(Argument? other) {
if (other is null) {
return false;
}
if (ReferenceEquals(this, other)) {
return true;
}
if (GetType() != other.GetType()) {
return false;
}
return keys == other.keys;
}
/// <inheritdoc/>
/// <remarks>
/// Checks if the that color is identical to this one.
/// </remarks>
public override bool Equals(object? obj) {
return Equals(obj as Color);
}
/// <inheritdoc/>
public override int GetHashCode() {
return keys.GetHashCode();
}
/// <inheritdoc/>
/// <remarks>
/// Calls <see cref="CloneArgument"/>.
/// </remarks>
public object Clone() {
return CloneArgument();
}

/// <summary>
/// Clones this color.
/// </summary>
/// <returns>The new copy of this color.</returns>
/// <exception cref="InvalidOperationException"/>
public Argument CloneArgument() {
return new Argument(keys, description, parameters);
internal Argument(ArgumentFormat format, string content) {
Format = format;
Content = content;
}
}
Loading