diff options
author | Adrian Kummerlaender | 2015-08-12 20:18:09 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2015-08-12 20:18:09 +0200 |
commit | 2cbab1bd52ebdc6dae1f3ba63903b107cfd674be (patch) | |
tree | 32f342a98e67136eaf742e9818f0b7b55262bbe1 | |
parent | 610cc9d77f89ab106fdbfbc006934c9d192a55a8 (diff) | |
download | MetaTerm-2cbab1bd52ebdc6dae1f3ba63903b107cfd674be.tar MetaTerm-2cbab1bd52ebdc6dae1f3ba63903b107cfd674be.tar.gz MetaTerm-2cbab1bd52ebdc6dae1f3ba63903b107cfd674be.tar.bz2 MetaTerm-2cbab1bd52ebdc6dae1f3ba63903b107cfd674be.tar.lz MetaTerm-2cbab1bd52ebdc6dae1f3ba63903b107cfd674be.tar.xz MetaTerm-2cbab1bd52ebdc6dae1f3ba63903b107cfd674be.tar.zst MetaTerm-2cbab1bd52ebdc6dae1f3ba63903b107cfd674be.zip |
Add special error formatting to command output
-rw-r--r-- | qml/CommandInput.qml | 28 | ||||
-rw-r--r-- | 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 += '<i><font color="red">' + msg + '</font></i>'; } 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(''); |