Skip to content

Support for Advanced Styling in the Terminal #10

Description

@erikareads

I need a styling library for teashop,
ansi supports many of the operations that I want to support,
but not quite in the right way.

This issue is an open question of whether it makes sense to adapt/enhance ansi to support my styling needs.

For performance reasons, I would like to apply as many styles at once as possible, to avoid unnecessary string concatenations. Especially for Erlang. For teashop I might need to render multiple styles at 60 FPS.

For this, I would like to do something like a builder API:

pub fn bold(style, bool) { Style(..style, bold: bool) }

I would also like to support operations that don't feel like they fit into ansi, such as text alignment, padding, and borders.

Here is an incomplete list of all the things I want to be able to support:

pub type Style {
  Style(
    background: Option(Color),
    blink: Bool,
    bold: Bool,
    faint: Bool,
    foreground: Option(Color),
    height: Option(Int),
    italic: Bool,
    margin_bottom: Int,
    margin_left: Int,
    margin_right: Int,
    margin_top: Int,
    max_height: Option(Int),
    max_width: Option(Int),
    padding_bottom: Int,
    padding_left: Int,
    padding_right: Int,
    padding_top: Int,
    reverse: Bool,
    strikethrough: Bool,
    underline: Bool,
    width: Option(Int),
    horizontal_alignment: Option(Alignment),
    vertical_alignment: Option(Alignment),
    underline_spaces: Bool,
    strikethrough_spaces: Bool,
    transform: Option(fn(String) -> String),
  )
}

I will be using ANSI escape codes to achieve these colors and styles.
As much as possible, I would like to present a unified interface for building a style.

In Go, the styles are built up first, then concatenated in one operation:

https://github.com/muesli/termenv/blob/9850e567a4bfc1af41a28a48fbb1f6fde4e7f20a/style.go#L43-L57

Does it make sense to add such functionality to ansi?

Regardless of decision, I think it's important to note that ansi works right now with teashop, since teashop doesn't care where the ANSI strings come from.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions