Parcourir la source

Use unicode_width crate

Ben S il y a 10 ans
Parent
commit
d7d11f77f3
5 fichiers modifiés avec 15 ajouts et 6 suppressions
  1. 1 0
      Cargo.lock
  2. 2 1
      Cargo.toml
  3. 5 2
      src/column.rs
  4. 4 2
      src/file.rs
  5. 3 1
      src/main.rs

+ 1 - 0
Cargo.lock

@@ -12,6 +12,7 @@ dependencies = [
  "num_cpus 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "num_cpus 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "number_prefix 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "number_prefix 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "pad 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
  "pad 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
+ "unicode-width 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "users 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "users 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 ]
 
 

+ 2 - 1
Cargo.toml

@@ -8,6 +8,7 @@ name = "exa"
 
 
 [dependencies]
 [dependencies]
 ansi_term = "0.5.0"
 ansi_term = "0.5.0"
+bitflags = "0.1"
 datetime = "0.1.3"
 datetime = "0.1.3"
 getopts = "0.2.1"
 getopts = "0.2.1"
 locale = "0.1.2"
 locale = "0.1.2"
@@ -15,8 +16,8 @@ natord = "1.0.7"
 num_cpus = "*"
 num_cpus = "*"
 number_prefix = "0.2.3"
 number_prefix = "0.2.3"
 pad = "0.1.1"
 pad = "0.1.1"
+unicode-width = "*"
 users = "0.3.1"
 users = "0.3.1"
-bitflags = "0.1"
 
 
 [features]
 [features]
 default = [ "git" ]
 default = [ "git" ]

+ 5 - 2
src/column.rs

@@ -1,8 +1,11 @@
 use std::iter::repeat;
 use std::iter::repeat;
 
 
+use options::{SizeFormat, TimeType};
+
 use ansi_term::Style;
 use ansi_term::Style;
+use unicode_width::UnicodeWidthStr;
+
 
 
-use options::{SizeFormat, TimeType};
 
 
 #[derive(PartialEq, Debug, Copy, Clone)]
 #[derive(PartialEq, Debug, Copy, Clone)]
 pub enum Column {
 pub enum Column {
@@ -86,7 +89,7 @@ impl Cell {
     pub fn paint(style: Style, string: &str) -> Cell {
     pub fn paint(style: Style, string: &str) -> Cell {
         Cell {
         Cell {
             text: style.paint(string).to_string(),
             text: style.paint(string).to_string(),
-            length: string.width(false),
+            length: UnicodeWidthStr::width(string),
         }
         }
     }
     }
 }
 }

+ 4 - 2
src/file.rs

@@ -18,7 +18,8 @@ use ansi_term::Colour::{Red, Green, Yellow, Blue, Purple, Cyan, Fixed};
 use users::Users;
 use users::Users;
 
 
 use locale;
 use locale;
-use output::details::UserLocale;
+
+use unicode_width::UnicodeWidthStr;
 
 
 use number_prefix::{binary_prefix, decimal_prefix, Prefixed, Standalone, PrefixNames};
 use number_prefix::{binary_prefix, decimal_prefix, Prefixed, Standalone, PrefixNames};
 
 
@@ -30,6 +31,7 @@ use column::Column::*;
 use dir::Dir;
 use dir::Dir;
 use filetype::HasType;
 use filetype::HasType;
 use options::{SizeFormat, TimeType};
 use options::{SizeFormat, TimeType};
+use output::details::UserLocale;
 use feature::Attribute;
 use feature::Attribute;
 
 
 /// This grey value is directly in between white and black, so it's guaranteed
 /// This grey value is directly in between white and black, so it's guaranteed
@@ -216,7 +218,7 @@ impl<'a> File<'a> {
     /// characters are 1 columns wide, but in some contexts, certain
     /// characters are 1 columns wide, but in some contexts, certain
     /// characters are actually 2 columns wide.
     /// characters are actually 2 columns wide.
     pub fn file_name_width(&self) -> usize {
     pub fn file_name_width(&self) -> usize {
-        self.name.width(false)
+        UnicodeWidthStr::width(&self.name[..])
     }
     }
 
 
     /// Assuming the current file is a symlink, follows the link and
     /// Assuming the current file is a symlink, follows the link and

+ 3 - 1
src/main.rs

@@ -1,4 +1,4 @@
-#![feature(convert, core, exit_status, fs_ext, fs_time, io, libc, os, scoped, std_misc, unicode)]
+#![feature(collections, convert, core, exit_status, fs_ext, fs_time, io, libc, os, scoped, std_misc)]
 #![allow(deprecated)]
 #![allow(deprecated)]
 
 
 // Other platforms than macos don't need std_misc but you can't
 // Other platforms than macos don't need std_misc but you can't
@@ -14,6 +14,8 @@ extern crate num_cpus;
 extern crate number_prefix;
 extern crate number_prefix;
 extern crate pad;
 extern crate pad;
 extern crate users;
 extern crate users;
+extern crate unicode_width;
+
 
 
 #[cfg(feature="git")]
 #[cfg(feature="git")]
 extern crate git2;
 extern crate git2;