aboutsummaryrefslogtreecommitdiffstats
path: root/crates/turtle/src/atuin_client/settings.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/turtle/src/atuin_client/settings.rs')
-rw-r--r--crates/turtle/src/atuin_client/settings.rs68
1 files changed, 35 insertions, 33 deletions
diff --git a/crates/turtle/src/atuin_client/settings.rs b/crates/turtle/src/atuin_client/settings.rs
index c966ba67..074b2634 100644
--- a/crates/turtle/src/atuin_client/settings.rs
+++ b/crates/turtle/src/atuin_client/settings.rs
@@ -47,7 +47,7 @@ pub(crate) enum SearchMode {
}
impl SearchMode {
- pub(crate) fn as_str(&self) -> &'static str {
+ pub(crate) fn as_str(self) -> &'static str {
match self {
SearchMode::Prefix => "PREFIX",
SearchMode::FullText => "FULLTXT",
@@ -56,7 +56,7 @@ impl SearchMode {
SearchMode::DaemonFuzzy => "DAEMON",
}
}
- pub(crate) fn next(&self, settings: &Settings) -> Self {
+ pub(crate) fn next(self, settings: &Settings) -> Self {
match self {
SearchMode::Prefix => SearchMode::FullText,
// if the user is using skim, we go to skim
@@ -94,7 +94,7 @@ pub(crate) enum FilterMode {
}
impl FilterMode {
- pub(crate) fn as_str(&self) -> &'static str {
+ pub(crate) fn as_str(self) -> &'static str {
match self {
FilterMode::Global => "GLOBAL",
FilterMode::Host => "HOST",
@@ -427,7 +427,7 @@ pub(crate) struct Search {
pub(crate) frecency_score_multiplier: f64,
}
-/// Log level for file logging. Maps to tracing's LevelFilter.
+/// Log level for file logging. Maps to tracing's [`LevelFilter`].
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub(crate) enum LogLevel {
@@ -440,8 +440,8 @@ pub(crate) enum LogLevel {
}
impl LogLevel {
- /// Convert to a tracing directive string for use with EnvFilter.
- pub(crate) fn as_directive(&self) -> &'static str {
+ /// Convert to a tracing directive string for use with [`EnvFilter`].
+ pub(crate) fn as_directive(self) -> &'static str {
match self {
LogLevel::Trace => "trace",
LogLevel::Debug => "debug",
@@ -478,7 +478,7 @@ pub(crate) struct Logs {
pub(crate) dir: String,
/// Default log level for file logging. Defaults to "info".
- /// Note: ATUIN_LOG environment variable overrides this.
+ /// Note: [`ATUIN_LOG`] environment variable overrides this.
#[serde(default)]
pub(crate) level: LogLevel,
@@ -641,7 +641,7 @@ pub(crate) enum UiColumnType {
impl UiColumnType {
/// Returns the default width for this column type (in characters).
/// The Command column returns 0 as it expands to fill remaining space.
- pub(crate) fn default_width(&self) -> u16 {
+ pub(crate) fn default_width(self) -> u16 {
match self {
UiColumnType::Duration => 5, // "814ms"
UiColumnType::Time => 9, // "459ms ago"
@@ -683,7 +683,7 @@ impl UiColumn {
// Custom deserialize to handle both string and object formats:
// "duration" or { type = "duration", width = 8, expand = true }
-impl<'de> serde::Deserialize<'de> for UiColumn {
+impl<'de> Deserialize<'de> for UiColumn {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: serde::Deserializer<'de>,
@@ -695,7 +695,7 @@ impl<'de> serde::Deserialize<'de> for UiColumn {
impl<'de> Visitor<'de> for UiColumnVisitor {
type Value = UiColumn;
- fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
+ fn expecting(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(
"a column type string or an object with 'type' and optional 'width'/'expand'",
)
@@ -706,7 +706,7 @@ impl<'de> serde::Deserialize<'de> for UiColumn {
E: de::Error,
{
let column_type: UiColumnType =
- serde::Deserialize::deserialize(serde::de::value::StrDeserializer::new(value))?;
+ Deserialize::deserialize(de::value::StrDeserializer::new(value))?;
Ok(UiColumn::new(column_type))
}
@@ -730,7 +730,7 @@ impl<'de> serde::Deserialize<'de> for UiColumn {
expand = Some(map.next_value()?);
}
_ => {
- let _: serde::de::IgnoredAny = map.next_value()?;
+ let _: de::IgnoredAny = map.next_value()?;
}
}
}
@@ -979,18 +979,19 @@ impl Settings {
}
pub(crate) fn builder() -> Result<ConfigBuilder<DefaultState>> {
- Self::builder_with_data_dir(&crate::atuin_common::utils::data_dir())
+ Self::builder_with_data_dir(&utils::data_dir())
}
+ #[expect(clippy::too_many_lines)]
fn builder_with_data_dir(data_dir: &std::path::Path) -> Result<ConfigBuilder<DefaultState>> {
let db_path = data_dir.join("history.db");
let record_store_path = data_dir.join("records.db");
let kv_path = data_dir.join("kv.db");
let scripts_path = data_dir.join("scripts.db");
let ai_sessions_path = data_dir.join("ai_sessions.db");
- let socket_path = crate::atuin_common::utils::runtime_dir().join("atuin.sock");
+ let socket_path = utils::runtime_dir().join("atuin.sock");
let pidfile_path = data_dir.join("atuin-daemon.pid");
- let logs_dir = crate::atuin_common::utils::logs_dir();
+ let logs_dir = utils::logs_dir();
let key_path = data_dir.join("key");
let meta_path = data_dir.join("meta.db");
@@ -1091,10 +1092,10 @@ impl Settings {
.set_default("tmux.height", "60%")?
.set_default(
"prefers_reduced_motion",
- std::env::var("NO_MOTION")
- .ok()
- .map(|_| config::Value::new(None, config::ValueKind::Boolean(true)))
- .unwrap_or_else(|| config::Value::new(None, config::ValueKind::Boolean(false))),
+ std::env::var("NO_MOTION").ok().map_or_else(
+ || config::Value::new(None, config::ValueKind::Boolean(false)),
+ |_| config::Value::new(None, config::ValueKind::Boolean(true)),
+ ),
)?
.set_default("no_mouse", false)?
.add_source(
@@ -1105,18 +1106,19 @@ impl Settings {
}
pub(crate) fn get_config_path() -> Result<PathBuf> {
- let config_dir = crate::atuin_common::utils::config_dir();
+ let config_dir = utils::config_dir();
create_dir_all(&config_dir)
.wrap_err_with(|| format!("could not create dir {}", config_dir.display()))?;
- let mut config_file = if let Ok(p) = std::env::var("ATUIN_CONFIG_DIR") {
- PathBuf::from(p)
- } else {
- let mut config_file = PathBuf::new();
- config_file.push(config_dir);
- config_file
- };
+ let mut config_file = std::env::var("ATUIN_CONFIG_DIR").map_or_else(
+ |_| {
+ let mut config_file = PathBuf::new();
+ config_file.push(config_dir);
+ config_file
+ },
+ PathBuf::from,
+ );
config_file.push("config.toml");
@@ -1162,16 +1164,16 @@ impl Settings {
.map_err(|e| eyre!("failed to expand data_dir path: {}", e))?;
PathBuf::from(expanded.as_ref())
}
- None => crate::atuin_common::utils::data_dir(),
+ None => utils::data_dir(),
}
} else {
- crate::atuin_common::utils::data_dir()
+ utils::data_dir()
};
DATA_DIR.set(effective_data_dir.clone()).ok();
create_dir_all(&effective_data_dir)
- .wrap_err_with(|| format!("could not create dir {effective_data_dir:?}"))?;
+ .wrap_err_with(|| format!("could not create dir {}", effective_data_dir.display()))?;
let mut config_builder = Self::builder_with_data_dir(&effective_data_dir)?;
@@ -1205,7 +1207,7 @@ impl Settings {
]
.iter()
.map(|key| (key, built.get_string(key).unwrap_or_default()))
- .filter_map(|(key, value)| match Self::expand_path(value) {
+ .filter_map(|(key, value)| match Self::expand_path(&value) {
Ok(expanded) => Some((key, expanded)),
Err(e) => {
log::warn!("failed to expand path for {key}: {e}");
@@ -1263,7 +1265,7 @@ impl Settings {
let full_key = if prefix.is_empty() {
k.clone()
} else {
- format!("{}.{}", prefix, k)
+ format!("{prefix}.{k}")
};
match &v.kind {
@@ -1302,7 +1304,7 @@ impl Settings {
Ok(settings)
}
- fn expand_path(path: String) -> Result<String> {
+ fn expand_path(path: &str) -> Result<String> {
shellexpand::full(&path)
.map(|p| p.to_string())
.map_err(|e| eyre!("failed to expand path: {}", e))