flix

0.69.2

Sys.Console

eff ConsoleSource

An effect used to interact with the console.

Operations

def eprint(s: String): Unit \ Console Source

Prints the given string s to the standard err.

def eprintln(s: String): Unit \ Console Source

Prints the given string s to the standard err followed by a new line.

def print(s: String): Unit \ Console Source

Prints the given string s to the standard out.

def println(s: String): Unit \ Console Source

Prints the given string s to the standard out followed by a new line.

def readln(): String \ Console Source

Reads a single line from the console.

Definitions

def confirm(p: a, default: { default = Bool }): Bool \ Console + Aef[a] with Formattable[a] Source

Prints prompt p with a yes/no hint and reads a boolean answer.

Appends [Y/n] if default#default is true, or [y/N] if false. Empty input returns default#default. Recognizes "y", "yes", "n", "no" (case-insensitive). Any other input returns default#default.

def handle(f: a -> b \ ef): a -> b \ (ef - Console) + IO Source

Handles the Console effect of the given function f.

In other words, re-interprets the Console effect using the IO effect.

def pick(p: a, choices: List[b]): Option[b] \ Console + Aef[a] + Aef[b] with Formattable[a], Formattable[b] Source

Prints prompt p followed by a numbered list of options, then reads a selection.

Returns Some(element) if the user enters a valid number, None otherwise.

def pickWith(p: a, choices: List[b]): b \ Console + Aef[a] + Aef[b] with Formattable[a], Formattable[b] Source

Like pick, but re-prompts until the user makes a valid selection.

def readlnWith(p: a, f: String -> Result[String, b]): b \ Console + Aef[a] with Formattable[a] Source

Prints prompt p, reads a line, and applies f to the input.

If f returns Err(msg), prints msg to stderr and re-prompts. If f returns Ok(v), returns v.

def readlnWithDefault(p: a, default: String): String \ Console + Aef[a] with Formattable[a] Source

Prints prompt p, reads a line, and returns default if the input is empty or whitespace.

@DefaultHandler
def runWithIO(f: Unit -> a \ ef): a \ (ef - Console) + IO Source

Runs the Console effect of the given function f.

In other words, re-interprets the Console effect using the IO effect.