Skip to content

Commit

Permalink
JS prettier formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tombh committed Jul 11, 2018
1 parent c2fe5a1 commit d66d3e2
Show file tree
Hide file tree
Showing 24 changed files with 3,111 additions and 1,635 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -22,14 +22,15 @@ env:
- secure: "boYctu4EQI2og3YWpD54yo1LzibgBNrYN3exbfwxaNNbJuQscprAlOOG5Y1O7MBgzG9AP1DeON3X0al7g/IYMrsMsrSGhJLq9w2/ntwMiUIyKfTAP8rB5fASRSYxA5mqhpjXK4iIzqG2xiOr1SmCbpT9ew0AXP/HgxQprsppBbH+H4HyrP4cejIbfk8ajU/XvrDmhOY4s/IZIy+vfEfZH5xheJnG3iWFICwWUF5CIjjr6fQpq9ZbL2sDMvzruYPMAQ3iDfBrUr+ZhN4PPjrzvCRUNpoUoPsXCsFDPMcZpBjSHH5ZELPRBzHSdJignIjHaV0UtLtFApZl49lzq749r2Sno2ba4JCd0RIgMERjNluXynkJiHrL2tMR8HYhOmoeLMdX0zrguv+136+Jn04gQde3S+FI1/sN0/Xa14xD7SGMUT1MgFnwKgFXOFeUd3VpvbpFg6RWVgpCnaDd2/AKL+mQDEgL4yRg9q95a6Q5ub/c6nla8/E4asEvYGlJPj0OG/MKvJMi0gnKuP4+nil0jgGeKki3k1UxwvldlS+n7HUhQ7c4B9c61KS19i+z5SxBiXjilL+zGlAVVgRcalIoKQrTRDSRKnKZkR5Ant0CLjt44pncHLwlYXD/aPuLNihCa4AqUlpYPYru0pQawXNkVnk6E/cg2DAsp7oDcpcg540="

before_install:
- diff -u <(echo -n) <(gofmt -d ./)
- ./interfacer/contrib/setup_go.sh
- ./webext/contrib/setup_node.sh
- mkdir -p $REPO_ROOT && cp -rfp $TRAVIS_BUILD_DIR -T $REPO_ROOT
install:
- cd $REPO_ROOT/interfacer && dep ensure
- cd $REPO_ROOT/webext
- source ~/.nvm/nvm.sh
- diff -u <(echo -n) <(gofmt -d ./)
- prettier --list-different "webext/{src,test}/**/*.js"
- npm run get-gobindata
- npm install
- npm run build
Expand Down
2,320 changes: 1,796 additions & 524 deletions webext/package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions webext/package.json
Expand Up @@ -18,6 +18,7 @@
"copy-webpack-plugin": "^4.5.2",
"eslint": "^5.1.0",
"mocha": "^5.2.0",
"prettier": "1.13.7",
"pty.js": "^0.3.1",
"sinon": "^6.1.3",
"strip-ansi": "^4.0.0",
Expand Down
57 changes: 30 additions & 27 deletions webext/src/background/common_mixin.js
@@ -1,36 +1,39 @@
import stripAnsi from 'strip-ansi';
import stripAnsi from "strip-ansi";

// Here we keep the public functions used to mediate communications between
// the background process, tabs and the terminal.
export default (MixinBase) => class extends MixinBase {
sendToCurrentTab(message) {
if (this.currentTab().channel === undefined) {
this.log(`Attempting to send "${message}" to tab without a channel`);
} else {
this.currentTab().channel.postMessage(message);
export default MixinBase =>
class extends MixinBase {
sendToCurrentTab(message) {
if (this.currentTab().channel === undefined) {
this.log(`Attempting to send "${message}" to tab without a channel`);
} else {
this.currentTab().channel.postMessage(message);
}
}
}

sendToTerminal(message) {
if (this.terminal === undefined) { return }
if (this.terminal.readyState === 1) {
this.terminal.send(message);
sendToTerminal(message) {
if (this.terminal === undefined) {
return;
}
if (this.terminal.readyState === 1) {
this.terminal.send(message);
}
}
}

log(...messages) {
if (messages === undefined) {
messages = "undefined";
log(...messages) {
if (messages === undefined) {
messages = "undefined";
}
if (messages.length === 1) {
messages = messages[0].toString();
messages = stripAnsi(messages);
messages = messages.replace(/\u001b\[/g, "ESC");
}
this.sendToTerminal(messages);
}
if (messages.length === 1) {
messages = messages[0].toString();
messages = stripAnsi(messages);
messages = messages.replace(/\u001b\[/g, 'ESC');
}
this.sendToTerminal(messages);
}

currentTab() {
return this.tabs[this.active_tab_id];
}
}
currentTab() {
return this.tabs[this.active_tab_id];
}
};
56 changes: 33 additions & 23 deletions webext/src/background/dimensions.js
@@ -1,7 +1,7 @@
import _ from 'lodash';
import _ from "lodash";

import utils from 'utils';
import CommonMixin from 'background/common_mixin';
import utils from "utils";
import CommonMixin from "background/common_mixin";

export default class extends utils.mixins(CommonMixin) {
constructor() {
Expand All @@ -25,56 +25,66 @@ export default class extends utils.mixins(CommonMixin) {
this.raw_text_tty_size = {
width: 100,
height: 30
}
};
}

setCharValues(incoming) {
if (this.char.width != incoming.width ||
this.char.height != incoming.height) {
if (
this.char.width != incoming.width ||
this.char.height != incoming.height
) {
this.char = _.clone(incoming);
this.log(
`Requesting browser resize for new char dimensions: ` +
`${this.char.width}x${this.char.height}`
`${this.char.width}x${this.char.height}`
);
this.resizeBrowserWindow();
}
}

resizeBrowserWindow() {
if (!this.tty.width || !this.char.width || !this.tty.height || !this.char.height) {
if (
!this.tty.width ||
!this.char.width ||
!this.tty.height ||
!this.char.height
) {
this.log(
'Not resizing browser window without all of the TTY and character dimensions'
"Not resizing browser window without all of the TTY and character dimensions"
);
return;
}
// Does this include scrollbars???
const window_width = parseInt(Math.round(this.tty.width * this.char.width));
// Leave room for tabs and URL bar
const tty_dom_height = this.tty.height - 2;
const window_height = parseInt(Math.round(
(tty_dom_height + this._window_ui_magic_number) * this.char.height
));
const window_height = parseInt(
Math.round(
(tty_dom_height + this._window_ui_magic_number) * this.char.height
)
);
const current_window = browser.windows.getCurrent();
current_window.then(
active_window => {
this._sendWindowResizeRequest(active_window, window_width, window_height);
this._sendWindowResizeRequest(
active_window,
window_width,
window_height
);
},
error => {
this.log('Error getting current browser window', error);
this.log("Error getting current browser window", error);
}
);
}

_sendWindowResizeRequest(active_window, width, height) {
const tag = 'Resizing browser window';
const updating = browser.windows.update(
active_window.id,
{
width: width,
height: height,
focused: false
}
);
const tag = "Resizing browser window";
const updating = browser.windows.update(active_window.id, {
width: width,
height: height,
focused: false
});
updating.then(
info => this.log(`${tag} successful (${info.width}x${info.height})`),
error => this.log(tag + " error: ", error)
Expand Down

0 comments on commit d66d3e2

Please sign in to comment.