From 2cbab1bd52ebdc6dae1f3ba63903b107cfd674be Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Wed, 12 Aug 2015 20:18:09 +0200 Subject: Add special error formatting to command output --- qml/CommandInput.qml | 28 +++++++++++++++++++++++----- qml/commands.js | 12 ++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/qml/CommandInput.qml b/qml/CommandInput.qml index 6add27a..c4e6302 100644 --- a/qml/CommandInput.qml +++ b/qml/CommandInput.qml @@ -50,8 +50,8 @@ Item { id: container function reset() { - command.text = ''; - output.text = ''; + command.initialize(); + output.initialize(); } TextInput { @@ -69,7 +69,13 @@ Item { selectedTextColor: settings.background selectByMouse: true + function initialize() { + text = ''; + } + onAccepted: { + output.initialize(); + const prefix = String(text).charAt(0); const cmd = String(text).substring(1, String(text).length); @@ -79,11 +85,11 @@ Item { break; } default: { - output.log('"' + prefix + '"' + " is not a command prefix."); + output.error('"' + prefix + '"' + ' is not a command prefix.'); } } - if ( output.text === '' ) { + if ( output.isInitial() ) { item.executed(); } } @@ -102,8 +108,20 @@ Item { color: settings.fontColor + function isInitial() { + return text === ''; + } + + function initialize() { + text = ''; + } + function log(msg) { - text = msg; + text += msg; + } + + function error(msg) { + text += '' + msg + ''; } onTextChanged: { diff --git a/qml/commands.js b/qml/commands.js index b116b23..765a747 100644 --- a/qml/commands.js +++ b/qml/commands.js @@ -1,27 +1,27 @@ function execute(output, command) { - var msg = function(name) { - output.log('"' + name + '"' + " is not implemented."); + var notImplemented = function(name) { + output.error('"' + name + '"' + ' is not implemented.'); }; var args = command.split(' '); try { var closure = eval(args[0]); - if ( typeof closure === "function" ) { + if ( typeof closure === 'function' ) { args.shift(); closure(output, args); } else { - msg(args[0]); + notImplemented(args[0]); } } catch (exception) { - msg(args[0]); + notImplemented(args[0]); } } function exec(output, args) { var result = eval(args.join(' ')); - if ( typeof result !== "undefined" ) { + if ( typeof result !== 'undefined' ) { output.log(result); } else { output.log(''); -- cgit v1.2.3