summaryrefslogtreecommitdiffstats
path: root/src/bat
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2019-10-29 20:01:30 -0700
committerDan Davison <dandavison7@gmail.com>2019-10-29 20:03:19 -0700
commitfa14a6b144df8a4fae995aa3608c414aad73ed9c (patch)
tree98081e0f8e0a2b1673ddc2174c3de251f036dbc7 /src/bat
parentf8d2151891a4c16b64f592949f3b5ce0cd0e0d4d (diff)
Add env module
Diffstat (limited to 'src/bat')
-rw-r--r--src/bat/output.rs14
1 files changed, 3 insertions, 11 deletions
diff --git a/src/bat/output.rs b/src/bat/output.rs
index eec76e75..02edd987 100644
--- a/src/bat/output.rs
+++ b/src/bat/output.rs
@@ -1,7 +1,6 @@
// https://github.com/sharkdp/bat a1b9334a44a2c652f52dddaa83dbacba57372468
// src/output.rs
// See src/bat/LICENSE
-use std::env;
use std::ffi::OsString;
use std::io::{self, Write};
use std::path::PathBuf;
@@ -9,6 +8,8 @@ use std::process::{Child, Command, Stdio};
use shell_words;
+use crate::env;
+
#[derive(Debug, Clone, Copy, PartialEq)]
#[allow(dead_code)]
pub enum PagingMode {
@@ -23,15 +24,6 @@ pub enum OutputType {
Stdout(io::Stdout),
}
-/// If key is set and, after trimming whitespace, is not empty string, then return that trimmed
-/// string. Else None.
-pub fn get_env_var(key: &str) -> Option<String> {
- match env::var(key).unwrap_or("".to_string()).trim() {
- "" => None,
- non_empty_string => Some(non_empty_string.to_string()),
- }
-}
-
impl OutputType {
pub fn from_mode(mode: PagingMode, pager: Option<&str>) -> Result<Self> {
use self::PagingMode::*;
@@ -46,7 +38,7 @@ impl OutputType {
fn try_pager(quit_if_one_screen: bool, pager_from_config: Option<&str>) -> Result<Self> {
let mut replace_arguments_to_less = false;
- let pager_from_env = match (get_env_var("BAT_PAGER"), get_env_var("PAGER")) {
+ let pager_from_env = match (env::get_env_var("BAT_PAGER"), env::get_env_var("PAGER")) {
(Some(bat_pager), _) => Some(bat_pager),
(_, Some(pager)) => {
// less needs to be called with the '-R' option in order to properly interpret the