summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-12-08 21:00:24 +0800
committer魏曹先生 <1992414357@qq.com>2025-12-08 21:00:24 +0800
commita570d168d145f44ac44b9a2c60b7a089dad65f87 (patch)
tree662193ed15af545287db31fac070c60441f4fb1f
parente9bfa7b8cb4a577d1a0864624f866bc98a379ffb (diff)
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
-rw-r--r--Cargo.lock127
-rw-r--r--Cargo.toml3
-rw-r--r--locales/help_docs/en.yml4
-rw-r--r--locales/help_docs/zh-CN.yml4
-rw-r--r--scripts/jv_cli.ps12
-rw-r--r--scripts/jv_cli.sh2
-rw-r--r--src/bin/jvii.rs19
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
@@ -467,6 +467,31 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -962,6 +987,7 @@ dependencies = [
"chrono",
"clap",
"colored",
+ "crossterm",
"dirs",
"env_logger",
"just_enough_vcs",
@@ -1029,6 +1055,18 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69d83b0086dc8ecf3ce9ae2874b2d1290252e2a30720bea58a5c6639b0092873"
@@ -1674,6 +1712,27 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1835,7 +1894,7 @@ checksum = "ff360e02eab121e0bc37a2d3b4d4dc622e6eda3a8e5253d5435ecf5bd4c68408"
dependencies = [
"bytes",
"libc",
- "mio",
+ "mio 1.1.0",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
@@ -2248,6 +2307,15 @@ dependencies = [
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
@@ -2284,6 +2352,21 @@ dependencies = [
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
@@ -2317,6 +2400,12 @@ dependencies = [
[[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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
@@ -2329,6 +2418,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
@@ -2341,6 +2436,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
@@ -2365,6 +2466,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
@@ -2377,6 +2484,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
@@ -2389,6 +2502,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
@@ -2401,6 +2520,12 @@ 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"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
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(&current_locales());
+
let args = JustEnoughVcsInputer::parse();
// Check if a file argument was provided