-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
help util: replace jtextutils with asciitable (#415)
* main motivation: jtextutils became vulnerable because the domain `com.massisframework` is available for sale... * also: asciitable is better IMO
- Loading branch information
1 parent
7392bb8
commit ad8bec6
Showing
4 changed files
with
42 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name := "overflowdb-traversal" | ||
|
||
libraryDependencies ++= Seq( | ||
"net.oneandone.reflections8" % "reflections8" % "0.11.7", // go back to reflections once 0.9.13 is released | ||
"com.massisframework" % "j-text-utils" % "0.3.4" | ||
"net.oneandone.reflections8" % "reflections8" % "0.11.7", | ||
"de.vandermeer" % "asciitable" % "0.3.2", | ||
) |
36 changes: 22 additions & 14 deletions
36
traversal/src/main/scala/overflowdb/traversal/help/Table.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
package overflowdb.traversal.help | ||
|
||
import dnl.utils.text.table.TextTable | ||
import java.io.{ByteArrayOutputStream, PrintStream} | ||
import java.nio.charset.StandardCharsets | ||
import scala.util.Using | ||
import de.vandermeer.asciitable.AsciiTable | ||
import de.vandermeer.asciithemes.TA_GridThemes | ||
import de.vandermeer.skb.interfaces.transformers.textformat.TextAlignment | ||
|
||
case class Table(columnNames: Iterable[String], rows: Iterable[Iterable[String]]) { | ||
import scala.jdk.CollectionConverters.SeqHasAsJava | ||
|
||
lazy val render: String = { | ||
Using.Manager { use => | ||
val charset = StandardCharsets.UTF_8 | ||
val baos = use(new ByteArrayOutputStream) | ||
val ps = use(new PrintStream(baos, true, charset.name)) | ||
val rowsAsArray = rows.map(_.map(_ + " ").toArray.asInstanceOf[Array[Object]]).toArray | ||
new TextTable(columnNames.toArray, rowsAsArray).printTable(ps, 0) | ||
new String(baos.toByteArray, charset) | ||
}.get | ||
case class Table(columnNames: Seq[String], rows: Seq[Seq[String]]) { | ||
|
||
def render(width: Int = 120): String = { | ||
if (columnNames.isEmpty && rows.isEmpty) { | ||
"" | ||
} else { | ||
val table = new AsciiTable() | ||
table.addRule() | ||
table.addRow(columnNames.asJava) | ||
table.addRule() | ||
if (rows.nonEmpty) { | ||
rows.map(_.asJava).foreach(table.addRow) | ||
} | ||
table.addRule() | ||
table.getContext.setGridTheme(TA_GridThemes.FULL) | ||
table.setTextAlignment(TextAlignment.LEFT) | ||
table.render(width) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters