Ejemplo n.º 1
0
        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;
        }