Skip to content

Commit

Permalink
Disable pager feature on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Jan 22, 2020
1 parent 7b3f7a6 commit bcdfd5e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ docopt = "1"
env_logger = { version = "0.7", optional = true }
flate2 = "1"
log = "0.4"
pager = "0.15"
reqwest = "0.9.5"
serde = "1.0.21"
serde_derive = "1.0.21"
Expand All @@ -30,6 +29,9 @@ toml = "0.5.1"
walkdir = "2.0.1"
xdg = "2.1.0"

[target.'cfg(not(windows))'.dependencies]
pager = "0.15"

[dev-dependencies]
assert_cmd = "0.10"
escargot = "0.3"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ Specifies whether the pager should be used by default or not (default `false`).
When enabled, `less -R` is used as pager. To override the pager command used,
set the `PAGER` environment variable.

NOTE: This feature is not available on Windows.

#### `compact`

Set this to enforce more compact output, where empty lines are stripped out
Expand Down
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ use std::time::Duration;
use ansi_term::Color;
use app_dirs::AppInfo;
use docopt::Docopt;
#[cfg(not(target_os = "windows"))]
use pager::Pager;
use serde_derive::Deserialize;

Expand Down Expand Up @@ -83,8 +84,9 @@ To render a local file (for testing):
$ tldr --render /path/to/file.md
";
const ARCHIVE_URL: &str = "https://github.com/tldr-pages/tldr/archive/master.tar.gz";
const PAGER_COMMAND: &str = "less -R";
const MAX_CACHE_AGE: Duration = Duration::from_secs(2_592_000); // 30 days
#[cfg(not(target_os = "windows"))]
const PAGER_COMMAND: &str = "less -R";

#[derive(Debug, Deserialize)]
struct Args {
Expand Down Expand Up @@ -129,6 +131,7 @@ fn print_page(path: &Path, enable_styles: bool) -> Result<(), String> {
}

/// Set up display pager
#[cfg(not(target_os = "windows"))]
fn configure_pager(args: &Args, enable_styles: bool) {
// Flags have precedence
if args.flag_pager {
Expand All @@ -154,6 +157,11 @@ fn configure_pager(args: &Args, enable_styles: bool) {
}
}

#[cfg(target_os = "windows")]
fn configure_pager(_args: &Args, _enable_styles: bool) {
eprintln!("Warning: -p / --pager flag not available on Windows!");
}

/// Check the cache for freshness
fn check_cache(args: &Args, cache: &Cache) {
if !args.flag_update {
Expand Down

0 comments on commit bcdfd5e

Please sign in to comment.