diff --git a/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs index 22e74c25..f8bed5b1 100644 --- a/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs @@ -34,7 +34,7 @@ public partial class ExportChannelsCommand : ExportCommandBase var channelIds = new List(ChannelIds); 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)); } diff --git a/DiscordChatExporter.Cli/Utils/Extensions/ConsoleExtensions.cs b/DiscordChatExporter.Cli/Utils/Extensions/ConsoleExtensions.cs index 80e40253..25c8c539 100644 --- a/DiscordChatExporter.Cli/Utils/Extensions/ConsoleExtensions.cs +++ b/DiscordChatExporter.Cli/Utils/Extensions/ConsoleExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Threading; using System.Threading.Tasks; using CliFx.Infrastructure; using Spectre.Console; @@ -64,10 +65,13 @@ internal static class ConsoleExtensions } } - public static async IAsyncEnumerable ReadAllLinesAsync(this TextReader reader) + public static async IAsyncEnumerable ReadLinesAsync( + this TextReader reader, + [System.Runtime.CompilerServices.EnumeratorCancellation] + CancellationToken cancellationToken = default + ) { - string? line; - while ((line = await reader.ReadLineAsync()) is not null) + while (await reader.ReadLineAsync(cancellationToken) is { } line) { line = line.Trim(); if (!string.IsNullOrEmpty(line))