From 99d21463574bb88fa86f176c2e4ad154be5e1353 Mon Sep 17 00:00:00 2001 From: A Farzat Date: Sun, 7 Jun 2026 20:53:20 +0300 Subject: Refactor language detection in a util module --- src/renderer.rs | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) (limited to 'src/renderer.rs') diff --git a/src/renderer.rs b/src/renderer.rs index ad5201f..f492f1e 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -4,7 +4,11 @@ use std::{ path::Path, }; -use crate::{logger::Logger, normalizer::NormalizedPath, util::path_display::display_path}; +use crate::{ + logger::Logger, + normalizer::NormalizedPath, + util::{language::detect_language, path_display::display_path}, +}; const DEFAULT_MAX_FILE_SIZE: u64 = 1_000_000; @@ -142,31 +146,6 @@ fn human_readable_size(bytes: u64) -> String { } } -fn detect_language(filename: &Path, contents: &str) -> &'static str { - let ext = filename - .extension() - .and_then(|e| e.to_str()) - .map(|e| e.to_ascii_lowercase()); - let ext_str = ext.as_deref(); - match ext_str { - Some("rs") => "rust", - Some("py") => "python", - Some("json") => "json", - _ => { - if let Some(first_line) = contents.lines().next() { - if first_line.contains("python") - { - return "python"; - } - if first_line.contains("bash") { - return "bash"; - } - } - "" - } - } -} - #[cfg(test)] mod tests { use std::{ -- cgit v1.3.1