// NOTE: This method currently assumes all characters are 1 column wide. This should be
// ok for now since we're just displaying the current directory and date/time, which are
// unlikely to contain characters that use 2 columns.
This method currently assumes all characters are 1 column wide. This should be
ok for now since we're just displaying the current directory and date/time, which are
unlikely to contain characters that use 2 columns.
This method currently assumes all characters are 1 column wide . This should be ok for now since we ' re just displaying the current directory and date / time which are unlikely to contain characters that use 2 columns .
pub fn print_prompt(&mut self) -> String {
        let mut prompt_str = String::new();
        let cols = usize::from(get_terminal_size().0);
        let mut left_prompt = get_working_dir().unwrap_or_else(|_| String::from("no path"));
        left_prompt.truncate(cols);
        let left_prompt_width = left_prompt.chars().count();
        prompt_str.push_str(&left_prompt);
        let right_prompt = get_now();
        let right_prompt_width = right_prompt.chars().count();
        // Only print right prompt if there's enough room for it.
        if left_prompt_width + usize::from(self.min_center_spacing) + right_prompt_width <= cols {
            let right_prompt = format!("{:>width$}", get_now(), width = cols - left_prompt_width);
            prompt_str.push_str(&right_prompt);
        } else if left_prompt_width < cols {
            let right_padding = format!("{:>width$}", "", width = cols - left_prompt_width);
            prompt_str.push_str(&right_padding);
        }
        prompt_str.push_str(&self.prompt_indicator);
        prompt_str
    }
pub fn print_prompt ( & mut self ) -> String { let mut prompt_str = String :: new ( ) ; let cols = usize :: from ( get_terminal_size ( ) . 0 ) ; let mut left_prompt = get_working_dir ( ) . unwrap_or_else ( | _ | String :: from ( " " ) ) ; left_prompt . truncate ( cols ) ; let left_prompt_width = left_prompt . chars ( ) . count ( ) ; prompt_str . push_str ( & left_prompt ) ; let right_prompt = get_now ( ) ; let right_prompt_width = right_prompt . chars ( ) . count ( ) ; // Only print right prompt if there's enough room for it. if left_prompt_width + usize :: from ( self . min_center_spacing ) + right_prompt_width <= cols { let right_prompt = format ! ( " " get_now ( ) width cols left_prompt_width ) ; prompt_str . push_str ( & right_prompt ) ; } else if left_prompt_width < cols { let right_padding = format ! ( " " " " width cols left_prompt_width ) ; prompt_str . push_str ( & right_padding ) ; } prompt_str . push_str ( & self . prompt_indicator ) ; prompt_str }
NOTE: This method currently assumes all characters are 1 column wide.
NOTE : This method currently assumes all characters are 1 column wide .
&mut self