Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
蜕变的菜鸟
glances
提交
f7e24b22
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,体验更适合开发者的 AI 搜索 >>
提交
f7e24b22
编写于
1月 05, 2019
作者:
S
sangoh.hong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
curses-browser's server list paging added.
Browsing with Up/Down/PageUp/PageDown key.
上级
1d3961a9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
60 addition
and
8 deletion
+60
-8
glances/outputs/glances_curses_browser.py
glances/outputs/glances_curses_browser.py
+60
-8
未找到文件。
glances/outputs/glances_curses_browser.py
浏览文件 @
f7e24b22
...
...
@@ -20,7 +20,7 @@
"""Curses browser interface class ."""
import
sys
import
math
import
curses
from
glances.outputs.glances_curses
import
_GlancesCurses
...
...
@@ -57,6 +57,10 @@ class GlancesCursesBrowser(_GlancesCurses):
# Active Glances server number
self
.
_active_server
=
None
self
.
_current_page
=
0
self
.
_page_max
=
0
self
.
_page_max_lines
=
0
@
property
def
active_server
(
self
):
"""Return the active server or None if it's the browser list."""
...
...
@@ -77,20 +81,51 @@ class GlancesCursesBrowser(_GlancesCurses):
"""Set the cursor position."""
self
.
cursor_position
=
position
def
get_pagelines
(
self
,
stats
):
if
self
.
_current_page
==
self
.
_page_max
-
1
:
page_lines
=
len
(
stats
)
%
self
.
_page_max_lines
else
:
page_lines
=
self
.
_page_max_lines
return
page_lines
def
cursor_up
(
self
,
stats
):
"""Set the cursor to position N-1 in the list."""
if
self
.
cursor_position
>
0
:
if
0
<=
self
.
cursor_position
-
1
:
self
.
cursor_position
-=
1
else
:
self
.
cursor_position
=
len
(
stats
)
-
1
if
self
.
_current_page
-
1
<
0
:
self
.
_current_page
=
self
.
_page_max
-
1
self
.
cursor_position
=
(
len
(
stats
)
-
1
)
%
self
.
_page_max_lines
else
:
self
.
_current_page
-=
1
self
.
cursor_position
=
self
.
_page_max_lines
-
1
def
cursor_down
(
self
,
stats
):
"""Set the cursor to position N-1 in the list."""
if
self
.
cursor_position
<
len
(
stats
)
-
1
:
if
self
.
cursor_position
+
1
<
self
.
get_pagelines
(
stats
):
self
.
cursor_position
+=
1
else
:
if
self
.
_current_page
+
1
<
self
.
_page_max
:
self
.
_current_page
+=
1
else
:
self
.
_current_page
=
0
self
.
cursor_position
=
0
def
cursor_pageup
(
self
,
stats
):
"""Set prev page."""
if
self
.
_current_page
-
1
<
0
:
self
.
_current_page
=
self
.
_page_max
-
1
else
:
self
.
_current_page
-=
1
self
.
cursor_position
=
0
def
cursor_pagedown
(
self
,
stats
):
"""Set next page."""
if
self
.
_current_page
+
1
<
self
.
_page_max
:
self
.
_current_page
+=
1
self
.
cursor_position
=
0
def
__catch_key
(
self
,
stats
):
# Catch the browser pressed key
self
.
pressedkey
=
self
.
get_key
(
self
.
term_window
)
...
...
@@ -106,8 +141,8 @@ class GlancesCursesBrowser(_GlancesCurses):
sys
.
exit
(
0
)
elif
self
.
pressedkey
==
10
:
# 'ENTER' > Run Glances on the selected server
self
.
active_server
=
self
.
cursor
logger
.
debug
(
"Server {}/{} selected"
.
format
(
self
.
cursor
+
1
,
len
(
stats
)))
self
.
active_server
=
self
.
_current_page
*
self
.
_page_max_lines
+
self
.
cursor_position
logger
.
debug
(
"Server {}/{} selected"
.
format
(
self
.
active_server
,
len
(
stats
)))
elif
self
.
pressedkey
==
curses
.
KEY_UP
or
self
.
pressedkey
==
65
:
# 'UP' > Up in the server list
self
.
cursor_up
(
stats
)
...
...
@@ -116,6 +151,14 @@ class GlancesCursesBrowser(_GlancesCurses):
# 'DOWN' > Down in the server list
self
.
cursor_down
(
stats
)
logger
.
debug
(
"Server {}/{} selected"
.
format
(
self
.
cursor
+
1
,
len
(
stats
)))
elif
self
.
pressedkey
==
curses
.
KEY_PPAGE
:
# 'Page UP' > Prev page in the server list
self
.
cursor_pageup
(
stats
)
logger
.
debug
(
"PageUP: Server ({}/{}) pages."
.
format
(
self
.
_current_page
+
1
,
self
.
_page_max
))
elif
self
.
pressedkey
==
curses
.
KEY_NPAGE
:
# '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
))
# Return the key code
return
self
.
pressedkey
...
...
@@ -176,6 +219,8 @@ class GlancesCursesBrowser(_GlancesCurses):
stats_max
=
screen_y
-
3
stats_len
=
len
(
stats
)
self
.
_page_max_lines
=
stats_max
self
.
_page_max
=
int
(
math
.
ceil
(
stats_len
/
stats_max
))
# Init position
x
=
0
y
=
0
...
...
@@ -199,7 +244,7 @@ class GlancesCursesBrowser(_GlancesCurses):
screen_x
-
x
,
self
.
colors_list
[
'TITLE'
])
if
stats_len
>
stats_max
and
screen_y
>
2
:
msg
=
'
Warning: Only {} servers will be displayed (please increase your terminal size)'
.
format
(
stats
_max
)
msg
=
'
{} servers displayed.({}/{})'
.
format
(
self
.
get_pagelines
(
stats
),
self
.
_current_page
+
1
,
self
.
_page
_max
)
self
.
term_window
.
addnstr
(
y
+
1
,
x
,
msg
,
screen_x
-
x
)
...
...
@@ -242,9 +287,16 @@ class GlancesCursesBrowser(_GlancesCurses):
# Set the cursor position to the latest item
self
.
cursor
=
len
(
stats
)
-
1
start_line
=
self
.
_page_max_lines
*
self
.
_current_page
end_line
=
start_line
+
self
.
_page_max_lines
if
end_line
>
stats_len
:
end_line
=
stats_len
current_page
=
stats
[
start_line
:
end_line
]
# Display table
line
=
0
for
v
in
stats
:
for
v
in
current_page
:
# Limit the number of displayed server (see issue #1256)
if
line
>=
stats_max
:
continue
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录