paline 0.5.0

一个用 Rust 编写的代码行数统计命令行工具。递归扫描目录,按编程语言统计行数,并以彩色横向条形图在终端中可视化展示。
pub mod project;
pub mod stats;

mod parallel;
mod reader;
mod source;

use rayon::prelude::*;

pub use crate::analyzer::project::Project;
pub use crate::analyzer::stats::ProjectStats;
use crate::config::LanguageIndex;
use crate::logger::{logger, Level, Log, Verbosity};

const CHUNK_FILES: usize = 256;

pub fn analyze_project(project: &Project, index: &LanguageIndex, verbose: &u8) -> ProjectStats {
    let file_paths = project.file_paths();
    let source = project.to_analysis_source();

    logger(
        Log::new(
            Level::Info,
            format!("Found {} files", file_paths.len()),
            Some(Verbosity::Verbose),
        ),
        Some(Verbosity::from_u8(verbose)),
    );

    file_paths
        .par_chunks(CHUNK_FILES)
        .fold(ProjectStats::new, |mut stats, chunk| {
            for path in chunk {
                if let Some((lang_id, lines, bytes)) = source.analyze_file(path, index, verbose) {
                    stats.add(lang_id, lines, bytes);
                }
            }
            stats
        })
        .reduce(ProjectStats::new, |mut a, b| {
            a.merge(&b);
            a
        })
}