Skip to content

Commit

Permalink
add hterm cursor blink support (#1547)
Browse files Browse the repository at this point in the history
* add hterm cursor blink support

* update website with cursorblink doc
  • Loading branch information
Henrik authored and rauchg committed Feb 18, 2017
1 parent 27cf69f commit 0ee48c9
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/config-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ module.exports = {
// `BEAM` for |, `UNDERLINE` for _, `BLOCK` for █
cursorShape: 'BLOCK',

// set to true for blinking cursor
cursorBlink: false,

This comment has been minimized.

Copy link
@rnagella

rnagella Mar 9, 2017

This is fun when you set this to true and use hyperpower plugin. Thanks.


// color of the text
foregroundColor: '#fff',

Expand Down
1 change: 1 addition & 0 deletions lib/components/term-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class TermGroup_ extends Component {
fontSize: this.props.fontSize,
cursorColor: this.props.cursorColor,
cursorShape: this.props.cursorShape,
cursorBlink: this.props.cursorBlink,
fontFamily: this.props.fontFamily,
fontSmoothing: this.props.fontSmoothing,
foregroundColor: this.props.foregroundColor,
Expand Down
10 changes: 10 additions & 0 deletions lib/components/term.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default class Term extends Component {
prefs.set('font-size', props.fontSize);
prefs.set('font-smoothing', props.fontSmoothing);
prefs.set('cursor-color', this.validateColor(props.cursorColor, 'rgba(255,255,255,0.5)'));
prefs.set('cursor-blink', props.cursorBlink);
prefs.set('enable-clipboard-notice', false);
prefs.set('foreground-color', props.foregroundColor);

Expand Down Expand Up @@ -77,6 +78,8 @@ export default class Term extends Component {
this.term.modifierKeys = props.modifierKeys;
// this.term.CursorNode_ is available at this point.
this.term.setCursorShape(props.cursorShape);
// required to be set for CursorBlink to work
this.term.setCursorVisible(true);

// emit onTitle event when hterm instance
// wants to set the title of its tab
Expand Down Expand Up @@ -333,6 +336,10 @@ export default class Term extends Component {
this.term.setCursorShape(nextProps.cursorShape);
}

if (this.props.cursorBlink !== nextProps.cursorBlink) {
prefs.set('cursor-blink', nextProps.cursorBlink);
}

if (this.props.colors !== nextProps.colors) {
prefs.set('color-palette-overrides', getColorList(nextProps.colors));
}
Expand All @@ -355,6 +362,9 @@ export default class Term extends Component {
}

componentWillUnmount() {
// turn blinking off to prevent leaking a timeout when disposing terminal
const prefs = this.term.getPrefs();
prefs.set('cursor-blink', false);
clearTimeout(this.scrollbarsHideTimer);
this.props.ref_(null);
}
Expand Down
1 change: 1 addition & 0 deletions lib/components/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export default class Terms extends Component {
borderColor: this.props.borderColor,
cursorColor: this.props.cursorColor,
cursorShape: this.props.cursorShape,
cursorBlink: this.props.cursorBlink,
fontFamily: this.props.fontFamily,
fontSmoothing: this.props.fontSmoothing,
foregroundColor: this.props.foregroundColor,
Expand Down
1 change: 1 addition & 0 deletions lib/containers/terms.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const TermsContainer = connect(
padding: state.ui.padding,
cursorColor: state.ui.cursorColor,
cursorShape: state.ui.cursorShape,
cursorBlink: state.ui.cursorBlink,
borderColor: state.ui.borderColor,
colors: state.ui.colors,
foregroundColor: state.ui.foregroundColor,
Expand Down
6 changes: 6 additions & 0 deletions lib/reducers/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {UPDATE_AVAILABLE} from '../constants/updater';
import {values} from '../utils/object';

const allowedCursorShapes = new Set(['BEAM', 'BLOCK', 'UNDERLINE']);
const allowedCursorBlinkValues = new Set([true, false]);
const allowedBells = new Set(['SOUND', false]);
const allowedHamburgerMenuValues = new Set([true, false]);
const allowedWindowControlsValues = new Set([true, false, 'left']);
Expand All @@ -34,6 +35,7 @@ const initial = Immutable({
activeUid: null,
cursorColor: '#F81CE5',
cursorShape: 'BLOCK',
cursorBlink: false,
borderColor: '#333',
fontSize: 12,
padding: '12px 14px',
Expand Down Expand Up @@ -125,6 +127,10 @@ const reducer = (state = initial, action) => {
ret.cursorShape = config.cursorShape;
}

if (allowedCursorBlinkValues.has(config.cursorBlink)) {
ret.cursorBlink = config.cursorBlink;
}

if (config.borderColor) {
ret.borderColor = config.borderColor;
}
Expand Down
5 changes: 5 additions & 0 deletions website/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,11 @@ <h2 id="cfg"><a href="#cfg">Configuration</a></h2>
<td>"BLOCK"</td>
<td>The shape of the caret in the terminal. Available options are: 'BEAM', 'UNDERLINE', 'BLOCK'</td>
</tr>
<tr>
<td>"cursorBlink"</td>
<td>"false"</td>
<td>If true, cursor will blink</td>
</tr>
<tr>
<td>"foregroundColor"</td>
<td>"#fff"</td>
Expand Down

0 comments on commit 0ee48c9

Please sign in to comment.