23 |

24 | react-console

25 | 26 |

Simple React.js console emulator.

27 | 28 |
29 | 30 | 33 | 34 |

Code

35 | 36 |

37 | Example

38 | 39 |

Simple prompt that echoes back input:

40 | 41 |
let EchoConsole = React.createClass({
 42 |     echo: function(text) {
 43 |         this.refs.console.log(text);
 44 |         this.refs.console.return();
 45 |     },
 46 |     render: function() {
 47 |         return <Console ref="console"
 48 |             handler={this.echo}
 49 |             autofocus={true}
 50 |         />;
 51 |     }
 52 | });
53 | 54 |

See the example project used in the live demo.

55 | 56 |

57 | Installation

58 | 59 |
npm install --save-dev react-console-component
 60 | 
61 | 62 |

63 | Features

64 | 65 |
    66 |
  • Readline emulation
  • 67 |
  • Mobile friendly
  • 68 |
  • Input Method Editor (IME) support
  • 69 |
70 | 71 |

72 | Props

73 | 74 |

Properties you can pass to the console element

75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 |
PropTypeDescription
autofocus?boolAutofocus the console on component mount.
cancel?()=>anyFunction that should stop execution of the current command and call this.return().
complete?(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?(prompt: string)=>boolReturn a boolean indicating whether to continue asking for user input on a newline given the current prompt text (prompt).
handler(command: string)=>anyHandle a command (command), logging data with this.log() or this.logX(), and calling this.return() when finished.
promptLabel?string | ()=>stringString or function that generates a string displayed to prompt user for input.
welcomeMessage?stringInitial message displayed after mount.
122 | 123 |

124 | Public members

125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 |
MemberTypeDescription
log(...messages: any)=>voidLog messages to the console. If string, print the value, otherwise, print the JSON value of the message.
logX(type: string, ...messages: any)=>voidLog messages of a particular type to the console. The messages will be given the class react-console-message-{type}.
return()=>voidSignal the current command has finished and a new prompt should be displayed.
152 | 153 |

154 | Awknoledgements

155 | 156 |

React-console is inspired by chrisdone/jquery-console.

157 | 158 | 163 | 164 |