Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vnotepad
Exa
提交
1dbe20c8
E
Exa
项目概览
vnotepad
/
Exa
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
Exa
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1dbe20c8
编写于
5月 26, 2014
作者:
B
Ben S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move sorting and reversing into options object
上级
05b2d541
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
48 addition
and
38 deletion
+48
-38
exa.rs
exa.rs
+2
-7
file.rs
file.rs
+25
-14
options.rs
options.rs
+21
-17
未找到文件。
exa.rs
浏览文件 @
1dbe20c8
...
...
@@ -43,12 +43,7 @@ fn exa(options: &Options, path: Path) {
Err
(
e
)
=>
fail
!
(
"readdir: {}"
,
e
),
};
let
mut
files
=
paths
.iter
()
.map
(|
path
|
File
::
from_path
(
path
))
.collect
();
options
.sort
(
&
mut
files
);
if
options
.reverse
{
files
.reverse
();
}
let
files
:
Vec
<
File
>
=
options
.transform_files
(
paths
.iter
()
.map
(|
path
|
File
::
from_path
(
path
))
.collect
());
let
columns
=
options
.columns
();
let
table
:
Vec
<
Vec
<
String
>>
=
files
.iter
()
...
...
@@ -57,7 +52,7 @@ fn exa(options: &Options, path: Path) {
.collect
();
let
lengths
:
Vec
<
Vec
<
uint
>>
=
table
.iter
()
.map
(|
row
|
row
.iter
()
.map
(|
col
|
colours
::
strip_formatting
(
col
)
.len
()
)
.collect
())
.map
(|
row
|
row
.iter
()
.map
(|
col
|
colours
::
strip_formatting
(
col
)
.len
())
.collect
())
.collect
();
let
maxes
:
Vec
<
uint
>
=
range
(
0
,
columns
.len
())
...
...
file.rs
浏览文件 @
1dbe20c8
...
...
@@ -120,23 +120,34 @@ impl<'a> File<'a> {
let
bits
=
self
.stat.perm
;
return
format!
(
"{}{}{}{}{}{}{}{}{}{}"
,
self
.type_char
(),
bit
(
bits
,
io
::
UserRead
,
"r"
,
Yellow
.bold
()),
bit
(
bits
,
io
::
UserWrite
,
"w"
,
Red
.bold
()),
bit
(
bits
,
io
::
UserExecute
,
"x"
,
Green
.bold
()
.underline
()),
bit
(
bits
,
io
::
GroupRead
,
"r"
,
Yellow
.normal
()),
bit
(
bits
,
io
::
GroupWrite
,
"w"
,
Red
.normal
()),
bit
(
bits
,
io
::
GroupExecute
,
"x"
,
Green
.normal
()),
bit
(
bits
,
io
::
OtherRead
,
"r"
,
Yellow
.normal
()),
bit
(
bits
,
io
::
OtherWrite
,
"w"
,
Red
.normal
()),
bit
(
bits
,
io
::
OtherExecute
,
"x"
,
Green
.normal
()),
File
::
bit
(
bits
,
io
::
UserRead
,
"r"
,
Yellow
.bold
()),
File
::
bit
(
bits
,
io
::
UserWrite
,
"w"
,
Red
.bold
()),
File
::
bit
(
bits
,
io
::
UserExecute
,
"x"
,
Green
.bold
()
.underline
()),
File
::
bit
(
bits
,
io
::
GroupRead
,
"r"
,
Yellow
.normal
()),
File
::
bit
(
bits
,
io
::
GroupWrite
,
"w"
,
Red
.normal
()),
File
::
bit
(
bits
,
io
::
GroupExecute
,
"x"
,
Green
.normal
()),
File
::
bit
(
bits
,
io
::
OtherRead
,
"r"
,
Yellow
.normal
()),
File
::
bit
(
bits
,
io
::
OtherWrite
,
"w"
,
Red
.normal
()),
File
::
bit
(
bits
,
io
::
OtherExecute
,
"x"
,
Green
.normal
()),
);
}
fn
bit
(
bits
:
io
::
FilePermission
,
bit
:
io
::
FilePermission
,
other
:
&
'static
str
,
style
:
Style
)
->
String
{
if
bits
.contains
(
bit
)
{
style
.paint
(
other
.as_slice
())
}
else
{
Black
.bold
()
.paint
(
"-"
.as_slice
())
}
}
}
fn
bit
(
bits
:
io
::
FilePermission
,
bit
:
io
::
FilePermission
,
other
:
&
'static
str
,
style
:
Style
)
->
String
{
if
bits
.contains
(
bit
)
{
style
.paint
(
other
.as_slice
())
}
else
{
Black
.bold
()
.paint
(
"-"
.as_slice
())
impl
<
'a
>
Clone
for
File
<
'a
>
{
fn
clone
(
&
self
)
->
File
<
'a
>
{
return
File
{
path
:
self
.path
,
stat
:
self
.stat
,
name
:
self
.name
.clone
(),
ext
:
self
.ext
.clone
(),
};
}
}
options.rs
浏览文件 @
1dbe20c8
...
...
@@ -16,7 +16,7 @@ pub struct Options {
}
impl
SortField
{
pub
fn
from_word
(
word
:
String
)
->
SortField
{
fn
from_word
(
word
:
String
)
->
SortField
{
match
word
.as_slice
()
{
"name"
=>
Name
,
"size"
=>
Size
,
...
...
@@ -24,18 +24,6 @@ impl SortField {
_
=>
fail
!
(
"Invalid sorting order"
),
}
}
fn
sort
(
&
self
,
files
:
&
mut
Vec
<
File
>
)
{
match
*
self
{
Name
=>
files
.sort_by
(|
a
,
b
|
a
.name
.cmp
(
&
b
.name
)),
Size
=>
files
.sort_by
(|
a
,
b
|
a
.stat.size
.cmp
(
&
b
.stat.size
)),
Extension
=>
files
.sort_by
(|
a
,
b
|
{
let
exts
=
a
.ext
.cmp
(
&
b
.ext
);
let
names
=
a
.name
.cmp
(
&
b
.name
);
lexical_ordering
(
exts
,
names
)
}),
}
}
}
impl
Options
{
...
...
@@ -57,10 +45,6 @@ impl Options {
}
}
pub
fn
sort
(
&
self
,
files
:
&
mut
Vec
<
File
>
)
{
self
.sortField
.sort
(
files
);
}
pub
fn
show
(
&
self
,
f
:
&
File
)
->
bool
{
if
self
.showInvisibles
{
true
...
...
@@ -69,6 +53,26 @@ impl Options {
}
}
pub
fn
transform_files
<
'a
>
(
&
self
,
unordered_files
:
Vec
<
File
<
'a
>>
)
->
Vec
<
File
<
'a
>>
{
let
mut
files
=
unordered_files
.clone
();
match
self
.sortField
{
Name
=>
files
.sort_by
(|
a
,
b
|
a
.name
.cmp
(
&
b
.name
)),
Size
=>
files
.sort_by
(|
a
,
b
|
a
.stat.size
.cmp
(
&
b
.stat.size
)),
Extension
=>
files
.sort_by
(|
a
,
b
|
{
let
exts
=
a
.ext
.cmp
(
&
b
.ext
);
let
names
=
a
.name
.cmp
(
&
b
.name
);
lexical_ordering
(
exts
,
names
)
}),
}
if
self
.reverse
{
files
.reverse
();
}
return
files
;
}
pub
fn
columns
(
&
self
)
->
~
[
Column
]
{
return
~
[
Permissions
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录