From 507a71d4292378231da42d2c901ce984a9cd3a24 Mon Sep 17 00:00:00 2001 From: Mara Kim Date: Wed, 1 Jun 2016 18:48:10 -0500 Subject: [PATCH] Document and add example of promptLabel as a function --- README.md | 2 +- example/echo.tsx | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3cc1d71..4735e6c 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/example/echo.tsx b/example/echo.tsx index 68bbf42..4be8e21 100644 --- a/example/echo.tsx +++ b/example/echo.tsx @@ -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 this.child.console = ref} handler={this.echo} + promptLabel={this.promptLabel} autofocus={true} />; }