From f9fa7d65d775959efbc9609ccafd1fdce76129e4 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Fri, 23 Jan 2026 09:42:09 +0800 Subject: Add localization and refactor status command output --- src/utils/display.rs | 24 ++++----- src/utils/workspace_reader.rs | 121 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 133 insertions(+), 12 deletions(-) (limited to 'src/utils') diff --git a/src/utils/display.rs b/src/utils/display.rs index f0532f3..835313b 100644 --- a/src/utils/display.rs +++ b/src/utils/display.rs @@ -268,17 +268,17 @@ pub fn md(text: impl AsRef) -> String { } } - // Check for inline code `text` - if chars[i] == '`' { + // Check for angle-bracketed content + if chars[i] == '<' { let mut j = i + 1; - while j < chars.len() && chars[j] != '`' { + while j < chars.len() && chars[j] != '>' { j += 1; } if j < chars.len() { - // Include the backticks in the output - let code_text: String = chars[i..=j].iter().collect(); - let mut formatted_text = code_text.green().to_string(); + // Include the angle brackets in the output + let angle_text: String = chars[i..=j].iter().collect(); + let mut formatted_text = angle_text.cyan().to_string(); // Apply current color stack for color in color_stack.iter().rev() { @@ -291,17 +291,17 @@ pub fn md(text: impl AsRef) -> String { } } - // Check for angle-bracketed content - if chars[i] == '<' { + // Check for inline code `text` + if chars[i] == '`' { let mut j = i + 1; - while j < chars.len() && chars[j] != '>' { + while j < chars.len() && chars[j] != '`' { j += 1; } if j < chars.len() { - // Include the angle brackets in the output - let angle_text: String = chars[i..=j].iter().collect(); - let mut formatted_text = angle_text.cyan().to_string(); + // Include the backticks in the output + let code_text: String = chars[i..=j].iter().collect(); + let mut formatted_text = code_text.green().to_string(); // Apply current color stack for color in color_stack.iter().rev() { diff --git a/src/utils/workspace_reader.rs b/src/utils/workspace_reader.rs index a3bc754..c001330 100644 --- a/src/utils/workspace_reader.rs +++ b/src/utils/workspace_reader.rs @@ -253,4 +253,125 @@ impl LocalWorkspaceReader { }; Ok(analyzed.into()) } + + // Pop the local configuration (take ownership if cached) + pub async fn pop_local_config(&mut self) -> Result { + if let Some(local_config) = self.local_config.take() { + Ok(local_config) + } else { + let workspace_dir = self.workspace_dir()?; + let local_config = entry_dir!(workspace_dir, { + LocalConfig::read() + .await + .map_err(|_| CmdPrepareError::LocalConfigNotFound)? + }); + Ok(local_config) + } + } + + // Pop the local workspace (take ownership if cached) + pub async fn pop_local_workspace(&mut self) -> Result { + if let Some(local_workspace) = self.local_workspace.take() { + Ok(local_workspace) + } else { + let workspace_dir = self.workspace_dir()?.clone(); + let local_config = self.local_config().await?.clone(); + let Some(local_workspace) = entry_dir!(&workspace_dir, { + LocalWorkspace::init_current_dir(local_config) + }) else { + return Err(CmdPrepareError::LocalWorkspaceNotFound); + }; + Ok(local_workspace) + } + } + + // Pop the latest information (take ownership if cached) + pub async fn pop_latest_info(&mut self) -> Result { + if let Some(latest_info) = self.latest_info.take() { + Ok(latest_info) + } else { + let local_dir = self.workspace_dir()?.clone(); + let local_config = self.local_config().await?.clone(); + let latest_info = entry_dir!(&local_dir, { + match LatestInfo::read_from(LatestInfo::latest_info_path( + &local_dir, + &local_config.current_account(), + )) + .await + { + Ok(info) => info, + Err(_) => { + return Err(CmdPrepareError::LatestInfoNotFound); + } + } + }); + Ok(latest_info) + } + } + + // Pop the latest file data for a specific account (take ownership if cached) + pub async fn pop_latest_file_data( + &mut self, + account: &MemberId, + ) -> Result { + if let Some(latest_file_data) = self.latest_file_data.remove(account) { + Ok(latest_file_data) + } else { + let local_dir = self.workspace_dir()?; + let latest_file_data_path = + match entry_dir!(&local_dir, { LatestFileData::data_path(account) }) { + Ok(p) => p, + Err(_) => return Err(CmdPrepareError::LatestFileDataNotExist(account.clone())), + }; + let latest_file_data = LatestFileData::read_from(&latest_file_data_path).await?; + Ok(latest_file_data) + } + } + + // Pop the cached sheet for a specific sheet name (take ownership if cached) + pub async fn pop_cached_sheet( + &mut self, + sheet_name: &SheetName, + ) -> Result { + if let Some(cached_sheet) = self.cached_sheet.remove(sheet_name) { + Ok(cached_sheet) + } else { + let workspace_dir = self.workspace_dir()?; + let cached_sheet = entry_dir!(&workspace_dir, { + match just_enough_vcs::vcs::data::local::cached_sheet::CachedSheet::cached_sheet_data(sheet_name).await { + Ok(data) => data, + Err(_) => return Err(CmdPrepareError::CachedSheetNotFound(sheet_name.clone())), + } + }); + Ok(cached_sheet) + } + } + + // Pop the local sheet data for a specific account and sheet name (take ownership if cached) + pub async fn pop_local_sheet_data( + &mut self, + account: &MemberId, + sheet_name: &SheetName, + ) -> Result { + let key = (account.clone(), sheet_name.clone()); + if let Some(local_sheet_data) = self.local_sheet_data.remove(&key) { + Ok(local_sheet_data) + } else { + let workspace_dir = self.workspace_dir()?.clone(); + let local_workspace = self.local_workspace().await?; + let path = entry_dir!(&workspace_dir, { + local_workspace.local_sheet_path(account, sheet_name) + }); + let local_sheet_data = match LocalSheetData::read_from(path).await { + Ok(data) => data, + Err(_) => { + return Err(CmdPrepareError::LocalSheetNotFound( + account.clone(), + sheet_name.clone(), + )); + } + }; + Ok(local_sheet_data) + } + } } -- cgit