Is there no way to wipe all the previous println's...
# getting-started
r
Is there no way to wipe all the previous println's in the terminal output? I am making a simple terminal game and am trying to create an animation of characters moving across the screen, so I need to be erasing the terminal each time.
c
There's nothing out of the box, since it things like colors and clearing terminal text depends on how the terminal interprets the output, and can get quite difficult. You can do it by manually outputting ANSI control codes, but I wouldn't recommend trying that. Instead, you might check out Mosaic, which is Compose for terminal UIs https://github.com/JakeWharton/mosaic
r
I can't expect my children students to know how to set that up šŸ˜•,
and don't want them to have to copy paste a template
just trying to find a way to make this language work for teaching.
it is obviously the best in terms of syntax. but the whole ecosystem is so framework oriented and complicated..
like, just making a simple cellular automata program on the command line, is somehow not trivial to do
i am comparing this to previous teaching experience using python where students are able to create a single file, write a few lines of code to receive input and print text, and clear the terminal each time to simulate animation
c
Personally, I don't see any issue with having students start their projects from a template repo. Any language is going to make you do that, so it prepares them for real world programming. Most of the projects I did in college started by copying a repo. I agree that Mosaic probably isn't appropriate for teaching, though. In that case, it might be worth it teaching them to use ANSI control codes. Or alternatively, many of my college projects just printed a few newlines between each "update". Sure you'll see multiple steps in the terminal at once, but that might be a better option to help focus the lesson on one specific thing, and not get in the weeds of terminal codes and stuff like that.
Also, the comparison to Python isn't really a great one, because Python was designed to be a scripting language. Kotlin was not. However, it does support some level of scripting, so you might consider installing the
kotlinc
compiler, and using that directly from the terminal to run
.kts
files instead of a full project https://kotlinlang.org/docs/custom-script-deps-tutorial.html
The scripting functionality won't be as nice as Python, because Kotlin is not primarily a scripting language, but it can help reduce some of the pain of setting up new projects for assignments. Also, you might consider Intellij Idea for Education https://www.jetbrains.com/idea-edu/
a
Mordant is another nice library for pretty terminal output https://ajalt.github.io/mordant/guide/ Controlling the terminal is done using ANSI escape codes, which aren't supported by all environments, which is why the answers here are inconsistent.
e
c
Kotter is another pretty good terminal output library
m
Sure youā€™ll see multiple steps in the terminal at once
That just means you are not printing enough newlines. šŸ˜„ Given enough newlines, the new output will be always be at the same place at the bottom of the screen with nothing else visible, end so effectively ā€œupdate in placeā€. Of course itā€™s a very hacky way of achieving it, but it is very simple to do.