Skip to content

Improvements on the Debug Console #600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 37 additions & 16 deletions home.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<!-- this file is just for development purpose, real code in main.go -->
<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>Arduino Create Agent Debug Console</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700&display=swap" rel="stylesheet">
Expand All @@ -17,19 +18,38 @@
var MESSAGES_MAX_COUNT = 2000;

function appendLog(msg) {
var startsWithBracked = msg.indexOf('{') == 0;
let jsonMsg = {};
let portListing = false;
try {
jsonMsg = JSON.parse(msg);
portsListing = jsonMsg.Ports;
} catch {
// no valid json
}

var startsWithList = msg.indexOf('list') == 0;

if (listenabled.checked || (typeof msg === 'string' && !startsWithBracked && !startsWithList)) {
messages.push(msg);
if (messages.length > MESSAGES_MAX_COUNT) {
messages.shift();
}
log.innerHTML = messages.join('<br>');
if (autoscroll.checked) {
log.scrollTop = log.scrollHeight - log.clientHeight;
}
}
if (listenabled.checked || (!portsListing && !startsWithList)) {
let printMsg = msg;
if (jsonMsg.Ports) {
const validKeys = ['Name', 'SerialNumber', 'IsOpen', 'VendorID', 'ProductID'];
if (jsonMsg.Network) {
printMsg = "<b>Network Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2);
} else {
printMsg = "<b>Serial Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2);
}
} else if (Object.keys(jsonMsg).length !== 0) {
printMsg = JSON.stringify(jsonMsg, undefined, 2);
}
messages.push(printMsg);
if (messages.length > MESSAGES_MAX_COUNT) {
messages.shift();
}
log.innerHTML = messages.join('<br><br>');
if (autoscroll.checked) {
log.scrollTop = log.scrollHeight - log.clientHeight;
}
}
}

$('#form').submit(function(e) {
Expand All @@ -47,6 +67,7 @@
var link = document.createElement('a');
link.setAttribute('download', 'agent-log.txt');
var text = log.innerHTML.replace(/<br>/g, '\n');
text = text.replace(/<b>|<\/b>/g, '');
link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
link.click();
});
Expand Down Expand Up @@ -92,14 +113,15 @@
#container {
display: flex;
flex-direction: column;
height: 100%;
height: 100vh;
width: 100%;
}

#log {
flex-grow: 1;
font-family: "Roboto Mono", "Courier", "Lucida Grande", Verdana, sans-serif;
background-color: #DAE3E3;
height: calc(100vh - 61px);
margin: 15px 15px 10px;
padding: 8px 10px;
overflow-y: auto;
Expand Down Expand Up @@ -182,16 +204,15 @@
font-size: 1em;
outline: none;
}

</style>
</head>
<body>
<div id="container">
<div id="log">This is some random text This is some random textThis is some random textThis is some random textThis is some random textThis is some random textThis is some random text<br />This is some random text<br />This is some random text<br /></div>
<pre id="log"></pre>
<div id="footer">
<form id="form">
<input type="submit" class="button" value="Send" />
<input type="text" id="input" class="textfield" />
<input type="text" id="input" class="textfield" aria-label="send command" />
</form>
<div id="secondary-controls">
<div>
Expand Down
53 changes: 36 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ var homeTemplate = template.Must(template.New("home").Parse(homeTemplateHtml))
// If you navigate to this server's homepage, you'll get this HTML
// so you can directly interact with the serial port server
const homeTemplateHtml = `<!DOCTYPE html>
<html>
<html lang="en">
<head>
<title>Arduino Create Agent Debug Console</title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700&display=swap" rel="stylesheet">
Expand All @@ -430,19 +430,38 @@ const homeTemplateHtml = `<!DOCTYPE html>
var MESSAGES_MAX_COUNT = 2000;

function appendLog(msg) {
var startsWithBracked = msg.indexOf('{') == 0;
let jsonMsg = {};
let portListing = false;
try {
jsonMsg = JSON.parse(msg);
portsListing = jsonMsg.Ports;
} catch {
// no valid json
}

var startsWithList = msg.indexOf('list') == 0;

if (listenabled.checked || (typeof msg === 'string' && !startsWithBracked && !startsWithList)) {
messages.push(msg);
if (messages.length > MESSAGES_MAX_COUNT) {
messages.shift();
}
log.innerHTML = messages.join('<br>');
if (autoscroll.checked) {
log.scrollTop = log.scrollHeight - log.clientHeight;
}
}
if (listenabled.checked || (!portsListing && !startsWithList)) {
let printMsg = msg;
if (jsonMsg.Ports) {
const validKeys = ['Name', 'SerialNumber', 'IsOpen', 'VendorID', 'ProductID'];
if (jsonMsg.Network) {
printMsg = "<b>Network Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2);
} else {
printMsg = "<b>Serial Ports</b>:<br>"+JSON.stringify(jsonMsg.Ports, validKeys, 2);
}
} else if (Object.keys(jsonMsg).length !== 0) {
printMsg = JSON.stringify(jsonMsg, undefined, 2);
}
messages.push(printMsg);
if (messages.length > MESSAGES_MAX_COUNT) {
messages.shift();
}
log.innerHTML = messages.join('<br><br>');
if (autoscroll.checked) {
log.scrollTop = log.scrollHeight - log.clientHeight;
}
}
}

$('#form').submit(function(e) {
Expand All @@ -460,6 +479,7 @@ const homeTemplateHtml = `<!DOCTYPE html>
var link = document.createElement('a');
link.setAttribute('download', 'agent-log.txt');
var text = log.innerHTML.replace(/<br>/g, '\n');
text = text.replace(/<b>|<\/b>/g, '');
link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
link.click();
});
Expand Down Expand Up @@ -505,14 +525,15 @@ body {
#container {
display: flex;
flex-direction: column;
height: 100%;
height: 100vh;
width: 100%;
}

#log {
flex-grow: 1;
font-family: "Roboto Mono", "Courier", "Lucida Grande", Verdana, sans-serif;
background-color: #DAE3E3;
height: calc(100vh - 61px);
margin: 15px 15px 10px;
padding: 8px 10px;
overflow-y: auto;
Expand Down Expand Up @@ -595,16 +616,15 @@ body {
font-size: 1em;
outline: none;
}

</style>
</head>
<body>
<div id="container">
<div id="log">This is some random text This is some random textThis is some random textThis is some random textThis is some random textThis is some random textThis is some random text<br />This is some random text<br />This is some random text<br /></div>
<pre id="log"></pre>
<div id="footer">
<form id="form">
<input type="submit" class="button" value="Send" />
<input type="text" id="input" class="textfield" />
<input type="text" id="input" class="textfield" aria-label="send command" />
</form>
<div id="secondary-controls">
<div>
Expand All @@ -622,7 +642,6 @@ body {
</div>
</body>
</html>

`

func parseIni(filename string) (args []string, err error) {
Expand Down