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

font size improvements #57

Merged
merged 5 commits into from Jul 6, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/css/hyperterm.css
Expand Up @@ -44,15 +44,20 @@ header {
}

.resize-indicator {
background: rgba(255, 255, 255, .2);
padding: 6px 14px;
color: #fff;
font: 11px Menlo;
position: fixed;
bottom: 20px;
right: 20px;
opacity: 0;
transition: opacity 150ms ease-in;
display: flex;
}

.resize-indicator > div {
background: rgba(255, 255, 255, .2);
padding: 6px 14px;
margin-left: 10px;
}

.resize-indicator.showing {
Expand Down
40 changes: 20 additions & 20 deletions app/hyperterm.js
Expand Up @@ -22,8 +22,10 @@ export default class HyperTerm extends Component {
activeMarkers: [],
mac: /Mac/.test(navigator.userAgent),
resizeIndicatorShowing: false,
fontSizeIndicatorShowing: false,
updateVersion: null,
updateNote: null
updateNote: null,
fontSize: 12
};

// we set this to true when the first tab
Expand Down Expand Up @@ -77,6 +79,7 @@ export default class HyperTerm extends Component {
ref={`term-${uid}`}
cols={this.state.cols}
rows={this.state.rows}
fontSize={this.state.fontSize}
url={this.state.urls[uid]}
onResize={this.onResize}
onTitle={this.setTitle.bind(this, uid)}
Expand All @@ -89,7 +92,8 @@ export default class HyperTerm extends Component {
}</div>
</div>
<div className={classes('resize-indicator', { showing: this.state.resizeIndicatorShowing })}>
{ this.state.cols }x{ this.state.rows }
{this.state.fontSizeIndicatorShowing && <div>{ this.state.fontSize }px</div>}
<div>{ this.state.cols }x{ this.state.rows }</div>
</div>
<div className={classes('update-indicator', { showing: null !== this.state.updateVersion })}>
Update available (<b>{ this.state.updateVersion }</b>).
Expand Down Expand Up @@ -269,30 +273,28 @@ export default class HyperTerm extends Component {
}
}

changeFontSize (value) {
const uid = this.state.sessions[this.state.active];
const term = this.refs[`term-${uid}`];
if (term) {
const size = term.term.prefs_.get('font-size');
term.term.prefs_.set('font-size', size + value);
}
changeFontSize (value, { relative = false } = {}) {
this.setState({
fontSize: relative ? this.state.fontSize + value : value,
fontSizeIndicatorShowing: true
});

clearTimeout(this.fontSizeIndicatorTimeout);
this.fontSizeIndicatorTimeout = setTimeout(() => {
this.setState({ fontSizeIndicatorShowing: false });
}, 1500);
}

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);
}
this.changeFontSize(12);
}

increaseFontSize () {
this.changeFontSize(1);
this.changeFontSize(1, { relative: true });
}

decreaseFontSize () {
this.changeFontSize(-1);
this.changeFontSize(-1, { relative: true });
}

onSessionExit ({ uid }) {
Expand Down Expand Up @@ -373,9 +375,6 @@ 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 Expand Up @@ -456,6 +455,7 @@ export default class HyperTerm extends Component {
componentWillUnmount () {
this.rpc.destroy();
clearTimeout(this.resizeIndicatorTimeout);
clearTimeout(this.fontSizeIndicatorTimeout);
if (this.keys) this.keys.reset();
delete this.clicks;
clearTimeout(this.clickTimer);
Expand Down
8 changes: 7 additions & 1 deletion app/term.js
Expand Up @@ -62,7 +62,7 @@ export default class Term extends Component {
}

this.term.prefs_.set('font-family', "Menlo, 'DejaVu Sans Mono', 'Lucida Console', monospace");
this.term.prefs_.set('font-size', 11);
this.term.prefs_.set('font-size', this.props.fontSize);
this.term.prefs_.set('cursor-color', '#F81CE5');
this.term.prefs_.set('enable-clipboard-notice', false);
this.term.prefs_.set('background-color', '#000');
Expand Down Expand Up @@ -90,6 +90,12 @@ export default class Term extends Component {
return this.term.document_;
}

componentWillReceiveProps (nextProps) {
if (this.props.fontSize !== nextProps.fontSize) {
this.term.prefs_.set('font-size', nextProps.fontSize);
}
}

shouldComponentUpdate (nextProps) {
if (this.props.url !== nextProps.url) {
// when the url prop changes, we make sure
Expand Down