summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/jvii.rs8
-rw-r--r--src/bin/jvn.rs127
-rw-r--r--src/data.rs2
-rw-r--r--src/data/ipaddress_history.rs34
-rw-r--r--src/systems/cmd/errors.rs27
5 files changed, 68 insertions, 130 deletions
diff --git a/src/bin/jvii.rs b/src/bin/jvii.rs
index fbd7139..6277619 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::legacy::display::display_width;
-use cli_utils::legacy::display::md;
-use cli_utils::legacy::env::current_locales;
+use cli_utils::display::markdown::Markdown;
+use cli_utils::display::str_width::display_width;
+use cli_utils::env::locales::current_locales;
use crossterm::{
QueueableCommand,
cursor::MoveTo,
@@ -309,7 +309,7 @@ impl Editor {
} else {
"".to_string()
},
- md(t!("jvii.hints"))
+ t!("jvii.hints").to_string().markdown()
);
stdout.queue(SetForegroundColor(Color::Black))?;
diff --git a/src/bin/jvn.rs b/src/bin/jvn.rs
index f35b845..0373552 100644
--- a/src/bin/jvn.rs
+++ b/src/bin/jvn.rs
@@ -5,8 +5,7 @@ use std::{
};
use cli_utils::{
- display::markdown::Markdown,
- legacy::{display::md, env::current_locales, levenshtein_distance},
+ display::markdown::Markdown, env::locales::current_locales, math::levenshtein_distance,
};
use just_progress::{
progress,
@@ -193,17 +192,27 @@ async fn main() {
handle_render_error(cmd_render_error);
}
CmdProcessError::Error(error) => {
- eprintln!("{}", md(t!("process_error.other", error = error)));
+ eprintln!(
+ "{}",
+ t!("process_error.other", error = error)
+ .to_string()
+ .markdown()
+ );
}
CmdProcessError::NoNodeFound(node) => {
- eprintln!("{}", md(t!("process_error.no_node_found", node = node)));
+ eprintln!(
+ "{}",
+ t!("process_error.no_node_found", node = node)
+ .to_string()
+ .markdown()
+ );
}
CmdProcessError::NoMatchingCommand => {
handle_no_matching_command_error(args);
}
CmdProcessError::ParseError(help) => {
if help.trim().is_empty() {
- eprintln!("{}", md(t!("process_error.parse_error")));
+ eprintln!("{}", t!("process_error.parse_error").to_string().markdown());
} else {
eprintln!("{}", help)
}
@@ -211,11 +220,16 @@ async fn main() {
CmdProcessError::RendererOverrideButRequestHelp => {
eprintln!(
"{}",
- md(t!("process_error.renderer_override_but_request_help"))
+ t!("process_error.renderer_override_but_request_help")
+ .to_string()
+ .markdown()
);
}
CmdProcessError::DowncastFailed => {
- eprintln!("{}", md(t!("process_error.downcast_failed")));
+ eprintln!(
+ "{}",
+ t!("process_error.downcast_failed").to_string().markdown()
+ );
}
}
}
@@ -282,14 +296,21 @@ fn handle_no_matching_command_error(args: Vec<String>) {
}
}
if similar_nodes.is_empty() {
- eprintln!("{}", md(t!("process_error.no_matching_command")));
+ eprintln!(
+ "{}",
+ t!("process_error.no_matching_command")
+ .to_string()
+ .markdown()
+ );
} else {
eprintln!(
"{}",
- md(t!(
+ t!(
"process_error.no_matching_command_but_similar",
similars = similar_nodes[0]
- ))
+ )
+ .to_string()
+ .markdown()
);
}
}
@@ -299,55 +320,19 @@ fn handle_prepare_error(cmd_prepare_error: CmdPrepareError) {
CmdPrepareError::Io(error) => {
eprintln!(
"{}",
- md(t!("prepare_error.io", error = display_io_error(error)))
+ t!("prepare_error.io", error = display_io_error(error))
+ .to_string()
+ .markdown()
);
}
CmdPrepareError::Error(msg) => {
- eprintln!("{}", md(t!("prepare_error.error", error = msg)));
- }
- CmdPrepareError::LocalWorkspaceNotFound => {
- eprintln!("{}", md(t!("prepare_error.local_workspace_not_found")));
- }
- CmdPrepareError::LocalConfigNotFound => {
- eprintln!("{}", md(t!("prepare_error.local_config_not_found")));
- }
- CmdPrepareError::LatestInfoNotFound => {
- eprintln!("{}", md(t!("prepare_error.latest_info_not_found")));
- }
- CmdPrepareError::LatestFileDataNotExist(member_id) => {
eprintln!(
"{}",
- md(t!(
- "prepare_error.latest_file_data_not_exist",
- member_id = member_id
- ))
+ t!("prepare_error.error", error = msg)
+ .to_string()
+ .markdown()
);
}
- CmdPrepareError::CachedSheetNotFound(sheet_name) => {
- eprintln!(
- "{}",
- md(t!(
- "prepare_error.cached_sheet_not_found",
- sheet_name = sheet_name
- ))
- );
- }
- CmdPrepareError::LocalSheetNotFound(member_id, sheet_name) => {
- eprintln!(
- "{}",
- md(t!(
- "prepare_error.local_sheet_not_found",
- member_id = member_id,
- sheet_name = sheet_name
- ))
- );
- }
- CmdPrepareError::LocalStatusAnalyzeFailed => {
- eprintln!("{}", md(t!("prepare_error.local_status_analyze_failed")));
- }
- CmdPrepareError::NoSheetInUse => {
- eprintln!("{}", md(t!("prepare_error.no_sheet_in_use")));
- }
CmdPrepareError::EarlyOutput(_) => {
// Early output is not an error
// No additional handling needed,
@@ -362,12 +347,19 @@ fn handle_execute_error(cmd_execute_error: CmdExecuteError) {
CmdExecuteError::Io(error) => {
eprintln!(
"{}",
- md(t!("execute_error.io", error = display_io_error(error)))
+ t!("execute_error.io", error = display_io_error(error))
+ .to_string()
+ .markdown()
);
}
CmdExecuteError::Prepare(cmd_prepare_error) => handle_prepare_error(cmd_prepare_error),
CmdExecuteError::Error(msg) => {
- eprintln!("{}", md(t!("execute_error.error", error = msg)));
+ eprintln!(
+ "{}",
+ t!("execute_error.error", error = msg)
+ .to_string()
+ .markdown()
+ );
}
}
}
@@ -377,37 +369,46 @@ fn handle_render_error(cmd_render_error: CmdRenderError) {
CmdRenderError::Io(error) => {
eprintln!(
"{}",
- md(t!("render_error.io", error = display_io_error(error)))
+ t!("render_error.io", error = display_io_error(error))
+ .to_string()
+ .markdown()
);
}
CmdRenderError::Prepare(cmd_prepare_error) => handle_prepare_error(cmd_prepare_error),
CmdRenderError::Execute(cmd_execute_error) => handle_execute_error(cmd_execute_error),
CmdRenderError::Error(msg) => {
- eprintln!("{}", md(t!("render_error.error", error = msg)));
+ eprintln!(
+ "{}",
+ t!("render_error.error", error = msg).to_string().markdown()
+ );
}
CmdRenderError::SerializeFailed(error) => {
eprintln!(
"{}",
- md(t!(
- "render_error.serialize_failed",
- error = error.to_string()
- ))
+ t!("render_error.serialize_failed", error = error.to_string())
+ .to_string()
+ .markdown()
);
}
CmdRenderError::RendererNotFound(renderer_name) => {
eprintln!(
"{}",
- md(t!(
+ t!(
"render_error.renderer_not_found",
renderer_name = renderer_name
- ))
+ )
+ .to_string()
+ .markdown()
);
}
CmdRenderError::TypeMismatch {
expected: _,
actual: _,
} => {
- eprintln!("{}", md(t!("render_error.type_mismatch")));
+ eprintln!(
+ "{}",
+ t!("render_error.type_mismatch").to_string().markdown()
+ );
}
}
}
diff --git a/src/data.rs b/src/data.rs
index d1c5d53..036fd98 100644
--- a/src/data.rs
+++ b/src/data.rs
@@ -1,4 +1,2 @@
#[allow(dead_code)]
pub mod compile_info;
-
-pub mod ipaddress_history;
diff --git a/src/data/ipaddress_history.rs b/src/data/ipaddress_history.rs
deleted file mode 100644
index 142797d..0000000
--- a/src/data/ipaddress_history.rs
+++ /dev/null
@@ -1,34 +0,0 @@
-use just_enough_vcs::lib::env::current_cfg_dir;
-
-const IP_HISTORY_NAME: &str = "ip_history.txt";
-
-pub struct IpAddressHistory {
- pub recent_ip_address: Vec<String>,
-}
-
-pub async fn get_recent_ip_address() -> Vec<String> {
- if let Some(local) = current_cfg_dir() {
- let path = local.join(IP_HISTORY_NAME);
- match tokio::fs::read_to_string(path).await {
- Ok(content) => content.lines().map(String::from).collect(),
- Err(_) => Vec::new(),
- }
- } else {
- Vec::new()
- }
-}
-
-pub async fn insert_recent_ip_address(ip: impl Into<String>) {
- let ip = ip.into();
- if let Some(local) = current_cfg_dir() {
- let path = local.join(IP_HISTORY_NAME);
- let mut recent_ips = get_recent_ip_address().await;
- recent_ips.retain(|existing_ip| existing_ip != &ip);
- recent_ips.insert(0, ip);
- if recent_ips.len() > 8 {
- recent_ips.truncate(8);
- }
- let content = recent_ips.join("\n");
- let _ = tokio::fs::write(path, content).await;
- }
-}
diff --git a/src/systems/cmd/errors.rs b/src/systems/cmd/errors.rs
index efa12a9..4559651 100644
--- a/src/systems/cmd/errors.rs
+++ b/src/systems/cmd/errors.rs
@@ -1,5 +1,3 @@
-use just_enough_vcs::lib::data::{member::MemberId, sheet::SheetName};
-
use crate::systems::cmd::cmd_system::AnyOutput;
#[derive(thiserror::Error, Debug)]
@@ -10,31 +8,6 @@ pub enum CmdPrepareError {
#[error("{0}")]
Error(String),
- // Workspace Reader Errors
- #[error("LocalWorkspace not found")]
- LocalWorkspaceNotFound,
-
- #[error("LocalConfig not found")]
- LocalConfigNotFound,
-
- #[error("LatestInfo not found")]
- LatestInfoNotFound,
-
- #[error("LatestFileData of {0} not found")]
- LatestFileDataNotExist(MemberId),
-
- #[error("CachedSheet `{0}` not found")]
- CachedSheetNotFound(SheetName),
-
- #[error("LocalSheet `{0}/{1}` not found")]
- LocalSheetNotFound(MemberId, SheetName),
-
- #[error("LocalStatusAnalyzeFailed")]
- LocalStatusAnalyzeFailed,
-
- #[error("No sheet in use")]
- NoSheetInUse,
-
#[error("Error occurred and returned early")]
EarlyOutput(AnyOutput),
}