mirror of
https://github.com/BorysLevytskyi/BitwiseCmd.git
synced 2025-12-23 13:12:42 +01:00
Add support for UnknownCommandResult
This commit is contained in:
@@ -55,8 +55,7 @@ var cmd = {
|
||||
};
|
||||
|
||||
function displayCommandError(input, message) {
|
||||
var error = new app.models.ErrorResult(message);
|
||||
cmdController.display(new app.models.DisplayResult(input, error));
|
||||
console.error('[displayCommandError] not implemented');
|
||||
}
|
||||
|
||||
function invokeHandler (input, handler) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import appState from './appState';
|
||||
import HelpResult from './models/HelpResult';
|
||||
import UnknownCommandResult from './models/UnknownCommandResult';
|
||||
|
||||
var cmdConfig = {};
|
||||
|
||||
@@ -41,5 +42,10 @@ export default {
|
||||
},
|
||||
'-notrack': function () {}
|
||||
});
|
||||
|
||||
cmd.command({
|
||||
canHandle: () => true,
|
||||
handle: (c) => appState.addCommandResult(new UnknownCommandResult(c.input))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ export default class AppRoot extends React.Component {
|
||||
this.setState(this.props.appState);
|
||||
}
|
||||
render() {
|
||||
var results = this.state.commandResults.map((r, i) => <DisplayResultView key={i} content={r} input="sad" inputHash="asd" />);
|
||||
var results = this.state.commandResults.map((r, i) => <DisplayResultView key={i} content={r} input={r.input} inputHash={r.inputHash} />);
|
||||
return <div>
|
||||
<div className="header">
|
||||
<h1>Bitwise<span style={{color: "#c5c5c5"}}>Cmd</span></h1>
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import React from 'react';
|
||||
import HelpResultView from './HelpResultView';
|
||||
import HelpResult from '../../models/HelpResult';
|
||||
import UnknownCommandResult from '../../models/UnknownCommandResult';
|
||||
|
||||
|
||||
export default class DisplayResult extends React.Component {
|
||||
render() {
|
||||
|
||||
if(this.props.content instanceof UnknownCommandResult) {
|
||||
return this.renderUnknown();
|
||||
}
|
||||
|
||||
return <div className="result">
|
||||
<div className="input mono"><span className="cur">></span>{this.props.content.input}<a class="hashLink" title="Link for this expression" href={window.location.pathname + '#' + this.props.inputHash}>#</a></div>
|
||||
<div className="content">
|
||||
@@ -12,6 +19,10 @@ export default class DisplayResult extends React.Component {
|
||||
</div>;
|
||||
}
|
||||
|
||||
renderUnknown() {
|
||||
return <div className="error">Sorry, i don't know what <strong>{this.props.input}</strong> is :(</div>
|
||||
}
|
||||
|
||||
findResultComponent(result, key) {
|
||||
if(result instanceof HelpResult) {
|
||||
return <HelpResultView key={key} content={result} />
|
||||
|
||||
@@ -9,6 +9,7 @@ import AppRoot from './components/AppRoot';
|
||||
commands.initialize(cmd);
|
||||
|
||||
cmd.execute('help');
|
||||
cmd.execute('bluh');
|
||||
|
||||
var root = <AppRoot appState={appState} />;
|
||||
ReactDOM.render(root, document.getElementById('root'));
|
||||
@@ -1,5 +1,10 @@
|
||||
export default class CommandResult {
|
||||
constructor(input) {
|
||||
this.input = input;
|
||||
this.inputHash = this.encodeHash(input);
|
||||
}
|
||||
|
||||
encodeHash (string) {
|
||||
return encodeURI(string.trim().replace(/\s/g,','));
|
||||
}
|
||||
}
|
||||
8
src/app/models/UnknownCommandResult.js
Normal file
8
src/app/models/UnknownCommandResult.js
Normal file
@@ -0,0 +1,8 @@
|
||||
import CommandResult from './CommandResult';
|
||||
|
||||
export default class UnknownCommandResult extends CommandResult {
|
||||
constructor(input) {
|
||||
super(input);
|
||||
this.message = `Sorry, i don''t know what ${input} is :(`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user