diff --git a/pages/tldr.md b/pages/tealdeer.md
similarity index 61%
rename from pages/tldr.md
rename to pages/tealdeer.md
index dda1d77..b77b131 100644
--- a/pages/tldr.md
+++ b/pages/tealdeer.md
@@ -1,25 +1,9 @@
# tldr
-> A fast tldr client written in Rust.
+> This is a builtin page that shows information for your installed tealdeer version.
> More information: .
-- Show the tldr page for a command:
-
-`tldr {{command}}`
-
-- Show the tldr page for a subcommand:
-
-`tldr {{command}} {{subcommand}}`
-
-- Show the tldr page for a specific platform:
-
-`tldr --platform {{android|common|freebsd|linux|netbsd|openbsd|osx|sunos|windows}} {{command}}`
-
-- Show the tldr page in a specific language:
-
-`tldr --language {{language_code}} {{command}}`
-
-- Download or update the local page cache:
+> This page shows tealdeer specific functionality. See tldr tldr for more examples.
`tldr --update`
diff --git a/src/cache.rs b/src/cache.rs
index 5cc89a2..b181310 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -40,7 +40,6 @@ pub struct Cache<'a> {
pub struct PageLookupResult {
pub page_path: PathBuf,
pub patch_path: Option,
- pub embedded: Option<&'static str>,
}
impl<'a> Cache<'a> {
@@ -266,18 +265,10 @@ impl<'a> Cache<'a> {
}
impl PageLookupResult {
- pub fn with_embedded(content: &'static str) -> Self {
- Self {
- page_path: PathBuf::new(),
- patch_path: None,
- embedded: Some(content),
- }
- }
pub fn with_page(page_path: PathBuf) -> Self {
Self {
page_path,
patch_path: None,
- embedded: None,
}
}
@@ -292,11 +283,6 @@ impl PageLookupResult {
/// This will return an error if either the page file or the patch file
/// cannot be opened.
pub fn reader(&self) -> Result>> {
- // Open embedded file
- if let Some(content) = self.embedded {
- return Ok(BufReader::new(Box::new(Cursor::new(content.as_bytes()))));
- }
-
// Open page file
let page_file = File::open(&self.page_path)
.with_context(|| format!("Could not open page file at {}", self.page_path.display()))?;
diff --git a/src/main.rs b/src/main.rs
index 1d2bfab..8586eac 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -29,7 +29,7 @@ compile_error!(
use std::{
env,
fs::create_dir_all,
- io::{self, IsTerminal},
+ io::{self, Cursor, IsTerminal},
path::Path,
process::{Command, ExitCode},
};
@@ -68,7 +68,8 @@ const APP_INFO: AppInfo = AppInfo {
name: NAME,
author: NAME,
};
-const SELF_PAGE: &str = include_str!("../pages/tldr.md");
+static TEALDEER_PAGE: &str =
+ include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/pages/tealdeer.md"));
/// Clear the cache
fn clear_cache(cache: Cache, quietly: bool) -> Result<()> {
@@ -259,8 +260,8 @@ fn try_main(args: Cli, enable_styles: bool) -> Result {
// If a local file was passed in, render it and exit
if let Some(file) = args.render {
- let path = PageLookupResult::with_page(file);
- print_page(&path, args.raw, enable_styles, args.pager, &config)?;
+ let reader = PageLookupResult::with_page(file).reader()?;
+ print_page(reader, args.raw, enable_styles, args.pager, &config)?;
return Ok(ExitCode::SUCCESS);
}
@@ -408,8 +409,8 @@ fn try_main(args: Cli, enable_styles: bool) -> Result {
);
}
- let lookup_result = if command == "tldr" || command == "tealdeer" {
- PageLookupResult::with_embedded(SELF_PAGE)
+ let reader: Box = if command == "tealdeer" {
+ Box::new(Cursor::new(TEALDEER_PAGE.as_bytes()))
} else {
let Some(result) = cache.find_page(&command) else {
if !args.quiet {
@@ -425,10 +426,10 @@ fn try_main(args: Cli, enable_styles: bool) -> Result {
}
return Ok(ExitCode::FAILURE);
};
- result
+ Box::new(result.reader()?)
};
- print_page(&lookup_result, args.raw, enable_styles, args.pager, &config)?;
+ print_page(reader, args.raw, enable_styles, args.pager, &config)?;
}
Ok(ExitCode::SUCCESS)
diff --git a/src/output.rs b/src/output.rs
index 927d20e..9305c20 100644
--- a/src/output.rs
+++ b/src/output.rs
@@ -1,12 +1,11 @@
//! Functions for printing pages to the terminal
-use std::io::{self, BufRead, Write};
+use std::io::{self, BufRead, BufReader, Read, Write};
use anyhow::{Context, Result};
use yansi::Paint;
use crate::{
- cache::PageLookupResult,
config::{Config, StyleConfig},
formatter::{highlight_lines, PageSnippet},
line_iterator::LineIterator,
@@ -30,14 +29,13 @@ fn configure_pager(enable_styles: bool) {
/// Print page by path
pub fn print_page(
- lookup_result: &PageLookupResult,
+ reader: impl Read,
enable_markdown: bool,
enable_styles: bool,
use_pager: bool,
config: &Config,
) -> Result<()> {
- // Create reader from file(s)
- let reader = lookup_result.reader()?;
+ let reader = BufReader::new(reader);
// Configure pager if applicable
if use_pager || config.display.use_pager {