Skip to content

Commit 3f9fb6e

Browse files
committed
remove react-console-component, create methods for updating console on message received
1 parent 8aee0e6 commit 3f9fb6e

File tree

3 files changed

+74
-53
lines changed

3 files changed

+74
-53
lines changed

app/dist/dist/css/factorio-server-manager.css

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
top: 0; left: 0; bottom: 0; right: 0;
1212
}
1313

14-
div.react-console-container {
14+
div.console-container {
1515
font-size: 0.85em;
1616
font-family: "Menlo", "Consolas", "DejaVu Sans Mono", monospace;
1717
width: 60em;
@@ -23,39 +23,6 @@ div.react-console-container {
2323
overflow: auto;
2424
white-space: pre; }
2525

26-
div.react-console-prompt-box {
27-
color: #444; }
28-
29-
span.react-console-prompt-label {
30-
font-weight: bold; }
31-
32-
div.react-console-focus span.react-console-cursor {
33-
background: #333;
34-
color: #eee; }
35-
36-
div.react-console-nofocus span.react-console-cursor {
37-
background: none;
38-
color: #444;
39-
outline: 0.1em solid #333;
40-
outline-offset: -0.1em; }
41-
42-
div.react-console-focus span.react-console-cursor-idle {
43-
animation: react-console-cursor-animation 1s infinite; }
44-
45-
@keyframes react-console-cursor-animation {
46-
0% {
47-
background: #333;
48-
color: #eee; }
49-
50% {
50-
background: #333;
51-
color: #eee; }
52-
51% {
53-
background: none;
54-
color: #444; }
55-
100% {
56-
background: none;
57-
color: #444; } }
58-
59-
div.react-console-message {
60-
color: #999;
61-
padding: 0.1em; }
26+
div.console-prompt-box {
27+
color: #444;
28+
max-width: 100%}

src/factorio_server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"strconv"
1616
"strings"
1717

18-
"github.com/MajorMJR/rcon"
18+
"github.com/majormjr/rcon"
1919
)
2020

2121
type FactorioServer struct {

ui/App/components/ConsoleContent.jsx

Lines changed: 69 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import {IndexLink} from 'react-router';
3-
import Console from 'react-console-component'
43
import Socket from '../../socket.js';
54

65
class ConsoleContent extends React.Component {
@@ -10,20 +9,37 @@ class ConsoleContent extends React.Component {
109
this.connectWebsocket = this.connectWebsocket.bind(this);
1110
this.handleCommand = this.handleCommand.bind(this);
1211
this.onConnect = this.onConnect.bind(this);
13-
this.onNewLogLine = this.onNewLogLine.bind(this);
14-
this.state = {}
12+
this.handleInput = this.handleInput.bind(this);
13+
this.clearInput = this.clearInput.bind(this);
14+
this.clearHistory = this.clearHistory.bind(this);
15+
this.addHistory = this.addHistory.bind(this);
16+
this.handleClick = this.handleClick.bind(this);
17+
this.newLogLine = this.newLogLine.bind(this);
18+
this.state = {
19+
commands: {},
20+
history: [],
21+
prompt: '$ ',
22+
}
1523
}
1624

1725
componentDidMount() {
1826
this.connectWebsocket();
1927
}
2028

29+
componentDidUpdate() {
30+
var el = this.refs.output;
31+
console.log(this.refs);
32+
var container = document.getElementById("console-output");
33+
console.log(container)
34+
container.scrollTop = this.refs.output.scrollHeight;
35+
}
36+
2137
connectWebsocket() {
2238
var ws_scheme = window.location.protocol == "https:" ? "wss" : "ws";
2339
let ws = new WebSocket(ws_scheme + "://" + window.location.host + "/ws");
2440
let socket = this.socket = new Socket(ws);
2541
socket.on('connect', this.onConnect.bind(this));
26-
socket.on('log update', this.onNewLogLine.bind(this));
42+
socket.on('log update', this.newLogLine.bind(this));
2743
}
2844

2945
handleCommand(command) {
@@ -34,17 +50,52 @@ class ConsoleContent extends React.Component {
3450
onConnect() {
3551
this.setState({connected: true});
3652
this.socket.emit("log subscribe");
37-
this.refs.console.log("connected to Factorio Server")
3853
}
3954

40-
onNewLogLine(logline) {
41-
console.log(logline);
42-
console.log(this.refs.console);
43-
this.refs.console.log({message: logline});
44-
this.refs.console.return();
55+
handleInput(e) {
56+
if (e.key === "Enter") {
57+
var input_text = this.refs.term.value;
58+
59+
this.addHistory(this.state.prompt + " " + input_text);
60+
61+
this.clearInput();
62+
}
63+
}
64+
65+
clearInput() {
66+
this.refs.term.value = "";
67+
}
68+
69+
clearHistory() {
70+
ths.setState({ history: []});
71+
}
72+
73+
addHistory(output) {
74+
var history = this.state.history;
75+
history.push(output);
76+
this.setState({
77+
'history': history
78+
});
79+
}
80+
81+
handleClick() {
82+
var term = this.refs.term;
83+
term.focus();
84+
}
85+
86+
newLogLine(logline) {
87+
var history = this.state.history;
88+
history.push(logline);
89+
this.setState({
90+
'history': history
91+
});
4592
}
4693

4794
render() {
95+
var output = this.state.history.map((op, i) => {
96+
return <p key={i}>{op}</p>
97+
});
98+
4899
return(
49100
<div className="content-wrapper">
50101
<section className="content-header">
@@ -59,11 +110,14 @@ class ConsoleContent extends React.Component {
59110
</section>
60111

61112
<section className="content">
62-
63-
<Console ref="console"
64-
autofocus={true}
65-
handler={this.handleCommand}
66-
/>
113+
114+
<div id='console-output' className='console-container' onClick={this.handleClick} ref="output">
115+
{output}
116+
</div>
117+
<p>
118+
<span className="console-prompt-box">{this.state.prompt}</span>
119+
<input type="text" onKeyPress={this.handleInput} ref="term" />
120+
</p>
67121

68122
</section>
69123
</div>

0 commit comments

Comments
 (0)