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
|
||||
target
|
||||
src/test
|
||||
.settings
|
||||
.commit_message
|
||||
*.bk
|
||||
*.rustfmt
|
||||
.idea/
|
||||
*.iml
|
||||
|
||||
### Other ###
|
||||
|
||||
# macOS
|
||||
.DS_Store
|
||||
|
||||
# settings
|
||||
.settings
|
||||
.tokeirc
|
||||
|
||||
# benchmark
|
||||
results.csv
|
||||
|
||||
node_modules
|
||||
*.code-workspace
|
||||
|
|
|
@ -8,6 +8,10 @@ use tokei::{Config, LanguageType, Sort};
|
|||
|
||||
use crate::{
|
||||
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,
|
||||
};
|
||||
|
||||
|
@ -413,7 +417,7 @@ impl Cli {
|
|||
}),
|
||||
Some(Streaming::Simple) => Some(|l: LanguageType, e| {
|
||||
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(),
|
||||
e.name.to_string_lossy().to_string(),
|
||||
e.stats.lines(),
|
||||
|
|
|
@ -13,10 +13,14 @@ use num_format::ToFormattedString;
|
|||
use crate::input::Format;
|
||||
use tokei::{find_char_boundary, CodeStats, Language, LanguageType, Report};
|
||||
|
||||
pub const FALLBACK_ROW_LEN: usize = 79;
|
||||
const NO_LANG_HEADER_ROW_LEN: usize = 67;
|
||||
const NO_LANG_ROW_LEN: usize = 61;
|
||||
const NO_LANG_ROW_LEN_NO_SPACES: usize = 54;
|
||||
use crate::consts::{
|
||||
BLANKS_COLUMN_WIDTH, CODE_COLUMN_WIDTH, COMMENTS_COLUMN_WIDTH, FILES_COLUMN_WIDTH,
|
||||
LINES_COLUMN_WIDTH,
|
||||
};
|
||||
|
||||
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 = "(!)";
|
||||
|
||||
pub fn crate_version() -> String {
|
||||
|
@ -151,9 +155,11 @@ impl<W> Printer<W> {
|
|||
impl<W: Write> Printer<W> {
|
||||
pub fn print_header(&mut self) -> io::Result<()> {
|
||||
self.print_row()?;
|
||||
|
||||
let files_column_width: usize = FILES_COLUMN_WIDTH + 6;
|
||||
writeln!(
|
||||
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(),
|
||||
"Files".bold().blue(),
|
||||
"Lines".bold().blue(),
|
||||
|
@ -181,7 +187,7 @@ impl<W: Write> Printer<W> {
|
|||
write!(self.writer, " ")?;
|
||||
writeln!(
|
||||
self.writer,
|
||||
"{:>6} {:>12} {:>12} {:>12} {:>12}",
|
||||
"{:>FILES_COLUMN_WIDTH$} {:>LINES_COLUMN_WIDTH$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||
language
|
||||
.reports
|
||||
.len()
|
||||
|
@ -201,7 +207,7 @@ impl<W: Write> Printer<W> {
|
|||
write!(self.writer, " ")?;
|
||||
writeln!(
|
||||
self.writer,
|
||||
"{:>6} {:>12} {:>12} {:>12} {:>12}",
|
||||
"{:>FILES_COLUMN_WIDTH$} {:>LINES_COLUMN_WIDTH$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||
language
|
||||
.children
|
||||
.values()
|
||||
|
@ -282,7 +288,7 @@ impl<W: Write> Printer<W> {
|
|||
} else {
|
||||
writeln!(
|
||||
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),
|
||||
(code + comments + blanks).to_formatted_string(&self.number_format),
|
||||
code.to_formatted_string(&self.number_format),
|
||||
|
@ -413,7 +419,7 @@ impl<W: Write> Printer<W> {
|
|||
|
||||
writeln!(
|
||||
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.code.to_formatted_string(&self.number_format),
|
||||
|
@ -463,9 +469,10 @@ impl<W: Write> Printer<W> {
|
|||
max_len: usize,
|
||||
report: &Report,
|
||||
) -> io::Result<()> {
|
||||
let lines_column_width: usize = FILES_COLUMN_WIDTH + 6;
|
||||
writeln!(
|
||||
self.writer,
|
||||
" {: <max$} {:>12} {:>12} {:>12} {:>12}",
|
||||
" {: <max$} {:>lines_column_width$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||
name,
|
||||
report
|
||||
.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]
|
||||
mod utils;
|
||||
mod config;
|
||||
mod consts;
|
||||
mod language;
|
||||
mod sort;
|
||||
mod stats;
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -3,6 +3,7 @@ extern crate log;
|
|||
|
||||
mod cli;
|
||||
mod cli_utils;
|
||||
mod consts;
|
||||
mod input;
|
||||
|
||||
use std::{error::Error, io, process};
|
||||
|
@ -11,7 +12,11 @@ use tokei::{Config, Languages, Sort};
|
|||
|
||||
use crate::{
|
||||
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,
|
||||
};
|
||||
|
||||
|
@ -56,11 +61,11 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||
|
||||
if cli.streaming == Some(crate::cli::Streaming::Simple) {
|
||||
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"
|
||||
);
|
||||
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..80).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 std::{collections::BTreeMap, fmt, ops, path::PathBuf};
|
||||
|
||||
/// A struct representing stats about a single blob of code.
|
||||
#[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) => {
|
||||
write!(
|
||||
$f,
|
||||
" {: <max$} {:>12} {:>12} {:>12} {:>12}",
|
||||
" {: <max$} {:>LINES_COLUMN_WIDTH$} {:>CODE_COLUMN_WIDTH$} {:>COMMENTS_COLUMN_WIDTH$} {:>BLANKS_COLUMN_WIDTH$}",
|
||||
$name,
|
||||
$this.stats.lines(),
|
||||
$this.stats.code,
|
||||
|
@ -125,7 +127,8 @@ impl fmt::Display for Report {
|
|||
let name = self.name.to_string_lossy();
|
||||
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 {
|
||||
display_stats!(f, self, name, max_len)
|
||||
|
|
Loading…
Reference in a new issue