mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-12 07:26:31 +00:00
Use string width, rather than length, to calculate column size
This commit is contained in:
parent
4cbc1f063a
commit
b1560edb85
14
src/exa.rs
14
src/exa.rs
@ -3,6 +3,10 @@ extern crate regex;
|
|||||||
#[phase(plugin)] extern crate regex_macros;
|
#[phase(plugin)] extern crate regex_macros;
|
||||||
extern crate ansi_term;
|
extern crate ansi_term;
|
||||||
|
|
||||||
|
extern crate unicode;
|
||||||
|
use std::char::UnicodeChar;
|
||||||
|
use std::iter::AdditiveIterator;
|
||||||
|
|
||||||
use std::os;
|
use std::os;
|
||||||
|
|
||||||
use file::File;
|
use file::File;
|
||||||
@ -62,11 +66,19 @@ fn exa(opts: &Options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn width(string: &str) -> uint {
|
||||||
|
string.as_slice().chars()
|
||||||
|
.map(|c| c.width(true))
|
||||||
|
.filter(|o| o.is_some())
|
||||||
|
.map(|o| o.unwrap())
|
||||||
|
.sum()
|
||||||
|
}
|
||||||
|
|
||||||
fn grid_view(options: &Options, across: bool, dir: Dir) {
|
fn grid_view(options: &Options, across: bool, dir: Dir) {
|
||||||
let unsorted_files = dir.files();
|
let unsorted_files = dir.files();
|
||||||
let files: Vec<&File> = options.transform_files(&unsorted_files);
|
let files: Vec<&File> = options.transform_files(&unsorted_files);
|
||||||
|
|
||||||
let max_column_length = files.iter().map(|f| f.name.len()).max().unwrap();
|
let max_column_length = files.iter().map(|f| width(f.name.as_slice())).max().unwrap();
|
||||||
let console_width = 80;
|
let console_width = 80;
|
||||||
let num_columns = (console_width + 1) / (max_column_length + 1);
|
let num_columns = (console_width + 1) / (max_column_length + 1);
|
||||||
let count = files.len();
|
let count = files.len();
|
||||||
|
Loading…
Reference in New Issue
Block a user