Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
webssh
Overview
Overview
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
郑天保
webssh
Commits
c439f2b6
Commit
c439f2b6
authored
May 23, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Instantly update pseudo-terminal size by client terminal size
parent
82929ea4
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
13 deletions
+41
-13
test_app.py
tests/test_app.py
+1
-1
handler.py
webssh/handler.py
+11
-1
main.js
webssh/static/js/main.js
+29
-11
No files found.
tests/test_app.py
View file @
c439f2b6
...
@@ -136,5 +136,5 @@ class TestApp(AsyncHTTPTestCase):
...
@@ -136,5 +136,5 @@ class TestApp(AsyncHTTPTestCase):
ws
=
yield
tornado
.
websocket
.
websocket_connect
(
ws_url
)
ws
=
yield
tornado
.
websocket
.
websocket_connect
(
ws_url
)
msg
=
yield
ws
.
read_message
()
msg
=
yield
ws
.
read_message
()
self
.
assertIn
(
b
'Welcome!'
,
msg
)
self
.
assertIn
(
b
'Welcome!'
,
msg
)
yield
ws
.
write_message
(
'bye'
)
yield
ws
.
write_message
(
json
.
dumps
({
'resize'
:
[
79
,
23
],
'data'
:
'bye'
})
)
ws
.
close
()
ws
.
close
()
webssh/handler.py
View file @
c439f2b6
import
io
import
io
import
json
import
logging
import
logging
import
socket
import
socket
import
threading
import
threading
...
@@ -199,7 +200,16 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
...
@@ -199,7 +200,16 @@ class WsockHandler(MixinHandler, tornado.websocket.WebSocketHandler):
def
on_message
(
self
,
message
):
def
on_message
(
self
,
message
):
logging
.
debug
(
'{!r} from {}:{}'
.
format
(
message
,
*
self
.
src_addr
))
logging
.
debug
(
'{!r} from {}:{}'
.
format
(
message
,
*
self
.
src_addr
))
worker
=
self
.
worker_ref
()
worker
=
self
.
worker_ref
()
worker
.
data_to_dst
.
append
(
message
)
msg
=
json
.
loads
(
message
)
resize
=
msg
.
get
(
'resize'
)
if
resize
:
try
:
worker
.
chan
.
resize_pty
(
*
resize
)
except
paramiko
.
SSHException
:
pass
data
=
msg
.
get
(
'data'
)
if
data
:
worker
.
data_to_dst
.
append
(
data
)
worker
.
on_write
()
worker
.
on_write
()
def
on_close
(
self
):
def
on_close
(
self
):
...
...
webssh/static/js/main.js
View file @
c439f2b6
...
@@ -38,6 +38,7 @@ jQuery(function($){
...
@@ -38,6 +38,7 @@ jQuery(function($){
});
});
function
parse_xterm_style
()
{
function
parse_xterm_style
()
{
var
text
=
$
(
'.xterm-helpers style'
).
text
();
var
text
=
$
(
'.xterm-helpers style'
).
text
();
var
arr
=
text
.
split
(
'xterm-normal-char{width:'
);
var
arr
=
text
.
split
(
'xterm-normal-char{width:'
);
...
@@ -46,13 +47,28 @@ jQuery(function($){
...
@@ -46,13 +47,28 @@ jQuery(function($){
style
.
height
=
parseInt
(
arr
[
1
]);
style
.
height
=
parseInt
(
arr
[
1
]);
}
}
function
current_geometry
()
{
function
current_geometry
()
{
if
(
!
style
.
width
||
!
style
.
height
)
{
if
(
!
style
.
width
||
!
style
.
height
)
{
parse_xterm_style
();
parse_xterm_style
();
}
}
cols
=
parseInt
(
window
.
innerWidth
/
style
.
width
);
cols
=
parseInt
(
window
.
innerWidth
/
style
.
width
);
rows
=
parseInt
(
window
.
innerHeight
/
style
.
height
);
rows
=
parseInt
(
window
.
innerHeight
/
style
.
height
);
return
[
cols
,
rows
];
return
{
'cols'
:
cols
,
'rows'
:
rows
};
}
function
resize_term
(
term
,
socket
)
{
var
geometry
=
current_geometry
(),
cols
=
geometry
.
cols
,
rows
=
geometry
.
rows
;
// console.log([cols, rows]);
// console.log(term.geometry);
if
(
cols
!=
term
.
geometry
[
0
]
||
rows
!=
term
.
geometry
[
1
])
{
console
.
log
(
'resizing term'
);
term
.
resize
(
cols
,
rows
);
socket
.
send
(
JSON
.
stringify
({
'resize'
:
[
cols
,
rows
]}));
}
}
}
...
@@ -69,19 +85,16 @@ jQuery(function($){
...
@@ -69,19 +85,16 @@ jQuery(function($){
var
ws_url
=
window
.
location
.
href
.
replace
(
'http'
,
'ws'
),
var
ws_url
=
window
.
location
.
href
.
replace
(
'http'
,
'ws'
),
join
=
(
ws_url
[
ws_url
.
length
-
1
]
==
'/'
?
''
:
'/'
),
join
=
(
ws_url
[
ws_url
.
length
-
1
]
==
'/'
?
''
:
'/'
),
url
=
ws_url
+
join
+
'ws?id='
+
msg
.
id
,
url
=
ws_url
+
join
+
'ws?id='
+
msg
.
id
,
socket
=
new
WebSocket
(
url
),
terminal
=
document
.
getElementById
(
'#terminal'
);
terminal
=
document
.
getElementById
(
'#terminal'
),
socket
=
new
WebSocket
(
url
);
geometry
=
current_geometry
();
term
=
new
Terminal
({
term
=
new
Terminal
({
cursorBlink
:
true
,
cursorBlink
:
true
,
cols
:
geometry
[
0
],
rows
:
geometry
[
1
]
});
});
console
.
log
(
url
);
console
.
log
(
url
);
term
.
on
(
'data'
,
function
(
data
)
{
term
.
on
(
'data'
,
function
(
data
)
{
// console.log(data);
// console.log(data);
socket
.
send
(
data
);
socket
.
send
(
JSON
.
stringify
({
'data'
:
data
})
);
});
});
socket
.
onopen
=
function
(
e
)
{
socket
.
onopen
=
function
(
e
)
{
...
@@ -97,6 +110,10 @@ jQuery(function($){
...
@@ -97,6 +110,10 @@ jQuery(function($){
var
text
=
decoder
.
decode
(
reader
.
result
);
var
text
=
decoder
.
decode
(
reader
.
result
);
// console.log(text);
// console.log(text);
term
.
write
(
text
);
term
.
write
(
text
);
if
(
!
term
.
resized
)
{
resize_term
(
term
,
socket
);
term
.
resized
=
true
;
}
};
};
reader
.
readAsArrayBuffer
(
msg
.
data
);
reader
.
readAsArrayBuffer
(
msg
.
data
);
};
};
...
@@ -108,17 +125,18 @@ jQuery(function($){
...
@@ -108,17 +125,18 @@ jQuery(function($){
socket
.
onclose
=
function
(
e
)
{
socket
.
onclose
=
function
(
e
)
{
console
.
log
(
e
);
console
.
log
(
e
);
term
.
destroy
();
term
.
destroy
();
term
=
undefined
;
socket
=
undefined
;
$
(
'.container'
).
show
();
$
(
'.container'
).
show
();
status
.
text
(
e
.
reason
);
status
.
text
(
e
.
reason
);
btn
.
prop
(
'disabled'
,
false
);
btn
.
prop
(
'disabled'
,
false
);
};
};
}
}
$
(
window
).
resize
(
function
(){
$
(
window
).
resize
(
function
(){
if
(
typeof
term
!=
'undefined'
)
{
if
(
typeof
term
!=
'undefined'
&&
typeof
socket
!=
'undefined'
)
{
geometry
=
current_geometry
();
resize_term
(
term
,
socket
);
term
.
geometry
=
geometry
;
term
.
resize
(
geometry
[
0
],
geometry
[
1
]);
}
}
});
});
...
...
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