Skip to content

Commit 8fad9a6

Browse files
committed
2 parents aebffac + d3529de commit 8fad9a6

12 files changed

+31
-45
lines changed

Terminal/ANSI.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ namespace OxDED.Terminal;
55
/// </summary>
66
public static class ANSI {
77
/// <summary>
8-
/// (1B)
8+
/// (0x1B)
99
/// </summary>
1010
public const string ESC = "\x1B";
1111
/// <summary>
12-
/// CSI
12+
/// CSI (ESC + [)
1313
/// </summary>
1414
public const string CSI = ESC+"[";
1515

@@ -24,7 +24,7 @@ public static class ANSI {
2424
/// <summary>
2525
/// Will return as CSI{row};{column}R <para/>
2626
/// Where CSI is CSI,
27-
/// {row} is the row,
27+
/// {row} is the row and
2828
/// {column} is the column.
2929
/// </summary>
3030
public const string RequestCursorPosition = CSI+"6n";

Terminal/Assertion/Asserter.cs

-1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,5 @@ public static ExceptionAssertion<T, Exception> Throws<T>(this Asserter<Func<T>>
172172
/// <returns>A new exception assertion.</returns>
173173
public static ExceptionAssertion<Exception> Throws(this Asserter<Action> asserter) {
174174
return Assert.Throws(asserter.value);
175-
176175
}
177176
}

Terminal/Assertion/Assertion.cs

+4-3
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,9 @@ public Assertion OnFailure(Action<Assertion> callback) {
7373
/// <returns>This assertion.</returns>
7474
public Assertion Log(Logger logger, Severity severity = Severity.Error) {
7575
logger.LogTrace($"Assertion done: {ToString()}");
76-
logger.Log(severity, $"Assertion failed with result: {result}");
77-
return this;
76+
return OnFailure(failedAssertion => {
77+
logger.Log(severity, $"Assertion failed with result: {result}");
78+
});
7879
}
7980

8081
/// <summary>
@@ -83,7 +84,7 @@ public Assertion Log(Logger logger, Severity severity = Severity.Error) {
8384
/// <param name="exception">The exception to throw (defaults to <see cref="AssertException{T}"/>).</param>
8485
/// <returns>This assertion.</returns>
8586
public Assertion Throw(Exception? exception = null) {
86-
return OnFailure((Assertion failedAssertion) => {
87+
return OnFailure(failedAssertion => {
8788
throw exception ?? new AssertException<Assertion>("Assertion failed", this);
8889
});
8990
}

Terminal/Logging/ITarget.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ public interface ITarget : IDisposable {
77
/// <summary>
88
/// The method to write to output.
99
/// </summary>
10-
/// <typeparam name="T">The type of the text.</typeparam>
1110
/// <param name="severity">The severity of the message.</param>
1211
/// <param name="time">The time when it has been logged.</param>
1312
/// <param name="logger">The logger.</param>
1413
/// <param name="text">The text to write (<see cref="object.ToString"/>).</param>
15-
public void Write<T>(Severity severity, DateTime time, Logger logger, T? text);
14+
public void Write(Severity severity, DateTime time, Logger logger, object? text);
1615
}

Terminal/Logging/Logger.cs

+9-17
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,9 @@ public bool HandleUnhandledExceptions {
322322
/// <summary>
323323
/// Logs something (<see cref="object.ToString"/>).
324324
/// </summary>
325-
/// <typeparam name="T">The type of the data.</typeparam>
326325
/// <param name="severity">The severity of the text.</param>
327326
/// <param name="text">The text to write (<see cref="object.ToString"/>).</param>
328-
public void Log<T>(Severity severity, T? text) {
327+
public void Log(Severity severity, object? text) {
329328
DateTime time = DateTime.Now;
330329
OnLog?.Invoke(this, text?.ToString()??"", severity, time);
331330
if (((byte)severity) > ((byte)logLevel)) { return; }
@@ -339,61 +338,54 @@ public void Log<T>(Severity severity, T? text) {
339338
/// <summary>
340339
/// Logs something with Trace severity.
341340
/// </summary>
342-
/// <typeparam name="T">The type of the data.</typeparam>
343341
/// <param name="text">The text to write (<see cref="object.ToString"/>).</param>
344-
public void LogTrace<T>(T? text) {
342+
public void LogTrace(object? text) {
345343
Log(Severity.Trace, text);
346344
}
347345
/// <summary>
348346
/// Logs something with Debug severity.
349347
/// </summary>
350-
/// <typeparam name="T">The type of the data.</typeparam>
351348
/// <param name="text">The text to write (<see cref="object.ToString"/>).</param>
352-
public void LogDebug<T>(T? text) {
349+
public void LogDebug(object? text) {
353350
Log(Severity.Debug, text);
354351
}
355352
/// <summary>
356353
/// Logs something with Info severity.
357354
/// </summary>
358-
/// <typeparam name="T">The type of the data.</typeparam>
359355
/// <param name="text">The text to write (<see cref="object.ToString"/>).</param>
360-
public void LogInfo<T>(T? text) {
356+
public void LogInfo(object? text) {
361357
Log(Severity.Info, text);
362358
}
363359
/// <summary>
364360
/// Logs something with Message severity.
365361
/// </summary>
366-
/// <typeparam name="T">The type of the data.</typeparam>
367362
/// <param name="text">The text to write (<see cref="object.ToString"/>).</param>
368-
public void LogMessage<T>(T? text) {
363+
public void LogMessage(object? text) {
369364
Log(Severity.Message, text);
370365
}
371366
/// <summary>
372367
/// Logs something with Warning severity.
373368
/// </summary>
374-
/// <typeparam name="T">The type of the data.</typeparam>
375369
/// <param name="text">The text to write (<see cref="object.ToString"/>).</param>
376-
public void LogWarning<T>(T? text) {
370+
public void LogWarning(object? text) {
377371
Log(Severity.Warning, text);
378372
}
379373
/// <summary>
380374
/// Logs something with Error severity.
381375
/// </summary>
382-
/// <typeparam name="T">The type of the data.</typeparam>
383376
/// <param name="text">The text to write (<see cref="object.ToString"/>).</param>
384-
public void LogError<T>(T? text) {
377+
public void LogError(object? text) {
385378
Log(Severity.Error, text);
386379
}
387380
/// <summary>
388381
/// Logs something with Fatal severity.
389382
/// </summary>
390-
/// <typeparam name="T">The type of the data.</typeparam>
391383
/// <param name="text">The text to write (<see cref="object.ToString"/>).</param>
392-
public void LogFatal<T>(T? text) {
384+
public void LogFatal(object? text) {
393385
Log(Severity.Fatal, text);
394386
}
395387

396-
private string GetStacktrace(Exception e) {
388+
private static string GetStacktrace(Exception e) {
397389
string stackTrace = e.StackTrace ?? " (Unknown)";
398390
if (e.InnerException != null) {
399391
Exception inner = e.InnerException;

Terminal/Logging/Severity.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace OxDED.Terminal.Logging;
22

33
/// <summary>
4-
/// Logger severity.
4+
/// Logger severity (from high severity to low severity).
55
/// </summary>
66
public enum Severity : byte {
77
///

Terminal/Logging/Targets/FileTarget.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public FileTarget(string path, string? format = null) {
2424
/// <remarks>
2525
/// Writes a line.
2626
/// </remarks>
27-
public override void Write<T>(Severity severity, DateTime time, Logger logger, T? text) where T : default {
27+
public override void Write(Severity severity, DateTime time, Logger logger, object? text) {
2828
FileOut.WriteLine(GetText(logger, time, severity, text?.ToString() ?? "(Null)"));
2929
}
3030
/// <inheritdoc/>

Terminal/Logging/Targets/FormattedTarget.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected string GetText(Logger logger, DateTime time, Severity severity, string
5151
}
5252

5353
/// <inheritdoc/>
54-
public abstract void Write<T>(Severity severity, DateTime time, Logger logger, T? text);
54+
public abstract void Write(Severity severity, DateTime time, Logger logger, object? text);
5555

5656
/// <inheritdoc/>
5757
public abstract void Dispose();

Terminal/Logging/Targets/TerminalTarget.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ private string GetText(Logger logger, DateTime time, Severity severity, string t
5050
/// <remarks>
5151
/// Writes a line.
5252
/// </remarks>
53-
public override void Write<T>(Severity severity, DateTime time, Logger logger, T? text) where T : default {
53+
public override void Write(Severity severity, DateTime time, Logger logger, object? text) {
5454
if (((byte)severity) < 2) {
5555
Error.WriteLine(GetText(logger, time, severity, text?.ToString() ?? "(Null)", SeverityColors[(byte)severity].ToForegroundANSI()));
5656
} else {

Terminal/Terminal.cs

+8-13
Original file line numberDiff line numberDiff line change
@@ -93,51 +93,48 @@ public static TerminalWindow CreateWindow(string title) {
9393
/// <summary>
9494
/// Writes something (<see cref="object.ToString"/>) to the terminal, with a style.
9595
/// </summary>
96-
/// <typeparam name="T">The type of what to write (<see cref="object.ToString"/>).</typeparam>
9796
/// <param name="text">The thing to write to the terminal.</param>
9897
/// <param name="style">The text decoration to use.</param>
99-
public static void Write<T>(T? text, Style? style = null) {
98+
public static void Write(object? text, Style? style = null) {
10099
Out.Write((style ?? new Style()).ToANSI()+text?.ToString()+ANSI.Styles.ResetAll);
101100
}
102101
/// <summary>
103102
/// Writes something (<see cref="object.ToString"/>) to the terminal, with a style.
104103
/// </summary>
105-
/// <typeparam name="T">The type of what to write (<see cref="object.ToString"/>).</typeparam>
106104
/// <param name="text">The thing to write to the terminal.</param>
107105
/// <param name="style">The text decoration to use.</param>
108-
public static void WriteLine<T>(T? text, Style? style = null) {
106+
public static void WriteLine(object? text, Style? style = null) {
109107
Out.WriteLine((style ?? new Style()).ToANSI()+text?.ToString()+ANSI.Styles.ResetAll);
110108
}
111109
/// <summary>
112110
/// Writes a line to the terminal, with a style.
113111
/// </summary>
114112
/// <param name="style">The text decoration to use.</param>
115113
public static void WriteLine(Style? style = null) {
116-
WriteLine<object>(null, style);
114+
WriteLine(null, style);
117115
}
118116
/// <summary>
119117
/// Writes something (<see cref="object.ToString"/>) to the error stream, with a style.
120118
/// </summary>
121119
/// <typeparam name="T">The type of what to write (<see cref="object.ToString"/>).</typeparam>
122120
/// <param name="text">The text to write to the error output stream.</param>
123121
/// <param name="style">The style to use (default: with red foreground).</param>
124-
public static void WriteErrorLine<T>(T? text, Style? style = null) {
122+
public static void WriteErrorLine<T>(object? text, Style? style = null) {
125123
Error.WriteLine((style ?? new Style {ForegroundColor = Colors.Red}).ToANSI()+text?.ToString()+ANSI.Styles.ResetAll);
126124
}
127125
/// <summary>
128126
/// Writes a line to the error stream, with a style.
129127
/// </summary>
130128
/// <param name="style">The text decoration to use (default: with red foreground).</param>
131129
public static void WriteErrorLine(Style? style = null) {
132-
WriteLine<object>(null, style);
130+
WriteLine(null, style);
133131
}
134132
/// <summary>
135133
/// Writes something (<see cref="object.ToString"/>) to the error stream, with a style.
136134
/// </summary>
137-
/// <typeparam name="T">The type of what to write (<see cref="object.ToString"/>).</typeparam>
138135
/// <param name="text">The text to write to the error output stream.</param>
139136
/// <param name="style">The style to use (default: with red foreground).</param>
140-
public static void WriteError<T>(T? text, Style? style = null) {
137+
public static void WriteError(object? text, Style? style = null) {
141138
Error.Write((style ?? new Style {ForegroundColor = Colors.Red}).ToANSI()+text?.ToString()+ANSI.Styles.ResetAll);
142139
}
143140
/// <summary>
@@ -160,23 +157,21 @@ public static (int x, int y) GetCursorPosition() {
160157
/// <summary>
161158
/// Sets the something (<see cref="object.ToString"/>) at a <paramref name="pos"/>, with a <paramref name="style"/>.
162159
/// </summary>
163-
/// <typeparam name="T"></typeparam>
164160
/// <param name="text">The thing to set at <paramref name="pos"/> to the terminal.</param>
165161
/// <param name="pos">The position to set <paramref name="text"/> at.</param>
166162
/// <param name="style">The text decoration to use.</param>
167-
public static void Set<T>(T? text, (int x, int y) pos, Style? style = null) {
163+
public static void Set(object? text, (int x, int y) pos, Style? style = null) {
168164
Goto(pos);
169165
Write(text, style);
170166
}
171167

172168
/// <summary>
173169
/// Sets the something in the error stream (<see cref="object.ToString"/>) at a <paramref name="pos"/>, with a <paramref name="style"/>.
174170
/// </summary>
175-
/// <typeparam name="T"></typeparam>
176171
/// <param name="text">The thing to set at <paramref name="pos"/> to the terminal.</param>
177172
/// <param name="pos">The position to set <paramref name="text"/> at.</param>
178173
/// <param name="style">The text decoration to use.</param>
179-
public static void SetError<T>(T? text, (int x, int y) pos, Style? style = null) {
174+
public static void SetError(object? text, (int x, int y) pos, Style? style = null) {
180175
Goto(pos);
181176
WriteError(text, style);
182177
}

Terminal/Terminal.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<PublishTrimmed>true</PublishTrimmed>
88
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
99
<PackageId>0xDED.Terminal</PackageId>
10-
<Version>4.2.3</Version>
10+
<Version>4.2.5</Version>
1111
<Authors>0xDED</Authors>
1212
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1313
<PackageReadmeFile>README.md</PackageReadmeFile>

examples/Assertion/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public static void Main(string[] args) {
2323

2424
// Assertions contain methods to check or handle the result:
2525
Assert.Is(4, 2).Log(logger)
26-
.OnFailure((Assertion failedAssertion) => { // Gets executed when the result is not Success.
26+
.OnFailure(failedAssertion => { // Gets executed when the result is not Success.
2727
logger.LogFatal("Panic!");
2828
})
2929
.IsSuccess(); // True if the result is Success.

0 commit comments

Comments
 (0)