Skip to content

Commit

Permalink
Merge pull request #873 from cyhyraethz/master
Browse files Browse the repository at this point in the history
fix: #845 Add config option to support tealdeer
  • Loading branch information
denisidoro authored Jan 19, 2024
2 parents 80e30b5 + c3d7538 commit c45b767
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
7 changes: 5 additions & 2 deletions docs/config_file_example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ finder:
# path: /path/to/some/dir # (DEPRECATED) equivalent to the --path option

# search:
# tags: git,!checkout # equivalent to the --tag-rules option
# tags: git,!checkout # equivalent to the --tag-rules option

# client:
# tealdeer: true # enables tealdeer support for navi --tldr

shell:
# Shell used for shell out. Possible values: bash, zsh, dash, ...
# For Windows, use `cmd.exe` instead.
command: bash

# finder_command: bash # similar, but for fzf's internals
12 changes: 8 additions & 4 deletions src/clients/tldr.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::config::CONFIG;
use std::process::{Command, Stdio};

lazy_static! {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -86,18 +89,19 @@ Note:
Ok(lines)
} else {
let msg = format!(
"Failed to call:
"Failed to call:
tldr {}
Output:
{}
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(" "),
Expand Down
4 changes: 4 additions & 0 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
15 changes: 15 additions & 0 deletions src/config/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -86,6 +92,7 @@ pub struct YamlConfig {
pub cheats: Cheats,
pub search: Search,
pub shell: Shell,
pub client: Client,
}

impl YamlConfig {
Expand Down Expand Up @@ -162,3 +169,11 @@ impl Default for Shell {
}
}
}

impl Default for Client {
fn default() -> Self {
Self {
tealdeer: false,
}
}
}

0 comments on commit c45b767

Please sign in to comment.