Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
15fba1b8
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,发现更多精彩内容 >>
未验证
提交
15fba1b8
编写于
1月 20, 2019
作者:
N
Nicolas Hennion
提交者:
GitHub
1月 20, 2019
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1396 from limfreee/develop
Curses's browser server list sorting added.
上级
067e1981
d4f06b3e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
62 addition
and
7 deletion
+62
-7
.gitignore
.gitignore
+2
-2
glances/outputs/glances_curses_browser.py
glances/outputs/glances_curses_browser.py
+60
-5
未找到文件。
.gitignore
浏览文件 @
15fba1b8
...
...
@@ -48,5 +48,5 @@ _build
node_modules/
bower_components/
# visual stdio code
.vscode/
\ No newline at end of file
# visual stdio code
.vscode/
glances/outputs/glances_curses_browser.py
浏览文件 @
15fba1b8
...
...
@@ -62,6 +62,8 @@ class GlancesCursesBrowser(_GlancesCurses):
self
.
_page_max_lines
=
0
self
.
is_end
=
False
self
.
_revesed_sorting
=
False
self
.
_stats_list
=
None
@
property
def
active_server
(
self
):
...
...
@@ -90,6 +92,33 @@ class GlancesCursesBrowser(_GlancesCurses):
page_lines
=
self
.
_page_max_lines
return
page_lines
def
_get_status_count
(
self
,
stats
):
counts
=
{}
for
item
in
stats
:
color
=
item
[
'status'
]
counts
[
color
]
=
counts
.
get
(
color
,
0
)
+
1
result
=
''
for
key
in
counts
.
keys
():
result
+=
key
+
': '
+
str
(
counts
[
key
])
+
' '
return
result
def
_get_stats
(
self
,
stats
):
stats_list
=
None
if
self
.
_stats_list
is
not
None
:
stats_list
=
self
.
_stats_list
stats_list
.
sort
(
reverse
=
self
.
_revesed_sorting
,
key
=
lambda
x
:
{
'UNKNOWN'
:
0
,
'OFFLINE'
:
1
,
'PROTECTED'
:
2
,
'SNMP'
:
3
,
'ONLINE'
:
4
}.
get
(
x
[
'status'
],
99
))
else
:
stats_list
=
stats
return
stats_list
def
cursor_up
(
self
,
stats
):
"""Set the cursor to position N-1 in the list."""
if
0
<=
self
.
cursor_position
-
1
:
...
...
@@ -133,7 +162,7 @@ class GlancesCursesBrowser(_GlancesCurses):
def
__catch_key
(
self
,
stats
):
# Catch the browser pressed key
self
.
pressedkey
=
self
.
get_key
(
self
.
term_window
)
refresh
=
False
if
self
.
pressedkey
!=
-
1
:
logger
.
debug
(
"Key pressed. Code=%s"
%
self
.
pressedkey
)
...
...
@@ -164,6 +193,22 @@ class GlancesCursesBrowser(_GlancesCurses):
# 'Page Down' > Next page in the server list
self
.
cursor_pagedown
(
stats
)
logger
.
debug
(
"PageDown: Server {}/{} pages"
.
format
(
self
.
_current_page
+
1
,
self
.
_page_max
))
elif
self
.
pressedkey
==
ord
(
'1'
):
self
.
_stats_list
=
None
refresh
=
True
elif
self
.
pressedkey
==
ord
(
'2'
):
self
.
_revesed_sorting
=
False
self
.
_stats_list
=
stats
.
copy
()
refresh
=
True
elif
self
.
pressedkey
==
ord
(
'3'
):
self
.
_revesed_sorting
=
True
self
.
_stats_list
=
stats
.
copy
()
refresh
=
True
if
refresh
:
self
.
_current_page
=
0
self
.
cursor_position
=
0
self
.
flush
(
stats
)
# Return the key code
return
self
.
pressedkey
...
...
@@ -248,12 +293,21 @@ class GlancesCursesBrowser(_GlancesCurses):
msg
,
screen_x
-
x
,
self
.
colors_list
[
'TITLE'
])
if
stats_len
>
stats_max
and
screen_y
>
2
:
msg
=
'{}
servers displayed.({}/{})'
.
format
(
self
.
get_pagelines
(
stats
),
self
.
_current_page
+
1
,
self
.
_page_max
)
msg
=
'{}
'
.
format
(
self
.
_get_status_count
(
stats
)
)
self
.
term_window
.
addnstr
(
y
+
1
,
x
,
msg
,
screen_x
-
x
)
if
stats_len
>
stats_max
and
screen_y
>
2
:
msg
=
'{} servers displayed.({}/{}) {}'
.
format
(
self
.
get_pagelines
(
stats
),
self
.
_current_page
+
1
,
self
.
_page_max
,
self
.
_get_status_count
(
stats
))
self
.
term_window
.
addnstr
(
y
+
1
,
x
,
msg
,
screen_x
-
x
)
if
stats_len
==
0
:
return
False
...
...
@@ -292,9 +346,10 @@ class GlancesCursesBrowser(_GlancesCurses):
# Set the cursor position to the latest item
self
.
cursor
=
len
(
stats
)
-
1
stats_list
=
self
.
_get_stats
(
stats
)
start_line
=
self
.
_page_max_lines
*
self
.
_current_page
end_line
=
start_line
+
self
.
get_pagelines
(
stats
)
current_page
=
stats
[
start_line
:
end_line
]
end_line
=
start_line
+
self
.
get_pagelines
(
stats
_list
)
current_page
=
stats
_list
[
start_line
:
end_line
]
# Display table
line
=
0
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录