gchudnov / swearwolf   2.1.0

MIT License GitHub

A Scala library to write to and read from the terminal

Scala versions: 3.x 2.13

swearwolf

A Scala library to write to and read from the terminal.

Scala CI

Built for Scala 3.1.

Use the previous version of the library for scala 2.13.


Preview

preview

Usage

Add the following dependency to your build.sbt:

libraryDependencies += "com.github.gchudnov" %% "swearwolf-term" % "2.1.0"

// Optionally, include rich-text & shapes libraries
libraryDependencies += "com.github.gchudnov" %% "swearwolf-rich" % "2.1.0"
libraryDependencies += "com.github.gchudnov" %% "swearwolf-shapes" % "2.1.0"

ZIO-integration: instead of the imports listed above, use the ones with zio suffix:

libraryDependencies += "com.github.gchudnov" %% "swearwolf-term-zio" % "2.1.0"
libraryDependencies += "com.github.gchudnov" %% "swearwolf-rich-zio" % "2.1.0"
libraryDependencies += "com.github.gchudnov" %% "swearwolf-shapes-zio" % "2.1.0"

A Non-Interactive example:

import com.github.gchudnov.swearwolf.rich.IdRichText.*
import com.github.gchudnov.swearwolf.rich.RichText
import com.github.gchudnov.swearwolf.term.*
import com.github.gchudnov.swearwolf.util.*

object Main extends App:
  import TextStyle.*

  val term   = Term.syncId()
  val writer = Writer.syncId(term)

  val rich = RichText("<b>BOLD</b><fg='#AA0000'><bg='#00FF00'>NOR</bg></fg>MAL<i>italic</i><k>BLINK</k>\n")

  writer.put("HELLO ", Bold | Foreground(Color.Blue))
  writer.put("WORLD!\n", Foreground(Color.Blue) | Background(Color.Yellow))
  writer.putRich(rich)

  writer.flush()

See examples directory for the list of demo applications.

Modules

  • /util - A collection of utilities, other libraries in the project depend on.
  • /term - Enable interactive and non-interactive IO in the terminal.
  • /shapes - A collection of shapes (box, chart, grid, label, table) to use with the library.
  • /rich - Rich text to display in the terminal.
  • /zio - Integration with ZIO.

Building Examples

The project contains several demo applications that demonstrate how to use the library with the keyboard and mouse input.

To build, invoke:

sbt assembly

After building, several executables will be available in /target directory:

./example-either
./example-log
./example-noninteractive
./example-zio

Compatibility

The library was built and tested on Ubuntu 18.04.5 LTS with GNU bash, version 4.4.20.

Contact

[Grigorii Chudnov] (mailto:[email protected])

License

Distributed under the The MIT License (MIT).