mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-04-04 03:23:05 -06:00
Refine ReadLinesAsync: pattern matching, rename, cancellation token
Agent-Logs-Url: https://github.com/Tyrrrz/DiscordChatExporter/sessions/e4a61491-645a-418c-91cd-74e835baaf44 Co-authored-by: Tyrrrz <1935960+Tyrrrz@users.noreply.github.com>
This commit is contained in:
parent
316e8c6ea8
commit
f656234c38
|
|
@ -34,7 +34,7 @@ public partial class ExportChannelsCommand : ExportCommandBase
|
||||||
var channelIds = new List<Snowflake>(ChannelIds);
|
var channelIds = new List<Snowflake>(ChannelIds);
|
||||||
if (channelIds.Count == 0 && console.IsInputRedirected)
|
if (channelIds.Count == 0 && console.IsInputRedirected)
|
||||||
{
|
{
|
||||||
await foreach (var line in console.Input.ReadAllLinesAsync())
|
await foreach (var line in console.Input.ReadLinesAsync(cancellationToken))
|
||||||
channelIds.Add(Snowflake.Parse(line));
|
channelIds.Add(Snowflake.Parse(line));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using CliFx.Infrastructure;
|
using CliFx.Infrastructure;
|
||||||
using Spectre.Console;
|
using Spectre.Console;
|
||||||
|
|
@ -64,10 +65,13 @@ internal static class ConsoleExtensions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async IAsyncEnumerable<string> ReadAllLinesAsync(this TextReader reader)
|
public static async IAsyncEnumerable<string> ReadLinesAsync(
|
||||||
|
this TextReader reader,
|
||||||
|
[System.Runtime.CompilerServices.EnumeratorCancellation]
|
||||||
|
CancellationToken cancellationToken = default
|
||||||
|
)
|
||||||
{
|
{
|
||||||
string? line;
|
while (await reader.ReadLineAsync(cancellationToken) is { } line)
|
||||||
while ((line = await reader.ReadLineAsync()) is not null)
|
|
||||||
{
|
{
|
||||||
line = line.Trim();
|
line = line.Trim();
|
||||||
if (!string.IsNullOrEmpty(line))
|
if (!string.IsNullOrEmpty(line))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue