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:
self
.
ws
=
None
self
.
root_path
=
root_path
self
.
name
=
name
self
.
lock
=
threading
.
Lock
()
if
name
is
None
:
self
.
name
=
self
.
config
[
'NAME'
]
...
...
@@ -97,14 +98,20 @@ class Coco:
self
.
sshd
.
shutdown
()
def
add_client
(
self
,
client
):
self
.
clients
.
append
(
client
)
print
(
"
%
s add client, now
%
d s"
%
(
self
.
name
,
len
(
self
.
clients
)))
with
self
.
lock
:
self
.
clients
.
append
(
client
)
print
(
"
%
s add client, now
%
d s"
%
(
self
.
name
,
len
(
self
.
clients
)))
def
remove_client
(
self
,
client
):
self
.
clients
.
remove
(
client
)
client
.
send
(
"Closed by server"
)
client
.
close
()
print
(
"
%
s remove client, now
%
d s"
%
(
self
.
name
,
len
(
self
.
clients
)))
with
self
.
lock
:
self
.
clients
.
remove
(
client
)
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
):
pass
...
...
coco/interactive.py
View file @
05c0e693
...
...
@@ -44,45 +44,43 @@ class InteractiveServer:
self
.
request
.
meta
.
get
(
"height"
,
24
))
self
.
client
.
send
(
wr
(
prompt
,
before
=
1
,
after
=
0
))
while
True
:
r
,
w
,
x
=
select
.
select
([
self
.
client
],
[],
[])
if
self
.
client
in
r
:
data
=
self
.
client
.
recv
(
10
)
if
len
(
data
)
==
0
:
self
.
app
.
remove_client
(
self
.
client
)
# Client input backspace
if
data
in
char
.
BACKSPACE_CHAR
:
# If input words less than 0, should send 'BELL'
if
len
(
input_data
)
>
0
:
data
=
char
.
BACKSPACE_CHAR
[
data
]
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
()
data
=
self
.
client
.
recv
(
10
)
if
len
(
data
)
==
0
:
self
.
app
.
remove_client
(
self
.
client
)
break
# Client input backspace
if
data
in
char
.
BACKSPACE_CHAR
:
# If input words less than 0, should send 'BELL'
if
len
(
input_data
)
>
0
:
data
=
char
.
BACKSPACE_CHAR
[
data
]
input_data
.
pop
()
else
:
self
.
client
.
send
(
data
)
input_data
.
append
(
data
)
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
:
self
.
client
.
send
(
data
)
input_data
.
append
(
data
)
def
dispatch
(
self
,
opt
):
print
(
opt
)
if
opt
in
[
'q'
,
'Q'
]:
self
.
app
.
remove_client
(
self
.
client
)
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