mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-14 17:02:30 +01:00
62 lines
2.2 KiB
JavaScript
62 lines
2.2 KiB
JavaScript
import HelpResult from './models/HelpResult';
|
|
import AboutResult from './models/AboutResult';
|
|
import UnknownCommandResult from './models/UnknownCommandResult';
|
|
import ExpressionResult from './models/ExpressionResult';
|
|
import ErrorResult from './models/ErrorResult';
|
|
import WahtsnewResult from './models/WhatsnewResult';
|
|
import * as expression from './expression';
|
|
|
|
var cmdConfig = {};
|
|
|
|
export default {
|
|
initialize (cmd, appState) {
|
|
|
|
cmd.commands({
|
|
'help': function(c) {
|
|
appState.addCommandResult(new HelpResult(c.input));
|
|
},
|
|
'clear': function() {
|
|
appState.clearCommmandResults();
|
|
},
|
|
'em': function() {
|
|
appState.toggleEmphasizeBytes();
|
|
},
|
|
'dark': function() {
|
|
appState.setUiTheme('dark');
|
|
},
|
|
'light': function () {
|
|
appState.setUiTheme('light');
|
|
},
|
|
'midnight': function() {
|
|
appState.setUiTheme('midnight');
|
|
},
|
|
'about': function(c) {
|
|
appState.addCommandResult(new AboutResult(c.input));
|
|
},
|
|
'whatsnew': function(c) {
|
|
appState.addCommandResult(new WahtsnewResult(c.input));
|
|
},
|
|
'-notrack': function () {},
|
|
'-debug': function() {
|
|
console.log('Debug mode on')
|
|
cmd.debugMode = true;
|
|
}
|
|
});
|
|
|
|
cmd.command({
|
|
canHandle: (input) => expression.parser.canParse(input),
|
|
handle: function(c) {
|
|
var expr = expression.parser.parse(c.input);
|
|
appState.addCommandResult(new ExpressionResult(c.input, expr));
|
|
}
|
|
})
|
|
|
|
// Last command handler reports that input is unknown
|
|
cmd.command({
|
|
canHandle: () => true,
|
|
handle: (c) => appState.addCommandResult(new UnknownCommandResult(c.input))
|
|
});
|
|
|
|
cmd.onError((input, err) => appState.addCommandResult(new ErrorResult(input, err)));
|
|
}
|
|
} |