Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
07b62056
G
glances
项目概览
蜕变的菜鸟
/
glances
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
glances
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
07b62056
编写于
10月 10, 2015
作者:
N
nicolargo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor the huge Curses script (first phase, should be continued)
上级
6767a096
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
85 addition
and
66 deletion
+85
-66
glances/outputs/glances_curses.py
glances/outputs/glances_curses.py
+85
-66
未找到文件。
glances/outputs/glances_curses.py
浏览文件 @
07b62056
...
...
@@ -70,23 +70,76 @@ class _GlancesCurses(object):
logger
.
critical
(
"Cannot init the curses library.
\n
"
)
sys
.
exit
(
1
)
# Set curses options
if
hasattr
(
curses
,
'start_color'
):
curses
.
start_color
()
if
hasattr
(
curses
,
'use_default_colors'
):
curses
.
use_default_colors
()
# Init cursor
self
.
_init_cursor
()
# Init the colors
self
.
_init_colors
()
# Init main window
self
.
term_window
=
self
.
screen
.
subwin
(
0
,
0
)
# Init refresh time
self
.
__refresh_time
=
args
.
time
# Init edit filter tag
self
.
edit_filter
=
False
# Catch key pressed with non blocking mode
self
.
no_flash_cursor
()
self
.
term_window
.
nodelay
(
1
)
self
.
pressedkey
=
-
1
# History tag
self
.
_init_history
()
def
_init_history
(
self
):
'''Init the history option'''
self
.
reset_history_tag
=
False
self
.
history_tag
=
False
if
self
.
args
.
enable_history
:
logger
.
info
(
'Stats history enabled with output path %s'
%
self
.
args
.
path_history
)
from
glances.exports.glances_history
import
GlancesHistory
self
.
glances_history
=
GlancesHistory
(
self
.
args
.
path_history
)
if
not
self
.
glances_history
.
graph_enabled
():
self
.
args
.
enable_history
=
False
logger
.
error
(
'Stats history disabled because MatPlotLib is not installed'
)
def
_init_cursor
(
self
):
'''Init cursors'''
if
hasattr
(
curses
,
'noecho'
):
curses
.
noecho
()
if
hasattr
(
curses
,
'cbreak'
):
curses
.
cbreak
()
self
.
set_cursor
(
0
)
def
_init_colors
(
self
):
'''Init the Curses color layout'''
# Set curses options
if
hasattr
(
curses
,
'start_color'
):
curses
.
start_color
()
if
hasattr
(
curses
,
'use_default_colors'
):
curses
.
use_default_colors
()
# Init colors
self
.
hascolors
=
False
if
curses
.
has_colors
()
and
curses
.
COLOR_PAIRS
>
8
:
self
.
hascolors
=
True
# FG color, BG color
if
args
.
theme_white
:
if
self
.
args
.
disable_bold
:
A_BOLD
=
curses
.
A_BOLD
else
:
A_BOLD
=
0
self
.
title_color
=
A_BOLD
self
.
title_underline_color
=
A_BOLD
|
curses
.
A_UNDERLINE
self
.
help_color
=
A_BOLD
if
curses
.
has_colors
():
# The screen is compatible with a colored design
if
self
.
args
.
theme_white
:
# White theme: black ==> white
curses
.
init_pair
(
1
,
curses
.
COLOR_BLACK
,
-
1
)
else
:
curses
.
init_pair
(
1
,
curses
.
COLOR_WHITE
,
-
1
)
...
...
@@ -97,34 +150,28 @@ class _GlancesCurses(object):
curses
.
init_pair
(
6
,
curses
.
COLOR_RED
,
-
1
)
curses
.
init_pair
(
7
,
curses
.
COLOR_GREEN
,
-
1
)
curses
.
init_pair
(
8
,
curses
.
COLOR_BLUE
,
-
1
)
try
:
curses
.
init_pair
(
9
,
curses
.
COLOR_MAGENTA
,
-
1
)
except
Exception
:
if
args
.
theme_white
:
curses
.
init_pair
(
9
,
curses
.
COLOR_BLACK
,
-
1
)
else
:
curses
.
init_pair
(
9
,
curses
.
COLOR_WHITE
,
-
1
)
try
:
curses
.
init_pair
(
10
,
curses
.
COLOR_CYAN
,
-
1
)
except
Exception
:
if
args
.
theme_white
:
curses
.
init_pair
(
10
,
curses
.
COLOR_BLACK
,
-
1
)
else
:
curses
.
init_pair
(
10
,
curses
.
COLOR_WHITE
,
-
1
)
else
:
self
.
hascolors
=
False
# Colors text styles
if
curses
.
COLOR_PAIRS
>
8
:
try
:
curses
.
init_pair
(
9
,
curses
.
COLOR_MAGENTA
,
-
1
)
except
Exception
:
if
self
.
args
.
theme_white
:
curses
.
init_pair
(
9
,
curses
.
COLOR_BLACK
,
-
1
)
else
:
curses
.
init_pair
(
9
,
curses
.
COLOR_WHITE
,
-
1
)
try
:
curses
.
init_pair
(
10
,
curses
.
COLOR_CYAN
,
-
1
)
except
Exception
:
if
self
.
args
.
theme_white
:
curses
.
init_pair
(
10
,
curses
.
COLOR_BLACK
,
-
1
)
else
:
curses
.
init_pair
(
10
,
curses
.
COLOR_WHITE
,
-
1
)
if
args
.
disable_bold
:
A_BOLD
=
curses
.
A_BOLD
else
:
A_BOLD
=
0
self
.
ifWARNING_color2
=
curses
.
color_pair
(
9
)
|
A_BOLD
self
.
ifCRITICAL_color2
=
curses
.
color_pair
(
6
)
|
A_BOLD
self
.
filter_color
=
curses
.
color_pair
(
10
)
|
A_BOLD
self
.
title_color
=
A_BOLD
self
.
title_underline_color
=
A_BOLD
|
curses
.
A_UNDERLINE
self
.
help_color
=
A_BOLD
if
self
.
hascolors
:
# Colors text styles
self
.
no_color
=
curses
.
color_pair
(
1
)
self
.
default_color
=
curses
.
color_pair
(
3
)
|
A_BOLD
self
.
nice_color
=
curses
.
color_pair
(
9
)
|
A_BOLD
...
...
@@ -134,11 +181,10 @@ class _GlancesCurses(object):
self
.
ifCRITICAL_color
=
curses
.
color_pair
(
2
)
|
A_BOLD
self
.
default_color2
=
curses
.
color_pair
(
7
)
|
A_BOLD
self
.
ifCAREFUL_color2
=
curses
.
color_pair
(
8
)
|
A_BOLD
self
.
ifWARNING_color2
=
curses
.
color_pair
(
9
)
|
A_BOLD
self
.
ifCRITICAL_color2
=
curses
.
color_pair
(
6
)
|
A_BOLD
self
.
filter_color
=
curses
.
color_pair
(
10
)
|
A_BOLD
else
:
# B&W text styles
# The screen is NOT compatible with a colored design
# switch to B&W text styles
self
.
no_color
=
curses
.
A_NORMAL
self
.
default_color
=
curses
.
A_NORMAL
self
.
nice_color
=
A_BOLD
...
...
@@ -175,33 +221,6 @@ class _GlancesCurses(object):
'PASSWORD'
:
curses
.
A_PROTECT
}
# Init main window
self
.
term_window
=
self
.
screen
.
subwin
(
0
,
0
)
# Init refresh time
self
.
__refresh_time
=
args
.
time
# Init edit filter tag
self
.
edit_filter
=
False
# Catch key pressed with non blocking mode
self
.
no_flash_cursor
()
self
.
term_window
.
nodelay
(
1
)
self
.
pressedkey
=
-
1
# History tag
self
.
reset_history_tag
=
False
self
.
history_tag
=
False
if
args
.
enable_history
:
logger
.
info
(
'Stats history enabled with output path %s'
%
args
.
path_history
)
from
glances.exports.glances_history
import
GlancesHistory
self
.
glances_history
=
GlancesHistory
(
args
.
path_history
)
if
not
self
.
glances_history
.
graph_enabled
():
args
.
enable_history
=
False
logger
.
error
(
'Stats history disabled because MatPlotLib is not installed'
)
def
flash_cursor
(
self
):
self
.
term_window
.
keypad
(
1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录