Skip to content

Commit

Permalink
Document and add example of promptLabel as a function
Browse files Browse the repository at this point in the history
  • Loading branch information
astralarya committed Jun 1, 2016
1 parent da26e61 commit 507a71d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Properties you can pass to the console element
| complete? | function(words: string[], cursor: number, prompt: string): string[] | Return a list of possible completions given a list of (`words`), index of the word containing the cursor (`cursor`) , and the full prompt text (`prompt`).
| continue? | function(prompt: string): bool | Return a boolean indicating whether to continue asking for user input on a newline given the current prompt text (`prompt`).
| handler | function(command: string): any | Handle a command (`command`), logging data with `this.log()` or `this.logX()`, and calling `this.return()` when finished.
| promptLabel? | string | String displayed to prompt user for input.
| promptLabel? | string | function(): string | String displayed to prompt user for input.
| welcomeMessage? | string | Initial message displayed after mount.

## Public members
Expand Down
19 changes: 17 additions & 2 deletions example/echo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';
import Console from '../src/react-console.tsx';

class EchoConsole extends React.Component<{},{}> {
interface EchoConsoleState {
count: number;
}
class EchoConsole extends React.Component<{},EchoConsoleState> {
constructor(props: {}) {
super(props);
this.state = {
count: 0,
};
}
child: {
console?: Console,
} = {};
echo = (text: string) => {
this.child.console.log(text);
this.child.console.return();
this.setState({
count: this.state.count+1,
}, this.child.console.return);
}
promptLabel = () => {
return this.state.count + "> ";
}
render() {
return <Console ref={ref => this.child.console = ref}
handler={this.echo}
promptLabel={this.promptLabel}
autofocus={true}
/>;
}
Expand Down

0 comments on commit 507a71d

Please sign in to comment.