-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
80 lines (65 loc) · 1.72 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import {
executeInput, recievedOutput, recievedError, updateInput, adjustPos,
deactivate, activate, toLeft, toRight, lineHeight, newPrompt, toNext,
toPrev, oldPropmt, cutInput,
} from './t_actions';
import { connect } from 'react-redux';
import Terminal from './Terminal';
export default connect(
({ terminal }) => ({
prompt: terminal.prompt,
history: terminal.history,
input_status: terminal.input_status,
}),
(dispatch, { serverPromise, id, height }) => ({
height: height === null ? 300 : height,
onChange: (e) => {
if (e.target.value.charCodeAt() === 10) {
e.target.value = '';
return;
}
const tmpChar = e.target.value;
e.target.value = '';
dispatch(updateInput(tmpChar));
},
onEnter: (input) =>
dispatch(executeInput(serverPromise(input), input))
.then(
output => {
dispatch(recievedOutput(output.result, id));
return dispatch(newPrompt());
},
error => {
dispatch(recievedError(error.result));
return dispatch(newPrompt());
}),
toLeft: (e) => {
dispatch(toLeft(e));
},
toPrev: (e) => {
dispatch(toPrev(e));
dispatch(oldPropmt());
},
toRight: (e) => {
dispatch(toRight(e));
},
toNext: (e) => {
dispatch(toNext(e));
dispatch(oldPropmt());
},
adjustPos: (index, pos) => {
dispatch(adjustPos(index, pos));
},
activate: () => {
dispatch(activate());
},
deactivate: () => {
dispatch(deactivate());
},
lineHeight: (lHeight) => {
dispatch(lineHeight(lHeight));
},
toDelete: () => {
dispatch(cutInput());
},
}))(Terminal);