Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
coco
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ops
coco
Commits
c1813021
Unverified
Commit
c1813021
authored
Feb 01, 2018
by
liuzheng712
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(interactive.py): add Ctrl-C and Ctrl-D
parent
08752ff7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
3 deletions
+14
-3
interactive.py
coco/interactive.py
+14
-3
No files found.
coco/interactive.py
View file @
c1813021
...
...
@@ -82,6 +82,7 @@ class InteractiveServer:
self
.
client
.
send
(
wr
(
prompt
,
before
=
1
,
after
=
0
))
while
True
:
data
=
self
.
client
.
recv
(
10
)
logger
.
debug
(
data
)
if
len
(
data
)
==
0
:
self
.
app
.
remove_client
(
self
.
client
)
break
...
...
@@ -96,6 +97,15 @@ class InteractiveServer:
self
.
client
.
send
(
data
)
continue
if
data
.
startswith
(
b
'
\x03
'
):
# Ctrl-C
self
.
client
.
send
(
b
'^C
\r\n
Opt> '
)
input_data
=
[]
continue
elif
data
.
startswith
(
b
'
\x04
'
):
# Ctrl-D
return
'q'
# Todo: Move x1b to char
if
data
.
startswith
(
b
'
\x1b
'
)
or
data
in
char
.
UNSUPPORTED_CHAR
:
self
.
client
.
send
(
b
''
)
...
...
@@ -182,7 +192,7 @@ class InteractiveServer:
amount_max_length
=
max
(
len
(
str
(
max
([
group
.
assets_amount
for
group
in
self
.
asset_groups
]))),
10
)
header
=
'{1:>
%
d} {0.name:
%
d} {0.assets_amount:<
%
s} '
%
(
id_max_length
,
name_max_length
,
amount_max_length
)
comment_length
=
self
.
request
.
meta
[
"width"
]
-
len
(
header
.
format
(
fake_group
,
id_max_length
))
line
=
header
+
'{0.comment:
%
s}'
%
(
comment_length
//
2
)
# comment中可能有中文
line
=
header
+
'{0.comment:
%
s}'
%
(
comment_length
//
2
)
# comment中可能有中文
header
+=
"{0.comment:
%
s}"
%
comment_length
self
.
client
.
send
(
title
(
header
.
format
(
fake_group
,
"ID"
)))
for
index
,
group
in
enumerate
(
self
.
asset_groups
,
1
):
...
...
@@ -195,12 +205,13 @@ class InteractiveServer:
self
.
display_asset_groups
()
return
self
.
search_result
=
self
.
asset_groups
[
_id
-
1
]
.
assets_granted
self
.
search_result
=
self
.
asset_groups
[
_id
-
1
]
.
assets_granted
self
.
display_search_result
()
def
display_search_result
(
self
):
self
.
search_result
=
sort_assets
(
self
.
search_result
,
self
.
app
.
config
[
"ASSET_LIST_SORT_BY"
])
fake_asset
=
Asset
(
hostname
=
_
(
"Hostname"
),
ip
=
_
(
"IP"
),
_system_users_name_list
=
_
(
"LoginAs"
),
comment
=
_
(
"Comment"
))
fake_asset
=
Asset
(
hostname
=
_
(
"Hostname"
),
ip
=
_
(
"IP"
),
_system_users_name_list
=
_
(
"LoginAs"
),
comment
=
_
(
"Comment"
))
id_max_length
=
max
(
len
(
str
(
len
(
self
.
search_result
))),
3
)
hostname_max_length
=
max
(
max
([
len
(
asset
.
hostname
)
for
asset
in
self
.
search_result
+
[
fake_asset
]]),
15
)
sysuser_max_length
=
max
([
len
(
asset
.
system_users_name_list
)
for
asset
in
self
.
search_result
+
[
fake_asset
]])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment