btcli 0.5.8

An online command-line translation tool for Chinese and other languages with TUI interface.
// Copyright (C) 2026 S.A. (@snoware)
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

#[cfg(feature = "ui")]
use cursive::{Cursive, CursiveExt};

#[cfg(feature = "ui")]
pub fn ui_main() {
    let mut siv = Cursive::default();

    let mut theme = siv.current_theme().clone();
    theme
        .palette
        .set_color("Background", cursive::theme::Color::Rgb(200, 230, 230));
    theme
        .palette
        .set_color("View", cursive::theme::Color::Rgb(220, 250, 250));
    siv.set_theme(theme);

    siv.add_layer(crate::ui::index::build_main_view());

    siv.set_global_callback('t', |s| {
        crate::ui::index::translate_with_ask(s);
    });
    siv.set_global_callback('c', |s| {
        crate::ui::index::clear_texts(s);
    });
    siv.set_global_callback('v', |s| {
        s.add_layer(crate::ui::settings::build_view_only_settings_view());
        // 延迟填充设置,确保UI控件已完全加载
        s.cb_sink()
            .send(std::boxed::Box::new(|s| {
                crate::ui::settings::populate_view_only_settings_view(s);
            }))
            .unwrap_or(());
    });
    siv.set_global_callback('h', |s| {
        s.add_layer(crate::ui::help::build_help_view());
    });
    siv.set_global_callback('a', |s| {
        s.add_layer(crate::ui::about::build_about_view());
    });
    siv.set_global_callback('r', |s| {
        crate::ui::index::copy_translation_result(s);
    });

    // 按Q键退出
    siv.set_global_callback('q', |s| {
        s.quit(); // 退出程序
    });

    siv.run();
}

#[cfg(not(feature = "ui"))]
pub fn ui_main() {
    eprintln!("UI功能未启用。请使用命令行参数运行此程序。");
}