rust/rhg/src/ui.rs
changeset 48729 99b1dfc06571
parent 48513 47f2a82ae3e4
child 48730 1aaf11e35aec
equal deleted inserted replaced
48728:3199b575375d 48729:99b1dfc06571
     1 use format_bytes::format_bytes;
     1 use format_bytes::format_bytes;
       
     2 use hg::utils::files::get_bytes_from_os_string;
     2 use std::borrow::Cow;
     3 use std::borrow::Cow;
     3 use std::env;
     4 use std::env;
     4 use std::io;
     5 use std::io;
     5 use std::io::{ErrorKind, Write};
     6 use std::io::{ErrorKind, Write};
     6 
     7 
    63     ///
    64     ///
    64     /// The return value can either be
    65     /// The return value can either be
    65     /// - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT
    66     /// - False if HGPLAIN is not set, or feature is in HGPLAINEXCEPT
    66     /// - False if feature is disabled by default and not included in HGPLAIN
    67     /// - False if feature is disabled by default and not included in HGPLAIN
    67     /// - True otherwise
    68     /// - True otherwise
    68     pub fn plain(&self) -> bool {
    69     pub fn plain(&self, feature: Option<&str>) -> bool {
    69         // TODO: add support for HGPLAINEXCEPT
    70         plain(feature)
       
    71     }
       
    72 }
       
    73 
       
    74 fn plain(opt_feature: Option<&str>) -> bool {
       
    75     if let Some(except) = env::var_os("HGPLAINEXCEPT") {
       
    76         opt_feature.map_or(true, |feature| {
       
    77             get_bytes_from_os_string(except)
       
    78                 .split(|&byte| byte == b',')
       
    79                 .all(|exception| exception != feature.as_bytes())
       
    80         })
       
    81     } else {
    70         env::var_os("HGPLAIN").is_some()
    82         env::var_os("HGPLAIN").is_some()
    71     }
    83     }
    72 }
    84 }
    73 
    85 
    74 /// A buffered stdout writer for faster batch printing operations.
    86 /// A buffered stdout writer for faster batch printing operations.