Skip to content

Commit

Permalink
Work with (and require) newer notebook version
Browse files Browse the repository at this point in the history
- Update for newer version & location of xterm
- Bump minimum required notebook version
  • Loading branch information
yuvipanda committed Jun 15, 2018
1 parent de5a21a commit 3714d00
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 44 deletions.
48 changes: 6 additions & 42 deletions nbgitpuller/static/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
require([
'jquery',
'base/js/utils',
'components/xterm.js/dist/xterm'
'components/xterm.js/index',
'components/xterm.js-fit/index'
], function(
$,
utils,
Terminal
Terminal,
fit
) {

Terminal.applyAddon(fit);

function GitSync(baseUrl, repo, branch, path) {
// Class that talks to the API backend & emits events as appropriate
Expand Down Expand Up @@ -82,7 +85,7 @@ require([
$(this.termSelector).parent().addClass('hidden');
}
this.visible = visible;
this._fitTerm();
this.term.fit();
}

GitSyncView.prototype.setProgressValue = function(val) {
Expand Down Expand Up @@ -110,45 +113,6 @@ require([
}
};

GitSyncView.prototype._fitTerm = function() {
// Vendored in from the xterm.js fit addon
// Because I can't for the life of me get the addon to be
// actually included here as an require.js thing.
// And life is too short.
var term = this.term;
if (!term.element.parentElement) {
return null;
}
var parentElementStyle = window.getComputedStyle(term.element.parentElement),
parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height')),
parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')) - 17),
elementStyle = window.getComputedStyle(term.element),
elementPaddingVer = parseInt(elementStyle.getPropertyValue('padding-top')) + parseInt(elementStyle.getPropertyValue('padding-bottom')),
elementPaddingHor = parseInt(elementStyle.getPropertyValue('padding-right')) + parseInt(elementStyle.getPropertyValue('padding-left')),
availableHeight = parentElementHeight - elementPaddingVer,
availableWidth = parentElementWidth - elementPaddingHor,
container = term.rowContainer,
subjectRow = term.rowContainer.firstElementChild,
contentBuffer = subjectRow.innerHTML,
characterHeight,
rows,
characterWidth,
cols,
geometry;

subjectRow.style.display = 'inline';
subjectRow.innerHTML = 'W'; // Common character for measuring width, although on monospace
characterWidth = subjectRow.getBoundingClientRect().width;
subjectRow.style.display = ''; // Revert style before calculating height, since they differ.
characterHeight = subjectRow.getBoundingClientRect().height;
subjectRow.innerHTML = contentBuffer;

rows = parseInt(availableHeight / characterHeight);
cols = parseInt(availableWidth / characterWidth);

term.resize(cols, rows);
};

var gs = new GitSync(
utils.get_body_data('baseUrl'),
utils.get_body_data('repo'),
Expand Down
2 changes: 1 addition & 1 deletion nbgitpuller/templates/status.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
{{super()}}

<link rel="stylesheet" href="{{ static_url("terminal/css/override.css") }}" type="text/css" />
<link rel="stylesheet" href="{{ static_url("components/xterm.js/dist/xterm.css") }}" type="text/css" />
<link rel="stylesheet" href="{{ static_url("components/xterm.js-css/index.css") }}" type="text/css" />
<style>
#status-details-container {
padding: 16px;
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
packages=find_packages(),
include_package_data=True,
platforms='any',
install_requires=['notebook', 'tornado'],
install_requires=['notebook>=5.5.0', 'tornado'],
entry_points={
'console_scripts': [
'gitpuller = nbgitpuller.pull:main',
Expand Down

0 comments on commit 3714d00

Please sign in to comment.