mirror of
https://github.com/sharkdp/bat.git
synced 2025-04-01 19:58:14 +02:00
Move paging support behind a feature
This commit is contained in:
parent
4e11abdf9b
commit
014d754588
@ -26,9 +26,11 @@ application = [
|
|||||||
"git",
|
"git",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"liquid",
|
"liquid",
|
||||||
|
"paging",
|
||||||
"wild",
|
"wild",
|
||||||
]
|
]
|
||||||
git = ["git2"] # Support indicating git modifications
|
git = ["git2"] # Support indicating git modifications
|
||||||
|
paging = ["shell-words"] # Support applying a pager on the output
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
atty = { version = "0.2.14", optional = true }
|
atty = { version = "0.2.14", optional = true }
|
||||||
@ -40,7 +42,7 @@ lazy_static = { version = "1.4", optional = true }
|
|||||||
wild = { version = "2.0", optional = true }
|
wild = { version = "2.0", optional = true }
|
||||||
content_inspector = "0.2.4"
|
content_inspector = "0.2.4"
|
||||||
encoding = "0.2"
|
encoding = "0.2"
|
||||||
shell-words = "0.1.0"
|
shell-words = { version = "0.1.0", optional = true }
|
||||||
unicode-width = "0.1.7"
|
unicode-width = "0.1.7"
|
||||||
globset = "0.4"
|
globset = "0.4"
|
||||||
|
|
||||||
|
1
ci/script.bash
vendored
1
ci/script.bash
vendored
@ -16,3 +16,4 @@ fi
|
|||||||
# Check bat-as-a-library, which has a smaller set of dependencies
|
# Check bat-as-a-library, which has a smaller set of dependencies
|
||||||
cargo check --target "$TARGET" --verbose --lib --no-default-features
|
cargo check --target "$TARGET" --verbose --lib --no-default-features
|
||||||
cargo check --target "$TARGET" --verbose --lib --no-default-features --features git
|
cargo check --target "$TARGET" --verbose --lib --no-default-features --features git
|
||||||
|
cargo check --target "$TARGET" --verbose --lib --no-default-features --features paging
|
||||||
|
@ -6,7 +6,9 @@ pub use crate::wrap::OutputWrap;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||||
pub enum PagingMode {
|
pub enum PagingMode {
|
||||||
|
#[cfg(feature = "paging")]
|
||||||
Always,
|
Always,
|
||||||
|
#[cfg(feature = "paging")]
|
||||||
QuitIfOneScreen,
|
QuitIfOneScreen,
|
||||||
Never,
|
Never,
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
#![cfg(feature = "paging")]
|
||||||
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
pub fn retrieve_less_version() -> Option<usize> {
|
pub fn retrieve_less_version() -> Option<usize> {
|
||||||
|
@ -1,31 +1,39 @@
|
|||||||
use std::env;
|
|
||||||
use std::ffi::OsString;
|
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::path::PathBuf;
|
#[cfg(feature = "paging")]
|
||||||
use std::process::{Child, Command, Stdio};
|
use std::process::Child;
|
||||||
|
|
||||||
use crate::config::PagingMode;
|
use crate::config::PagingMode;
|
||||||
use crate::errors::*;
|
use crate::errors::*;
|
||||||
|
#[cfg(feature = "paging")]
|
||||||
use crate::less::retrieve_less_version;
|
use crate::less::retrieve_less_version;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum OutputType {
|
pub enum OutputType {
|
||||||
|
#[cfg(feature = "paging")]
|
||||||
Pager(Child),
|
Pager(Child),
|
||||||
Stdout(io::Stdout),
|
Stdout(io::Stdout),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OutputType {
|
impl OutputType {
|
||||||
pub fn from_mode(mode: PagingMode, pager: Option<&str>) -> Result<Self> {
|
pub fn from_mode(mode: PagingMode, pager: Option<&str>) -> Result<Self> {
|
||||||
use self::PagingMode::*;
|
let _ = pager;
|
||||||
Ok(match mode {
|
Ok(match mode {
|
||||||
Always => OutputType::try_pager(false, pager)?,
|
#[cfg(feature = "paging")]
|
||||||
QuitIfOneScreen => OutputType::try_pager(true, pager)?,
|
PagingMode::Always => OutputType::try_pager(false, pager)?,
|
||||||
|
#[cfg(feature = "paging")]
|
||||||
|
PagingMode::QuitIfOneScreen => OutputType::try_pager(true, pager)?,
|
||||||
_ => OutputType::stdout(),
|
_ => OutputType::stdout(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to launch the pager. Fall back to stdout in case of errors.
|
/// Try to launch the pager. Fall back to stdout in case of errors.
|
||||||
|
#[cfg(feature = "paging")]
|
||||||
fn try_pager(quit_if_one_screen: bool, pager_from_config: Option<&str>) -> Result<Self> {
|
fn try_pager(quit_if_one_screen: bool, pager_from_config: Option<&str>) -> Result<Self> {
|
||||||
|
use std::env;
|
||||||
|
use std::ffi::OsString;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
let mut replace_arguments_to_less = false;
|
let mut replace_arguments_to_less = false;
|
||||||
|
|
||||||
let pager_from_env = match (env::var("BAT_PAGER"), env::var("PAGER")) {
|
let pager_from_env = match (env::var("BAT_PAGER"), env::var("PAGER")) {
|
||||||
@ -114,6 +122,7 @@ impl OutputType {
|
|||||||
|
|
||||||
pub fn handle(&mut self) -> Result<&mut dyn Write> {
|
pub fn handle(&mut self) -> Result<&mut dyn Write> {
|
||||||
Ok(match *self {
|
Ok(match *self {
|
||||||
|
#[cfg(feature = "paging")]
|
||||||
OutputType::Pager(ref mut command) => command
|
OutputType::Pager(ref mut command) => command
|
||||||
.stdin
|
.stdin
|
||||||
.as_mut()
|
.as_mut()
|
||||||
@ -123,6 +132,7 @@ impl OutputType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "paging")]
|
||||||
impl Drop for OutputType {
|
impl Drop for OutputType {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if let OutputType::Pager(ref mut command) = *self {
|
if let OutputType::Pager(ref mut command) = *self {
|
||||||
|
Loading…
Reference in New Issue
Block a user