Simple menus for Scala console applications
- Functional API
- Menu is displayed using Show instance of menu elements. (You are not restricted to use String elements only.)
- Pluggable effect type, based on cats-effect
Include it in your project by adding the following to your build.sbt:
libraryDependencies += "com.github.kovszilard" %% "smenu" % "0.1.0"
// Using IO for effect, and String for menu elements
import cats.Show
import cats.instances.all._
import cats.syntax.all._
import cats.data.NonEmptyList
import cats.effect.IO
import smenu.Menu._
singleChoiceMenu[IO, String]("What is your favourite fruit?", NonEmptyList.of("Apple", "Banana", "Orange"))
// Using IO for effect, and Pet for menu elements
import cats.Show
import cats.instances.all._
import cats.syntax.all._
import cats.data.NonEmptyList
import cats.effect.IO
import smenu.Menu._
trait Pet
case object Cat extends Pet
case object Dog extends Pet
implicit def showPet: Show[Pet] = Show[String].contramap(_.toString)
multipleChoiceMenu[IO, Pet]("Cats or dogs or both?", NonEmptyList.of(Cat, Dog))
Please give it a star. It is just one click for you and it keeps me motivated to write open source tools like this.