Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --no-pager flag #396

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion completion/bash_tealdeer
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _tealdeer()
_init_completion || return

case $prev in
-h|--help|-v|--version|-l|--list|-u|--update|--no-auto-update|-c|--clear-cache|--pager|-r|--raw|--show-paths|--seed-config|-q|--quiet)
-h|--help|-v|--version|-l|--list|-u|--update|--no-auto-update|-c|--clear-cache|--pager|--no-pager|-r|--raw|--show-paths|--seed-config|-q|--quiet)
return
;;
-f|--render)
Expand Down
1 change: 1 addition & 0 deletions completion/fish_tealdeer
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ complete -c tldr -s u -l update -d 'Update the local cache.' -f
complete -c tldr -l no-auto-update -d 'If auto update is configured, disable it for this run.' -f
complete -c tldr -s c -l clear-cache -d 'Clear the local cache.' -f
complete -c tldr -l pager -d 'Use a pager to page output.' -f
complete -c tldr -l no-pager -d 'Do not use a pager to page output, overrides --pager and config.' -f
complete -c tldr -s r -l raw -d 'Display the raw markdown instead of rendering it.' -f
complete -c tldr -s q -l quiet -d 'Suppress informational messages.' -f
complete -c tldr -l show-paths -d 'Show file and directory paths used by tealdeer.' -f
Expand Down
1 change: 1 addition & 0 deletions completion/zsh_tealdeer
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ _tealdeer() {
"($I)--no-auto-update[If auto update is configured, disable it for this run]"
"($I -c --clear-cache)"{-c,--clear-cache}"[Clear the local cache]"
"($I)--pager[Use a pager to page output]"
"($I)--no-pager[Do not use a pager to page output, overrides --pager and config]"
"($I -r --raw)"{-r,--raw}"[Display the raw markdown instead of rendering it]"
"($I -q --quiet)"{-q,--quiet}"[Suppress informational messages]"
"($I)--show-paths[Show file and directory paths used by tealdeer]"
Expand Down
1 change: 1 addition & 0 deletions docs/src/usage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Options:
--no-auto-update If auto update is configured, disable it for this run
-c, --clear-cache Clear the local cache
--pager Use a pager to page output
--no-pager Do not use a pager to page output, overrides `--pager` and config
-r, --raw Display the raw markdown instead of rendering it
-q, --quiet Suppress informational messages
--show-paths Show file and directory paths used by tealdeer
Expand Down
4 changes: 4 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ pub(crate) struct Cli {
#[arg(long = "pager", requires = "command_or_file")]
pub pager: bool,

/// Do not use a pager to page output, overrides `--pager` and config
#[arg(long = "no-pager")]
pub no_pager: bool,

/// Display the raw markdown instead of rendering it
#[arg(short = 'r', long = "raw", requires = "command_or_file")]
pub raw: bool,
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ fn main() {
// If a local file was passed in, render it and exit
if let Some(file) = args.render {
let path = PageLookupResult::with_page(file);
if let Err(ref e) = print_page(&path, args.raw, enable_styles, args.pager, &config) {
if let Err(ref e) = print_page(&path, args.raw, enable_styles, args.pager, args.no_pager, &config) {
print_error(enable_styles, e);
process::exit(1);
} else {
Expand Down Expand Up @@ -361,7 +361,7 @@ fn main() {
platforms,
) {
if let Err(ref e) =
print_page(&lookup_result, args.raw, enable_styles, args.pager, &config)
print_page(&lookup_result, args.raw, enable_styles, args.pager, args.no_pager, &config)
{
print_error(enable_styles, e);
process::exit(1);
Expand Down
3 changes: 2 additions & 1 deletion src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ pub fn print_page(
enable_markdown: bool,
enable_styles: bool,
use_pager: bool,
not_use_pager: bool,
config: &Config,
) -> Result<()> {
// Create reader from file(s)
let reader = lookup_result.reader()?;

// Configure pager if applicable
if use_pager || config.display.use_pager {
if (use_pager || config.display.use_pager) && !not_use_pager {
configure_pager(enable_styles);
}

Expand Down
19 changes: 19 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,18 @@ fn test_pager_flag_enable() {
.args(["--pager", "which"])
.assert()
.success();

testenv
.command()
.args(["--no-pager", "which"])
.assert()
.success();

testenv
.command()
.args(["--pager", "--no-pager", "which"])
.assert()
.success();
}

#[test]
Expand Down Expand Up @@ -908,6 +920,13 @@ fn test_pager_warning() {
.assert()
.success()
.stderr(contains("pager flag not available on Windows"));

// no-pager flag should not cause issues
testenv
.command()
.args(["--no-pager", "which"])
.assert()
.success()
}

/// Ensure that page lookup is case insensitive, so a page lookup for `eyed3`
Expand Down
Loading