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
05c0e693
Commit
05c0e693
authored
Oct 20, 2017
by
ibuler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove select from interacitve
parent
6a623a6d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
42 deletions
+47
-42
app.py
coco/app.py
+13
-6
interactive.py
coco/interactive.py
+34
-36
No files found.
coco/app.py
View file @
05c0e693
...
@@ -41,6 +41,7 @@ class Coco:
...
@@ -41,6 +41,7 @@ class Coco:
self
.
ws
=
None
self
.
ws
=
None
self
.
root_path
=
root_path
self
.
root_path
=
root_path
self
.
name
=
name
self
.
name
=
name
self
.
lock
=
threading
.
Lock
()
if
name
is
None
:
if
name
is
None
:
self
.
name
=
self
.
config
[
'NAME'
]
self
.
name
=
self
.
config
[
'NAME'
]
...
@@ -97,14 +98,20 @@ class Coco:
...
@@ -97,14 +98,20 @@ class Coco:
self
.
sshd
.
shutdown
()
self
.
sshd
.
shutdown
()
def
add_client
(
self
,
client
):
def
add_client
(
self
,
client
):
self
.
clients
.
append
(
client
)
with
self
.
lock
:
print
(
"
%
s add client, now
%
d s"
%
(
self
.
name
,
len
(
self
.
clients
)))
self
.
clients
.
append
(
client
)
print
(
"
%
s add client, now
%
d s"
%
(
self
.
name
,
len
(
self
.
clients
)))
def
remove_client
(
self
,
client
):
def
remove_client
(
self
,
client
):
self
.
clients
.
remove
(
client
)
with
self
.
lock
:
client
.
send
(
"Closed by server"
)
self
.
clients
.
remove
(
client
)
client
.
close
()
print
(
"
%
s remove client, now
%
d s"
%
(
self
.
name
,
len
(
self
.
clients
)))
print
(
"
%
s remove client, now
%
d s"
%
(
self
.
name
,
len
(
self
.
clients
)))
try
:
client
.
send
(
"Closed by server"
)
client
.
close
()
except
:
pass
def
monitor_session
(
self
):
def
monitor_session
(
self
):
pass
pass
...
...
coco/interactive.py
View file @
05c0e693
...
@@ -44,45 +44,43 @@ class InteractiveServer:
...
@@ -44,45 +44,43 @@ class InteractiveServer:
self
.
request
.
meta
.
get
(
"height"
,
24
))
self
.
request
.
meta
.
get
(
"height"
,
24
))
self
.
client
.
send
(
wr
(
prompt
,
before
=
1
,
after
=
0
))
self
.
client
.
send
(
wr
(
prompt
,
before
=
1
,
after
=
0
))
while
True
:
while
True
:
r
,
w
,
x
=
select
.
select
([
self
.
client
],
[],
[])
data
=
self
.
client
.
recv
(
10
)
if
self
.
client
in
r
:
if
len
(
data
)
==
0
:
data
=
self
.
client
.
recv
(
10
)
self
.
app
.
remove_client
(
self
.
client
)
if
len
(
data
)
==
0
:
break
self
.
app
.
remove_client
(
self
.
client
)
# Client input backspace
# Client input backspace
if
data
in
char
.
BACKSPACE_CHAR
:
if
data
in
char
.
BACKSPACE_CHAR
:
# If input words less than 0, should send 'BELL'
# If input words less than 0, should send 'BELL'
if
len
(
input_data
)
>
0
:
if
len
(
input_data
)
>
0
:
data
=
char
.
BACKSPACE_CHAR
[
data
]
data
=
char
.
BACKSPACE_CHAR
[
data
]
input_data
.
pop
()
input_data
.
pop
()
else
:
data
=
char
.
BELL_CHAR
self
.
client
.
send
(
data
)
continue
# Todo: Move x1b to char
if
data
.
startswith
(
b
'
\x1b
'
)
or
data
in
char
.
UNSUPPORTED_CHAR
:
self
.
client
.
send
(
''
)
continue
# handle shell expect
multi_char_with_enter
=
False
if
len
(
data
)
>
1
and
data
[
-
1
]
in
char
.
ENTER_CHAR
:
self
.
client
.
send
(
data
)
input_data
.
append
(
data
[:
-
1
])
multi_char_with_enter
=
True
# If user type ENTER we should get user input
if
data
in
char
.
ENTER_CHAR
or
multi_char_with_enter
:
self
.
client
.
send
(
wr
(
''
,
after
=
2
))
option
=
parser
.
parse_input
(
b
''
.
join
(
input_data
))
return
option
.
strip
()
else
:
else
:
self
.
client
.
send
(
data
)
data
=
char
.
BELL_CHAR
input_data
.
append
(
data
)
self
.
client
.
send
(
data
)
continue
# Todo: Move x1b to char
if
data
.
startswith
(
b
'
\x1b
'
)
or
data
in
char
.
UNSUPPORTED_CHAR
:
self
.
client
.
send
(
''
)
continue
# handle shell expect
multi_char_with_enter
=
False
if
len
(
data
)
>
1
and
data
[
-
1
]
in
char
.
ENTER_CHAR
:
self
.
client
.
send
(
data
)
input_data
.
append
(
data
[:
-
1
])
multi_char_with_enter
=
True
# If user type ENTER we should get user input
if
data
in
char
.
ENTER_CHAR
or
multi_char_with_enter
:
self
.
client
.
send
(
wr
(
''
,
after
=
2
))
option
=
parser
.
parse_input
(
b
''
.
join
(
input_data
))
return
option
.
strip
()
else
:
self
.
client
.
send
(
data
)
input_data
.
append
(
data
)
def
dispatch
(
self
,
opt
):
def
dispatch
(
self
,
opt
):
print
(
opt
)
if
opt
in
[
'q'
,
'Q'
]:
if
opt
in
[
'q'
,
'Q'
]:
self
.
app
.
remove_client
(
self
.
client
)
self
.
app
.
remove_client
(
self
.
client
)
return
return
...
...
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