Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vnotepad
Exa
提交
cb6dd57c
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,发现更多精彩内容 >>
提交
cb6dd57c
编写于
5月 25, 2014
作者:
B
Ben S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move getopts code into options module
上级
ff0bef66
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
33 deletion
+40
-33
exa.rs
exa.rs
+19
-33
options.rs
options.rs
+21
-0
未找到文件。
exa.rs
浏览文件 @
cb6dd57c
...
@@ -2,13 +2,12 @@
...
@@ -2,13 +2,12 @@
extern
crate
regex
;
extern
crate
regex
;
#[phase(syntax)]
extern
crate
regex_macros
;
#[phase(syntax)]
extern
crate
regex_macros
;
extern
crate
getopts
;
use
std
::
os
;
use
std
::
os
;
use
std
::
io
::
fs
;
use
std
::
io
::
fs
;
use
file
::
File
;
use
file
::
File
;
use
column
::
defaultColumns
;
use
column
::
defaultColumns
;
use
options
::
{
Options
,
SortField
,
Name
}
;
use
options
::
Options
;
pub
mod
colours
;
pub
mod
colours
;
pub
mod
column
;
pub
mod
column
;
...
@@ -18,40 +17,28 @@ pub mod unix;
...
@@ -18,40 +17,28 @@ pub mod unix;
pub
mod
options
;
pub
mod
options
;
fn
main
()
{
fn
main
()
{
let
args
:
Vec
<
StrBuf
>
=
os
::
args
()
.iter
()
let
args
=
os
::
args
()
.iter
()
.map
(|
x
|
x
.to_strbuf
())
.map
(|
x
|
x
.to_strbuf
())
.collect
();
.collect
();
let
opts
=
~
[
match
Options
::
getopts
(
args
)
{
getopts
::
optflag
(
"a"
,
"all"
,
"show dot-files"
),
Err
(
err
)
=>
println!
(
"Invalid options:
\n
{}"
,
err
.to_err_msg
()),
getopts
::
optflag
(
"r"
,
"reverse"
,
"reverse order of files"
),
Ok
(
opts
)
=>
{
getopts
::
optopt
(
"s"
,
"sort"
,
"field to sort by"
,
"WORD"
),
let
strs
=
if
opts
.dirs
.is_empty
()
{
];
vec!
(
"./"
.to_strbuf
())
}
let
matches
=
match
getopts
::
getopts
(
args
.tail
(),
opts
)
{
else
{
Ok
(
m
)
=>
m
,
opts
.dirs
.clone
()
Err
(
f
)
=>
fail
!
(
"Invalid options
\n
{}"
,
f
.to_err_msg
()),
};
};
for
dir
in
strs
.move_iter
()
{
let
opts
=
Options
{
exa
(
&
opts
,
Path
::
new
(
dir
))
showInvisibles
:
matches
.opt_present
(
"all"
),
}
reverse
:
matches
.opt_present
(
"reverse"
),
}
sortField
:
matches
.opt_str
(
"sort"
)
.map
(|
word
|
SortField
::
from_word
(
word
))
.unwrap_or
(
Name
),
};
let
strs
=
if
matches
.free
.is_empty
()
{
vec!
(
"./"
.to_strbuf
())
}
else
{
matches
.free
.clone
()
};
};
for
dir
in
strs
.move_iter
()
{
list
(
opts
,
Path
::
new
(
dir
))
}
}
}
fn
list
(
options
:
Options
,
path
:
Path
)
{
fn
exa
(
options
:
&
Options
,
path
:
Path
)
{
let
paths
=
match
fs
::
readdir
(
&
path
)
{
let
paths
=
match
fs
::
readdir
(
&
path
)
{
Ok
(
paths
)
=>
paths
,
Ok
(
paths
)
=>
paths
,
Err
(
e
)
=>
fail
!
(
"readdir: {}"
,
e
),
Err
(
e
)
=>
fail
!
(
"readdir: {}"
,
e
),
...
@@ -64,7 +51,6 @@ fn list(options: Options, path: Path) {
...
@@ -64,7 +51,6 @@ fn list(options: Options, path: Path) {
}
}
let
columns
=
defaultColumns
();
let
columns
=
defaultColumns
();
let
num_columns
=
columns
.len
();
let
table
:
Vec
<
Vec
<
StrBuf
>>
=
files
.iter
()
let
table
:
Vec
<
Vec
<
StrBuf
>>
=
files
.iter
()
.filter
(|
&
f
|
options
.show
(
f
))
.filter
(|
&
f
|
options
.show
(
f
))
...
@@ -75,7 +61,7 @@ fn list(options: Options, path: Path) {
...
@@ -75,7 +61,7 @@ fn list(options: Options, path: Path) {
.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
();
.collect
();
let
maxes
:
Vec
<
uint
>
=
range
(
0
,
num_columns
)
let
maxes
:
Vec
<
uint
>
=
range
(
0
,
columns
.len
()
)
.map
(|
n
|
lengths
.iter
()
.map
(|
row
|
*
row
.get
(
n
))
.max
()
.unwrap
())
.map
(|
n
|
lengths
.iter
()
.map
(|
row
|
*
row
.get
(
n
))
.max
()
.unwrap
())
.collect
();
.collect
();
...
...
options.rs
浏览文件 @
cb6dd57c
extern
crate
getopts
;
use
file
::
File
;
use
file
::
File
;
use
std
::
cmp
::
lexical_ordering
;
use
std
::
cmp
::
lexical_ordering
;
...
@@ -9,6 +11,7 @@ pub struct Options {
...
@@ -9,6 +11,7 @@ pub struct Options {
pub
showInvisibles
:
bool
,
pub
showInvisibles
:
bool
,
pub
sortField
:
SortField
,
pub
sortField
:
SortField
,
pub
reverse
:
bool
,
pub
reverse
:
bool
,
pub
dirs
:
Vec
<
StrBuf
>
,
}
}
impl
SortField
{
impl
SortField
{
...
@@ -35,6 +38,24 @@ impl SortField {
...
@@ -35,6 +38,24 @@ impl SortField {
}
}
impl
Options
{
impl
Options
{
pub
fn
getopts
(
args
:
Vec
<
StrBuf
>
)
->
Result
<
Options
,
getopts
::
Fail_
>
{
let
opts
=
~
[
getopts
::
optflag
(
"a"
,
"all"
,
"show dot-files"
),
getopts
::
optflag
(
"r"
,
"reverse"
,
"reverse order of files"
),
getopts
::
optopt
(
"s"
,
"sort"
,
"field to sort by"
,
"WORD"
),
];
match
getopts
::
getopts
(
args
.tail
(),
opts
)
{
Err
(
f
)
=>
Err
(
f
),
Ok
(
matches
)
=>
Ok
(
Options
{
showInvisibles
:
matches
.opt_present
(
"all"
),
reverse
:
matches
.opt_present
(
"reverse"
),
sortField
:
matches
.opt_str
(
"sort"
)
.map
(|
word
|
SortField
::
from_word
(
word
))
.unwrap_or
(
Name
),
dirs
:
matches
.free
,
})
}
}
pub
fn
sort
(
&
self
,
files
:
&
mut
Vec
<
File
>
)
{
pub
fn
sort
(
&
self
,
files
:
&
mut
Vec
<
File
>
)
{
self
.sortField
.sort
(
files
);
self
.sortField
.sort
(
files
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录