Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to xterm.js #25

Merged
merged 3 commits into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,10 @@
],
"dependencies": {
"angular": ">=1.3.8 <1.6",
"term.js": "#0.0.7",
"xterm.js": "#2.8.0",
"font-awesome": "*"
},
"devDependencies": {
"patternfly": ">=1.2.1"
},
"overrides": {
"term.js": {
"main": [
"src/term.js"
]
}
}
}
39 changes: 32 additions & 7 deletions container-terminal.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kubernetes-container-terminal {
position: relative;
display: block;
display: inline-block;
}

kubernetes-container-terminal .terminal {
Expand All @@ -9,11 +9,9 @@ kubernetes-container-terminal .terminal {
color: #F0F0F0;
text-align: left;
outline: medium none;
background-color: black;
border: 1px solid black;
padding: 10px;
display: inline-block; /* size DIV to contents */
border: 3px solid black;
line-height: 1em;
display: inline-block;
}

@media (min-width: 568px) {
Expand All @@ -25,12 +23,11 @@ kubernetes-container-terminal .terminal {
kubernetes-container-terminal .terminal-cursor {
background: #f0f0f0;
color: #000;
position: absolute;
}

kubernetes-container-terminal .terminal-wrapper {
display: inline-block;
vertical-align: top;
display: inline-block;
}

kubernetes-container-terminal .terminal-actions {
Expand All @@ -42,6 +39,34 @@ kubernetes-container-terminal .terminal-actions {
z-index: 1;
}

kubernetes-container-terminal .terminal .xterm-viewport {
overflow-y: auto;
}

kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar {
height: 10px;
overflow: visible;
width: 15px;
}

kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar-corner {
background: transparent;
}

kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar-thumb {
background-color: rgba(255,255,255,.25);
box-shadow: inset 1px 1px 0 rgba(255,255,255,.1),inset 0 -1px 0 rgba(255,255,255,.07);
}

kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar-thumb:active,
kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar-thumb:hover {
background-color: rgba(255,255,255,.35);
}

kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar-track {
background: transparent;
}

/* https://github.com/patternfly/patternfly/pull/135 */
.spinner-white {
border-bottom: 4px solid rgba(255, 255, 255, 0.25) !important;
Expand Down
19 changes: 18 additions & 1 deletion container-terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@
var term = new Terminal({
cols: scope.cols || defaultCols,
rows: scope.rows || defaultRows,
screenKeys: scope.screenKeys || true
cursorBlink: true,
screenKeys: scope.screenKeys || true,
applicationCursor: true, // Needed for proper scrollback behavior in applications like vi
mouseEvents: true // Needed for proper scrollback behavior in applications like vi
});

outer.empty();
Expand All @@ -121,10 +124,24 @@
ws.send("0" + utf8_to_b64(data));
});

var sizeViewport = function () {
var cols = scope.cols || defaultCols;
if (!term.charMeasure.width) {
return;
}
var xtermViewport = document.getElementsByClassName("xterm-viewport")[0];
// character width * number of columns + space for a scrollbar
// TODO determine the max width of a scrollbar across browsers
xtermViewport.style.width = (term.charMeasure.width * cols + 17) + "px";
};

term.charMeasure.on('charsizechanged', sizeViewport);

var sizeTerminal = function() {
var cols = scope.cols || defaultCols;
var rows = scope.rows || defaultRows;
term.resize(cols, rows);
sizeViewport();
if (ws && ws.readyState === 1) {
ws.send("4" + window.btoa('{"Width":' + cols + ',"Height":' + rows + '}'));
}
Expand Down
39 changes: 32 additions & 7 deletions dist/container-terminal.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
kubernetes-container-terminal {
position: relative;
display: block;
display: inline-block;
}

kubernetes-container-terminal .terminal {
Expand All @@ -9,11 +9,9 @@ kubernetes-container-terminal .terminal {
color: #F0F0F0;
text-align: left;
outline: medium none;
background-color: black;
border: 1px solid black;
padding: 10px;
display: inline-block; /* size DIV to contents */
border: 3px solid black;
line-height: 1em;
display: inline-block;
}

@media (min-width: 568px) {
Expand All @@ -25,12 +23,11 @@ kubernetes-container-terminal .terminal {
kubernetes-container-terminal .terminal-cursor {
background: #f0f0f0;
color: #000;
position: absolute;
}

kubernetes-container-terminal .terminal-wrapper {
display: inline-block;
vertical-align: top;
display: inline-block;
}

kubernetes-container-terminal .terminal-actions {
Expand All @@ -42,6 +39,34 @@ kubernetes-container-terminal .terminal-actions {
z-index: 1;
}

kubernetes-container-terminal .terminal .xterm-viewport {
overflow-y: auto;
}

kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar {
height: 10px;
overflow: visible;
width: 15px;
}

kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar-corner {
background: transparent;
}

kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar-thumb {
background-color: rgba(255,255,255,.25);
box-shadow: inset 1px 1px 0 rgba(255,255,255,.1),inset 0 -1px 0 rgba(255,255,255,.07);
}

kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar-thumb:active,
kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar-thumb:hover {
background-color: rgba(255,255,255,.35);
}

kubernetes-container-terminal .terminal .xterm-viewport::-webkit-scrollbar-track {
background: transparent;
}

/* https://github.com/patternfly/patternfly/pull/135 */
.spinner-white {
border-bottom: 4px solid rgba(255, 255, 255, 0.25) !important;
Expand Down
19 changes: 18 additions & 1 deletion dist/container-terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@
var term = new Terminal({
cols: scope.cols || defaultCols,
rows: scope.rows || defaultRows,
screenKeys: scope.screenKeys || true
cursorBlink: true,
screenKeys: scope.screenKeys || true,
applicationCursor: true, // Needed for proper scrollback behavior in applications like vi
mouseEvents: true // Needed for proper scrollback behavior in applications like vi
});

outer.empty();
Expand All @@ -121,10 +124,24 @@
ws.send("0" + utf8_to_b64(data));
});

var sizeViewport = function () {
var cols = scope.cols || defaultCols;
if (!term.charMeasure.width) {
return;
}
var xtermViewport = document.getElementsByClassName("xterm-viewport")[0];
// character width * number of columns + space for a scrollbar
// TODO determine the max width of a scrollbar across browsers
xtermViewport.style.width = (term.charMeasure.width * cols + 17) + "px";
};

term.charMeasure.on('charsizechanged', sizeViewport);

var sizeTerminal = function() {
var cols = scope.cols || defaultCols;
var rows = scope.rows || defaultRows;
term.resize(cols, rows);
sizeViewport();
if (ws && ws.readyState === 1) {
ws.send("4" + window.btoa('{"Width":' + cols + ',"Height":' + rows + '}'));
}
Expand Down
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
</style>
<link rel="stylesheet" href="bower_components/patternfly/dist/css/patternfly.css">
<link rel="stylesheet" href="bower_components/patternfly/dist/css/patternfly-additions.css">
<link rel="stylesheet" href="bower_components/xterm.js/dist/xterm.css">
<link rel="stylesheet" href="container-terminal.css">
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/term.js/src/term.js"></script>
<script src="bower_components/xterm.js/dist/xterm.js"></script>
<script src="container-terminal.js"></script>
</head>
<body ng-app="exampleApp">
Expand Down