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
4ae2a336
Commit
4ae2a336
authored
Aug 21, 2018
by
Sheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added resize_terminal function to wssh
parent
e0cc2091
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
44 additions
and
27 deletions
+44
-27
main.js
webssh/static/js/main.js
+44
-27
No files found.
webssh/static/js/main.js
View file @
4ae2a336
...
@@ -30,19 +30,10 @@ jQuery(function($){
...
@@ -30,19 +30,10 @@ jQuery(function($){
}
}
function
resize_term
(
term
,
sock
)
{
wssh
.
window_size
=
function
()
{
var
geometry
=
current_geometry
(),
var
geo
=
current_geometry
();
cols
=
geometry
.
cols
,
console
.
log
(
'Current window size: '
+
geo
.
cols
+
','
+
geo
.
rows
);
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
);
sock
.
send
(
JSON
.
stringify
({
'resize'
:
[
cols
,
rows
]}));
}
}
function
callback
(
msg
)
{
function
callback
(
msg
)
{
...
@@ -67,10 +58,15 @@ jQuery(function($){
...
@@ -67,10 +58,15 @@ jQuery(function($){
console
.
log
(
url
);
console
.
log
(
url
);
console
.
log
(
'The deault encoding of your server is '
+
encoding
);
console
.
log
(
'The deault encoding of your server is '
+
encoding
);
wssh
.
sock
=
sock
;
//
wssh.sock = sock;
wssh
.
term
=
term
;
//
wssh.term = term;
var
test_decoder
;
var
test_decoder
;
function
resize_terminal
(
term
)
{
var
geometry
=
current_geometry
();
term
.
on_resize
(
geometry
.
cols
,
geometry
.
rows
);
}
wssh
.
set_encoding
=
function
(
new_encoding
)
{
wssh
.
set_encoding
=
function
(
new_encoding
)
{
try
{
try
{
test_decoder
=
new
window
.
TextDecoder
(
new_encoding
);
test_decoder
=
new
window
.
TextDecoder
(
new_encoding
);
...
@@ -90,6 +86,34 @@ jQuery(function($){
...
@@ -90,6 +86,34 @@ jQuery(function($){
console
.
log
(
'Reset encoding to '
+
msg
.
encoding
);
console
.
log
(
'Reset encoding to '
+
msg
.
encoding
);
};
};
wssh
.
resize_terminal
=
function
(
raw_cols
,
raw_rows
)
{
// for console use
var
cols
=
parseInt
(
raw_cols
,
10
),
rows
=
parseInt
(
raw_rows
,
10
),
valid_args
=
false
;
if
(
cols
>
0
&&
rows
>
0
)
{
var
geometry
=
current_geometry
();
if
(
cols
<=
geometry
.
cols
&&
rows
<=
geometry
.
rows
)
{
valid_args
=
true
;
}
}
if
(
!
valid_args
)
{
console
.
log
(
'Invalid arguments: '
+
raw_cols
+
','
+
raw_rows
);
}
else
{
term
.
on_resize
(
cols
,
rows
);
}
};
term
.
on_resize
=
function
(
cols
,
rows
)
{
if
(
cols
!==
this
.
geometry
[
0
]
||
rows
!==
this
.
geometry
[
1
])
{
console
.
log
(
'Resizing terminal size to: '
+
cols
+
','
+
rows
);
this
.
resize
(
cols
,
rows
);
sock
.
send
(
JSON
.
stringify
({
'resize'
:
[
cols
,
rows
]}));
}
};
term
.
on
(
'data'
,
function
(
data
)
{
term
.
on
(
'data'
,
function
(
data
)
{
// console.log(data);
// console.log(data);
sock
.
send
(
JSON
.
stringify
({
'data'
:
data
}));
sock
.
send
(
JSON
.
stringify
({
'data'
:
data
}));
...
@@ -110,7 +134,7 @@ jQuery(function($){
...
@@ -110,7 +134,7 @@ jQuery(function($){
// console.log(text);
// console.log(text);
term
.
write
(
text
);
term
.
write
(
text
);
if
(
!
term
.
resized
)
{
if
(
!
term
.
resized
)
{
resize_term
(
term
,
sock
);
resize_term
inal
(
term
);
term
.
resized
=
true
;
term
.
resized
=
true
;
}
}
};
};
...
@@ -125,12 +149,14 @@ jQuery(function($){
...
@@ -125,12 +149,14 @@ jQuery(function($){
sock
.
onclose
=
function
(
e
)
{
sock
.
onclose
=
function
(
e
)
{
console
.
log
(
e
);
console
.
log
(
e
);
term
.
destroy
();
term
.
destroy
();
wssh
.
term
=
undefined
;
wssh
.
sock
=
undefined
;
$
(
'.container'
).
show
();
$
(
'.container'
).
show
();
status
.
text
(
e
.
reason
);
status
.
text
(
e
.
reason
);
btn
.
prop
(
'disabled'
,
false
);
btn
.
prop
(
'disabled'
,
false
);
};
};
$
(
window
).
resize
(
function
(){
resize_terminal
(
term
);
});
}
}
...
@@ -165,14 +191,5 @@ jQuery(function($){
...
@@ -165,14 +191,5 @@ jQuery(function($){
contentType
:
false
,
contentType
:
false
,
processData
:
false
processData
:
false
});
});
});
});
$
(
window
).
resize
(
function
(){
if
(
wssh
.
term
&&
wssh
.
sock
)
{
resize_term
(
wssh
.
term
,
wssh
.
sock
);
}
});
});
});
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