Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
git
提交
d7173d94
G
git
项目概览
李少辉-开发者
/
git
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
git
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
d7173d94
编写于
3月 20, 2010
作者:
J
Junio C Hamano
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'jc/color-attrs'
* jc/color-attrs: color: allow multiple attributes
上级
49559cad
8b124135
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
14 deletion
+41
-14
color.c
color.c
+16
-8
color.h
color.h
+14
-2
t/t4026-color.sh
t/t4026-color.sh
+11
-4
未找到文件。
color.c
浏览文件 @
d7173d94
...
...
@@ -47,7 +47,7 @@ void color_parse_mem(const char *value, int value_len, const char *var,
{
const
char
*
ptr
=
value
;
int
len
=
value_len
;
int
attr
=
-
1
;
unsigned
int
attr
=
0
;
int
fg
=
-
2
;
int
bg
=
-
2
;
...
...
@@ -56,7 +56,7 @@ void color_parse_mem(const char *value, int value_len, const char *var,
return
;
}
/* [fg [bg]] [attr] */
/* [fg [bg]] [attr]
...
*/
while
(
len
>
0
)
{
const
char
*
word
=
ptr
;
int
val
,
wordlen
=
0
;
...
...
@@ -85,19 +85,27 @@ void color_parse_mem(const char *value, int value_len, const char *var,
goto
bad
;
}
val
=
parse_attr
(
word
,
wordlen
);
if
(
val
<
0
||
attr
!=
-
1
)
if
(
0
<=
val
)
attr
|=
(
1
<<
val
);
else
goto
bad
;
attr
=
val
;
}
if
(
attr
>=
0
||
fg
>=
0
||
bg
>=
0
)
{
if
(
attr
||
fg
>=
0
||
bg
>=
0
)
{
int
sep
=
0
;
int
i
;
*
dst
++
=
'\033'
;
*
dst
++
=
'['
;
if
(
attr
>=
0
)
{
*
dst
++
=
'0'
+
attr
;
sep
++
;
for
(
i
=
0
;
attr
;
i
++
)
{
unsigned
bit
=
(
1
<<
i
);
if
(
!
(
attr
&
bit
))
continue
;
attr
&=
~
bit
;
if
(
sep
++
)
*
dst
++
=
';'
;
*
dst
++
=
'0'
+
i
;
}
if
(
fg
>=
0
)
{
if
(
sep
++
)
...
...
color.h
浏览文件 @
d7173d94
#ifndef COLOR_H
#define COLOR_H
/* "\033[1;38;5;2xx;48;5;2xxm\0" is 23 bytes */
#define COLOR_MAXLEN 24
/* 2 + (2 * num_attrs) + 8 + 1 + 8 + 'm' + NUL */
/* "\033[1;2;4;5;7;38;5;2xx;48;5;2xxm\0" */
/*
* The maximum length of ANSI color sequence we would generate:
* - leading ESC '[' 2
* - attr + ';' 2 * 8 (e.g. "1;")
* - fg color + ';' 9 (e.g. "38;5;2xx;")
* - fg color + ';' 9 (e.g. "48;5;2xx;")
* - terminating 'm' NUL 2
*
* The above overcounts attr (we only use 5 not 8) and one semicolon
* but it is close enough.
*/
#define COLOR_MAXLEN 40
/*
* IMPORTANT: Due to the way these color codes are emulated on Windows,
...
...
t/t4026-color.sh
浏览文件 @
d7173d94
...
...
@@ -8,14 +8,13 @@ test_description='Test diff/status color escape codes'
color
()
{
git config diff.color.new
"
$1
"
&&
test
"
`
git config
--get-color
diff.color.new
`
"
=
"
$2
"
actual
=
$(
git config
--get-color
no.such.slot
"
$1
"
)
&&
test
"
$actual
"
=
"
$2
"
}
invalid_color
()
{
git config diff.color.new
"
$1
"
&&
test
-z
"
`
git config
--get-color
diff.color.new 2>/dev/null
`
"
test_must_fail git config
--get-color
no.such.slot
"
$1
"
}
test_expect_success
'reset'
'
...
...
@@ -42,6 +41,14 @@ test_expect_success 'fg bg attr' '
color "blue red ul" "[4;34;41m"
'
test_expect_success
'fg bg attr...'
'
color "blue bold dim ul blink reverse" "[1;2;4;5;7;34m"
'
test_expect_success
'long color specification'
'
color "254 255 bold dim ul blink reverse" "[1;2;4;5;7;38;5;254;48;5;255m"
'
test_expect_success
'256 colors'
'
color "254 bold 255" "[1;38;5;254;48;5;255m"
'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录