Skip to content

Commit 95762e4

Browse files
committed
feat: add console stdin helper
1 parent 393d654 commit 95762e4

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/WeihanLi.Common/Helpers/ConsoleHelper.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,21 @@ public static CommandResult PrintOutputToConsole(this CommandResult commandResul
201201

202202
return commandResult;
203203
}
204+
205+
public static bool HasStandardInput()
206+
{
207+
return Console.IsInputRedirected && Console.In.Peek() != -1;
208+
}
209+
210+
public static bool TryGetStandardInput([MaybeNullWhen(false)]out string input)
211+
{
212+
if (HasStandardInput())
213+
{
214+
input = Console.In.ReadToEnd();
215+
return true;
216+
}
217+
218+
input = null;
219+
return false;
220+
}
204221
}

0 commit comments

Comments
 (0)