summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDylan Premo <cyhyraethz@gmail.com>2024-01-18 15:28:12 -0800
committerDylan Premo <cyhyraethz@gmail.com>2024-01-18 15:48:14 -0800
commitc3d75383f89a568b0ee0dc6f807f18f1c8bb9311 (patch)
tree8bc968a3fb5d16fc3cede21da0475aa3d232e97c /src
parent80e30b508bc04cc91263bb549e527c1c06c31d25 (diff)
Add config option to support tealdeer
Diffstat (limited to 'src')
-rw-r--r--src/clients/tldr.rs12
-rw-r--r--src/config/mod.rs4
-rw-r--r--src/config/yaml.rs15
3 files changed, 27 insertions, 4 deletions
diff --git a/src/clients/tldr.rs b/src/clients/tldr.rs
index cd040e4..01cec89 100644
--- a/src/clients/tldr.rs
+++ b/src/clients/tldr.rs
@@ -1,4 +1,5 @@
use crate::prelude::*;
+use crate::config::CONFIG;
use std::process::{Command, Stdio};
lazy_static! {
@@ -51,7 +52,9 @@ fn markdown_lines(query: &str, markdown: &str) -> Vec<String> {
}
pub fn call(query: &str) -> Result<Vec<String>> {
- let args = [query, "--markdown"];
+ let tealdeer = CONFIG.tealdeer();
+ let output_flag = if tealdeer { "--raw" } else { "--markdown" };
+ let args = [query, output_flag];
let child = Command::new("tldr")
.args(args)
@@ -86,9 +89,9 @@ Note:
Ok(lines)
} else {
let msg = format!(
- "Failed to call:
+ "Failed to call:
tldr {}
-
+
Output:
{}
@@ -96,8 +99,9 @@ Error:
{}
Note:
+The client.tealdeer config option can be set to enable tealdeer support.
Please make sure you're using a version that supports the --markdown flag.
-If you are already using a supported version you can ignore this message.
+If you are already using a supported version you can ignore this message.
{}
",
args.join(" "),
diff --git a/src/config/mod.rs b/src/config/mod.rs
index b652608..a5b89c1 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -99,6 +99,10 @@ impl Config {
.or_else(|| self.yaml.finder.overrides_var.clone())
}
+ pub fn tealdeer(&self) -> bool {
+ self.yaml.client.tealdeer.clone()
+ }
+
pub fn shell(&self) -> String {
self.yaml.shell.command.clone()
}
diff --git a/src/config/yaml.rs b/src/config/yaml.rs
index 70a5a17..e0c7e87 100644
--- a/src/config/yaml.rs
+++ b/src/config/yaml.rs
@@ -78,6 +78,12 @@ pub struct Shell {
pub finder_command: Option<String>,
}
+#[derive(Deserialize, Debug)]
+#[serde(default)]
+pub struct Client {
+ pub tealdeer: bool,
+}
+
#[derive(Deserialize, Default, Debug)]
#[serde(default)]
pub struct YamlConfig {
@@ -86,6 +92,7 @@ pub struct YamlConfig {
pub cheats: Cheats,
pub search: Search,
pub shell: Shell,
+ pub client: Client,
}
impl YamlConfig {
@@ -162,3 +169,11 @@ impl Default for Shell {
}
}
}
+
+impl Default for Client {
+ fn default() -> Self {
+ Self {
+ tealdeer: false,
+ }
+ }
+}