have basic command line history down

This commit is contained in:
Peter Cottle 2012-09-11 22:10:40 -07:00
parent 513315af3c
commit 9b62f06bc2
2 changed files with 47 additions and 6 deletions

View file

@ -104,11 +104,14 @@ GitEngine.prototype.commit = function() {
if (this.currentOptions['--amend']) { if (this.currentOptions['--amend']) {
targetCommit = this.resolveId('HEAD~1'); targetCommit = this.resolveId('HEAD~1');
} }
if (this.currentOptions['-a']) {
events.trigger('commandProcessWarn', 'No need to add files in this demo');
}
var newCommit = this.makeCommit(targetCommit); var newCommit = this.makeCommit(targetCommit);
if (this.getDetachedHead()) { if (this.getDetachedHead()) {
events.trigger('commandProcessWarn', "Warning!! Detached HEAD state"); events.trigger('commandProcessWarn', 'Warning!! Detached HEAD state');
} else { } else {
var targetBranch = this.HEAD.get('target'); var targetBranch = this.HEAD.get('target');
targetBranch.set('target', newCommit); targetBranch.set('target', newCommit);

View file

@ -1,10 +1,15 @@
var CommandLineView = Backbone.View.extend({ var CommandLineView = Backbone.View.extend({
initialize: function(options) { initialize: function(options) {
this.commands = []; this.commands = [];
this.index = -1;
this.$('#commandTextField').keyup( this.$('#commandTextField').keyup(
$.proxy(this.keyUp, this) $.proxy(this.keyUp, this)
); );
events.on('commandConsumed', _.bind(
this.parseOrCatch, this
));
}, },
keyUp: function(e) { keyUp: function(e) {
@ -12,8 +17,17 @@ var CommandLineView = Backbone.View.extend({
// we need to capture some of these events // we need to capture some of these events
var keyMap = { var keyMap = {
// enter
13: _.bind(function() { 13: _.bind(function() {
this.submit(); this.submit();
}, this),
// up
38: _.bind(function() {
this.commandSelectChange(1);
}, this),
// down
40: _.bind(function() {
this.commandSelectChange(-1);
}, this) }, this)
}; };
@ -23,9 +37,18 @@ var CommandLineView = Backbone.View.extend({
} }
}, },
addCommand: function(e) { commandSelectChange: function(delta) {
e.preventDefault(); this.index += delta;
this.submit();
// if we are over / under, display blank line
if (this.index >= this.commands.length || this.index < 0) {
this.clear();
this.index = -1;
return;
}
// yay! we actually can display something
this.setTextField(this.commands[this.index]);
}, },
processError: function(err) { processError: function(err) {
@ -42,16 +65,30 @@ var CommandLineView = Backbone.View.extend({
} }
}, },
setTextField: function(value) {
this.$('#commandTextField').val(value);
},
clear: function() {
this.setTextField('');
},
submit: function() { submit: function() {
var value = this.$('#commandTextField').val().replace('\n', ''); var value = this.$('#commandTextField').val().replace('\n', '');
this.$('#commandTextField').val(''); this.clear();
if (value.length) {
this.commands.unshift(value);
}
this.index = -1;
events.trigger('commandConsumed', value); events.trigger('commandConsumed', value);
},
parseOrCatch: function(value) {
try { try {
var command = new Command(value); var command = new Command(value);
console.log(command); console.log(command);
// immediately execute for now, will change later
events.trigger('gitCommandReady', command); events.trigger('gitCommandReady', command);
} catch (err) { } catch (err) {
this.processError(err); this.processError(err);
@ -77,6 +114,7 @@ var CommandLineHistoryView = Backbone.View.extend({
this.commandResultPrint, this this.commandResultPrint, this
)); ));
// TODO: move these to a real template system
this.commandTemplate = ' \ this.commandTemplate = ' \
<p class="commandLine <%= className %>"> \ <p class="commandLine <%= className %>"> \
<span class="arrows">&gt; &gt; &gt;</span> \ <span class="arrows">&gt; &gt; &gt;</span> \