summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorsigoden <sigoden@gmail.com>2025-07-03 08:50:21 +0800
committerGitHub <noreply@github.com>2025-07-03 08:50:21 +0800
commita833512c19f501f1bea84166e6e41b97274f530b (patch)
tree73f4876d3123cc695f6bbfd094347bd519d4e31f /src
parent65efb2100fa774a3c403ede5a4245bc724c81572 (diff)
downloadaichat-a833512c19f501f1bea84166e6e41b97274f530b.tar.gz
refactor: update deps and models.yaml (#1339)
Diffstat (limited to 'src')
-rw-r--r--src/config/mod.rs4
-rw-r--r--src/render/markdown.rs6
-rw-r--r--src/utils/mod.rs5
3 files changed, 11 insertions, 4 deletions
diff --git a/src/config/mod.rs b/src/config/mod.rs
index b52debe..04ae4ef 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -1913,9 +1913,9 @@ impl Config {
Some(theme)
} else {
let theme = if self.light_theme() {
- bincode::deserialize_from(LIGHT_THEME).expect("Invalid builtin light theme")
+ decode_bin(LIGHT_THEME).context("Invalid builtin light theme")?
} else {
- bincode::deserialize_from(DARK_THEME).expect("Invalid builtin dark theme")
+ decode_bin(DARK_THEME).context("Invalid builtin dark theme")?
};
Some(theme)
}
diff --git a/src/render/markdown.rs b/src/render/markdown.rs
index 33cdf47..9671961 100644
--- a/src/render/markdown.rs
+++ b/src/render/markdown.rs
@@ -1,3 +1,5 @@
+use crate::utils::decode_bin;
+
use ansi_colours::AsRGB;
use anyhow::{anyhow, Context, Result};
use crossterm::style::{Color, Stylize};
@@ -30,8 +32,8 @@ pub struct MarkdownRender {
impl MarkdownRender {
pub fn init(options: RenderOptions) -> Result<Self> {
- let syntax_set: SyntaxSet = bincode::deserialize_from(SYNTAXES)
- .with_context(|| "MarkdownRender: invalid syntaxes binary")?;
+ let syntax_set: SyntaxSet =
+ decode_bin(SYNTAXES).with_context(|| "MarkdownRender: invalid syntaxes binary")?;
let code_color = options
.theme
diff --git a/src/utils/mod.rs b/src/utils/mod.rs
index 1f2a592..8a90516 100644
--- a/src/utils/mod.rs
+++ b/src/utils/mod.rs
@@ -214,6 +214,11 @@ pub fn set_proxy(
Ok(builder)
}
+pub fn decode_bin<T: serde::de::DeserializeOwned>(data: &[u8]) -> Result<T> {
+ let (v, _) = bincode::serde::decode_from_slice(data, bincode::config::legacy())?;
+ Ok(v)
+}
+
#[cfg(test)]
mod tests {
use super::*;