优化选择对话框默认选中项逻辑

This commit is contained in:
nilaoda 2022-07-10 03:12:50 +08:00
parent 386c923802
commit 21886d74c7
1 changed files with 10 additions and 1 deletions

View File

@ -37,12 +37,17 @@ namespace N_m3u8DL_RE.Parser.Util
.PageSize(10) .PageSize(10)
.MoreChoicesText(ResString.promptChoiceText) .MoreChoicesText(ResString.promptChoiceText)
.InstructionsText(ResString.promptInfo) .InstructionsText(ResString.promptInfo)
.AddChoiceGroup(new StreamSpec() { Name = "__Basic" }, basicStreams); ;
//默认选中第一个 //默认选中第一个
var first = lists.First(); var first = lists.First();
prompt.Select(first); prompt.Select(first);
if (basicStreams.Any())
{
prompt.AddChoiceGroup(new StreamSpec() { Name = "__Basic" }, basicStreams);
}
if (audios.Any()) if (audios.Any())
{ {
prompt.AddChoiceGroup(new StreamSpec() { Name = "__Audio" }, audios); prompt.AddChoiceGroup(new StreamSpec() { Name = "__Audio" }, audios);
@ -61,6 +66,10 @@ namespace N_m3u8DL_RE.Parser.Util
prompt.Select(subs.First(s => s.GroupId == first.SubtitleId)); prompt.Select(subs.First(s => s.GroupId == first.SubtitleId));
} }
} }
//如果此时还是没有选中任何流,自动选择一个
prompt.Select(basicStreams.Concat(audios).Concat(subs).First());
//多选 //多选
var selectedStreams = AnsiConsole.Prompt(prompt); var selectedStreams = AnsiConsole.Prompt(prompt);