Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vnotepad
Exa
提交
c205c359
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,发现更多精彩内容 >>
提交
c205c359
编写于
4月 28, 2017
作者:
B
Benjamin Sago
提交者:
GitHub
4月 28, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #159 from MakeNowJust/feature/classify
Implement -F/--classify option
上级
eacbf555
e81b83b4
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
51 addition
and
9 deletion
+51
-9
src/options/help.rs
src/options/help.rs
+1
-0
src/options/mod.rs
src/options/mod.rs
+1
-0
src/options/view.rs
src/options/view.rs
+8
-0
src/output/cell.rs
src/output/cell.rs
+15
-0
src/output/details.rs
src/output/details.rs
+7
-4
src/output/grid.rs
src/output/grid.rs
+4
-3
src/output/lines.rs
src/output/lines.rs
+2
-1
src/output/mod.rs
src/output/mod.rs
+13
-1
未找到文件。
src/options/help.rs
浏览文件 @
c205c359
...
...
@@ -7,6 +7,7 @@ DISPLAY OPTIONS
-R, --recurse recurse into directories
-T, --tree recurse into subdirectories in a tree view
-x, --across sort multi-column view entries across
-F, --classify show file type indicator (one of */=@|)
--color=WHEN, --colour=WHEN when to colourise the output (always, auto, never)
--color-scale, --colour-scale colour file sizes according to their magnitude
...
...
src/options/mod.rs
浏览文件 @
c205c359
...
...
@@ -55,6 +55,7 @@ impl Options {
opts
.optflag
(
"R"
,
"recurse"
,
"recurse into directories"
);
opts
.optflag
(
"T"
,
"tree"
,
"recurse into subdirectories in a tree view"
);
opts
.optflag
(
"x"
,
"across"
,
"sort multi-column view entries across"
);
opts
.optflag
(
"F"
,
"classify"
,
"show file type indicator (one of */=@|)"
);
opts
.optopt
(
""
,
"color"
,
"when to show anything in colours"
,
"WHEN"
);
opts
.optopt
(
""
,
"colour"
,
"when to show anything in colours (alternate spelling)"
,
"WHEN"
);
opts
.optflag
(
""
,
"color-scale"
,
"use a colour scale when displaying file sizes (alternate spelling)"
);
...
...
src/options/view.rs
浏览文件 @
c205c359
...
...
@@ -58,6 +58,7 @@ impl View {
filter
:
filter
.clone
(),
xattr
:
xattr
::
ENABLED
&&
matches
.opt_present
(
"extended"
),
colours
:
colours
,
classify
:
matches
.opt_present
(
"classify"
),
};
Ok
(
details
)
...
...
@@ -86,6 +87,8 @@ impl View {
};
let
other_options_scan
=
||
{
let
classify
=
matches
.opt_present
(
"classify"
);
let
term_colours
=
TerminalColours
::
deduce
(
matches
)
?
;
let
term_width
=
TerminalWidth
::
deduce
()
?
;
...
...
@@ -103,6 +106,7 @@ impl View {
else
{
let
lines
=
Lines
{
colours
:
colours
,
classify
:
classify
,
};
Ok
(
View
::
Lines
(
lines
))
...
...
@@ -116,6 +120,7 @@ impl View {
filter
:
filter
.clone
(),
// TODO: clone
xattr
:
false
,
colours
:
colours
,
classify
:
classify
,
};
Ok
(
View
::
Details
(
details
))
...
...
@@ -125,6 +130,7 @@ impl View {
across
:
matches
.opt_present
(
"across"
),
console_width
:
width
,
colours
:
colours
,
classify
:
classify
,
};
Ok
(
View
::
Grid
(
grid
))
...
...
@@ -148,6 +154,7 @@ impl View {
filter
:
filter
.clone
(),
xattr
:
false
,
colours
:
colours
,
classify
:
classify
,
};
Ok
(
View
::
Details
(
details
))
...
...
@@ -155,6 +162,7 @@ impl View {
else
{
let
lines
=
Lines
{
colours
:
colours
,
classify
:
classify
,
};
Ok
(
View
::
Lines
(
lines
))
...
...
src/output/cell.rs
浏览文件 @
c205c359
...
...
@@ -5,6 +5,8 @@ use std::ops::{Add, Deref, DerefMut};
use
ansi_term
::{
Style
,
ANSIString
,
ANSIStrings
};
use
unicode_width
::
UnicodeWidthStr
;
use
fs
::
File
;
/// An individual cell that holds text in a table, used in the details and
/// lines views to store ANSI-terminal-formatted data before it is printed.
...
...
@@ -178,6 +180,19 @@ impl TextCellContents {
#[derive(PartialEq,
Debug,
Clone,
Copy,
Default)]
pub
struct
DisplayWidth
(
usize
);
impl
DisplayWidth
{
pub
fn
from_file
(
file
:
&
File
,
classify
:
bool
)
->
DisplayWidth
{
let
name_width
=
*
DisplayWidth
::
from
(
&*
file
.name
);
if
classify
{
if
file
.is_executable_file
()
||
file
.is_directory
()
||
file
.is_pipe
()
||
file
.is_link
()
||
file
.is_socket
()
{
return
DisplayWidth
(
name_width
+
1
);
}
}
DisplayWidth
(
name_width
)
}
}
impl
<
'a
>
From
<&
'a
str
>
for
DisplayWidth
{
fn
from
(
input
:
&
'a
str
)
->
DisplayWidth
{
DisplayWidth
(
UnicodeWidthStr
::
width
(
input
))
...
...
src/output/details.rs
浏览文件 @
c205c359
...
...
@@ -140,6 +140,9 @@ pub struct Details {
/// The colours to use to display information in the table, including the
/// colour of the tree view symbols.
pub
colours
:
Colours
,
/// Whether to show a file type indiccator.
pub
classify
:
bool
,
}
/// The **environment** struct contains any data that could change between
...
...
@@ -303,7 +306,7 @@ impl Details {
for
(
index
,
egg
)
in
file_eggs
.into_iter
()
.enumerate
()
{
let
mut
files
=
Vec
::
new
();
let
mut
errors
=
egg
.errors
;
let
mut
width
=
DisplayWidth
::
from
(
&*
egg
.file.name
);
let
mut
width
=
DisplayWidth
::
from
_file
(
&
egg
.file
,
self
.classify
);
if
egg
.file.dir
.is_none
()
{
if
let
Some
(
parent
)
=
egg
.file.path
.parent
()
{
...
...
@@ -312,7 +315,7 @@ impl Details {
}
let
name
=
TextCell
{
contents
:
filename
(
&
egg
.file
,
&
self
.colours
,
true
),
contents
:
filename
(
&
egg
.file
,
&
self
.colours
,
true
,
self
.classify
),
width
:
width
,
};
...
...
@@ -453,7 +456,7 @@ impl<'a, U: Users+Groups+'a> Table<'a, U> {
}
pub
fn
filename_cell
(
&
self
,
file
:
File
,
links
:
bool
)
->
TextCell
{
let
mut
width
=
DisplayWidth
::
from
(
&*
file
.name
);
let
mut
width
=
DisplayWidth
::
from
_file
(
&
file
,
self
.opts.classify
);
if
file
.dir
.is_none
()
{
if
let
Some
(
parent
)
=
file
.path
.parent
()
{
...
...
@@ -462,7 +465,7 @@ impl<'a, U: Users+Groups+'a> Table<'a, U> {
}
TextCell
{
contents
:
filename
(
&
file
,
&
self
.opts.colours
,
links
),
contents
:
filename
(
&
file
,
&
self
.opts.colours
,
links
,
self
.opts.classify
),
width
:
width
,
}
}
...
...
src/output/grid.rs
浏览文件 @
c205c359
...
...
@@ -13,6 +13,7 @@ pub struct Grid {
pub
across
:
bool
,
pub
console_width
:
usize
,
pub
colours
:
Colours
,
pub
classify
:
bool
,
}
impl
Grid
{
...
...
@@ -28,7 +29,7 @@ impl Grid {
grid
.reserve
(
files
.len
());
for
file
in
files
.iter
()
{
let
mut
width
=
DisplayWidth
::
from
(
&*
file
.name
);
let
mut
width
=
DisplayWidth
::
from
_file
(
file
,
self
.classify
);
if
file
.dir
.is_none
()
{
if
let
Some
(
parent
)
=
file
.path
.parent
()
{
...
...
@@ -37,7 +38,7 @@ impl Grid {
}
grid
.add
(
grid
::
Cell
{
contents
:
filename
(
file
,
&
self
.colours
,
false
)
.strings
()
.to_string
(),
contents
:
filename
(
file
,
&
self
.colours
,
false
,
self
.classify
)
.strings
()
.to_string
(),
width
:
*
width
,
});
}
...
...
@@ -48,7 +49,7 @@ impl Grid {
else
{
// File names too long for a grid - drop down to just listing them!
for
file
in
files
.iter
()
{
writeln!
(
w
,
"{}"
,
filename
(
file
,
&
self
.colours
,
false
)
.strings
())
?
;
writeln!
(
w
,
"{}"
,
filename
(
file
,
&
self
.colours
,
false
,
self
.classify
)
.strings
())
?
;
}
Ok
(())
}
...
...
src/output/lines.rs
浏览文件 @
c205c359
...
...
@@ -11,13 +11,14 @@ use super::colours::Colours;
#[derive(Clone,
Copy,
Debug,
PartialEq)]
pub
struct
Lines
{
pub
colours
:
Colours
,
pub
classify
:
bool
,
}
/// The lines view literally just displays each file, line-by-line.
impl
Lines
{
pub
fn
view
<
W
:
Write
>
(
&
self
,
files
:
Vec
<
File
>
,
w
:
&
mut
W
)
->
IOResult
<
()
>
{
for
file
in
files
{
writeln!
(
w
,
"{}"
,
ANSIStrings
(
&
filename
(
&
file
,
&
self
.colours
,
true
)))
?
;
writeln!
(
w
,
"{}"
,
ANSIStrings
(
&
filename
(
&
file
,
&
self
.colours
,
true
,
self
.classify
)))
?
;
}
Ok
(())
}
...
...
src/output/mod.rs
浏览文件 @
c205c359
...
...
@@ -19,7 +19,7 @@ mod colours;
mod
tree
;
pub
fn
filename
(
file
:
&
File
,
colours
:
&
Colours
,
links
:
bool
)
->
TextCellContents
{
pub
fn
filename
(
file
:
&
File
,
colours
:
&
Colours
,
links
:
bool
,
classify
:
bool
)
->
TextCellContents
{
let
mut
bits
=
Vec
::
new
();
if
file
.dir
.is_none
()
{
...
...
@@ -78,6 +78,18 @@ pub fn filename(file: &File, colours: &Colours, links: bool) -> TextCellContents
// Do nothing -- the error gets displayed on the next line
}
}
}
else
if
classify
{
if
file
.is_executable_file
()
{
bits
.push
(
Style
::
default
()
.paint
(
"*"
));
}
else
if
file
.is_directory
()
{
bits
.push
(
Style
::
default
()
.paint
(
"/"
));
}
else
if
file
.is_pipe
()
{
bits
.push
(
Style
::
default
()
.paint
(
"|"
));
}
else
if
file
.is_link
()
{
bits
.push
(
Style
::
default
()
.paint
(
"@"
));
}
else
if
file
.is_socket
()
{
bits
.push
(
Style
::
default
()
.paint
(
"="
));
}
}
bits
.into
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录