Ncurses library on sololearn ! | Sololearn: Learn to code for FREE!


Ncurses library on sololearn !

I found today that one of my favorite libraries is available on Sololearn, namely ncurses. One little hiccup though, the output shows the ansi escape sequences as plain text. Is there a way to prevent this? See what i mean here:

1/26/2021 9:46:56 PM

ChillPill ๐ŸŒถ

21 Answers

New Answer


I don't believe there's a workaround: ncurses works by updating live console output, and sololearn input/output capture system cannot handle such things...


oups, less is not found. no less installed. weird cause i thought that was standard install on linux but i guess not.


ChillPill visph is correct, the i/o is handled by sololearn via plain text files only. Means even if you get the ANSI escape sequences interpreted via "less", still the final output will be piped to a plain text file only (logfile.txt which is later converted to completed.txt), making those escape sequences to again appear in final output. Check this out for more info about what SL is doing under the hood ( I didn't expect them to comment it so well ) ๐Ÿ‘‡ There are some possibe solutions I can think of to tackle this rn :- 1) strip off all the escape sequences from the output file (maybe via regex search) 2) try changing TERM variable so that ncurses doesn't send all the escape sequences with it 3) ( the Brian 's idea ) make use of SL's web code playground to interprete those escape sequences and then display it there.


imagine a ncurse interpreter that is basically a 2d array buffer. everytime you encounter a command like move cursor to y,x you get ready to write stuff at that position in the buffer. when you move up,down,left,right same thing. when you see a string you simply write it where the cursor is currently. clear screen would work too, just empty the buffer. now some commands might be missed like refresh() which is not an ansi code but a c function to shoot the buffer. but because we can only get the last frame returned to us from sololearn, doesnt matter, we can just flush the buffer once at the end of the program. ... edit as for the ansi color codes, we could just ignore them as the sololearn app can only display monochrome. same goes for many other ansi codes, we could just ignore and remove them.

+6 there are a few buffer files in "usercode" one for inputs one for stdout one for stderr


actually i had another idea that would give better results. the problem is that im too lazy to do it. here s my idea. make an ansi escape sequence interpreter. so it would read the output in logfile.txt, execute every escape codes. every time ncurses refreshes, output to usercode/errors which should display in the app as well. i dont get brian idea well though. not sure how to fool the app in displaying html code?


Brian you know what, we are just brainstorming here so s thank you very much for trying find a solution. i think it is good to explore all avenues.


Martin Taylor any thoughts about a hack for this? besides making an ansi code interpreter, because im really hoping for a lazy solution before i start coding an ansi interpreter. ... edit: shoots i already started something. i guess i ll have to make this happen afterall.


ncurses is great... but only works in "normal" interactive context, not through sololearn input/output capture system ^^


Yeah seems like you re right. Still maybe there is a way to hack this and make it work in Sololearn. I m wondering.


No idea. I dont know. Does the playground return an HTML string?


I rather think that input/output are exchanged as plain text... web i/o are handled at client side... (php, html; but node.js is server sided as others languages)


oh i found something guys i dont know if it s gonna work but i ll give it a try later. using "less".


ChillPill I really hope that you can figure this one out. I suppose that on SoloLearn it would have to be some kind of dynamic translator into HTML. How difficult would that be?


Redirect stdin and stdout of your C/C++ program to shared flat files or pipes that the JS can read/write during run time, and in turn update the DOM.


I also thought the same, but I thought that this is only applicable till the time we are text formatting (backspace,clearscreen etc) But could not think of a way to decode colour character and all that.


ChillPill I had naively proposed to use JS to issue a shell script to write and compile the curses-based program, run it, and redirect its i/o streams to some means of interprocess communication (IPC). From there, the JS would pick up the output and translate escape sequences into HTML directives for display on the screen. If it could work, then my own master plan would fall into place, and I could release my original 1980's interactive VT games! Alas, the IPC is the brick wall. I realized later that SoloLearn's JS runs on the client, not the server. It could not start a shell on SoloLearn's server and interact with files.


Martin Taylor if I am correct, we can change the TERM environment variable before executing the script to make sure ncurses sends appropriate ANSI escape sequences for that perticular terminal. My first attempt was to change it to something very bare bones (like dumb) so that there is less to no escape sequences to work with, but it ended up removing the entire output from the console, maybe there is something I am missing here.


i donโ€™t understand any of this, but i hope you figure it out!