i18n_ui 0.2.125

i18n 翻译进度终端界面:交互式并发面板与非交互逐行输出
docs.rs failed to build i18n_ui-0.2.125
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: i18n_ui-0.2.126

crates.io docs.rs license

English 简体中文 Français Deutsch Español 日本語 العربية Português Русский Italiano Nederlands 한국어 Türkçe Indonesia 正體中文 हिन्दी Polski தமிழ் Gaeilge Svenska বাংলা עברית ไทย Norsk Tiếng Việt मराठी Bahasa Melayu Dansk Română اردو Čeština فارسی తెలుగు ਪੰਜਾਬੀ ಕನ್ನಡ ગુજરાતી Ελληνικά Suomi Català Gàidhlig Қазақша Filipino Kiswahili ئۇيغۇرچە Magyar Українська Oʻzbekcha മലയാളം Slovenčina Afrikaans Hrvatski Српски Български Brezhoneg አማርኛ Cymraeg ଓଡ଼ିଆ සිංහල Hausa Euskara Ślōnskŏ Lietuvių Беларуская IsiZulu Galego မြန်မာ Slovenščina Azərbaycanca অসমীয়া ខ្មែរ नेपाली Kurdî IsiXhosa Latviešu Eesti Татарча Íslenska ქართული Bosanski Shqip Հայերեն Монгол Кыргызча Македонски ລາວ Тоҷикӣ Ikinyarwanda Esperanto Filipino Nynorsk سۆرانی Wolof Frysk

i18n_ui

Terminal UI for translation progress: the interactive panel displays concurrent tasks cell by cell; non-interactive environments output line by line.

The translation side holds only lightweight handles Ui / Job; events are sent through a channel to a dedicated rendering thread, so a slow terminal never blocks network I/O.

Usage

use i18n_ui::{Mode, Ui};

let ui = Ui::new(Mode::Auto, 3);
ui.plan(2, 0);

let mut job = ui.job("zh", "en/guide.md");
job.think("正在通读原文");
job.reply().reply("Translated line. ");
job.done();

ui.hit(); // cache hit, counted directly as done
ui.log("删除无源文件的译文 en/old.md");

The think / reply / fail methods of Job, Reply, and Retry stream status events to the UI; callers can forward them in the ai_api::OnThink / OnReply / OnFail callbacks.

cargo run -p i18n_ui --example demo              # interactive panel
I18N_UI=plain cargo run -p i18n_ui --example demo # line-by-line output

Modes

Mode::Auto uses the interactive panel when both stderr and stdout are terminals, the environment is not CI, and TERM is not dumb; the environment variable I18N_UI=tty|plain can force a specific mode.

Mode::Tty forces interactive mode; if stdout is redirected, cursor queries time out after about 2 seconds and fall back to line-by-line output. Mode::Plain outputs line by line on stderr, with no color.

API

Ui::new(mode, concurrency)

Starts the rendering thread. concurrency is the upper limit on concurrent model calls and determines the number of panel cells.

plan(job, cache)

Sets the total number of tasks and the number of cache hits among them.

hit() / grow() / skip()

hit records a cache hit; grow adds a task missed by the pre-check; skip subtracts a task from the total.

job(from, out)

Creates a new task handle; from is the source language and out is the translation path.

log(text)

Appends a line to the history section.

Job

Method Description
think(s) Append thought stream
reply() Returns the body-callback handle Reply
retry() Returns the failure-callback handle Retry for the cooldown countdown
done() Marks the task as done
fail(err) Marks the task as failed

Drop impls on Ui and Job perform cleanup and restore the terminal; Retry::fail parameters are the current round, total rounds, cooldown duration, endpoint, and error.