diff --git a/src/assets/css/style.less b/src/assets/css/style.less index 9383888..fb9ea1e 100644 --- a/src/assets/css/style.less +++ b/src/assets/css/style.less @@ -84,7 +84,7 @@ html, body { bottom: 0; width: 100%; min-height: 100%; - padding: 1.2em 1.6em 0.5em; + padding: 1.2em 1.6em 0.7em; font-size: 0.8em; } #commandLine { @@ -92,7 +92,6 @@ html, body { } #command { position: absolute; - margin-top: 1.25em; z-index: -2; } #cursor { diff --git a/src/index.php b/src/index.php index e8d437a..6bdb608 100644 --- a/src/index.php +++ b/src/index.php @@ -13,7 +13,8 @@
i love u
-fhqwhgadshgnsdhjsdbkhsdabkfabkveybvf

-
a>
+ +
a>
diff --git a/src/scripts/commandparser.js b/src/scripts/commandparser.js new file mode 100644 index 0000000..93ec8c9 --- /dev/null +++ b/src/scripts/commandparser.js @@ -0,0 +1,26 @@ +// from http://krasimirtsonev.com/blog/article/Simple-command-line-parser-in-JavaScript + +var CommandParser = (function() { + var parse = function(str, lookForQuotes) { + var args = []; + var readingPart = false; + var part = ''; + for(var i=0; i"]/g, fn); - } + }; - function syncTyping() { + var syncTyping = function () { var beforeSelection, selection, afterSelection; beforeSelection = this.value.slice(0, this.selectionStart); - selection = this.value.slice(this.selectionStart, this.selectionEnd) - afterSelection = this.value.slice(this.selectionEnd) - document.getElementById("typing").innerHTML = beforeSelection + (this.selectionStart == this.selectionEnd ? "" : "") + "" + selection + "" + afterSelection; - } - - var commandline = document.getElementById("command"); - commandline.value = ""; - commandline.oninput = syncTyping; - commandline.onkeydown = syncTyping; - commandline.onkeyup = syncTyping; - commandline.onselect = syncTyping; - commandline.onfocus = syncTyping; - commandline.focus(); - document.body.onmousedown = function() { - commandline.focus(); - return false; - // a little heavy handed, but works for now + selection = this.value.slice(this.selectionStart, this.selectionEnd); + afterSelection = this.value.slice(this.selectionEnd); + typing.innerHTML = beforeSelection + (this.selectionStart === this.selectionEnd ? "" : "") + "" + selection + "" + afterSelection; }; - var brightness = 0.0; - function alterBrightness(delta) { + var alterBrightness = function (delta) { brightness = Math.max(0, Math.min(1, brightness + delta)); - document.getElementById("scanlines").style.backgroundColor = "hsl(120, 100%, " + (16 * brightness) + "%)"; - } - document.getElementById("knobup").onmousedown = function() { - alterBrightness(1.0/6); - }; - document.getElementById("knobdown").onmousedown = function() { - alterBrightness(-1.0/6); + this.scanlines.style.backgroundColor = "hsl(120, 100%, " + (16 * brightness) + "%)"; }; - function handleForm() { - var history = document.getElementById('history'); + + var setInputEnabled = function (enabled) { + console.log(enabled); + if (enabled) { + commandInput.disabled = false; + commandLine.style.display = 'block'; + } else { + commandInput.disabled = true; + commandInput.value = ''; + typing.innerHTML = ''; + commandLine.style.display = 'none'; + } + }; + + var showResponse = function (response) { + commandHistory.innerHTML += response + '
'; + setInputEnabled(true); + }; + + var handleForm = function () { var val = this.command.value; - this.command.value = ''; - document.getElementById("typing").innerHTML = ''; - history.innerHTML = history.innerHTML + 'a>' + escapeHTML(val) + '
Command not found.
'; + setInputEnabled(false); + commandHistory.innerHTML += 'a>' + escapeHTML(val) + '
'; + setTimeout(function() { showResponse('Command not found.'); }, 500); return false; - } + }; - document.forms[0].onsubmit = handleForm; + var init = function() { + console.log('init'); + commandLine = document.getElementById("commandLine"); + commandInput = document.getElementById("command"); + scanlines = document.getElementById("scanlines"); + commandHistory = document.getElementById("history"); + typing = document.getElementById("typing"); + + commandInput.value = ""; + commandInput.oninput = syncTyping; + commandInput.onkeydown = syncTyping; + commandInput.onkeyup = syncTyping; + commandInput.onselect = syncTyping; + commandInput.onfocus = syncTyping; + commandInput.focus(); + document.body.onmousedown = function() { + commandInput.focus(); + return false; + // a little heavy handed, but works for now + }; + document.getElementById("knobup").onmousedown = function() { + alterBrightness(1.0/6); + }; + document.getElementById("knobdown").onmousedown = function() { + alterBrightness(-1.0/6); + }; + document.forms[0].onsubmit = handleForm; + }; + + document.addEventListener("DOMContentLoaded", init); }());