| 1 | // https://github.com/sharkdp/bat a1b9334a44a2c652f52dddaa83dbacba57372468 |
| 2 | // src/output.rs |
| 3 | // See src/utils/bat/LICENSE |
| 4 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#; |
| 5 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 6 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#; |
| 7 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::{Childrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Child#, Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#, Stdiorust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Stdio#}; |
| 8 | |
| 9 | use superrust-analyzer cargo git-delta 0.19.2 utils/bat/::lessrust-analyzer cargo git-delta 0.19.2 utils/bat/less/::retrieve_less_versionrust-analyzer cargo git-delta 0.19.2 utils/bat/less/retrieve_less_version().; |
| 10 | |
| 11 | use craterust-analyzer cargo git-delta 0.19.2 crate/::configrust-analyzer cargo git-delta 0.19.2 config/; |
| 12 | use craterust-analyzer cargo git-delta 0.19.2 crate/::envrust-analyzer cargo git-delta 0.19.2 env/::DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#; |
| 13 | use craterust-analyzer cargo git-delta 0.19.2 crate/::fatalrust-analyzer cargo git-delta 0.19.2 fatal().; |
| 14 | use craterust-analyzer cargo git-delta 0.19.2 crate/::featuresrust-analyzer cargo git-delta 0.19.2 features/::navigaterust-analyzer cargo git-delta 0.19.2 features/navigate/; |
| 15 | |
| 16 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 17 | pub struct PagerCfgrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg# { |
| 18 | pub navigaterust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#navigate.: bool, |
| 19 | pub show_themesrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#show_themes.: bool, |
| 20 | pub navigate_regexrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#navigate_regex.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 21 | } |
| 22 | |
| 23 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#> for PagerCfgrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg# { |
| 24 | fn fromrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[PagerCfg][`From<&config::Config>`]from().(cfg: &configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#) -> Selfrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[PagerCfg][`From<&config::Config>`] { |
| 25 | PagerCfgrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg# { |
| 26 | navigaterust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#navigate.: cfg.navigaterust-analyzer cargo git-delta 0.19.2 config/Config#navigate., |
| 27 | show_themesrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#show_themes.: cfg.show_themesrust-analyzer cargo git-delta 0.19.2 config/Config#show_themes., |
| 28 | navigate_regexrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#navigate_regex.: cfg.navigate_regexrust-analyzer cargo git-delta 0.19.2 config/Config#navigate_regex..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().(), |
| 29 | } |
| 30 | } |
| 31 | } |
| 32 | impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#> for PagerCfgrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg# { |
| 33 | fn fromrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[PagerCfg][`From<config::Config>`]from().(cfg: configrust-analyzer cargo git-delta 0.19.2 config/::Configrust-analyzer cargo git-delta 0.19.2 config/Config#) -> Selfrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[PagerCfg][`From<config::Config>`] { |
| 34 | (&cfg).intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().() |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 39 | #[allow(dead_code)] |
| 40 | pub enum PagingModerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode# { |
| 41 | Alwaysrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#Always#, |
| 42 | QuitIfOneScreenrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#QuitIfOneScreen#, |
| 43 | #[defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/default:] |
| 44 | Neverrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#Never#, |
| 45 | Capturerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#Capture#, |
| 46 | } |
| 47 | const LESSUTFCHARDEFrust-analyzer cargo git-delta 0.19.2 utils/bat/output/LESSUTFCHARDEF.: &str = "LESSUTFCHARDEF"; |
| 48 | use craterust-analyzer cargo git-delta 0.19.2 crate/::errorsrust-analyzer cargo git-delta 0.19.2 errors/::*; |
| 49 | |
| 50 | pub enum OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType# { |
| 51 | Pagerrust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#Pager#(Childrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Child#), |
| 52 | Stdoutrust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#Stdout#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/Stdout#), |
| 53 | Capturerust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#Capture#, |
| 54 | } |
| 55 | |
| 56 | impl Droprust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/drop/Drop# for OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType# { |
| 57 | fn droprust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType][Drop]drop().(&mut self) { |
| 58 | if let OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::Pagerrust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#Pager#(ref mut command) = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self { |
| 59 | let _ = command.waitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Child]wait().(); |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | impl OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType# { |
| 65 | /// Create a pager and write all data into it. Waits until the pager exits. |
| 66 | /// The expectation is that the program will exit afterwards. |
| 67 | pub fn oneshot_writerust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]oneshot_write().(data: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 68 | let mut output_type = OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::from_moderust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]from_mode().( |
| 69 | &DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#::initrust-analyzer cargo git-delta 0.19.2 env/impl#[DeltaEnv]init().(), |
| 70 | PagingModerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#::QuitIfOneScreenrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#QuitIfOneScreen#, |
| 71 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 72 | &PagerCfgrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#::defaultrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[PagerCfg][Default]default().(), |
| 73 | ) |
| 74 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 75 | let mut writer = output_type.handlerust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]handle().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 76 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut writer, "{data}") |
| 77 | } |
| 78 | |
| 79 | pub fn from_moderust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]from_mode().( |
| 80 | env: &DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#, |
| 81 | mode: PagingModerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#, |
| 82 | pager: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 83 | config: &PagerCfgrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#, |
| 84 | ) -> Resultrust-analyzer cargo anyhow 1.0.102 Result#<Selfrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]> { |
| 85 | use selfrust-analyzer cargo git-delta 0.19.2 utils/bat/output/::PagingModerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#::*; |
| 86 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(match mode { |
| 87 | Alwaysrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#Always# => OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::try_pagerrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]try_pager().(env, false, pager, config)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 88 | QuitIfOneScreenrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#QuitIfOneScreen# => OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::try_pagerrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]try_pager().(env, true, pager, config)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 89 | Capturerust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagingMode#Capture# => OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::Capturerust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#Capture#, |
| 90 | _ => OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::stdoutrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]stdout().(), |
| 91 | }) |
| 92 | } |
| 93 | |
| 94 | /// Try to launch the pager. Fall back to stdout in case of errors. |
| 95 | fn try_pagerrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]try_pager().( |
| 96 | env: &DeltaEnvrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#, |
| 97 | quit_if_one_screen: bool, |
| 98 | pager_from_config: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 99 | config: &PagerCfgrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#, |
| 100 | ) -> Resultrust-analyzer cargo anyhow 1.0.102 Result#<Selfrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]> { |
| 101 | let mut replace_arguments_to_less = false; |
| 102 | |
| 103 | let pager_from_env = match env.pagersrust-analyzer cargo git-delta 0.19.2 env/DeltaEnv#pagers..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone#clone().() { |
| 104 | (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(delta_pager), _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(delta_pager), |
| 105 | (_, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pager)) => { |
| 106 | // less needs to be called with the '-R' option in order to properly interpret ANSI |
| 107 | // color sequences. If someone has set PAGER="less -F", we therefore need to |
| 108 | // overwrite the arguments and add '-R'. |
| 109 | // We only do this for PAGER, since it is used in other contexts. |
| 110 | replace_arguments_to_less = true; |
| 111 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pager) |
| 112 | } |
| 113 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 114 | }; |
| 115 | |
| 116 | if pager_from_config.is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() { |
| 117 | replace_arguments_to_less = false; |
| 118 | } |
| 119 | |
| 120 | let pager_cmd = shell_wordsrust-analyzer cargo shell-words 1.1.0 crate/::splitrust-analyzer cargo shell-words 1.1.0 split().( |
| 121 | &pager_from_config |
| 122 | .orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]or().(pager_from_env) |
| 123 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("less")), |
| 124 | ) |
| 125 | .contextrust-analyzer cargo anyhow 1.0.102 context/impl#[`Result<T, E>`][`Context<T, E>`]context().("Could not parse pager command.")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 126 | |
| 127 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(match pager_cmd.split_firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_first().() { |
| 128 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((pager_path, args)) => { |
| 129 | let pager_path = PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][`From<&T>`]from().(pager_path); |
| 130 | |
| 131 | let is_less = pager_path.file_stemrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_stem().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().("less")); |
| 132 | |
| 133 | let process = if is_less { |
| 134 | _make_process_from_less_pathrust-analyzer cargo git-delta 0.19.2 utils/bat/output/_make_process_from_less_path().( |
| 135 | pager_path, |
| 136 | args, |
| 137 | replace_arguments_to_less, |
| 138 | quit_if_one_screen, |
| 139 | config, |
| 140 | ) |
| 141 | } else { |
| 142 | _make_process_from_pager_pathrust-analyzer cargo git-delta 0.19.2 utils/bat/output/_make_process_from_pager_path().(pager_path, args) |
| 143 | }; |
| 144 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut process) = process { |
| 145 | process |
| 146 | .stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]stdin().(Stdiorust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Stdio#::pipedrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Stdio]piped().()) |
| 147 | .spawnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]spawn().() |
| 148 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::Pagerrust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#Pager#) |
| 149 | .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or_else().(|_| OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::stdoutrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]stdout().()) |
| 150 | } else { |
| 151 | OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::stdoutrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]stdout().() |
| 152 | } |
| 153 | } |
| 154 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::stdoutrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]stdout().(), |
| 155 | }) |
| 156 | } |
| 157 | |
| 158 | fn stdoutrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]stdout().() -> Selfrust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType] { |
| 159 | OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::Stdoutrust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#Stdout#(iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().()) |
| 160 | } |
| 161 | |
| 162 | pub fn handlerust-analyzer cargo git-delta 0.19.2 utils/bat/output/impl#[OutputType]handle().(&mut self) -> Resultrust-analyzer cargo anyhow 1.0.102 Result#<&mut dyn Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> { |
| 163 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self { |
| 164 | OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::Pagerrust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#Pager#(ref mut command) => command |
| 165 | .stdinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Child#stdin. |
| 166 | .as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_mut().() |
| 167 | .contextrust-analyzer cargo anyhow 1.0.102 context/impl#[`Option<T>`][`Context<T, Infallible>`]context().("Could not open stdin for pager")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 168 | OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::Stdoutrust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#Stdout#(ref mut handle) => handle, |
| 169 | OutputTyperust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#::Capturerust-analyzer cargo git-delta 0.19.2 utils/bat/output/OutputType#Capture# => unreachablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/unreachable!!("capture can not be set"), |
| 170 | }) |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | fn _make_process_from_less_pathrust-analyzer cargo git-delta 0.19.2 utils/bat/output/_make_process_from_less_path().( |
| 175 | less_path: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, |
| 176 | args: &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#], |
| 177 | replace_arguments_to_less: bool, |
| 178 | quit_if_one_screen: bool, |
| 179 | config: &PagerCfgrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#, |
| 180 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#> { |
| 181 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(less_path) = grep_clirust-analyzer cargo grep-cli 0.1.12 crate/::resolve_binaryrust-analyzer cargo grep-cli 0.1.12 decompress/resolve_binary().(less_path) { |
| 182 | let mut p = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().(less_path.clonerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf][Clone]clone().()); |
| 183 | if args.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() || replace_arguments_to_less { |
| 184 | p.argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]args().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["--RAW-CONTROL-CHARS"]); |
| 185 | |
| 186 | // Passing '--no-init' fixes a bug with '--quit-if-one-screen' in older |
| 187 | // versions of 'less'. Unfortunately, it also breaks mouse-wheel support. |
| 188 | // |
| 189 | // See: http://www.greenwoodsoftware.com/less/news.530.html |
| 190 | // |
| 191 | // For newer versions (530 or 558 on Windows), we omit '--no-init' as it |
| 192 | // is not needed anymore. |
| 193 | match retrieve_less_versionrust-analyzer cargo git-delta 0.19.2 utils/bat/less/retrieve_less_version().(less_path) { |
| 194 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 195 | p.argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("--no-init"); |
| 196 | } |
| 197 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(version) if (version rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().530 || (cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(windows) && version rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().558)) => { |
| 198 | p.argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("--no-init"); |
| 199 | } |
| 200 | _ => {} |
| 201 | } |
| 202 | |
| 203 | if quit_if_one_screen { |
| 204 | p.argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("--quit-if-one-screen"); |
| 205 | } |
| 206 | } else { |
| 207 | p.argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]args().(args); |
| 208 | } |
| 209 | |
| 210 | // less >= 633 (from May 2023) prints any characters from the Private Use Area of Unicode |
| 211 | // as control characters (e.g. <U+E012> instead of hoping that the terminal can render it). |
| 212 | // This means any Nerd Fonts will not be displayed properly. Previous versions of less just |
| 213 | // passed these characters through, and terminals usually fall back to a less obtrusive |
| 214 | // box. Use this new env var less introduced to restore the previous behavior. This sets all |
| 215 | // chars to single width (':p', see less manual). If a user provided env var is present, |
| 216 | // use do not override it. |
| 217 | // Also see delta issue 1616 and nerd-fonts/issues/1337 |
| 218 | if stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(LESSUTFCHARDEFrust-analyzer cargo git-delta 0.19.2 utils/bat/output/LESSUTFCHARDEF.).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().() { |
| 219 | p.envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]env().(LESSUTFCHARDEFrust-analyzer cargo git-delta 0.19.2 utils/bat/output/LESSUTFCHARDEF., "E000-F8FF:p,F0000-FFFFD:p,100000-10FFFD:p"); |
| 220 | } |
| 221 | |
| 222 | p.envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]env().("LESSCHARSET", "UTF-8"); |
| 223 | p.envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]env().("LESSANSIENDCHARS", "mK"); |
| 224 | |
| 225 | if config.navigaterust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#navigate. { |
| 226 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(hist_file) = navigaterust-analyzer cargo git-delta 0.19.2 features/navigate/::copy_less_hist_file_and_append_navigate_regexrust-analyzer cargo git-delta 0.19.2 features/navigate/copy_less_hist_file_and_append_navigate_regex().(config) { |
| 227 | p.envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]env().("LESSHISTFILE", hist_file); |
| 228 | if config.show_themesrust-analyzer cargo git-delta 0.19.2 utils/bat/output/PagerCfg#show_themes. { |
| 229 | p.argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("+n"); |
| 230 | } |
| 231 | } |
| 232 | } |
| 233 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(p) |
| 234 | } else { |
| 235 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | fn _make_process_from_pager_pathrust-analyzer cargo git-delta 0.19.2 utils/bat/output/_make_process_from_pager_path().(pager_path: PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#, args: &[Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#> { |
| 240 | if pager_path.file_stemrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_stem().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][`PartialEq<Self>`]eq().Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&OsStringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/OsString#::fromrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsString][`From<&T>`]from().("delta")) { |
| 241 | fatalrust-analyzer cargo git-delta 0.19.2 fatal().( |
| 242 | "\ |
| 243 | It looks like you have set delta as the value of $PAGER. \ |
| 244 | This would result in a non-terminating recursion. \ |
| 245 | delta is not an appropriate value for $PAGER \ |
| 246 | (but it is an appropriate value for $GIT_PAGER).", |
| 247 | ); |
| 248 | } |
| 249 | if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(pager_path) = grep_clirust-analyzer cargo grep-cli 0.1.12 crate/::resolve_binaryrust-analyzer cargo grep-cli 0.1.12 decompress/resolve_binary().(pager_path) { |
| 250 | let mut p = Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().(pager_path); |
| 251 | p.argsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]args().(args); |
| 252 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(p) |
| 253 | } else { |
| 254 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# |
| 255 | } |
| 256 | } |