Skip to content

Commit f485210

Browse files
committed
Better demo page + fixed prompt alignment
1 parent d05e331 commit f485210

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

example/src/App.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,45 @@ import React, { Component } from 'react'
33
import ReactConsole from 'react-console'
44

55
export default class App extends Component {
6-
render () {
6+
render() {
77
return (
88
<div>
99
<ReactConsole
1010
autoFocus
11-
welcomeMessage="Welcome"
11+
welcomeMessage="This is a welcome message 🎉🎉🎉"
1212
commands={{
1313
echo: {
1414
description: 'Echo',
1515
fn: (...args) => {
1616
return new Promise((resolve, reject) => {
1717
setTimeout(() => {
1818
resolve(`${args.join(' ')}`)
19-
}, 2000)
19+
}, 0)
2020
})
2121
}
2222
},
23-
test: {
24-
description: 'Test',
25-
fn: (...args) => {
23+
sleep: {
24+
description: 'sleep',
25+
fn: (timeout) => {
2626
return new Promise((resolve, reject) => {
2727
setTimeout(() => {
28-
resolve('Hello world \n\n hello \n')
29-
}, 2000)
28+
resolve('')
29+
}, timeout)
3030
})
3131
}
3232
}
3333
}}
3434
/>
35+
<table>
36+
<tr>
37+
<td><code>echo ...args</code></td>
38+
<td>Echo</td>
39+
</tr>
40+
<tr>
41+
<td><code>sleep `ms`</code></td>
42+
<td>Sleeps for a number of milliseconds</td>
43+
</tr>
44+
</table>
3545
</div>
3646
)
3747
}

src/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ export default class ReactConsole extends React.Component<Props, State> {
4545
}
4646
}
4747

48+
clear = () => {
49+
this.setState({output: [], input: ''})
50+
};
51+
4852
onSubmit = async (e: any) => {
4953
const {prompt} = this.props;
5054
e.preventDefault();
@@ -67,7 +71,7 @@ export default class ReactConsole extends React.Component<Props, State> {
6771
const [cmd, ...args] = inputString.split(" ");
6872

6973
if(cmd === 'clear') {
70-
this.setState({output: [], input: ''})
74+
this.clear()
7175
return
7276
}
7377

@@ -112,7 +116,7 @@ export default class ReactConsole extends React.Component<Props, State> {
112116
onSubmit={this.onSubmit}
113117
>
114118
<div className={styles.promptWrapper}>
115-
<span>{prompt}&nbsp;</span>
119+
<span className={styles.prompt}>{prompt}&nbsp;</span>
116120
<input
117121
disabled={this.state.commandInProgress}
118122
ref={ref => this.inputRef = ref}

src/styles.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
color: white;
2626
}
2727

28+
.prompt {
29+
display: flex;
30+
align-items: center;
31+
}
32+
2833
.input {
2934
flex: 1;
3035
background: transparent !important; /* we want to make this transparent whatever happens in the app*/

0 commit comments

Comments
 (0)