Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vnotepad
Exa
提交
5611a576
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,发现更多精彩内容 >>
提交
5611a576
编写于
2月 01, 2015
作者:
B
Ben S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Recurse into directories
上级
3242cb21
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
41 addition
and
34 deletion
+41
-34
src/dir.rs
src/dir.rs
+3
-3
src/main.rs
src/main.rs
+31
-24
src/options.rs
src/options.rs
+1
-1
src/output.rs
src/output.rs
+6
-6
未找到文件。
src/dir.rs
浏览文件 @
5611a576
...
...
@@ -21,11 +21,11 @@ impl Dir {
/// Create a new Dir object filled with all the files in the directory
/// pointed to by the given path. Fails if the directory can't be read, or
/// isn't actually a directory.
pub
fn
readdir
(
path
:
Path
)
->
IoResult
<
Dir
>
{
fs
::
readdir
(
&
path
)
.map
(|
paths
|
Dir
{
pub
fn
readdir
(
path
:
&
Path
)
->
IoResult
<
Dir
>
{
fs
::
readdir
(
path
)
.map
(|
paths
|
Dir
{
contents
:
paths
,
path
:
path
.clone
(),
git
:
Git
::
scan
(
&
path
)
.ok
(),
git
:
Git
::
scan
(
path
)
.ok
(),
})
}
...
...
src/main.rs
浏览文件 @
5611a576
...
...
@@ -25,37 +25,24 @@ pub mod output;
pub
mod
term
;
fn
exa
(
options
:
&
Options
)
{
let
mut
dirs
:
Vec
<
String
>
=
vec!
[];
let
mut
dirs
:
Vec
<
Path
>
=
vec!
[];
let
mut
files
:
Vec
<
File
>
=
vec!
[];
// It's only worth printing out directory names if the user supplied
// more than one of them.
let
mut
count
=
0
;
let
mut
stack
=
options
.path_strs
.clone
();
// Separate the user-supplied paths into directories and files.
// Files are shown first, and then each directory is expanded
// and listed second.
loop
{
let
file
=
match
stack
.pop
()
{
None
=>
break
,
Some
(
f
)
=>
f
,
};
let
path
=
Path
::
new
(
file
.clone
());
for
file
in
options
.path_strs
.iter
()
{
let
path
=
Path
::
new
(
file
);
match
fs
::
stat
(
&
path
)
{
Ok
(
stat
)
=>
{
if
stat
.kind
==
FileType
::
Directory
{
match
options
.dir_action
{
DirAction
::
AsFile
=>
files
.push
(
File
::
with_stat
(
stat
,
&
path
,
None
)),
DirAction
::
List
=>
dirs
.push
(
file
.clone
()),
DirAction
::
Recurse
=>
{
/* todo */
},
}
if
stat
.kind
==
FileType
::
Directory
&&
options
.dir_action
!=
DirAction
::
AsFile
{
dirs
.push
(
path
);
}
else
{
// May as well reuse the stat result from earlier
// instead of just using File::from_path().
files
.push
(
File
::
with_stat
(
stat
,
&
path
,
None
));
}
}
...
...
@@ -68,10 +55,19 @@ fn exa(options: &Options) {
let
mut
first
=
files
.is_empty
();
if
!
files
.is_empty
()
{
options
.view
(
None
,
files
);
options
.view
(
None
,
&
files
[]
);
}
for
dir_name
in
dirs
.iter
()
{
// Directories are put on a stack rather than just being iterated through,
// as the vector can change as more directories are added.
loop
{
let
dir_path
=
match
dirs
.pop
()
{
None
=>
break
,
Some
(
f
)
=>
f
,
};
// Put a gap between directories, or between the list of files and the
// first directory.
if
first
{
first
=
false
;
}
...
...
@@ -79,19 +75,30 @@ fn exa(options: &Options) {
print!
(
"
\n
"
);
}
match
Dir
::
readdir
(
Path
::
new
(
dir_name
.clone
())
)
{
match
Dir
::
readdir
(
&
dir_path
)
{
Ok
(
ref
dir
)
=>
{
let
unsorted_files
=
dir
.files
();
let
files
:
Vec
<
File
>
=
options
.transform_files
(
unsorted_files
);
// When recursing, add any directories to the dirs stack
// backwards: the *last* element of the stack is used each
// time, so by inserting them backwards, they get displayed in
// the correct sort order.
if
options
.dir_action
==
DirAction
::
Recurse
{
for
dir
in
files
.iter
()
.filter
(|
f
|
f
.stat.kind
==
FileType
::
Directory
)
.rev
()
{
dirs
.push
(
dir
.path
.clone
());
}
}
if
count
>
1
{
println!
(
"{}:"
,
dir_
name
);
println!
(
"{}:"
,
dir_
path
.display
()
);
}
count
+=
1
;
options
.view
(
Some
(
dir
),
files
);
options
.view
(
Some
(
dir
),
&
files
[]
);
}
Err
(
e
)
=>
{
println!
(
"{}: {}"
,
dir_
name
,
e
);
println!
(
"{}: {}"
,
dir_
path
.display
()
,
e
);
return
;
}
};
...
...
src/options.rs
浏览文件 @
5611a576
...
...
@@ -74,7 +74,7 @@ impl Options {
}
/// Display the files using this Option's View.
pub
fn
view
(
&
self
,
dir
:
Option
<&
Dir
>
,
files
:
Vec
<
File
>
)
{
pub
fn
view
(
&
self
,
dir
:
Option
<&
Dir
>
,
files
:
&
[
File
]
)
{
self
.view
.view
(
dir
,
files
)
}
...
...
src/output.rs
浏览文件 @
5611a576
...
...
@@ -18,7 +18,7 @@ pub enum View {
}
impl
View
{
pub
fn
view
(
&
self
,
dir
:
Option
<&
Dir
>
,
files
:
Vec
<
File
>
)
{
pub
fn
view
(
&
self
,
dir
:
Option
<&
Dir
>
,
files
:
&
[
File
]
)
{
match
*
self
{
View
::
Grid
(
across
,
width
)
=>
grid_view
(
across
,
width
,
files
),
View
::
Details
(
ref
cols
,
header
)
=>
details_view
(
&*
cols
.for_dir
(
dir
),
files
,
header
),
...
...
@@ -28,13 +28,13 @@ impl View {
}
/// The lines view literally just displays each file, line-by-line.
fn
lines_view
(
files
:
Vec
<
File
>
)
{
fn
lines_view
(
files
:
&
[
File
]
)
{
for
file
in
files
.iter
()
{
println!
(
"{}"
,
file
.file_name_view
()
.text
);
}
}
fn
fit_into_grid
(
across
:
bool
,
console_width
:
usize
,
files
:
&
Vec
<
File
>
)
->
Option
<
(
usize
,
Vec
<
usize
>
)
>
{
fn
fit_into_grid
(
across
:
bool
,
console_width
:
usize
,
files
:
&
[
File
]
)
->
Option
<
(
usize
,
Vec
<
usize
>
)
>
{
// TODO: this function could almost certainly be optimised...
// surely not *all* of the numbers of lines are worth searching through!
...
...
@@ -86,8 +86,8 @@ fn fit_into_grid(across: bool, console_width: usize, files: &Vec<File>) -> Optio
return
None
;
}
fn
grid_view
(
across
:
bool
,
console_width
:
usize
,
files
:
Vec
<
File
>
)
{
if
let
Some
((
num_lines
,
widths
))
=
fit_into_grid
(
across
,
console_width
,
&
files
)
{
fn
grid_view
(
across
:
bool
,
console_width
:
usize
,
files
:
&
[
File
]
)
{
if
let
Some
((
num_lines
,
widths
))
=
fit_into_grid
(
across
,
console_width
,
files
)
{
for
y
in
range
(
0
,
num_lines
)
{
for
x
in
range
(
0
,
widths
.len
())
{
let
num
=
if
across
{
...
...
@@ -122,7 +122,7 @@ fn grid_view(across: bool, console_width: usize, files: Vec<File>) {
}
}
fn
details_view
(
columns
:
&
[
Column
],
files
:
Vec
<
File
>
,
header
:
bool
)
{
fn
details_view
(
columns
:
&
[
Column
],
files
:
&
[
File
]
,
header
:
bool
)
{
// The output gets formatted into columns, which looks nicer. To
// do this, we have to write the results into a table, instead of
// displaying each file immediately, then calculating the maximum
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录