Where can I find (or enable) an "interactive" console in node-red?

ok - 20 minutes :slight_smile:


Here is an alternative version that uses ansi-to-html

NOTE:

You will need node-red V1.3.x as this demo uses function external modules

Us8oCqVmtk

[{"id":"270e0d17.f1c9b2","type":"ui_template","z":"553814a2.1248ec","group":"6d01ec93.b1d374","name":"","order":7,"width":"12","height":"8","format":"\n<div id=\"shell\" style=\"font-family: monospace;\"></div>\n\n<script>\n(function(scope) {\n  scope.$watch('msg', function(msg) {\n    if (msg) {\n        debugger\n      $(\"#shell\").html(msg.payload);\n      $(\"#shell\").closest(\".nr-dashboard-template\").scrollTop(function() { return this.scrollHeight; });\n    }\n  });\n})(scope);\n</script>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":880,"y":2020,"wires":[[]]},{"id":"3e727ae4.147346","type":"exec","z":"553814a2.1248ec","command":"","addpay":"payload","append":"","useSpawn":"false","timer":"","oldrc":false,"name":"","x":630,"y":2100,"wires":[["195bbabe.711bb5"],[],[]]},{"id":"4d08470d.865218","type":"ui_button","z":"553814a2.1248ec","name":"","group":"6d01ec93.b1d374","order":3,"width":"3","height":"1","passthru":false,"label":"time /T","tooltip":"","color":"","bgcolor":"","icon":"","payload":"time /T","payloadType":"str","topic":"topic","topicType":"msg","x":350,"y":2020,"wires":[["3e727ae4.147346","195bbabe.711bb5"]]},{"id":"195bbabe.711bb5","type":"function","z":"553814a2.1248ec","name":"","func":"\nif(!msg.payload) return;\nvar convert = new ansiToHtml();\nconst CR = '\\r';\nconst LF = '\\n';\nconst CRLF = CR+LF;\nlet input = msg.payload + \"\";\ninput = input.replace(new RegExp(CR, 'g'), LF)\ninput = input.replace(new RegExp(CRLF, 'g'), LF)\n\nconst MAXLINES = 200;\nlet data = context.get(\"data\") || [];\nif(msg.topic==\"clear\") {\n    data = [];\n} else {\n    const lines = input.split(LF);\n    data.push(...lines)\n    data = data.slice(-MAXLINES);\n}\ncontext.set(\"data\", data);\n\nvar html = convert.toHtml(data.join(\"<br>\"))\nmsg.payload = html;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"ansiToHtml","module":"ansi-to-html"}],"x":700,"y":2020,"wires":[["270e0d17.f1c9b2"]]},{"id":"aacf91fd.8dbd3","type":"ui_button","z":"553814a2.1248ec","name":"","group":"6d01ec93.b1d374","order":4,"width":"3","height":"1","passthru":false,"label":"where node","tooltip":"","color":"","bgcolor":"","icon":"","payload":"where node","payloadType":"str","topic":"topic","topicType":"msg","x":370,"y":2060,"wires":[["3e727ae4.147346","195bbabe.711bb5"]]},{"id":"16e0554b.d16f7b","type":"ui_button","z":"553814a2.1248ec","name":"","group":"6d01ec93.b1d374","order":5,"width":"3","height":"1","passthru":false,"label":"demo ANSI","tooltip":"","color":"","bgcolor":"","icon":"","payload":"where cmd","payloadType":"str","topic":"topic","topicType":"msg","x":370,"y":1960,"wires":[["55a5d564.95fd5c"]]},{"id":"ca6518ec.ca9f78","type":"ui_button","z":"553814a2.1248ec","name":"","group":"6d01ec93.b1d374","order":6,"width":"3","height":"1","passthru":false,"label":"clear","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"clear","topicType":"str","x":350,"y":2140,"wires":[["195bbabe.711bb5"]]},{"id":"14e64a77.db0856","type":"inject","z":"553814a2.1248ec","name":"demo ANSI colrs","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":380,"y":1920,"wires":[["55a5d564.95fd5c"]]},{"id":"55a5d564.95fd5c","type":"function","z":"553814a2.1248ec","name":"","func":"\nvar convert = new ansiToHtml();\n\nmsg.payload = `\\x1b[30mblack\\x1b[37mwhite\nnew line\nanother \\u001b[31mnew\\u001b[0m line\na new line with \\u001b[31mcolor\\u001b[0m embeded`\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[{"var":"ansiToHtml","module":"ansi-to-html"}],"x":560,"y":1960,"wires":[["195bbabe.711bb5"]]},{"id":"6d01ec93.b1d374","type":"ui_group","name":"UserEntry","tab":"5132060d.4cde48","order":2,"disp":true,"width":"12","collapse":false},{"id":"5132060d.4cde48","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]
1 Like