Skip to main content

btcli_lib/ui/
loader.rs

1// Copyright (C) 2026 S.A. (@snoware)
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
7use cursive::{Cursive, CursiveExt};
8
9pub fn ui_main() {
10    let mut siv = Cursive::default();
11
12    let mut theme = siv.current_theme().clone();
13    theme
14        .palette
15        .set_color("Background", cursive::theme::Color::Rgb(200, 230, 230));
16    theme
17        .palette
18        .set_color("View", cursive::theme::Color::Rgb(220, 250, 250));
19    siv.set_theme(theme);
20
21    siv.add_layer(crate::ui::index::build_main_view());
22
23    siv.set_global_callback('t', |s| {
24        crate::ui::index::translate_with_ask(s);
25    });
26    siv.set_global_callback('c', |s| {
27        crate::ui::index::clear_texts(s);
28    });
29    siv.set_global_callback('v', |s| {
30        s.add_layer(crate::ui::settings::build_view_only_settings_view());
31        // 延迟填充设置,确保UI控件已完全加载
32        s.cb_sink()
33            .send(std::boxed::Box::new(|s| {
34                crate::ui::settings::populate_view_only_settings_view(s);
35            }))
36            .unwrap_or(());
37    });
38    siv.set_global_callback('h', |s| {
39        s.add_layer(crate::ui::help::build_help_view());
40    });
41    siv.set_global_callback('a', |s| {
42        s.add_layer(crate::ui::about::build_about_view());
43    });
44
45    // 按Q键退出
46    siv.set_global_callback('q', |s| {
47        s.quit(); // 退出程序
48    });
49
50    siv.run();
51}