Skip to content

Commit 34800a4

Browse files
Stefaniaumbynos
Stefania
authored andcommitted
fix debug console template in correct file main.go
1 parent 0e28bed commit 34800a4

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

home.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
<!-- this file is just for development purpose, real code in main.go -->
12
<!DOCTYPE html>
23
<html lang="en">
34
<head>

main.go

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ var homeTemplate = template.Must(template.New("home").Parse(homeTemplateHtml))
412412
// If you navigate to this server's homepage, you'll get this HTML
413413
// so you can directly interact with the serial port server
414414
const homeTemplateHtml = `<!DOCTYPE html>
415-
<html>
415+
<html lang="en">
416416
<head>
417417
<title>Arduino Create Agent Debug Console</title>
418418
<link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,700&display=swap" rel="stylesheet">
@@ -430,19 +430,39 @@ const homeTemplateHtml = `<!DOCTYPE html>
430430
var MESSAGES_MAX_COUNT = 2000;
431431
432432
function appendLog(msg) {
433-
var startsWithBracked = msg.indexOf('{') == 0;
433+
let jsonMsg = {};
434+
let portListing = false;
435+
try {
436+
jsonMsg = JSON.parse(msg);
437+
portsListing = jsonMsg.Ports;
438+
} catch {
439+
// no valid json
440+
}
441+
434442
var startsWithList = msg.indexOf('list') == 0;
435443
436-
if (listenabled.checked || (typeof msg === 'string' && !startsWithBracked && !startsWithList)) {
437-
messages.push(msg);
438-
if (messages.length > MESSAGES_MAX_COUNT) {
439-
messages.shift();
440-
}
441-
log.innerHTML = messages.join('<br>');
442-
if (autoscroll.checked) {
443-
log.scrollTop = log.scrollHeight - log.clientHeight;
444-
}
445-
}
444+
if (listenabled.checked || (!portsListing && !startsWithList)) {
445+
let printMsg = msg;
446+
if (jsonMsg.Ports) {
447+
const validKeys = ['Name', 'SerialNumber', 'IsOpen', 'VendorID', 'ProductID'];
448+
if (jsonMsg.Network) {
449+
printMsg = "<b>Network Ports</b>:<br>${JSON.stringify(jsonMsg.Ports, validKeys, 2)}"
450+
} else {
451+
printMsg = "<b>Serial Ports</b>:<br>${JSON.stringify(jsonMsg.Ports, validKeys, 2)}"
452+
}
453+
} else if (Object.keys(jsonMsg).length !== 0) {
454+
printMsg = "${JSON.stringify(jsonMsg, undefined, 2)}";
455+
}
456+
messages.push(printMsg);
457+
if (messages.length > MESSAGES_MAX_COUNT) {
458+
messages.shift();
459+
}
460+
log.innerHTML = messages.join('<br><br>');
461+
if (autoscroll.checked) {
462+
log.scrollTop = log.scrollHeight - log.clientHeight;
463+
}
464+
}
465+
446466
}
447467
448468
$('#form').submit(function(e) {
@@ -505,14 +525,15 @@ body {
505525
#container {
506526
display: flex;
507527
flex-direction: column;
508-
height: 100%;
528+
height: 100vh;
509529
width: 100%;
510530
}
511531
512532
#log {
513533
flex-grow: 1;
514534
font-family: "Roboto Mono", "Courier", "Lucida Grande", Verdana, sans-serif;
515535
background-color: #DAE3E3;
536+
height: calc(100vh - 61px);
516537
margin: 15px 15px 10px;
517538
padding: 8px 10px;
518539
overflow-y: auto;
@@ -595,16 +616,15 @@ body {
595616
font-size: 1em;
596617
outline: none;
597618
}
598-
599619
</style>
600620
</head>
601621
<body>
602622
<div id="container">
603-
<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>
623+
<pre id="log"></pre>
604624
<div id="footer">
605625
<form id="form">
606626
<input type="submit" class="button" value="Send" />
607-
<input type="text" id="input" class="textfield" />
627+
<input type="text" id="input" class="textfield" aria-label="send command" />
608628
</form>
609629
<div id="secondary-controls">
610630
<div>
@@ -622,7 +642,6 @@ body {
622642
</div>
623643
</body>
624644
</html>
625-
626645
`
627646

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

0 commit comments

Comments
 (0)