Skip to content

Commit

Permalink
rebase (#547)
Browse files Browse the repository at this point in the history
Signed-off-by: Lzzzt <[email protected]>
  • Loading branch information
Lzzzzzt authored Jul 6, 2024
1 parent 07ad68f commit 6e09ec3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ unicode-width = "^0"
walkdir = "^2"
whoami = "^1"
xdg = "^2"
bytesize = "1.3.0"

[dependencies.nix]
version = "^0"
Expand Down
2 changes: 1 addition & 1 deletion config/joshuto.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ directories_first = true
reverse = false

[preview]
max_preview_size = 2097152 # 2MB
max_preview_size = "2MB" # 2MB
preview_script = "~/.config/joshuto/preview_file.sh" # make sure it's marked as executable

[search]
Expand Down
4 changes: 2 additions & 2 deletions docs/configuration/joshuto.toml.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ watch_files = true
# - `:mkdir ./b` keeps the cursor where it was
focus_on_create = true

# The maximum file size to show a preview for
max_preview_size = 2097152 # 2MB
# The maximum file size to show a preview for, it can be "2 MB", "2 Mb" or "2097152"
max_preview_size = "2 MB"

# Update the zoxide database with every navigation type instead of only with the z command
zoxide_update = false
Expand Down
33 changes: 31 additions & 2 deletions src/config/raw/app/display/preview.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use allmytoes::ThumbSize;
use bytesize::ByteSize;
use ratatui_image::picker::ProtocolType;
use serde::Deserialize;
use serde::{de::Unexpected, Deserialize, Deserializer};
use toml::Value;

pub const fn default_max_preview_size() -> u64 {
2 * 1024 * 1024 // 2 MB
Expand Down Expand Up @@ -43,7 +45,10 @@ impl XDGThumbSizes {

#[derive(Clone, Debug, Deserialize)]
pub struct PreviewOptionRaw {
#[serde(default = "default_max_preview_size")]
#[serde(
default = "default_max_preview_size",
deserialize_with = "deserialize_max_preview_size"
)]
pub max_preview_size: u64,
#[serde(default)]
pub preview_protocol: PreviewProtocol,
Expand Down Expand Up @@ -73,3 +78,27 @@ impl std::default::Default for PreviewOptionRaw {
}
}
}

fn deserialize_max_preview_size<'de, D>(deserializer: D) -> Result<u64, D::Error>
where
D: Deserializer<'de>,
{
let value: Value = Deserialize::deserialize(deserializer)?;

let string = match value {
Value::String(s) => s,
Value::Integer(i) => (i as u64).to_string(),
v => {
return Err(serde::de::Error::invalid_type(
Unexpected::Other(v.type_str()),
&"String or Integer",
))
}
};

let size = string
.parse::<ByteSize>()
.map_err(serde::de::Error::custom)?;

Ok(size.as_u64())
}

0 comments on commit 6e09ec3

Please sign in to comment.