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

No problem. Thanks for the comment.

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

Woah, that's fast! Thank you @Steve-Mcl for updating the flow.

Actually, I just edited it to set the font mono-spaced (better for terminal - you might want to re-import the flow from previous thread. Up to you.

1 Like

Hi again @Steve-Mcl , I upgraded my node-red to run your flow but it still says -

ReferenceError: ansiToHtml is not defined 

However, I am unclear why it is says so because I can clearly see ansi-to-html module in /home/pi/.node-red/node_modules.

ansi-to-html

I have tried installing it using npm as well as manually by cloning the git repo but still, no luck. I understand that you are calling a function ansiToHtml() in the function nodes but that does not seem to work for me. Do you have any idea how to fix this?

My node-red and node.js version info is as follows:

7 Jun 14:43:59 - [info] Node-RED version: v1.3.5
7 Jun 14:43:59 - [info] Node.js  version: v12.22.0
7 Jun 14:43:59 - [info] Linux 5.10.17-v7l+ arm LE
7 Jun 14:43:59 - [info] Loading palette nodes
7 Jun 14:44:01 - [info] Dashboard version 2.28.2 started at /
7 Jun 14:44:01 - [info] Settings file  : /home/pi/.node-red/settings.js
7 Jun 14:44:01 - [info] HTTP Static    : /home/pi/.node-red/static
7 Jun 14:44:01 - [info] Context store  : 'default' [module=memory]
7 Jun 14:44:01 - [info] User directory : /home/pi/.node-red
7 Jun 14:44:01 - [warn] Projects disabled : editorTheme.projects.enabled=false
7 Jun 14:44:01 - [info] Flows file     : /home/pi/.node-red/flows_rss-01.json
7 Jun 14:44:02 - [info] Server now running at http://127.0.0.1:1880/admin/

Did you enable function external modules ?

You don't install that package into node-red node_modules you use the "setup" tab on the function node to add the package.

I understand now that I had not configured the function node. However, I cannot see functionExternalModules in my settings.js file. As mentioned earlier, I am running node-red 1.3.5. Has the name changed by any chance? I am uploading my settings file as .txt for reference.

settings.txt (12.9 KB)

Just add functionExternalModules: true in the settings.

Be sure to add a comma before or after depending on where you add it.

Ok, now it works! Thank you for the help in debugging.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.