From a570d168d145f44ac44b9a2c60b7a089dad65f87 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 8 Dec 2025 21:00:24 +0800 Subject: Add crossterm dependency and implement jvii editor - Add crossterm crate for terminal UI capabilities - Update jvii editor with proper status bar and keyboard hints - Add i18n support for editor interface - Remove default nano editor configuration from shell scripts --- Cargo.lock | 127 +++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 3 ++ locales/help_docs/en.yml | 4 ++ locales/help_docs/zh-CN.yml | 4 ++ scripts/jv_cli.ps1 | 2 +- scripts/jv_cli.sh | 2 +- src/bin/jvii.rs | 19 +++++-- 7 files changed, 154 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index aa9b047..e732e29 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -466,6 +466,31 @@ version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" +[[package]] +name = "crossterm" +version = "0.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df" +dependencies = [ + "bitflags 2.9.4", + "crossterm_winapi", + "libc", + "mio 0.8.11", + "parking_lot", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +dependencies = [ + "winapi", +] + [[package]] name = "crypto-common" version = "0.1.6" @@ -962,6 +987,7 @@ dependencies = [ "chrono", "clap", "colored", + "crossterm", "dirs", "env_logger", "just_enough_vcs", @@ -1027,6 +1053,18 @@ version = "2.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273" +[[package]] +name = "mio" +version = "0.8.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.48.0", +] + [[package]] name = "mio" version = "1.1.0" @@ -1673,6 +1711,27 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signal-hook" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d881a16cf4426aa584979d30bd82cb33429027e42122b169753d6ef1085ed6e2" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b75a19a7a740b25bc7944bdee6172368f988763b744e3d4dfe753f6b4ece40cc" +dependencies = [ + "libc", + "mio 0.8.11", + "signal-hook", +] + [[package]] name = "signal-hook-registry" version = "1.4.6" @@ -1835,7 +1894,7 @@ checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408" dependencies = [ "bytes", "libc", - "mio", + "mio 1.1.0", "parking_lot", "pin-project-lite", "signal-hook-registry", @@ -2246,6 +2305,15 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.5", +] + [[package]] name = "windows-sys" version = "0.52.0" @@ -2282,6 +2350,21 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" +dependencies = [ + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", +] + [[package]] name = "windows-targets" version = "0.52.6" @@ -2315,6 +2398,12 @@ dependencies = [ "windows_x86_64_msvc 0.53.1", ] +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" + [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" @@ -2327,6 +2416,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" @@ -2339,6 +2434,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" +[[package]] +name = "windows_i686_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" + [[package]] name = "windows_i686_gnu" version = "0.52.6" @@ -2363,6 +2464,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" +[[package]] +name = "windows_i686_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" + [[package]] name = "windows_i686_msvc" version = "0.52.6" @@ -2375,6 +2482,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" @@ -2387,6 +2500,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" @@ -2399,6 +2518,12 @@ version = "0.53.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" diff --git a/Cargo.toml b/Cargo.toml index 6082cd6..92ed9ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -53,6 +53,9 @@ tokio = { version = "1", features = ["full"] } colored = "3.0" strip-ansi-escapes = "0.2.1" +# Terminal +crossterm = "0.27" + # i18n rust-i18n = "3" diff --git a/locales/help_docs/en.yml b/locales/help_docs/en.yml index fa458f2..ab175ef 100644 --- a/locales/help_docs/en.yml +++ b/locales/help_docs/en.yml @@ -940,6 +940,10 @@ jv: version_already_exist: | The version %{version} of file %{path} you are committing already exists in the upstream vault, please use a different version number! +jvii: + hints: | + [^S WRITE] [ESC EXIT] + editor: update_editor: | # You are using editor mode to track and update files diff --git a/locales/help_docs/zh-CN.yml b/locales/help_docs/zh-CN.yml index ddcd00f..86051a0 100644 --- a/locales/help_docs/zh-CN.yml +++ b/locales/help_docs/zh-CN.yml @@ -939,6 +939,10 @@ jv: version_already_exist: | 您正在提交的文件 %{path} 的版本 %{version} 在上游库中已存在,请使用其他版本号! +jvii: + hints: | + [^S 保存] [ESC 退出] + editor: update_editor: | # 您正在使用编辑器模式追踪和提交文件 diff --git a/scripts/jv_cli.ps1 b/scripts/jv_cli.ps1 index 123e28d..8e16646 100644 --- a/scripts/jv_cli.ps1 +++ b/scripts/jv_cli.ps1 @@ -15,7 +15,7 @@ $env:JV_AUTO_UPDATE = "yes" # Use JV_TEXT_EDITOR to set text editor for `jv track --work` `jv align --work` # DEFAULT: $EDITOR environment variable, falling back to "jvii" if not set -$env:JV_TEXT_EDITOR = "nano" +# $env:JV_TEXT_EDITOR = "nano" ############### ### ALIASES ### diff --git a/scripts/jv_cli.sh b/scripts/jv_cli.sh index eb7699a..e05df3d 100644 --- a/scripts/jv_cli.sh +++ b/scripts/jv_cli.sh @@ -16,7 +16,7 @@ export JV_AUTO_UPDATE=yes # Use JV_TEXT_EDITOR to set text editor for `jv track --work` `jv align --work` # DEFAULT: $EDITOR environment variable, falling back to "jvii" if not set -export JV_TEXT_EDITOR=nano +# export JV_TEXT_EDITOR=nano ############### ### ALIASES ### diff --git a/src/bin/jvii.rs b/src/bin/jvii.rs index 9e1b444..0d6a584 100644 --- a/src/bin/jvii.rs +++ b/src/bin/jvii.rs @@ -16,6 +16,13 @@ use crossterm::{ }, }; use just_enough_vcs_cli::utils::display::display_width; +use just_enough_vcs_cli::utils::display::md; +use just_enough_vcs_cli::utils::env::current_locales; +use rust_i18n::set_locale; +use rust_i18n::t; + +// Import i18n files +rust_i18n::i18n!("locales", fallback = "en"); #[derive(Parser, Debug)] #[command( @@ -280,14 +287,15 @@ impl Editor { stdout.queue(Clear(ClearType::CurrentLine))?; let status = format!( - "{} - {} lines{}", + "{} - {} lines{} {}", self.file_path.display(), self.content.len(), - if self.modified { " *" } else { "" } + if self.modified { " *" } else { "" }, + md(t!("jvii.hints")) ); - stdout.queue(SetForegroundColor(Color::White))?; - stdout.queue(style::SetBackgroundColor(Color::DarkBlue))?; + stdout.queue(SetForegroundColor(Color::Black))?; + stdout.queue(style::SetBackgroundColor(Color::White))?; let display_status = if display_width(&status) > width as usize { // Find the maximum number of characters that fit within width let mut current_width = 0; @@ -499,6 +507,9 @@ impl Editor { #[tokio::main] async fn main() { + // Init i18n + set_locale(¤t_locales()); + let args = JustEnoughVcsInputer::parse(); // Check if a file argument was provided -- cgit