@@ -412,7 +412,7 @@ var homeTemplate = template.Must(template.New("home").Parse(homeTemplateHtml))
412
412
// If you navigate to this server's homepage, you'll get this HTML
413
413
// so you can directly interact with the serial port server
414
414
const homeTemplateHtml = `<!DOCTYPE html>
415
- <html>
415
+ <html lang="en" >
416
416
<head>
417
417
<title>Arduino Create Agent Debug Console</title>
418
418
<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>
430
430
var MESSAGES_MAX_COUNT = 2000;
431
431
432
432
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
+
434
442
var startsWithList = msg.indexOf('list') == 0;
435
443
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
+
446
466
}
447
467
448
468
$('#form').submit(function(e) {
@@ -505,14 +525,15 @@ body {
505
525
#container {
506
526
display: flex;
507
527
flex-direction: column;
508
- height: 100% ;
528
+ height: 100vh ;
509
529
width: 100%;
510
530
}
511
531
512
532
#log {
513
533
flex-grow: 1;
514
534
font-family: "Roboto Mono", "Courier", "Lucida Grande", Verdana, sans-serif;
515
535
background-color: #DAE3E3;
536
+ height: calc(100vh - 61px);
516
537
margin: 15px 15px 10px;
517
538
padding: 8px 10px;
518
539
overflow-y: auto;
@@ -595,16 +616,15 @@ body {
595
616
font-size: 1em;
596
617
outline: none;
597
618
}
598
-
599
619
</style>
600
620
</head>
601
621
<body>
602
622
<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 >
604
624
<div id="footer">
605
625
<form id="form">
606
626
<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" />
608
628
</form>
609
629
<div id="secondary-controls">
610
630
<div>
@@ -622,7 +642,6 @@ body {
622
642
</div>
623
643
</body>
624
644
</html>
625
-
626
645
`
627
646
628
647
func parseIni (filename string ) (args []string , err error ) {
0 commit comments