mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-04 00:56:31 +02:00
Handle Clear gracefully in non-interactive console without crashing
This commit is contained in:
@@ -39,14 +39,16 @@ public class ConsoleStatementsTests
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ClearThrowsInNonInteractiveConsoleTest()
|
||||
public void ClearDoesNotCrashInNonInteractiveConsoleTest()
|
||||
{
|
||||
List<string> lines =
|
||||
[
|
||||
"clear"
|
||||
"clear",
|
||||
"var dummy = 0",
|
||||
"${dummy}"
|
||||
];
|
||||
|
||||
_ = Assert.Throws<IOException>(() => YesNtAssert.GetLastLine(lines));
|
||||
YesNtAssert.IsLastLineEqual(lines, "0");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
|
||||
using YesNt.Interpreter.Attributes;
|
||||
using YesNt.Interpreter.Enums;
|
||||
@@ -61,6 +62,13 @@ internal class ConsoleStatements : StatementRuntimeInformation
|
||||
[SuppressMessage("Performance", "CA1822:Mark members as static", Justification = "Won't work if static")]
|
||||
public void Clear(string _)
|
||||
{
|
||||
Console.Clear();
|
||||
try
|
||||
{
|
||||
Console.Clear();
|
||||
}
|
||||
catch (IOException)
|
||||
{
|
||||
// Silently fail if the console is not interactive
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user