diff --git a/src/git.js b/src/git.js index 719ade2d..743400cd 100644 --- a/src/git.js +++ b/src/git.js @@ -249,6 +249,11 @@ GitEngine.prototype._deleteBranch = function(name) { delete this.refs[id]; }; +GitEngine.prototype.dispatch = function(commandObj) { + // TODO: parse arguments + this[commandObj.method](); +}; + GitEngine.prototype.add = function() { throw new Error( "This demo is meant to demonstrate git branching, so don't worry about " + diff --git a/src/index.html b/src/index.html index 2aa8b6c5..8a80e131 100644 --- a/src/index.html +++ b/src/index.html @@ -12,15 +12,17 @@
+
+
+ +
+
-
- -
+
- diff --git a/src/mine.js b/src/mine.js index 144912fb..f1b7fb96 100644 --- a/src/mine.js +++ b/src/mine.js @@ -13,6 +13,10 @@ $(document).ready(function(){ new CommandLineView({ el: $('#commandLineBar') }); + new CommandLineHistoryView({ + el: $('#commandLineHistory') + }); + gitEngine = new GitEngine(); var repulsionBreathe = function(r) { diff --git a/src/style/main.css b/src/style/main.css index 1c46a46e..9d0f3b6d 100644 --- a/src/style/main.css +++ b/src/style/main.css @@ -26,5 +26,29 @@ html,body { } #commandTextField { - width: 100%; + width: 90%; +} + +p.commandLine { + opacity: 1; + font-size: 18px; + margin: 2px; +} + +span.arrows { + color: greenyellow; + font-weight: bold; +} + +#commandLineBar { + text-align: center; +} + +#commandLineHistory { + width: 100%; + height: 500px; + overflow-y: scroll; + background: #000; + opacity: 0.85; + box-shadow: 0px 0px 3px rgba(0, 0, 0, 0.3) inset; } diff --git a/src/views.js b/src/views.js new file mode 100644 index 00000000..5b30ff18 --- /dev/null +++ b/src/views.js @@ -0,0 +1,78 @@ +var CommandLineView = Backbone.View.extend({ + initialize: function(options) { + this.commands = []; + + this.$('#commandTextField').keyup( + $.proxy(this.keyUp, this) + ); + }, + + keyUp: function(e) { + console.log(e); + + // we need to capture some of these events + var keyMap = { + 13: _.bind(function() { + this.submit(); + }, this) + }; + + if (keyMap[e.which] !== undefined) { + e.preventDefault(); + keyMap[e.which](); + } + }, + + addCommand: function(e) { + e.preventDefault(); + this.submit(); + }, + + submit: function() { + var value = this.$('#commandTextField').val(); + this.$('#commandTextField').val(''); + events.trigger('commandConsumed', value); + + if (!value.length) { + // return early, just want a blank line + } + console.log('the value'); + console.log(value); + + try { + var command = new Command(value); + console.log(command); + // immediately execute for now TODO + gitEngine.dispatch(command); + } catch (e) { + alert('Error with that command: ' + String(e)); + } + } +}); + +var CommandLineHistoryView = Backbone.View.extend({ + initialize: function(options) { + events.on('commandConsumed', _.bind( + this.addCommand, this + )); + + this.commandTemplate = ' \ +

\ + > > > \ + <%= command %> \ +

\ + '; + }, + + addCommand: function(commandText) { + this.$('#commandDisplay').append( + _.template( + this.commandTemplate, + { + class: 'pastCommand', + command: commandText + } + ) + ); + } +});