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

Work with (and require) newer notebook version #46

Merged
merged 2 commits into from
Jul 18, 2018
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
56 changes: 13 additions & 43 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 @@ -63,7 +66,6 @@ require([
convertEol: true
});
this.visible = false;
this.term.open($(termSelector)[0]);
this.$progress = $(progressSelector);

this.$termToggle = $(termToggleSelector);
Expand All @@ -82,7 +84,14 @@ require([
$(this.termSelector).parent().addClass('hidden');
}
this.visible = visible;
this._fitTerm();
if (visible) {
// See https://github.com/data-8/nbgitpuller/pull/46 on why this is here.
if (!this.term.element) {
this.term.open($(this.termSelector)[0]);
}
this.term.fit();
}

}

GitSyncView.prototype.setProgressValue = function(val) {
Expand Down Expand Up @@ -110,45 +119,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