I need to display a table in a console.
My simple solution, if you would call it a “solution”, is as follows:
override def toString() = {
var res = "\n"
var counter = 1;
res += stateDb._1 + "\n"
res += " +----------------------------+\n"
res += " + State Table +\n"
res += " +----------------------------+\n"
for (entry <- stateDb._2) {
res += " | " + counter + "\t | " + entry._1 + " | " + entry._2 + " |\n"
counter += 1;
}
res += " +----------------------------+\n"
res += "\n"
res
}
We don’t have to argue this
- a is looking bad when displayed
- b code looks kinda messed up
Actually, such a question was asked for C# but I would like to know a nice solution for Scala as well.
So what is a (nice/good/simple/whatever) way to draw such a table in Scala to the console?
-------------------------------------------------------------------------
| Column 1 | Column 2 | Column 3 | Column 4 |
-------------------------------------------------------------------------
| | | | |
| | | | |
| | | | |
-------------------------------------------------------------------------
I’ve pulled the following from my current project: