diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-12 14:28:08 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-12 14:28:08 +0800 |
| commit | 0a95bae451c1847f4f0b9601e60959f4e8e6b669 (patch) | |
| tree | 9e1cfad4f86a73176a4d738b28e7732b66fe5f97 /src | |
| parent | 8564c8f2177dec0c2c0c031d156347fa6b4485bc (diff) | |
Refactor display utilities
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/jv.rs | 10 | ||||
| -rw-r--r-- | src/bin/jvii.rs | 6 | ||||
| -rw-r--r-- | src/bin/jvn.rs | 4 | ||||
| -rw-r--r-- | src/bin/jvv.rs | 2 | ||||
| -rw-r--r-- | src/cmds/arg/storage_build.rs | 12 | ||||
| -rw-r--r-- | src/cmds/arg/storage_write.rs | 33 | ||||
| -rw-r--r-- | src/cmds/cmd/sheetedit.rs | 10 | ||||
| -rw-r--r-- | src/cmds/cmd/storage_build.rs | 70 | ||||
| -rw-r--r-- | src/cmds/cmd/storage_write.rs | 110 | ||||
| -rw-r--r-- | src/cmds/in/storage_rw.rs | 11 | ||||
| -rw-r--r-- | src/cmds/renderer/mappings_pretty.rs | 8 |
11 files changed, 20 insertions, 256 deletions
diff --git a/src/bin/jv.rs b/src/bin/jv.rs index c3dc4ca..0df6b32 100644 --- a/src/bin/jv.rs +++ b/src/bin/jv.rs @@ -21,7 +21,6 @@ // The new implementation is located in `jvn.rs`, please refer to it. // -use cli_utils::input::input_with_editor; use colored::Colorize; use just_enough_vcs::{ data::compile_info::CoreCompileInfo, @@ -113,14 +112,13 @@ use std::{ }; use clap::{Parser, Subcommand}; -use cli_utils::{ +use cli_utils::legacy::{ display::{SimpleTable, display_width, md, render_share_path_tree, size_str}, env::{auto_update_outdate, current_locales, enable_auto_update}, fs::move_across_partitions, globber::{GlobItem, Globber}, - input::{confirm_hint, confirm_hint_or, show_in_pager}, - push_version::push_version, - socket_addr_helper, + input::{confirm_hint, confirm_hint_or, input_with_editor, show_in_pager}, + push_version, socket_addr_helper, }; use just_enough_vcs::utils::tcp_connection::error::TcpTargetError; use just_enough_vcs_cli::{ @@ -4035,7 +4033,7 @@ async fn start_update_editor( for item in files { let path = item.0.display().to_string(); let base_ver = item.1.to_string(); - let next_ver = push_version(&base_ver).unwrap_or(" ".to_string()); + let next_ver = push_version::push_version(&base_ver).unwrap_or(" ".to_string()); table.push_item(vec![ path, base_ver, diff --git a/src/bin/jvii.rs b/src/bin/jvii.rs index 2f9cb6d..fbc3ed9 100644 --- a/src/bin/jvii.rs +++ b/src/bin/jvii.rs @@ -5,9 +5,9 @@ use std::path::PathBuf; use std::time::Duration; use clap::Parser; -use cli_utils::display::display_width; -use cli_utils::display::md; -use cli_utils::env::current_locales; +use cli_utils::legacy::display::display_width; +use cli_utils::legacy::display::md; +use cli_utils::legacy::env::current_locales; use crossterm::{ QueueableCommand, cursor::MoveTo, diff --git a/src/bin/jvn.rs b/src/bin/jvn.rs index f2c5cf6..f45c78b 100644 --- a/src/bin/jvn.rs +++ b/src/bin/jvn.rs @@ -1,6 +1,6 @@ use std::{ops::Deref, process::exit}; -use cli_utils::{display::md, env::current_locales, levenshtein_distance::levenshtein_distance}; +use cli_utils::legacy::{display::md, env::current_locales, levenshtein_distance}; use just_enough_vcs_cli::{ special_argument, special_flag, systems::{ @@ -197,7 +197,7 @@ fn handle_no_matching_command_error(args: Vec<String>) { continue; } let args_str = args[..node_len].join(" "); - let distance = levenshtein_distance(args_str.as_str(), node.as_str()); + let distance = levenshtein_distance::levenshtein_distance(args_str.as_str(), node.as_str()); if distance <= 2 { similar_nodes.push(node); } diff --git a/src/bin/jvv.rs b/src/bin/jvv.rs index 335e374..885f3e0 100644 --- a/src/bin/jvv.rs +++ b/src/bin/jvv.rs @@ -22,7 +22,7 @@ // use clap::{Parser, Subcommand}; -use cli_utils::{ +use cli_utils::legacy::{ display::{md, size_str}, env::current_locales, logger::build_env_logger, diff --git a/src/cmds/arg/storage_build.rs b/src/cmds/arg/storage_build.rs deleted file mode 100644 index 5d57b97..0000000 --- a/src/cmds/arg/storage_build.rs +++ /dev/null @@ -1,12 +0,0 @@ -use std::path::PathBuf; - -use clap::Parser; - -#[derive(Parser, Debug)] -pub struct JVStorageBuildArgument { - pub index_file: PathBuf, - pub storage: PathBuf, - - #[arg(short = 'o', long = "output")] - pub output_file: Option<PathBuf>, -} diff --git a/src/cmds/arg/storage_write.rs b/src/cmds/arg/storage_write.rs deleted file mode 100644 index e00dfdf..0000000 --- a/src/cmds/arg/storage_write.rs +++ /dev/null @@ -1,33 +0,0 @@ -use std::path::PathBuf; - -use clap::Parser; - -#[derive(Parser, Debug)] -pub struct JVStorageWriteArgument { - pub file: PathBuf, - pub storage: PathBuf, - - #[arg(short = 'o', long = "output")] - pub output_index: Option<PathBuf>, - - #[arg(long = "line")] - pub line_chunking: bool, - - #[arg(long = "cdc", default_value_t = 0)] - pub cdc_chunking: u32, - - #[arg(long = "fixed", default_value_t = 0)] - pub fixed_chunking: u32, - - #[arg(long)] - pub b: bool, - - #[arg(long)] - pub kb: bool, // default chunk size unit - - #[arg(long)] - pub mb: bool, - - #[arg(long)] - pub gb: bool, -} diff --git a/src/cmds/cmd/sheetedit.rs b/src/cmds/cmd/sheetedit.rs index 3e61642..74b0bbe 100644 --- a/src/cmds/cmd/sheetedit.rs +++ b/src/cmds/cmd/sheetedit.rs @@ -10,7 +10,9 @@ use crate::{ }, }; use cli_utils::{ - display::SimpleTable, env::get_default_editor, input::input_with_editor_cutsom, string_vec, + display::table::Table, + legacy::{env::get_default_editor, input::input_with_editor_cutsom}, + string_vec, }; use cmd_system_macros::exec; use just_enough_vcs::system::sheet_system::{mapping::LocalMapping, sheet::SheetData}; @@ -96,7 +98,7 @@ fn render_pretty_mappings(mappings: &Vec<LocalMapping>) -> String { t!("sheetedit.forward") ]; - let mut simple_table = SimpleTable::new(header); + let mut table = Table::new(header); for mapping in mappings { let mapping_str = mapping @@ -105,7 +107,7 @@ fn render_pretty_mappings(mappings: &Vec<LocalMapping>) -> String { .into_iter() .map(|s| s.to_string()) .collect::<Vec<String>>(); - simple_table.push_item(vec![ + table.push_item(vec![ format!( " {} ", mapping_str.get(0).unwrap_or(&String::default()) @@ -116,7 +118,7 @@ fn render_pretty_mappings(mappings: &Vec<LocalMapping>) -> String { format!("{} ", mapping_str.get(4).unwrap_or(&String::default())), // Forward ]); } - simple_table.to_string() + table.to_string() } crate::command_template!(); diff --git a/src/cmds/cmd/storage_build.rs b/src/cmds/cmd/storage_build.rs deleted file mode 100644 index 8e4d39c..0000000 --- a/src/cmds/cmd/storage_build.rs +++ /dev/null @@ -1,70 +0,0 @@ -use crate::{ - cmd_output, - cmds::{ - arg::storage_build::JVStorageBuildArgument, collect::empty::JVEmptyCollect, - r#in::storage_rw::JVStorageRWInput, out::none::JVNoneOutput, - }, - systems::cmd::{ - cmd_system::JVCommandContext, - errors::{CmdExecuteError, CmdPrepareError}, - }, -}; -use cli_utils::display::md; -use cmd_system_macros::exec; -use just_enough_vcs::system::storage_system::{error::StorageIOError, store::build_file}; -use rust_i18n::t; -use std::any::TypeId; - -pub struct JVStorageBuildCommand; -type Cmd = JVStorageBuildCommand; -type Arg = JVStorageBuildArgument; -type In = JVStorageRWInput; -type Collect = JVEmptyCollect; - -fn help_str() -> String { - todo!() -} - -async fn prepare(args: &Arg, _ctx: &JVCommandContext) -> Result<In, CmdPrepareError> { - let output_file = match &args.output_file { - Some(v) => v.clone(), - None => args.index_file.clone().with_extension("unknown"), - }; - - let (input, storage, output) = just_enough_vcs::system::storage_system::store::precheck( - args.index_file.clone(), - args.storage.clone(), - output_file, - ) - .await?; - - Ok(JVStorageRWInput { - input, - storage, - output, - chunking_policy: None, - }) -} - -async fn collect(_args: &Arg, _ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> { - Ok(Collect {}) -} - -#[exec] -async fn exec( - input: In, - _collect: Collect, -) -> Result<(Box<dyn std::any::Any + Send + 'static>, TypeId), CmdExecuteError> { - build_file(input.input, input.storage, input.output) - .await - .map_err(|e| match e { - StorageIOError::IOErr(error) => CmdExecuteError::Io(error), - StorageIOError::HashTooShort => { - CmdExecuteError::Error(md(t!("storage_write.hash_too_short")).to_string()) - } - })?; - - cmd_output!(JVNoneOutput => JVNoneOutput {}) -} - -crate::command_template!(); diff --git a/src/cmds/cmd/storage_write.rs b/src/cmds/cmd/storage_write.rs deleted file mode 100644 index 8c864a8..0000000 --- a/src/cmds/cmd/storage_write.rs +++ /dev/null @@ -1,110 +0,0 @@ -use crate::{ - cmd_output, - cmds::{ - arg::storage_write::JVStorageWriteArgument, collect::empty::JVEmptyCollect, - r#in::storage_rw::JVStorageRWInput, out::none::JVNoneOutput, - }, - systems::cmd::{ - cmd_system::JVCommandContext, - errors::{CmdExecuteError, CmdPrepareError}, - }, -}; -use cli_utils::display::md; -use cmd_system_macros::exec; -use just_enough_vcs::system::{ - constants::vault::values::vault_value_index_file_suffix, - storage_system::{ - error::StorageIOError, - store::{ChunkingPolicy, StorageConfig, write_file}, - }, -}; -use rust_i18n::t; -use std::any::TypeId; - -pub struct JVStorageWriteCommand; -type Cmd = JVStorageWriteCommand; -type Arg = JVStorageWriteArgument; -type In = JVStorageRWInput; -type Collect = JVEmptyCollect; - -fn help_str() -> String { - todo!() -} - -async fn prepare(args: &Arg, _ctx: &JVCommandContext) -> Result<In, CmdPrepareError> { - let output_path = match &args.output_index { - Some(v) => v.clone(), - None => args - .file - .clone() - .with_extension(vault_value_index_file_suffix()), - }; - - // Default to using kb as the unit - let scale = if args.gb { - 1024 * 1024 * 1024 - } else if args.mb { - 1024 * 1024 - } else if args.b { - 1 - } else { - 1024 - }; - - let (input, storage, output) = just_enough_vcs::system::storage_system::store::precheck( - args.file.clone(), - args.storage.clone(), - output_path, - ) - .await?; - - let chunking_policy: ChunkingPolicy = if args.cdc_chunking > 0 { - ChunkingPolicy::Cdc(args.cdc_chunking * scale) - } else if args.fixed_chunking > 0 { - ChunkingPolicy::FixedSize(args.fixed_chunking * scale) - } else if args.line_chunking { - ChunkingPolicy::Line - } else { - return Err(CmdPrepareError::Error(md(t!( - "storage_write.unknown_chunking_policy" - )))); - }; - - Ok(JVStorageRWInput { - input, - storage, - output, - chunking_policy: Some(chunking_policy), - }) -} - -async fn collect(_args: &Arg, _ctx: &JVCommandContext) -> Result<Collect, CmdPrepareError> { - Ok(JVEmptyCollect {}) -} - -#[exec] -async fn exec( - input: In, - _collect: Collect, -) -> Result<(Box<dyn std::any::Any + Send + 'static>, TypeId), CmdExecuteError> { - // There is no chance to return None in the Prepare phase, so unwrap is safe here - let chunking_policy = input.chunking_policy.unwrap(); - - write_file( - input.input, - input.storage, - input.output, - &StorageConfig { chunking_policy }, - ) - .await - .map_err(|e| match e { - StorageIOError::IOErr(error) => CmdExecuteError::Io(error), - StorageIOError::HashTooShort => { - CmdExecuteError::Error(md(t!("storage_write.hash_too_short")).to_string()) - } - })?; - - cmd_output!(JVNoneOutput => JVNoneOutput {}) -} - -crate::command_template!(); diff --git a/src/cmds/in/storage_rw.rs b/src/cmds/in/storage_rw.rs deleted file mode 100644 index 596c1f9..0000000 --- a/src/cmds/in/storage_rw.rs +++ /dev/null @@ -1,11 +0,0 @@ -use std::path::PathBuf; - -use just_enough_vcs::system::storage_system::store::ChunkingPolicy; - -pub struct JVStorageRWInput { - pub input: PathBuf, - pub storage: PathBuf, - pub output: PathBuf, - - pub chunking_policy: Option<ChunkingPolicy>, -} diff --git a/src/cmds/renderer/mappings_pretty.rs b/src/cmds/renderer/mappings_pretty.rs index dad4d95..6431302 100644 --- a/src/cmds/renderer/mappings_pretty.rs +++ b/src/cmds/renderer/mappings_pretty.rs @@ -1,4 +1,4 @@ -use cli_utils::{display::SimpleTable, string_vec}; +use cli_utils::{display::table::Table, string_vec}; use colored::Colorize; use just_enough_vcs::system::sheet_system::mapping::LocalMapping; use render_system_macros::result_renderer; @@ -29,7 +29,7 @@ fn render_pretty_mappings(mappings: &Vec<LocalMapping>) -> String { "|" ]; - let mut simple_table = SimpleTable::new(header); + let mut table = Table::new(header); let mut i = 1; for mapping in mappings { @@ -39,7 +39,7 @@ fn render_pretty_mappings(mappings: &Vec<LocalMapping>) -> String { .into_iter() .map(|s| s.to_string()) .collect::<Vec<String>>(); - simple_table.push_item(vec