From 75bb9e91e44b550c8d2dfc8120fe05d6b7bb10fe Mon Sep 17 00:00:00 2001 From: Bryan Ashby Date: Mon, 27 Apr 2015 20:19:17 -0600 Subject: [PATCH] * Some work on cursor hiding while redrawing. WIP. --- core/ansi_term.js | 20 ++++++++++++++++++++ core/client.js | 3 +++ core/edit_text_view.js | 7 +++++++ core/spinner_menu_view.js | 10 ++-------- core/text_view.js | 1 + core/view.js | 16 +++++++++++++++- 6 files changed, 48 insertions(+), 9 deletions(-) diff --git a/core/ansi_term.js b/core/ansi_term.js index 3c5d8165..e8472761 100644 --- a/core/ansi_term.js +++ b/core/ansi_term.js @@ -26,6 +26,7 @@ exports.goHome = goHome; exports.disableVT100LineWrapping = disableVT100LineWrapping; exports.setSyncTERMFont = setSyncTERMFont; exports.getSyncTERMFontFromAlias = getSyncTERMFontFromAlias; +exports.setCursorStyle = setCursorStyle; exports.fromPipeCode = fromPipeCode; @@ -247,6 +248,25 @@ function getSyncTERMFontFromAlias(alias) { return FONT_ALIAS_TO_SYNCTERM_MAP[alias.toLowerCase().replace(/ /g, '_')]; } +var DEC_CURSOR_STYLE = { + 'blinking block' : 0, + 'default' : 1, + 'steady block' : 2, + 'blinking underline' : 3, + 'steady underline' : 4, + 'blinking bar' : 5, + 'steady bar' : 6, +}; + +function setCursorStyle(cursorStyle) { + var ps = DEC_CURSOR_STYLE[cursorStyle]; + if(ps) { + return ESC_CSI + ps + ' q'; + } + return ''; + +} + /* var FONT_MAP = { diff --git a/core/client.js b/core/client.js index df0ed384..e142d2d8 100644 --- a/core/client.js +++ b/core/client.js @@ -23,6 +23,7 @@ var ANSI_KEY_NAME_MAP = { 0x7f : 'del', 0x1b : 'esc', 0x0d : 'enter', + 0x19 : 'ctrl-y' }; var ANSI_KEY_CSI_NAME_MAP = { @@ -94,6 +95,8 @@ function Client(input, output) { var c; var name; + console.log(data) + if(1 === len) { c = data[0]; diff --git a/core/edit_text_view.js b/core/edit_text_view.js index 5a26976f..3028e0b8 100644 --- a/core/edit_text_view.js +++ b/core/edit_text_view.js @@ -4,6 +4,8 @@ var TextView = require('./text_view.js').TextView; var miscUtil = require('./misc_util.js'); var strUtil = require('./string_util.js'); +var ansi = require('./ansi_term.js'); + var util = require('util'); var assert = require('assert'); var _ = require('lodash'); @@ -13,6 +15,7 @@ exports.EditTextView = EditTextView; function EditTextView(options) { options.acceptsFocus = miscUtil.valueWithDefault(options.acceptsFocus, true); options.acceptsInput = miscUtil.valueWithDefault(options.acceptsInput, true); + options.cursorStyle = miscUtil.valueWithDefault(options.cursorStyle, 'steady block'); options.resizable = false; TextView.call(this, options); @@ -73,6 +76,10 @@ EditTextView.prototype.onSpecialKeyPress = function(keyName) { } } } + } else if(this.isSpecialKeyMapped('clear', keyName)) { + // :TODO: this doesn't work right at all: + //this.setText(''); + //this.client.term.write(ansi.goto(this.position.x, this.position.y)); } diff --git a/core/spinner_menu_view.js b/core/spinner_menu_view.js index 90ce9a4b..8965ef8e 100644 --- a/core/spinner_menu_view.js +++ b/core/spinner_menu_view.js @@ -13,20 +13,14 @@ exports.SpinnerMenuView = SpinnerMenuView; function SpinnerMenuView(options) { options.justify = options.justify || 'center'; + options.cursor = options.cursor || 'hide'; MenuView.call(this, options); var self = this; this.cachePositions = function() { - if(self.positionCacheExpired) { - var count = this.items.length; - // :TODO: change all xPosition, yPosition -> position.x, .y - for(var i = 0; i < count; ++i) { - self.items[i].xPosition = self.position.x; - } - self.positionCacheExpired = false; - } + self.positionCacheExpired = false; }; this.updateSelection = function() { diff --git a/core/text_view.js b/core/text_view.js index 10628537..b7818455 100644 --- a/core/text_view.js +++ b/core/text_view.js @@ -42,6 +42,7 @@ function TextView(options) { // |ABCDEFG| ^_ this.text.length // ^-- this.dimens.width // + console.log(this.position.x) var textToDraw = _.isString(this.textMaskChar) ? new Array(s.length + 1).join(this.textMaskChar) : strUtil.stylizeString(s, this.hasFocus ? this.focusTextStyle : this.textStyle); diff --git a/core/view.js b/core/view.js index 0db3c4f0..05a198f2 100644 --- a/core/view.js +++ b/core/view.js @@ -18,6 +18,10 @@ var VIEW_SPECIAL_KEY_MAP_DEFAULT = { next : [ 'tab' ], up : [ 'up arrow' ], down : [ 'down arrow' ], + + clear : [ 'ctrl-y' ], + end : [ 'end' ], + home : [ 'home' ], }; function View(options) { @@ -31,6 +35,7 @@ function View(options) { this.client = options.client; this.cursor = options.cursor || 'show'; + this.cursorStyle = options.cursorStyle || 'default'; this.acceptsFocus = options.acceptsFocus || false; this.acceptsInput = options.acceptsInput || false; @@ -76,6 +81,15 @@ function View(options) { } return ansi.sgr(sgr); }; + + this.hideCusor = function() { + self.client.term.write(ansi.hideCursor()); + }; + + this.restoreCursor = function() { + //this.client.term.write(ansi.setCursorStyle(this.cursorStyle)); + this.client.term.write('show' === this.cursor ? ansi.showCursor() : ansi.hideCursor()); + }; } util.inherits(View, events.EventEmitter); @@ -162,7 +176,7 @@ View.prototype.setFocus = function(focused) { assert(this.acceptsFocus, 'View does not accept focus'); this.hasFocus = focused; - this.client.term.write('show' === this.cursor ? ansi.showCursor() : ansi.hideCursor()); + this.restoreCursor(); }; View.prototype.onKeyPress = function(key, isSpecial) {