mirror of
https://github.com/XAMPPRocky/tokei
synced 2024-09-29 20:43:51 +00:00
[issue_891] give more space for Files column (#933)
* [issue_891] give more space for Files column + put columns width magic numbers into some consts * [issue_891] adjust .gitignore * [issue_891] adjust column widths for all places New consts for that are moved into dedicated consts file
This commit is contained in:
parent
1770db0afd
commit
1428a7ee3e
41
.gitignore
vendored
41
.gitignore
vendored
|
@ -1,12 +1,41 @@
|
||||||
|
# Created by https://www.toptal.com/developers/gitignore/api/rust
|
||||||
|
# Edit at https://www.toptal.com/developers/gitignore?templates=rust
|
||||||
|
|
||||||
|
### Rust ###
|
||||||
|
# Generated by Cargo
|
||||||
|
# will have compiled files and executables
|
||||||
|
debug/
|
||||||
|
target/
|
||||||
|
|
||||||
|
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
|
||||||
|
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
|
||||||
|
Cargo.lock
|
||||||
|
|
||||||
|
# These are backup files generated by rustfmt
|
||||||
|
**/*.rs.bk
|
||||||
|
|
||||||
|
# MSVC Windows builds of rustc generate these, which store debugging information
|
||||||
|
*.pdb
|
||||||
|
|
||||||
|
# End of https://www.toptal.com/developers/gitignore/api/rust
|
||||||
|
|
||||||
|
|
||||||
|
### IDE ###
|
||||||
.vscode
|
.vscode
|
||||||
target
|
.idea/
|
||||||
src/test
|
*.iml
|
||||||
.settings
|
|
||||||
.commit_message
|
### Other ###
|
||||||
*.bk
|
|
||||||
*.rustfmt
|
# macOS
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
# settings
|
||||||
|
.settings
|
||||||
.tokeirc
|
.tokeirc
|
||||||
|
|
||||||
|
# benchmark
|
||||||
results.csv
|
results.csv
|
||||||
|
|
||||||
node_modules
|
node_modules
|
||||||
*.code-workspace
|
*.code-workspace
|
||||||
|
|
|
@ -8,6 +8,10 @@ use tokei::{Config, LanguageType, Sort};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cli_utils::{crate_version, parse_or_exit, NumberFormatStyle},
|
cli_utils::{crate_version, parse_or_exit, NumberFormatStyle},
|
||||||
|
consts::{
|
||||||
|
BLANKS_COLUMN_WIDTH, CODE_COLUMN_WIDTH, COMMENTS_COLUMN_WIDTH, LANGUAGE_COLUMN_WIDTH,
|
||||||
|
LINES_COLUMN_WIDTH, PATH_COLUMN_WIDTH,
|
||||||
|
},
|
||||||
input::Format,
|
input::Format,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -413,7 +417,7 @@ impl Cli {
|
||||||
}),
|
}),
|
||||||
Some(Streaming::Simple) => Some(|l: LanguageType, e| {
|
Some(Streaming::Simple) => Some(|l: LanguageType, e| {
|
||||||
println!(
|
println!(
|
||||||
"{:>10} {:<80} {:>12} {:>12} {:>12} {:>12}",
|
"{:>LANGUAGE_COLUMN_WIDTH$} {:<PATH_COLUMN_WIDTH$} {:>LINES_COLUMN_WIDTH$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||||
l.name(),
|
l.name(),
|
||||||
e.name.to_string_lossy().to_string(),
|
e.name.to_string_lossy().to_string(),
|
||||||
e.stats.lines(),
|
e.stats.lines(),
|
||||||
|
|
|
@ -13,10 +13,14 @@ use num_format::ToFormattedString;
|
||||||
use crate::input::Format;
|
use crate::input::Format;
|
||||||
use tokei::{find_char_boundary, CodeStats, Language, LanguageType, Report};
|
use tokei::{find_char_boundary, CodeStats, Language, LanguageType, Report};
|
||||||
|
|
||||||
pub const FALLBACK_ROW_LEN: usize = 79;
|
use crate::consts::{
|
||||||
const NO_LANG_HEADER_ROW_LEN: usize = 67;
|
BLANKS_COLUMN_WIDTH, CODE_COLUMN_WIDTH, COMMENTS_COLUMN_WIDTH, FILES_COLUMN_WIDTH,
|
||||||
const NO_LANG_ROW_LEN: usize = 61;
|
LINES_COLUMN_WIDTH,
|
||||||
const NO_LANG_ROW_LEN_NO_SPACES: usize = 54;
|
};
|
||||||
|
|
||||||
|
const NO_LANG_HEADER_ROW_LEN: usize = 69;
|
||||||
|
const NO_LANG_ROW_LEN: usize = 63;
|
||||||
|
const NO_LANG_ROW_LEN_NO_SPACES: usize = 56;
|
||||||
const IDENT_INACCURATE: &str = "(!)";
|
const IDENT_INACCURATE: &str = "(!)";
|
||||||
|
|
||||||
pub fn crate_version() -> String {
|
pub fn crate_version() -> String {
|
||||||
|
@ -151,9 +155,11 @@ impl<W> Printer<W> {
|
||||||
impl<W: Write> Printer<W> {
|
impl<W: Write> Printer<W> {
|
||||||
pub fn print_header(&mut self) -> io::Result<()> {
|
pub fn print_header(&mut self) -> io::Result<()> {
|
||||||
self.print_row()?;
|
self.print_row()?;
|
||||||
|
|
||||||
|
let files_column_width: usize = FILES_COLUMN_WIDTH + 6;
|
||||||
writeln!(
|
writeln!(
|
||||||
self.writer,
|
self.writer,
|
||||||
" {:<6$} {:>12} {:>12} {:>12} {:>12} {:>12}",
|
" {:<6$} {:>files_column_width$} {:>LINES_COLUMN_WIDTH$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||||
"Language".bold().blue(),
|
"Language".bold().blue(),
|
||||||
"Files".bold().blue(),
|
"Files".bold().blue(),
|
||||||
"Lines".bold().blue(),
|
"Lines".bold().blue(),
|
||||||
|
@ -181,7 +187,7 @@ impl<W: Write> Printer<W> {
|
||||||
write!(self.writer, " ")?;
|
write!(self.writer, " ")?;
|
||||||
writeln!(
|
writeln!(
|
||||||
self.writer,
|
self.writer,
|
||||||
"{:>6} {:>12} {:>12} {:>12} {:>12}",
|
"{:>FILES_COLUMN_WIDTH$} {:>LINES_COLUMN_WIDTH$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||||
language
|
language
|
||||||
.reports
|
.reports
|
||||||
.len()
|
.len()
|
||||||
|
@ -201,7 +207,7 @@ impl<W: Write> Printer<W> {
|
||||||
write!(self.writer, " ")?;
|
write!(self.writer, " ")?;
|
||||||
writeln!(
|
writeln!(
|
||||||
self.writer,
|
self.writer,
|
||||||
"{:>6} {:>12} {:>12} {:>12} {:>12}",
|
"{:>FILES_COLUMN_WIDTH$} {:>LINES_COLUMN_WIDTH$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||||
language
|
language
|
||||||
.children
|
.children
|
||||||
.values()
|
.values()
|
||||||
|
@ -282,7 +288,7 @@ impl<W: Write> Printer<W> {
|
||||||
} else {
|
} else {
|
||||||
writeln!(
|
writeln!(
|
||||||
self.writer,
|
self.writer,
|
||||||
" {:>6} {:>12} {:>12} {:>12} {:>12}",
|
" {:>FILES_COLUMN_WIDTH$} {:>LINES_COLUMN_WIDTH$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||||
stats.len().to_formatted_string(&self.number_format),
|
stats.len().to_formatted_string(&self.number_format),
|
||||||
(code + comments + blanks).to_formatted_string(&self.number_format),
|
(code + comments + blanks).to_formatted_string(&self.number_format),
|
||||||
code.to_formatted_string(&self.number_format),
|
code.to_formatted_string(&self.number_format),
|
||||||
|
@ -413,7 +419,7 @@ impl<W: Write> Printer<W> {
|
||||||
|
|
||||||
writeln!(
|
writeln!(
|
||||||
self.writer,
|
self.writer,
|
||||||
" {:>6} {:>12} {:>12} {:>12} {:>12}",
|
" {:>FILES_COLUMN_WIDTH$} {:>LINES_COLUMN_WIDTH$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||||
" ",
|
" ",
|
||||||
stats.lines().to_formatted_string(&self.number_format),
|
stats.lines().to_formatted_string(&self.number_format),
|
||||||
stats.code.to_formatted_string(&self.number_format),
|
stats.code.to_formatted_string(&self.number_format),
|
||||||
|
@ -463,9 +469,10 @@ impl<W: Write> Printer<W> {
|
||||||
max_len: usize,
|
max_len: usize,
|
||||||
report: &Report,
|
report: &Report,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
|
let lines_column_width: usize = FILES_COLUMN_WIDTH + 6;
|
||||||
writeln!(
|
writeln!(
|
||||||
self.writer,
|
self.writer,
|
||||||
" {: <max$} {:>12} {:>12} {:>12} {:>12}",
|
" {: <max$} {:>lines_column_width$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||||
name,
|
name,
|
||||||
report
|
report
|
||||||
.stats
|
.stats
|
||||||
|
|
12
src/consts.rs
Normal file
12
src/consts.rs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
// Set of common pub consts.
|
||||||
|
|
||||||
|
pub const FALLBACK_ROW_LEN: usize = 81;
|
||||||
|
|
||||||
|
// Column widths used for console printing.
|
||||||
|
pub const LANGUAGE_COLUMN_WIDTH: usize = 10;
|
||||||
|
pub const PATH_COLUMN_WIDTH: usize = 80;
|
||||||
|
pub const FILES_COLUMN_WIDTH: usize = 8;
|
||||||
|
pub const LINES_COLUMN_WIDTH: usize = 12;
|
||||||
|
pub const CODE_COLUMN_WIDTH: usize = 12;
|
||||||
|
pub const COMMENTS_COLUMN_WIDTH: usize = 12;
|
||||||
|
pub const BLANKS_COLUMN_WIDTH: usize = 12;
|
|
@ -50,6 +50,7 @@ extern crate serde;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
mod utils;
|
mod utils;
|
||||||
mod config;
|
mod config;
|
||||||
|
mod consts;
|
||||||
mod language;
|
mod language;
|
||||||
mod sort;
|
mod sort;
|
||||||
mod stats;
|
mod stats;
|
||||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -3,6 +3,7 @@ extern crate log;
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
mod cli_utils;
|
mod cli_utils;
|
||||||
|
mod consts;
|
||||||
mod input;
|
mod input;
|
||||||
|
|
||||||
use std::{error::Error, io, process};
|
use std::{error::Error, io, process};
|
||||||
|
@ -11,7 +12,11 @@ use tokei::{Config, Languages, Sort};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::Cli,
|
cli::Cli,
|
||||||
cli_utils::{Printer, FALLBACK_ROW_LEN},
|
cli_utils::Printer,
|
||||||
|
consts::{
|
||||||
|
BLANKS_COLUMN_WIDTH, CODE_COLUMN_WIDTH, COMMENTS_COLUMN_WIDTH, FALLBACK_ROW_LEN,
|
||||||
|
LANGUAGE_COLUMN_WIDTH, LINES_COLUMN_WIDTH, PATH_COLUMN_WIDTH,
|
||||||
|
},
|
||||||
input::add_input,
|
input::add_input,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -56,11 +61,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||||
|
|
||||||
if cli.streaming == Some(crate::cli::Streaming::Simple) {
|
if cli.streaming == Some(crate::cli::Streaming::Simple) {
|
||||||
println!(
|
println!(
|
||||||
"#{:^10} {:^80} {:^12} {:^12} {:^12} {:^12}",
|
"#{:^LANGUAGE_COLUMN_WIDTH$} {:^PATH_COLUMN_WIDTH$} {:^LINES_COLUMN_WIDTH$} {:^CODE_COLUMN_WIDTH$} {:^COMMENTS_COLUMN_WIDTH$} {:^BLANKS_COLUMN_WIDTH$}",
|
||||||
"language", "path", "lines", "code", "comments", "blanks"
|
"language", "path", "lines", "code", "comments", "blanks"
|
||||||
);
|
);
|
||||||
println!(
|
println!(
|
||||||
"{:>10} {:<80} {:>12} {:>12} {:>12} {:>12}",
|
"{:>LANGUAGE_COLUMN_WIDTH$} {:<PATH_COLUMN_WIDTH$} {:>LINES_COLUMN_WIDTH$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||||
(0..10).map(|_| "#").collect::<String>(),
|
(0..10).map(|_| "#").collect::<String>(),
|
||||||
(0..80).map(|_| "#").collect::<String>(),
|
(0..80).map(|_| "#").collect::<String>(),
|
||||||
(0..12).map(|_| "#").collect::<String>(),
|
(0..12).map(|_| "#").collect::<String>(),
|
||||||
|
|
11
src/stats.rs
11
src/stats.rs
|
@ -1,6 +1,8 @@
|
||||||
use std::{collections::BTreeMap, fmt, ops, path::PathBuf};
|
use crate::consts::{
|
||||||
|
BLANKS_COLUMN_WIDTH, CODE_COLUMN_WIDTH, COMMENTS_COLUMN_WIDTH, LINES_COLUMN_WIDTH,
|
||||||
|
};
|
||||||
use crate::LanguageType;
|
use crate::LanguageType;
|
||||||
|
use std::{collections::BTreeMap, fmt, ops, path::PathBuf};
|
||||||
|
|
||||||
/// A struct representing stats about a single blob of code.
|
/// A struct representing stats about a single blob of code.
|
||||||
#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
|
#[derive(Clone, Debug, Default, PartialEq, serde::Deserialize, serde::Serialize)]
|
||||||
|
@ -109,7 +111,7 @@ macro_rules! display_stats {
|
||||||
($f:expr, $this:expr, $name:expr, $max:expr) => {
|
($f:expr, $this:expr, $name:expr, $max:expr) => {
|
||||||
write!(
|
write!(
|
||||||
$f,
|
$f,
|
||||||
" {: <max$} {:>12} {:>12} {:>12} {:>12}",
|
" {: <max$} {:>LINES_COLUMN_WIDTH$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||||
$name,
|
$name,
|
||||||
$this.stats.lines(),
|
$this.stats.lines(),
|
||||||
$this.stats.code,
|
$this.stats.code,
|
||||||
|
@ -125,7 +127,8 @@ impl fmt::Display for Report {
|
||||||
let name = self.name.to_string_lossy();
|
let name = self.name.to_string_lossy();
|
||||||
let name_length = name.len();
|
let name_length = name.len();
|
||||||
|
|
||||||
let max_len = f.width().unwrap_or(25);
|
// Added 2 to max length to cover wider Files column (see https://github.com/XAMPPRocky/tokei/issues/891).
|
||||||
|
let max_len = f.width().unwrap_or(27) + 2;
|
||||||
|
|
||||||
if name_length <= max_len {
|
if name_length <= max_len {
|
||||||
display_stats!(f, self, name, max_len)
|
display_stats!(f, self, name, max_len)
|
||||||
|
|
Loading…
Reference in a new issue