Redirecting console.log #4183
Replies: 1 comment
-
Posted at 2023-04-03 by @gfwilliams Espruino has something called That could potentially be a good solution, although it won't work if you're printing huge amounts of data. For up to ~1000 bytes at once it should be fine though Posted at 2023-04-08 by Nicktonious Hello again! That was a very helpful advice, but now I'm struggling with such a problem - obviously after LoopbackA.setConsole() I lose opportunity to prompt commands into IDE console and it is inacceptable accordint to my plans. What could You advise? P.S looks like I already fixed it by piping default console (USB in my case) with LoopbackB. Posted at 2023-04-12 by @gfwilliams Yes, that's all you need - to pipe another input device in. You will lose the ability to do things like Ctrl-C to break out of executing code, but otherwise it's fine Posted at 2023-04-18 by Nicktonious Hello again. As REPL returns data (I am about data that comes on LoopbackB.on(data => ...) with various combinations of special symbols ['\r\n', '1x0B[', etc], I wanted to ask if it's possible to check all those "heads" and "tails" of messages. Posted at 2023-04-18 by @gfwilliams I'm not sure I really understand the question... There isn't anything built in to Espruino that separates specific commands in the output stream - it is just a sequence of characters (as would go to a VT100 terminal app). You may be seeing char code 8 which is a delete, because normally the console outputs To avoid that you can run Posted at 2023-04-18 by @fanoush If you are not interested in the interactive console I/O and just really care about output of
Posted at 2023-04-18 by @fanoush or full example - the
Posted at 2023-04-23 by Nicktonious I just wanted to say that when I catch console logs and answers from interactive console with code like this
I get logs like this:
That looks quite readable, but some situations lead to logs like this:
So I have to remove all special symbols somehow. Yeah, it's not hard at all to write a simple parser on regexps for those exact types of logs, but as I don't know how exactly IDE is formatting logs, I may easily trap into using code that doesnt work correctly for some cases. So, what would you advice? Posted at 2023-04-23 by Nicktonious Thanks for trying to help, but interactive I/O is needed. Posted at 2023-04-23 by Nicktonious Btw, I wanted to ask why it looks like I'm only slightly changing the route of data (as it still goes from REPL to IDE console through USB and vice versa) but on practice IDE console is loosing it's functionality ('ctrl+c' like u have said before, Up keyword doesn't print the previous command, backspaces don't properly clear console and etc). That all makes console kind of vulnerable for improper input. No way to change it? Posted at 2023-04-24 by @gfwilliams I'm not sure quite what you're doing with Ctrl-C doesn't work because JS is effectively single-threaded. Data is only transferred between USB/Loopback when your JS is run which transfers it - but if you are running other code then the JS that does that doesn't run. To work around it normally there's some special code in the interpreter which looks for Ctrl-C as it comes in, in the interrupt. If you want to figure out how to properly interpret the data you're getting, google VT100 - that's effectively what you have. Espruino does have a very simplistic implementation in https://www.espruino.com/modules/VT100.js which handles writing everything out to a Graphics instance, and potentially you could use that if you really needed to. Posted at 2023-04-26 by Nicktonious Thanks for all answers and advices you have given me! All of that was extremly helpful. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2023-04-02 by Nicktonious
I want to realize a certain logic, that would kind of change the way console.log works. I want it to send data not just into Espruino console, but into my webpage/node-red/somewhere else.
What would be the most optimal way to do it?
As I work with various Espruino devices, it's very important to choose the universal way, so I would rely on usb connection, but not bluetooth or something else.
Thank in advance!
Beta Was this translation helpful? Give feedback.
All reactions