public async Task Processing(CommandOptions options) { if (options.ListDicts) { _drawer.ListAllDictInfo(await _dictHttpApi.GetInfoList().Safety()); } else if (options.DictNum != null) { var bookName = await _dictHttpApi.SetCurrentDict(options.DictNum.Value).Safety(); if (string.IsNullOrWhiteSpace(bookName) == false) { Console.WriteLine($"set current dict to: {bookName}.", Color.Gold); } } else if (false == options.Prompt && false == string.IsNullOrWhiteSpace(options.Word)) { var result = await _dictHttpApi.Search(options.Word).Safety(); _drawer.DrawSearchResult(result); } else if (options.Prompt && false == string.IsNullOrWhiteSpace(options.Word)) { var prompts = await _dictHttpApi.Prompts(options.Word); if (prompts == null) { return; } // var dir = "/tmp/any-dict/prompt/"; // if (Directory.Exists(dir) == false) Directory.CreateDirectory(dir); // await File.WriteAllLinesAsync(dir + options.Word, prompts); var ps = prompts.Select(t => t.Trim().Replace("\n", "")); _drawer.DrawPromptResult(ps); } await Task.CompletedTask; }
public async Task Processing(CommandOptions options) { if (options.ListDicts) { _drawer.ListAllDictInfo(_dictParser.InfoList); } else if (options.DictNum != null && options.DictNum > 0 && options.DictNum <= _dictParser.InfoList?.Count) { var info = _dictParser.InfoList[options.DictNum.Value - 1]; var dict = await _dictParser.GetDictBytes(info.DirAndFileName.Item1, info.DirAndFileName.Item2); if (await _searcher.SetDict(dict, info)) { Console.WriteLine($"set current dict to: {info.BookName}.", Color.Gold); await OnSetCurrentDict?.Invoke(info.BookName); } } else if (false == string.IsNullOrWhiteSpace(options.Word)) { var result = await _searcher.Search(options.Word); _drawer.DrawSearchResult(result); } }