Skip to content

Commit

Permalink
Fix input and output printing for REPL
Browse files Browse the repository at this point in the history
Signed-off-by: ampan98 <[email protected]>
  • Loading branch information
ampan98 authored and wltan committed Jun 29, 2020
1 parent a25b832 commit caf3795
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
Binary file modified assets/select_background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 30 additions & 12 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,8 @@ class ReplBody extends StatefulWidget {
class _ReplBodyState extends State<ReplBody> {
final TextEditingController _controller = TextEditingController();
FocusNode replNode = FocusNode();
var prevSubmitList = [];
var outputList = [];
var containerId = 'none';

@override
void initState() {
Expand Down Expand Up @@ -347,7 +347,17 @@ class _ReplBodyState extends State<ReplBody> {
stream: widget.channel.stream,
builder: (context, snapshot) {
if (snapshot.hasData) {
outputList.add(snapshot.data);
Map<String, dynamic> outputData = jsonDecode(snapshot.data);
if (outputData["containerId"] != null) {
containerId = outputData["containerId"];
}
if (outputData["output"] != null) {
if (outputData["output"].substring(0,4) == '>>> ') {
outputList.add(outputData["output"].substring(4));
} else {
outputList.add(outputData["output"]);
}
}
}
debugPrint('$outputList');
if (!snapshot.hasData) {
Expand Down Expand Up @@ -438,16 +448,15 @@ class _ReplBodyState extends State<ReplBody> {
void _sendSubmit() {
if (_controller.text.isNotEmpty) {
//widget.channel.sink.add(_controller.text);
outputList.add('>>> ' + _controller.text);
widget.channel.sink.add(
json.encode(
{"action": "input",
"input": _controller.text,
}
)
);
prevSubmitList.add(_controller.text);
_controller.clear();
debugPrint('$prevSubmitList');
}
}

Expand All @@ -465,8 +474,8 @@ class _ReplBodyState extends State<ReplBody> {
class CompilerPage extends StatelessWidget {
CompilerPage({Key key, this.name}) : super(key: key);
final String name;
final String channelName = 'wss://echo.websocket.org'; // For testing websocket
//final String channelName = 'wss://s4tdw93cwd.execute-api.us-east-1.amazonaws.com/default/';
//final String channelName = 'wss://echo.websocket.org'; // For testing websocket
final String channelName = 'wss://s4tdw93cwd.execute-api.us-east-1.amazonaws.com/default/';

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -525,8 +534,8 @@ class _CompilerBodyState extends State<CompilerBody> {
FocusNode replNode = FocusNode();
bool _firstRun = true;
bool _visible = false;
var prevSubmitList = [];
var outputList = [];
var containerId = 'none';

@override
void initState() {
Expand Down Expand Up @@ -635,7 +644,14 @@ class _CompilerBodyState extends State<CompilerBody> {
stream: widget.channel.stream,
builder: (context, snapshot) {
if (snapshot.hasData) {
outputList.add(snapshot.data);
Map<String, dynamic> outputData = jsonDecode(snapshot.data);
if (outputData["containerId"] != null) {
containerId = outputData["containerId"];
}
if (outputData["output"] != null) {
outputList.add(outputData["output"]);
}
//outputList.add(snapshot.data);
}
debugPrint('$outputList');
if (!snapshot.hasData) {
Expand Down Expand Up @@ -743,8 +759,11 @@ class _CompilerBodyState extends State<CompilerBody> {
else {
widget.channel.sink.add(
json.encode(
{"action": "input",
"input": _topController.text,
{
"action": "launch",
"lang": widget.name.toLowerCase(),
"mode": "compile",
"prog": _topController.text,
}
)
);
Expand All @@ -756,16 +775,15 @@ class _CompilerBodyState extends State<CompilerBody> {
void _sendSubmit() {
if (_bottomController.text.isNotEmpty) {
//widget.channel.sink.add(_controller.text);
outputList.add(_bottomController.text);
widget.channel.sink.add(
json.encode(
{"action": "input",
"input": _bottomController.text,
}
)
);
prevSubmitList.add(_bottomController.text);
_bottomController.clear();
debugPrint('$prevSubmitList');
}
}

Expand Down

0 comments on commit caf3795

Please sign in to comment.