io.worxbend.tui.macros

Members list

Type members

Classlikes

trait Codec[A]

How a value becomes a compact line of text and comes back again — the typeclass behind persisted signals.

How a value becomes a compact line of text and comes back again — the typeclass behind persisted signals.

The text form is a stream of length-prefixed atoms, :, with no quoting or escaping anywhere: a String is one atom, a number is one atom holding its decimal spelling, a case class is its fields' encodings one after another (the field count is known from the type, so nothing frames it), an Option is a one-character atom followed by the value when present, a collection is its size followed by its elements, and an enum or sealed trait is the case name followed by that case's fields. Any string can therefore be carried verbatim, decoding is one left to right pass with no backtracking, and a file truncated or edited by hand fails with a message rather than an exception or a half-read value. Collection decoding has an input-sized expansion budget plus 1024 elements (shared by nested collections), including for custom codecs or empty products that consume no text. It is a storage format, not a wire or interchange format.

The text encode produces starts with a version tag, @;, and decode reads it back: a codec's version is 1 unless it was built with versioned, whose migration hook reads an older version's text into today's type — Codec.derived[Prefs].versioned(2) { case 1 => Codec.readAs[PrefsV1](old => Prefs(...)) }. Text with no tag, which is what a pre-tag release wrote, is version 1; no untagged text can start with @, because every atom starts with a digit. A version the codec cannot read decodes as a Left, which Persisted in tui-runtime treats as "start from the initial value". The tag is written once, at the top: a nested value carries none.

Instances for the primitives, Option and the immutable collections are in the companion, and so is Codec.derived, which hands any case class, enum or sealed hierarchy the codec deriveCodec builds — so a Codec[Settings] is summoned without a declaration, nested types included. A type of your own that is none of those, or that wants a different text form, joins by declaring a given Codec[YourType] next to it, usually through Codec.atom; a given in lexical scope wins over the derivation.

Pure and thread-agnostic: write and read touch only their arguments, so an instance may be shared and called from any thread — a persisted signal encodes on the render thread and writes the text on a worker.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object Codec

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Codec.type
final class DerivedField[A, V]

A field selected from one derived spec, with its exact declared Scala value type.

A field selected from one derived spec, with its exact declared Scala value type.

Validation can reject a value, never replace it. Parser transformations belong to Field or FormFieldType, not to this handle. The constructor is internal: only a compile-time checked case-class field selection creates one.

Attributes

Supertypes
class Object
trait Matchable
class Any
final case class Field[A](spec: FieldSpec, parse: String => Either[String, A])

A form field with parsing and validation, composing cue4s-style: transforms are stored lazily and run when the field's raw input is submitted.

A form field with parsing and validation, composing cue4s-style: transforms are stored lazily and run when the field's raw input is submitted.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object Field

Standalone parsers. map and mapValidated may change their result type, but FormState.of accepts only spec-owned FieldValidation rules, never these parsers. Customize derivation through FormFieldType instead.

Standalone parsers. map and mapValidated may change their result type, but FormState.of accepts only spec-owned FieldValidation rules, never these parsers. Customize derivation through FormFieldType instead.

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Field.type
enum FieldInput

What kind of input control a form field needs — chosen by the field type's FormFieldType.

What kind of input control a form field needs — chosen by the field type's FormFieldType.

Attributes

Supertypes
trait Enum
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class FieldSpec(name: String, input: FieldInput)

One field of a derived form: the case-class field name and its input kind.

One field of a derived form: the case-class field name and its input kind.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
sealed abstract class FieldValidation[A]

An immutable, spec-owned validation rule. No public constructor or parser replacement channel is exposed.

An immutable, spec-owned validation rule. No public constructor or parser replacement channel is exposed.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object FormFieldType

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
trait FormFieldType[A]

How one type becomes one form field: which control the user types into, and how the text they typed turns back into a value of that type.

How one type becomes one form field: which control the user types into, and how the text they typed turns back into a value of that type.

deriveForm summons one of these per case-class field. That is the whole extension point: a type the library has never heard of joins the derivation the moment a given FormFieldType[ThatType] is in its implicit scope — which for a type you declared yourself means "next to it, in its companion object".

opaque type Email = String

object Email:
 def from(raw: String): Either[String, Email] =
   if raw.contains("@") then Right(raw) else Left(s"'$raw' is not an email address")

 given FormFieldType[Email] = FormFieldType(FieldInput.TextField)(Email.from)

final case class Signup(email: Email, age: Int)
deriveForm[Signup] // compiles: Email brought its own instance

Pure and thread-agnostic: parse reads its argument and allocates a result, touching no shared state, so it is safe to call from any thread including the render thread. An implementation that blocks or mutates shared state breaks that promise — the form calls parse on the render thread when the user submits.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object FormSpec

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type
FormSpec.type
final class FormSpec[A]

A compile-time-derived description of a form for A: the controls, their original per-type parsers, and internal product assembly. Produced by deriveForm; owned by tui-macros so tui-dsl can consume it without a circular dependency.

A compile-time-derived description of a form for A: the controls, their original per-type parsers, and internal product assembly. Produced by deriveForm; owned by tui-macros so tui-dsl can consume it without a circular dependency.

Consumers inspect fields and obtain typed handles with field. The existential default parsers and Seq[Any] product assembly are internal to the library: only the original derived parsers supply those values, in declaration order. Validators check the resulting A and cannot replace any field value. The arity assertion protects this internal seam; no runtime type test or reflection is used to recover erased field types.

Value parameters

assemble

builds an A from one value per field, subject to the contract above

defaults

one Field per case-class field, in declaration order, each already carrying the FieldSpec and the parser its type's FormFieldType chose. Holding the whole Field — rather than only its spec — is what lets a field type nobody in this module knows about supply its own parser: there is no step that turns a FieldInput back into a parser, so the set of supported types never has to be closed.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
trait Pretty[A]

How a value of type A is described for display — the typeclass behind the DSL's inspect(value).

How a value of type A is described for display — the typeclass behind the DSL's inspect(value).

Instances for the primitives, String (quoted and escaped), Option and the immutable collections are in the companion, and so is Pretty.derived, which hands any case class, enum or sealed hierarchy the instance derivePretty builds through its Mirror — no reflection, so a native image needs no configuration. A type of your own that wants a different form declares a given Pretty[YourType] beside it, usually through Pretty.atom; a given in lexical or companion scope wins over the derivation, which is also how a field holding a secret is kept off the screen.

Pure and thread-agnostic: describe touches only its arguments.

Attributes

Companion
object
Supertypes
class Object
trait Matchable
class Any
object Pretty

Attributes

Companion
trait
Supertypes
class Object
trait Matchable
class Any
Self type
Pretty.type
final case class PrettyEntry[R](key: R, value: R)

One described map entry. Immutable and thread-agnostic; owned by the description builder.

One described map entry. Immutable and thread-agnostic; owned by the description builder.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
final case class PrettyField[R](name: String, value: R)

One labelled product field. Immutable and thread-agnostic; owned by the description builder.

One labelled product field. Immutable and thread-agnostic; owned by the description builder.

Attributes

Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
trait PrettyShape[R]

What a Pretty describes a value to: four ways to build a description of type R.

What a Pretty describes a value to: four ways to build a description of type R.

The description is built through this interface rather than returned as a data type of this module's own because tui-macros sits below every other module and names nothing from them: the DSL's inspect(value) hands in a shape that builds tui-widgets' PrettyValue, a test hands in one that spells a string, and neither module has to know about the other.

Type parameters

R

the description being built

Attributes

Supertypes
class Object
trait Matchable
class Any

Value members

Concrete methods

inline def deriveCodec[A](using mirror: Of[A]): Codec[A]

Derives a Codec for a case class, an enum or a sealed hierarchy at compile time through its Mirror.

Derives a Codec for a case class, an enum or a sealed hierarchy at compile time through its Mirror.

Each field, and each case of a sum, summons its own Codec — a hand-written given where there is one, and otherwise Codec.derived, which is this derivation again — so a nested case class or an enum field needs no declaration of its own. A field type with neither is a compile error naming the type, never a runtime failure, and nothing here reads a class at runtime: a native image needs no reflection configuration for the derived types.

The recursion is one inline step per field and per case, which is spent from the call site's -Xmax-inlines budget (32 by default). A very wide case class, or a deep nest of them, can run out; the fix is to derive the inner types into their own givens, which resets the budget at each one.

Attributes

inline def deriveForm[A](using m: ProductOf[A]): FormSpec[A]

Derives a FormSpec for a case class at compile time via Mirror.ProductOf — field names become field specs, and each field's type chooses its control and its parser by way of the FormFieldType summoned for it (String → text, Int/Long → whole-number, Double/BigDecimal → decimal, Boolean → checkbox, java.util.UUID and the java.time value types → text, Option[A] → the same control as A with blank meaning None). A field type with no instance in scope is a compile error, not a runtime surprise, and a type of your own joins the set by declaring given FormFieldType[YourType] in its companion — see FormFieldType.

Derives a FormSpec for a case class at compile time via Mirror.ProductOf — field names become field specs, and each field's type chooses its control and its parser by way of the FormFieldType summoned for it (String → text, Int/Long → whole-number, Double/BigDecimal → decimal, Boolean → checkbox, java.util.UUID and the java.time value types → text, Option[A] → the same control as A with blank meaning None). A field type with no instance in scope is a compile error, not a runtime surprise, and a type of your own joins the set by declaring given FormFieldType[YourType] in its companion — see FormFieldType.

The returned spec exposes typed handles for direct case-class field selections. Its original parsers and ordered product assembly remain internal; validation checks the typed candidate and never replaces field values.

No runtime reflection anywhere: constValueTuple and summonAll are resolved during compilation and fromProduct is a direct call, so a native image needs no reflect-config entry for the derived type.

One diagnostic is deliberately weaker than it could be: the compile error names the type that has no instance, not the field that carries it. Pairing each label with its type so the message could say both makes the compiler print the name as ("age" : String) followed by several lines of implicit-search trace, which reads worse than the short message. In a case class with two fields of the same unsupported type, look for the type rather than the name.

Attributes

inline def derivePretty[A](using mirror: Of[A]): Pretty[A]

Derives a Pretty for a case class, an enum or a sealed hierarchy at compile time through its Mirror — the same pattern as deriveCodec: each field and each case summons its own instance, a hand-written given where there is one and Pretty.derived otherwise, so nested types need no declaration and a missing instance is a compile error naming the type. The recursion spends the call site's -Xmax-inlines budget; derive inner types into their own givens to reset it.

Derives a Pretty for a case class, an enum or a sealed hierarchy at compile time through its Mirror — the same pattern as deriveCodec: each field and each case summons its own instance, a hand-written given where there is one and Pretty.derived otherwise, so nested types need no declaration and a missing instance is a compile error naming the type. The recursion spends the call site's -Xmax-inlines budget; derive inner types into their own givens to reset it.

Attributes