Skip to content

Commit

Permalink
change font size with command shortcuts (#34)
Browse files Browse the repository at this point in the history
* add standard behavior when you double click window title to maximize/unmaximize the window

* increase/decrease font sizes with command + / -

* DRY up code. added reset to reset font to original size. added window accelerators
  • Loading branch information
jhaynie authored and rauchg committed Jul 5, 2016
1 parent cf0a578 commit 55ac59c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/hyperterm.js
Expand Up @@ -45,6 +45,9 @@ export default class HyperTerm extends Component {

this.moveLeft = this.moveLeft.bind(this);
this.moveRight = this.moveRight.bind(this);
this.resetFontSize = this.resetFontSize.bind(this);
this.increaseFontSize = this.increaseFontSize.bind(this);
this.decreaseFontSize = this.decreaseFontSize.bind(this);
}

render () {
Expand Down Expand Up @@ -224,6 +227,9 @@ export default class HyperTerm extends Component {

this.rpc.on('move left', this.moveLeft);
this.rpc.on('move right', this.moveRight);
this.rpc.on('increase font size', this.increaseFontSize);
this.rpc.on('decrease font size', this.decreaseFontSize);
this.rpc.on('reset font size', this.resetFontSize);
}

clearCurrentTerm () {
Expand Down Expand Up @@ -263,6 +269,36 @@ export default class HyperTerm extends Component {
}
}

changeFontSize (value) {
const uid = this.state.sessions[this.state.active];
const term = this.refs[`term-${uid}`];
if (term) {
try {
const size = term.term.prefs_.get('font-size');
term.term.prefs_.set('font-size', size + value);
} catch (e) {
alert(e);
}
}
}

resetFontSize () {
const uid = this.state.sessions[this.state.active];
const term = this.refs[`term-${uid}`];
if (term) {
//TODO: once we have preferences, we need to read from it
term.term.prefs_.set('font-size', 12);
}
}

increaseFontSize () {
this.changeFontSize(1);
}

decreaseFontSize () {
this.changeFontSize(-1);
}

onSessionExit ({ uid }) {
if (!~this.state.sessions.indexOf(uid)) {
console.log('ignore exit of', uid);
Expand Down Expand Up @@ -341,6 +377,9 @@ export default class HyperTerm extends Component {
keys.bind('command+shift+]', this.moveRight);
keys.bind('command+alt+left', this.moveLeft);
keys.bind('command+alt+right', this.moveRight);
keys.bind('command+=', this.increaseFontSize);
keys.bind('command+-', this.decreaseFontSize);
keys.bind('command+0', this.resetFontSize);

this.keys = keys;
}
Expand Down
27 changes: 27 additions & 0 deletions index.js
Expand Up @@ -230,6 +230,33 @@ app.on('ready', () => {
},
{
role: 'togglefullscreen'
},
{
label: 'Actual Size',
accelerator: 'CmdOrCtrl+0',
click (item, focusedWindow) {
if (focusedWindow) {
focusedWindow.rpc.emit('reset font size');
}
}
},
{
label: 'Zoom In',
accelerator: 'CmdOrCtrl+plus',
click (item, focusedWindow) {
if (focusedWindow) {
focusedWindow.rpc.emit('increase font size');
}
}
},
{
label: 'Zoom Out',
accelerator: 'CmdOrCtrl+-',
click (item, focusedWindow) {
if (focusedWindow) {
focusedWindow.rpc.emit('decrease font size');
}
}
}
]
},
Expand Down

0 comments on commit 55ac59c

Please sign in to comment.