Skip to content

Commit f352e98

Browse files
committed
reorganize file structure
1 parent 7a37b01 commit f352e98

12 files changed

+55
-55
lines changed

src/cli.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
use crate::error::*;
2-
use crate::repo::deps::package_manager::PackageManager;
3-
use crate::repo::language::Language;
2+
use crate::info::deps::package_manager::PackageManager;
3+
use crate::info::info_field::{InfoField, InfoFieldOff};
4+
use crate::info::language::Language;
45
use crate::ui::image_backends;
56
use crate::ui::image_backends::ImageBackend;
6-
use crate::ui::info::info_field::{InfoField, InfoFieldOff};
77
use crate::ui::printer::SerializationFormat;
88
use clap::{crate_description, crate_name, crate_version, App, AppSettings, Arg};
99
use image::DynamicImage;
1010
use regex::Regex;
1111
use std::process::Command;
1212
use std::{convert::From, env, str::FromStr};
1313
use strum::IntoEnumIterator;
14-
use term_size;
1514

1615
const MAX_TERM_WIDTH: usize = 95;
1716

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/repo/language.rs renamed to src/info/language.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ macro_rules! define_languages {
2525
pub enum Language {
2626
$(
2727
$( #[strum(serialize = $serialize)] )?
28-
$name ,
28+
$name,
2929
)*
3030
}
3131

File renamed without changes.

src/ui/info/mod.rs renamed to src/info/mod.rs

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
use crate::cli::{self, Config};
22
use crate::error::*;
3-
use crate::repo::deps::DependencyDetector;
4-
use crate::repo::head_refs::HeadRefs;
5-
use crate::repo::language::Language;
6-
use crate::repo::license::Detector;
7-
use crate::repo::Repo;
8-
use crate::ui;
3+
use crate::ui::get_ascii_colors;
94
use crate::ui::text_color::TextColor;
105
use colored::{Color, ColoredString, Colorize};
6+
use deps::DependencyDetector;
117
use git2::Repository;
8+
use head_refs::HeadRefs;
9+
use language::Language;
10+
use license::Detector;
11+
use repo::Repo;
1212
use serde::ser::SerializeStruct;
1313
use serde::Serialize;
1414

15+
pub mod deps;
16+
mod head_refs;
1517
pub mod info_field;
18+
pub mod language;
19+
mod license;
20+
pub mod repo;
1621

1722
pub struct Info {
1823
git_username: String,
@@ -213,7 +218,7 @@ impl std::fmt::Display for Info {
213218
}
214219

215220
impl Info {
216-
pub fn new(config: Config) -> Result<Info> {
221+
pub fn new(config: Config) -> Result<Self> {
217222
let git_version = cli::get_git_version();
218223
let repo = Repository::discover(&config.repo_path)?;
219224
let internal_repo = Repo::new(&repo, config.no_merges, &config.bot_regex_pattern)?;
@@ -243,7 +248,7 @@ impl Info {
243248
);
244249
let text_colors = TextColor::get_text_colors(&config.text_colors, &ascii_colors);
245250

246-
Ok(Info {
251+
Ok(Self {
247252
git_username,
248253
git_version,
249254
repo_name,
@@ -421,32 +426,6 @@ impl Info {
421426
}
422427
}
423428

424-
fn get_ascii_colors(
425-
ascii_language: &Option<Language>,
426-
dominant_language: &Language,
427-
ascii_colors: &[String],
428-
true_color: bool,
429-
) -> Vec<Color> {
430-
let language =
431-
if let Some(ascii_language) = ascii_language { ascii_language } else { &dominant_language };
432-
433-
let colors = language.get_colors(true_color);
434-
435-
let colors: Vec<Color> = colors
436-
.iter()
437-
.enumerate()
438-
.map(|(index, default_color)| {
439-
if let Some(color_num) = ascii_colors.get(index) {
440-
if let Some(color) = ui::num_to_color(color_num) {
441-
return color;
442-
}
443-
}
444-
*default_color
445-
})
446-
.collect();
447-
colors
448-
}
449-
450429
impl Serialize for Info {
451430
fn serialize<S>(&self, serializer: S) -> std::result::Result<S::Ok, S::Error>
452431
where

src/repo/mod.rs renamed to src/info/repo.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::error::*;
2-
use crate::repo::head_refs::HeadRefs;
2+
use crate::info::head_refs::HeadRefs;
33
use byte_unit::Byte;
44
use chrono::{FixedOffset, TimeZone};
55
use chrono_humanize::HumanTime;
@@ -11,11 +11,6 @@ use git2::{
1111
use regex::Regex;
1212
use std::path::Path;
1313

14-
pub mod deps;
15-
pub mod head_refs;
16-
pub mod language;
17-
pub mod license;
18-
1914
pub struct Repo<'a> {
2015
repo: &'a Repository,
2116
logs: Vec<Commit<'a>>,
@@ -27,7 +22,7 @@ impl<'a> Repo<'a> {
2722
no_merges: bool,
2823
bot_regex_pattern: &Option<Regex>,
2924
) -> Result<Self> {
30-
let logs = Repo::get_logs(repo, no_merges, bot_regex_pattern)?;
25+
let logs = Self::get_logs(repo, no_merges, bot_regex_pattern)?;
3126
Ok(Self { repo, logs })
3227
}
3328

@@ -293,17 +288,17 @@ impl<'a> Repo<'a> {
293288
}
294289
}
295290

296-
pub fn is_bot(author: Signature, bot_regex_pattern: &Option<Regex>) -> bool {
291+
fn is_bot(author: Signature, bot_regex_pattern: &Option<Regex>) -> bool {
297292
let author_name = String::from_utf8_lossy(author.name_bytes()).into_owned();
298293
bot_regex_pattern.as_ref().unwrap().is_match(&author_name)
299294
}
300295

301-
pub fn bytes_to_human_readable(bytes: u128) -> String {
296+
fn bytes_to_human_readable(bytes: u128) -> String {
302297
let byte = Byte::from_bytes(bytes);
303298
byte.get_appropriate_unit(true).to_string()
304299
}
305300

306-
pub fn git_time_to_formatted_time(time: &Time, iso_time: bool) -> String {
301+
fn git_time_to_formatted_time(time: &Time, iso_time: bool) -> String {
307302
let (offset, _) = match time.offset_minutes() {
308303
n if n < 0 => (-n, '-'),
309304
n => (n, '+'),

src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44

55
use cli::Config;
66
use error::*;
7+
use info::{repo, Info};
78
use std::{io, process};
8-
use ui::info::Info;
99
use ui::printer::Printer;
1010

1111
mod cli;
1212
mod error;
13-
mod repo;
13+
mod info;
1414
mod ui;
1515

1616
fn run() -> Result<()> {
@@ -30,6 +30,7 @@ fn run() -> Result<()> {
3030
if !repo::is_valid(&config.repo_path)? {
3131
return Err("please run onefetch inside of a non-bare git repository".into());
3232
}
33+
3334
let info = Info::new(config)?;
3435

3536
let mut printer = Printer::new(io::BufWriter::new(io::stdout()), info);

src/ui/mod.rs

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,38 @@
1+
use crate::info::language::Language;
12
use colored::Color;
23

34
pub mod ascii_art;
45
pub mod image_backends;
5-
pub mod info;
66
pub mod printer;
7-
mod text_color;
7+
pub mod text_color;
88

9-
pub fn num_to_color(num: &str) -> Option<Color> {
9+
pub fn get_ascii_colors(
10+
ascii_language: &Option<Language>,
11+
dominant_language: &Language,
12+
ascii_colors: &[String],
13+
true_color: bool,
14+
) -> Vec<Color> {
15+
let language =
16+
if let Some(ascii_language) = ascii_language { ascii_language } else { &dominant_language };
17+
18+
let colors = language.get_colors(true_color);
19+
20+
let colors: Vec<Color> = colors
21+
.iter()
22+
.enumerate()
23+
.map(|(index, default_color)| {
24+
if let Some(color_num) = ascii_colors.get(index) {
25+
if let Some(color) = num_to_color(color_num) {
26+
return color;
27+
}
28+
}
29+
*default_color
30+
})
31+
.collect();
32+
colors
33+
}
34+
35+
fn num_to_color(num: &str) -> Option<Color> {
1036
let color = match num {
1137
"0" => Color::Black,
1238
"1" => Color::Red,

src/ui/printer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::error::*;
2+
use crate::info::Info;
23
use crate::ui::ascii_art::AsciiArt;
3-
use crate::ui::info::Info;
44
use colored::Color;
55
use std::io::Write;
66
use strum::{EnumIter, EnumString, IntoStaticStr};

0 commit comments

Comments
 (0)