<commit_before>use color::Color;
use part::*;
use powerline::*;
use std::{env, path};

pub struct Cwd {
	special: &'static str,
	max_length: usize,
	wanted_seg_num: usize,
	resolve_symlinks: bool,
}

impl Cwd {
	pub fn new(special: &'static str, max_length: usize, wanted_seg_num: usize, resolve_symlinks: bool) -> Cwd {
		Cwd {
			special,
			max_length,
			wanted_seg_num,
			resolve_symlinks,
		}
	}
}

fn append_cwd_segments<'a, I>(segments: &mut Vec<Segment>, iter: I)
where
	I: Iterator<Item = &'a str>,
{
	for val in iter {
		segments.push(Segment::special(&format!(" {} ", val), Color::PATH_FG, Color::PATH_BG, '\u{E0B1}', Color::SEPARATOR_FG));
	}
}

impl Part for Cwd {
	fn get_segments(self) -> Result<Vec<Segment>, Error> {
		let current_dir = if self.resolve_symlinks {
			env::current_dir()?
		} else {
			path::PathBuf::from(env::var("PWD")?)
		};

		let mut cwd = current_dir.to_str().unwrap();
		let mut segments = Vec::new();

		if let Some(home_path) = env::home_dir() {
			let home_str = home_path.to_str().unwrap();
			if cwd.starts_with(home_str) {
				segments.push(Segment::simple(&format!(" {} ", self.special), Color::HOME_FG, Color::HOME_BG));
				cwd = &cwd[home_str.len()..]
			}
		}

		let depth = cwd.matches("/").count() - 1;
		if (cwd.len() > self.max_length as usize) && (depth > self.wanted_seg_num) {
			let left = self.wanted_seg_num / 2;<commit_msg>[CWD] Change depth calculation in get_segments<commit_after>use color::Color;
use part::*;
use powerline::*;
use std::{env, path};

pub struct Cwd {
	special: &'static str,
	max_length: usize,
	wanted_seg_num: usize,
	resolve_symlinks: bool,
}

impl Cwd {
	pub fn new(special: &'static str, max_length: usize, wanted_seg_num: usize, resolve_symlinks: bool) -> Cwd {
		Cwd {
			special,
			max_length,
			wanted_seg_num,
			resolve_symlinks,
		}
	}
}

fn append_cwd_segments<'a, I>(segments: &mut Vec<Segment>, iter: I)
where
	I: Iterator<Item = &'a str>,
{
	for val in iter {
		segments.push(Segment::special(&format!(" {} ", val), Color::PATH_FG, Color::PATH_BG, '\u{E0B1}', Color::SEPARATOR_FG));
	}
}

impl Part for Cwd {
	fn get_segments(self) -> Result<Vec<Segment>, Error> {
		let current_dir = if self.resolve_symlinks {
			env::current_dir()?
		} else {
			path::PathBuf::from(env::var("PWD")?)
		};

		let mut cwd = current_dir.to_str().unwrap();
		let mut segments = Vec::new();

		if let Some(home_path) = env::home_dir() {
			let home_str = home_path.to_str().unwrap();
			if cwd.starts_with(home_str) {
				segments.push(Segment::simple(&format!(" {} ", self.special), Color::HOME_FG, Color::HOME_BG));
				cwd = &cwd[home_str.len()..]
			}
		}

		let depth = cwd.matches("/").count();
		if (cwd.len() > self.max_length as usize) && (depth > self.wanted_seg_num) {
			let left = self.wanted_seg_num / 2;
{'fraction_non_alphanumeric': 0.17516946129147343, 'fraction_numerical': 0.0024973242953977882, 'mean_word_length': 4.361376673040153, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7178858', 'n_tokens_mistral': 1174, 'n_tokens_neox': 1094, 'n_words': 233}