Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
vnotepad
Exa
提交
fdf58e88
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,发现更多精彩内容 >>
提交
fdf58e88
编写于
5月 24, 2014
作者:
B
Ben S
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Upgrade to latest Rust (s/~str/StrBuf/)
See
https://github.com/mozilla/rust/pull/14310
上级
f65d170b
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
28 addition
and
26 deletion
+28
-26
colours.rs
colours.rs
+11
-9
exa.rs
exa.rs
+2
-2
file.rs
file.rs
+10
-10
format.rs
format.rs
+3
-3
unix.rs
unix.rs
+2
-2
未找到文件。
colours.rs
浏览文件 @
fdf58e88
...
...
@@ -16,19 +16,20 @@ pub struct StyleStruct {
}
impl
Style
{
pub
fn
paint
(
&
self
,
input
:
~
str
)
->
~
str
{
pub
fn
paint
(
&
self
,
input
:
&
str
)
->
StrBuf
{
match
*
self
{
Plain
=>
input
,
Plain
=>
input
.to_strbuf
()
,
Foreground
(
c
)
=>
c
.paint
(
input
),
Style
(
s
)
=>
match
s
{
StyleStruct
{
foreground
,
background
,
bold
,
underline
}
=>
{
let
bg
:
~
str
=
match
background
{
let
bg
=
match
background
{
Some
(
c
)
=>
format!
(
"{};"
,
c
as
int
+
10
),
None
=>
""
.to_
owned
(),
None
=>
""
.to_
strbuf
()
};
let
bo
=
if
bold
{
"1;"
}
else
{
""
};
let
un
=
if
underline
{
"4;"
}
else
{
""
};
format!
(
"
\x1B
[{}{}{}{}m{}
\x1B
[0m"
,
bo
,
un
,
bg
,
foreground
as
int
,
input
)
let
re
=
format!
(
"
\x1B
[{}{}{}{}m{}
\x1B
[0m"
,
bo
,
un
,
bg
,
foreground
as
int
,
input
.to_strbuf
());
return
re
.to_owned
();
}
}
}
...
...
@@ -62,8 +63,9 @@ impl Style {
}
impl
Colour
{
pub
fn
paint
(
&
self
,
input
:
&
str
)
->
~
str
{
format!
(
"
\x1B
[{}m{}
\x1B
[0m"
,
*
self
as
int
,
input
)
pub
fn
paint
(
&
self
,
input
:
&
str
)
->
StrBuf
{
let
re
=
format!
(
"
\x1B
[{}m{}
\x1B
[0m"
,
*
self
as
int
,
input
);
return
re
.to_owned
();
}
pub
fn
underline
(
&
self
)
->
Style
{
...
...
@@ -83,7 +85,7 @@ impl Colour {
}
}
pub
fn
strip_formatting
(
input
:
&
~
str
)
->
~
str
{
pub
fn
strip_formatting
(
input
:
&
StrBuf
)
->
StrBuf
{
let
re
=
regex!
(
"
\x1B\\
[.+?m"
);
re
.replace_all
(
*
input
,
""
)
.to_owned
()
re
.replace_all
(
input
.as_slice
()
,
""
)
.to_owned
()
}
exa.rs
浏览文件 @
fdf58e88
...
...
@@ -58,7 +58,7 @@ fn list(opts: Options, path: Path) {
let
columns
=
defaultColumns
();
let
table
:
Vec
<
Vec
<
~
str
>>
=
files
.iter
()
let
table
:
Vec
<
Vec
<
StrBuf
>>
=
files
.iter
()
.map
(|
p
|
File
::
from_path
(
p
))
.filter
(|
f
|
!
f
.is_dotfile
()
||
opts
.showInvisibles
)
.map
(|
f
|
columns
.iter
()
.map
(|
c
|
f
.display
(
c
))
.collect
())
...
...
@@ -76,7 +76,7 @@ fn list(opts: Options, path: Path) {
}
else
{
print!
(
" "
);
}
print!
(
"{}"
,
cell
);
print!
(
"{}"
,
cell
.as_slice
()
);
for
_
in
range
(
cell
.len
(),
*
length
)
{
print!
(
" "
);
}
...
...
file.rs
浏览文件 @
fdf58e88
...
...
@@ -35,17 +35,17 @@ impl<'a> File<'a> {
self
.name
.starts_with
(
"."
)
}
pub
fn
display
(
&
self
,
column
:
&
Column
)
->
~
str
{
pub
fn
display
(
&
self
,
column
:
&
Column
)
->
StrBuf
{
match
*
column
{
Permissions
=>
self
.permissions
(),
FileName
=>
self
.file_colour
()
.paint
(
self
.name
.
to_owned
()),
FileName
=>
self
.file_colour
()
.paint
(
self
.name
.
as_slice
()),
FileSize
(
si
)
=>
self
.file_size
(
si
),
User
=>
get_user_name
(
self
.stat.unstable.uid
as
i32
)
.unwrap_or
(
self
.stat.unstable.uid
.to_str
()),
Group
=>
get_group_name
(
self
.stat.unstable.gid
as
u32
)
.unwrap_or
(
self
.stat.unstable.gid
.to_str
()),
}
}
fn
file_size
(
&
self
,
si
:
bool
)
->
~
str
{
fn
file_size
(
&
self
,
si
:
bool
)
->
StrBuf
{
let
sizeStr
=
if
si
{
formatBinaryBytes
(
self
.stat.size
)
}
else
{
...
...
@@ -56,12 +56,12 @@ impl<'a> File<'a> {
Green
.normal
()
}
else
{
Green
.bold
()
}
.paint
(
sizeStr
);
}
.paint
(
sizeStr
.as_slice
()
);
}
fn
type_char
(
&
self
)
->
~
str
{
fn
type_char
(
&
self
)
->
StrBuf
{
return
match
self
.stat.kind
{
io
::
TypeFile
=>
"."
.to_
owned
(),
io
::
TypeFile
=>
"."
.to_
strbuf
(),
io
::
TypeDirectory
=>
Blue
.paint
(
"d"
),
io
::
TypeNamedPipe
=>
Yellow
.paint
(
"|"
),
io
::
TypeBlockSpecial
=>
Purple
.paint
(
"s"
),
...
...
@@ -83,7 +83,7 @@ impl<'a> File<'a> {
}
}
fn
permissions
(
&
self
)
->
~
str
{
fn
permissions
(
&
self
)
->
StrBuf
{
let
bits
=
self
.stat.perm
;
return
format!
(
"{}{}{}{}{}{}{}{}{}{}"
,
self
.type_char
(),
...
...
@@ -100,10 +100,10 @@ impl<'a> File<'a> {
}
}
fn
bit
(
bits
:
io
::
FilePermission
,
bit
:
io
::
FilePermission
,
other
:
&
'static
str
,
style
:
Style
)
->
~
str
{
fn
bit
(
bits
:
io
::
FilePermission
,
bit
:
io
::
FilePermission
,
other
:
&
'static
str
,
style
:
Style
)
->
StrBuf
{
if
bits
.contains
(
bit
)
{
style
.paint
(
other
.
to_owned
())
style
.paint
(
other
.
as_slice
())
}
else
{
Black
.bold
()
.paint
(
"-"
.
to_owned
())
Black
.bold
()
.paint
(
"-"
.
as_slice
())
}
}
format.rs
浏览文件 @
fdf58e88
fn
formatBytes
(
mut
amount
:
u64
,
kilo
:
u64
,
prefixes
:
~
[
&
str
])
->
~
str
{
fn
formatBytes
(
mut
amount
:
u64
,
kilo
:
u64
,
prefixes
:
~
[
&
str
])
->
StrBuf
{
let
mut
prefix
=
0
;
while
amount
>
kilo
{
amount
/=
kilo
;
...
...
@@ -7,10 +7,10 @@ fn formatBytes(mut amount: u64, kilo: u64, prefixes: ~[&str]) -> ~str {
return
format!
(
"{:4}{}"
,
amount
,
prefixes
[
prefix
]);
}
pub
fn
formatBinaryBytes
(
amount
:
u64
)
->
~
str
{
pub
fn
formatBinaryBytes
(
amount
:
u64
)
->
StrBuf
{
formatBytes
(
amount
,
1024
,
~
[
"B "
,
"KiB"
,
"MiB"
,
"GiB"
,
"TiB"
])
}
pub
fn
formatDecimalBytes
(
amount
:
u64
)
->
~
str
{
pub
fn
formatDecimalBytes
(
amount
:
u64
)
->
StrBuf
{
formatBytes
(
amount
,
1000
,
~
[
"B "
,
"KB"
,
"MB"
,
"GB"
,
"TB"
])
}
unix.rs
浏览文件 @
fdf58e88
...
...
@@ -34,7 +34,7 @@ mod c {
}
}
pub
fn
get_user_name
(
uid
:
i32
)
->
Option
<
~
str
>
{
pub
fn
get_user_name
(
uid
:
i32
)
->
Option
<
StrBuf
>
{
let
pw
=
unsafe
{
c
::
getpwuid
(
uid
)
};
if
pw
.is_not_null
()
{
return
unsafe
{
Some
(
from_c_str
(
read
(
pw
)
.pw_name
))
};
...
...
@@ -44,7 +44,7 @@ pub fn get_user_name(uid: i32) -> Option<~str> {
}
}
pub
fn
get_group_name
(
gid
:
u32
)
->
Option
<
~
str
>
{
pub
fn
get_group_name
(
gid
:
u32
)
->
Option
<
StrBuf
>
{
let
gr
=
unsafe
{
c
::
getgrgid
(
gid
)
};
if
gr
.is_not_null
()
{
return
unsafe
{
Some
(
from_c_str
(
read
(
gr
)
.gr_name
))
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录