Skip to content

Commit bcb4e64

Browse files
committed
refacto use stmts and replace get_info_lines with async block
1 parent 42f56c1 commit bcb4e64

File tree

5 files changed

+103
-141
lines changed

5 files changed

+103
-141
lines changed

src/image_backends/kitty.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
use image::{imageops::FilterType, DynamicImage, GenericImageView};
2-
use libc::{
3-
c_void, ioctl, poll, pollfd, read, tcgetattr, tcsetattr, termios, winsize, ECHO, ICANON,
4-
POLLIN, STDIN_FILENO, STDOUT_FILENO, TCSANOW, TIOCGWINSZ,
1+
use {
2+
image::{imageops::FilterType, DynamicImage, GenericImageView},
3+
libc::{
4+
c_void, ioctl, poll, pollfd, read, tcgetattr, tcsetattr, termios, winsize, ECHO, ICANON,
5+
POLLIN, STDIN_FILENO, STDOUT_FILENO, TCSANOW, TIOCGWINSZ,
6+
},
7+
std::time::Instant,
58
};
6-
use std::time::Instant;
79

810
pub struct KittyBackend {}
911

src/image_backends/sixel.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
use image::{
2-
imageops::{colorops, FilterType},
3-
math::nq::NeuQuant,
4-
DynamicImage, GenericImageView, ImageBuffer, Pixel, Rgb,
1+
use {
2+
image::{
3+
imageops::{colorops, FilterType},
4+
math::nq::NeuQuant,
5+
DynamicImage, GenericImageView, ImageBuffer, Pixel, Rgb,
6+
},
7+
libc::{
8+
c_void, ioctl, poll, pollfd, read, tcgetattr, tcsetattr, termios, winsize, ECHO, ICANON,
9+
POLLIN, STDIN_FILENO, STDOUT_FILENO, TCSANOW, TIOCGWINSZ,
10+
},
11+
std::time::Instant,
512
};
6-
use libc::{
7-
c_void, ioctl, poll, pollfd, read, tcgetattr, tcsetattr, termios, winsize, ECHO, ICANON,
8-
POLLIN, STDIN_FILENO, STDOUT_FILENO, TCSANOW, TIOCGWINSZ,
9-
};
10-
use std::time::Instant;
1113

1214
pub struct SixelBackend {}
1315

src/info.rs

+63-91
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
use {
2-
crate::image_backends::ImageBackend,
3-
crate::language::Language,
4-
crate::license::Detector,
5-
crate::{AsciiArt, CommitInfo, Configuration, Error, InfoFieldOn},
2+
crate::{
3+
image_backends::ImageBackend,
4+
language::Language,
5+
license::Detector,
6+
{AsciiArt, CommitInfo, Configuration, Error, InfoFieldOn},
7+
},
68
colored::{Color, ColoredString, Colorize},
7-
futures,
89
futures::executor::block_on,
910
git2::Repository,
1011
image::DynamicImage,
11-
std::ffi::OsStr,
12-
std::fmt::Write,
13-
std::fs,
14-
std::process::Command,
12+
std::{ffi::OsStr, fmt::Write, fs, process::Command},
1513
};
1614

1715
type Result<T> = std::result::Result<T, crate::Error>;
@@ -307,93 +305,67 @@ impl Info {
307305
let (languages_stats, number_of_lines) =
308306
Language::get_language_stats(workdir_str, ignored_directories)?;
309307

310-
let (
311-
config,
312-
current_commit_info,
313-
authors,
314-
(git_v, git_user),
315-
version,
316-
commits,
317-
pending,
318-
repo_size,
319-
last_change,
320-
creation_date,
321-
project_license,
322-
dominant_language,
323-
) = block_on(Info::get_info_lines(
324-
no_merges,
325-
author_nb,
326-
&repo,
327-
workdir_str,
328-
&languages_stats,
329-
));
330-
331-
let conf = config?;
332-
let info = Info {
333-
git_version: git_v,
334-
git_username: git_user,
335-
project_name: conf.repository_name,
336-
current_commit: current_commit_info?,
337-
version: version?,
338-
creation_date: creation_date?,
339-
dominant_language,
340-
languages: languages_stats,
341-
authors,
342-
last_change: last_change?,
343-
repo: conf.repository_url,
344-
commits: commits?,
345-
pending: pending?,
346-
repo_size: repo_size?,
347-
number_of_lines,
348-
license: project_license?,
349-
custom_logo: logo,
350-
custom_colors: colors,
351-
disable_fields: disabled,
352-
bold_enabled: bold_flag,
353-
no_color_blocks: color_blocks_flag,
354-
custom_image,
355-
image_backend,
308+
let info = async {
309+
let (
310+
config,
311+
current_commit_info,
312+
authors,
313+
(git_v, git_user),
314+
version,
315+
commits,
316+
pending,
317+
repo_size,
318+
last_change,
319+
creation_date,
320+
project_license,
321+
dominant_language,
322+
) = futures::join!(
323+
Info::get_configuration(&repo),
324+
Info::get_current_commit_info(&repo),
325+
Info::get_authors(workdir_str, no_merges, author_nb),
326+
Info::get_git_info(workdir_str),
327+
Info::get_version(workdir_str),
328+
Info::get_commits(workdir_str, no_merges),
329+
Info::get_pending_pending(workdir_str),
330+
Info::get_packed_size(workdir_str),
331+
Info::get_last_change(workdir_str),
332+
Info::get_creation_time(workdir_str),
333+
Info::get_project_license(workdir_str),
334+
Language::get_dominant_language(languages_stats.clone())
335+
);
336+
337+
let conf = config.unwrap();
338+
Info {
339+
git_version: git_v,
340+
git_username: git_user,
341+
project_name: conf.repository_name,
342+
current_commit: current_commit_info.unwrap(),
343+
version: version.unwrap(),
344+
creation_date: creation_date.unwrap(),
345+
dominant_language,
346+
languages: languages_stats,
347+
authors,
348+
last_change: last_change.unwrap(),
349+
repo: conf.repository_url,
350+
commits: commits.unwrap(),
351+
pending: pending.unwrap(),
352+
repo_size: repo_size.unwrap(),
353+
number_of_lines,
354+
license: project_license.unwrap(),
355+
custom_logo: logo,
356+
custom_colors: colors,
357+
disable_fields: disabled,
358+
bold_enabled: bold_flag,
359+
no_color_blocks: color_blocks_flag,
360+
custom_image,
361+
image_backend,
362+
}
356363
};
357364

365+
let info = block_on(info);
358366
Ok(info)
359367
}
360368

361-
async fn get_info_lines(
362-
no_merges: bool,
363-
author_nb: usize,
364-
repo: &git2::Repository,
365-
workdir_str: &str,
366-
languages_stats: &Vec<(Language, f64)>,
367-
) -> (
368-
Result<Configuration>,
369-
Result<CommitInfo>,
370-
Vec<(String, usize, usize)>,
371-
(String, String),
372-
Result<String>,
373-
Result<String>,
374-
Result<String>,
375-
Result<String>,
376-
Result<String>,
377-
Result<String>,
378-
Result<String>,
379-
Language,
380-
) {
381-
futures::join!(
382-
Info::get_configuration(&repo),
383-
Info::get_current_commit_info(&repo),
384-
Info::get_authors(workdir_str, no_merges, author_nb),
385-
Info::get_git_info(workdir_str),
386-
Info::get_version(workdir_str),
387-
Info::get_commits(workdir_str, no_merges),
388-
Info::get_pending_pending(workdir_str),
389-
Info::get_packed_size(workdir_str),
390-
Info::get_last_change(workdir_str),
391-
Info::get_creation_time(workdir_str),
392-
Info::get_project_license(workdir_str),
393-
Language::get_dominant_language(languages_stats.clone())
394-
)
395-
}
396-
397369
async fn get_configuration(repo: &Repository) -> Result<Configuration> {
398370
let config = repo.config().map_err(|_| Error::NoGitData)?;
399371
let mut remote_url = String::new();

src/language.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use regex::Regex;
2-
use std::collections::HashMap;
3-
4-
use colored::Color;
5-
6-
use crate::{Error, Result};
1+
use {
2+
crate::{Error, Result},
3+
colored::Color,
4+
regex::Regex,
5+
std::collections::HashMap,
6+
};
77

88
#[derive(PartialEq, Eq, Hash, Clone, EnumString, EnumIter)]
99
#[strum(serialize_all = "lowercase")]

src/main.rs

+16-30
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
1-
extern crate bytecount;
2-
3-
extern crate askalono;
4-
extern crate colored;
5-
extern crate git2;
6-
extern crate regex;
7-
extern crate tokei;
81
#[macro_use]
92
extern crate clap;
10-
extern crate strum;
113
#[macro_use]
124
extern crate strum_macros;
13-
extern crate image;
14-
15-
#[cfg(target_os = "windows")]
16-
extern crate ansi_term;
175

186
#[cfg(target_os = "linux")]
19-
extern crate libc;
20-
21-
use clap::{App, Arg};
22-
use colored::*;
23-
use std::{
24-
convert::From,
25-
process::{Command, Stdio},
26-
result,
27-
str::FromStr,
7+
use image_backends::ImageBackend;
8+
use {
9+
ascii_art::AsciiArt,
10+
clap::{App, Arg},
11+
colored::*,
12+
commit_info::CommitInfo,
13+
error::Error,
14+
info::Info,
15+
language::Language,
16+
std::{
17+
convert::From,
18+
process::{Command, Stdio},
19+
result,
20+
str::FromStr,
21+
},
22+
strum::{EnumCount, IntoEnumIterator},
2823
};
29-
use strum::{EnumCount, IntoEnumIterator};
3024

3125
mod ascii_art;
3226
mod commit_info;
@@ -36,14 +30,6 @@ mod info;
3630
mod language;
3731
mod license;
3832

39-
use ascii_art::AsciiArt;
40-
use commit_info::CommitInfo;
41-
use error::Error;
42-
#[cfg(target_os = "linux")]
43-
use image_backends::ImageBackend;
44-
use info::Info;
45-
use language::Language;
46-
4733
type Result<T> = result::Result<T, Error>;
4834

4935
#[derive(Default)]

0 commit comments

Comments
 (0)