gleamtea/layout

Position a block of content within the terminal — centring, framing and floating overlays (modals/popovers). New in beamtea 0.1.2.

Pair these with gleamtea.window_size() to size content to the terminal from inside your view:

let #(cols, rows) = gleamtea.window_size()
layout.center(my_box, cols, rows)

Types

Horizontal alignment. The constructors compile straight to the atoms beamtea expects (left / center / right).

pub type HAlign {
  Left
  Center
  Right
}

Constructors

  • Left
  • Center
  • Right

Vertical alignment (top / middle / bottom).

pub type VAlign {
  Top
  Middle
  Bottom
}

Constructors

  • Top
  • Middle
  • Bottom

Values

pub fn center(content: String, cols: Int, rows: Int) -> String

Centre content both horizontally and vertically in a cols × rows area.

pub fn frame(
  content: String,
  cols: Int,
  rows: Int,
  border: color.Color,
) -> String

Draw a bordered panel that fills the whole cols × rows terminal and place content inside it. Lines wider than the inner width are truncated.

pub fn overlay(
  bg bg: String,
  fg fg: String,
  col col: Int,
  row row: Int,
  cols cols: Int,
  rows rows: Int,
) -> String

Composite fg on top of bg at #(col, row) (0-based) within a cols × rows area — the basis for a floating modal/popover.

pub fn overlay_center(
  bg: String,
  fg: String,
  cols: Int,
  rows: Int,
) -> String

Centre fg over bg within a cols × rows area.

pub fn place(
  content: String,
  cols: Int,
  rows: Int,
  align: #(HAlign, VAlign),
) -> String

Place content within a cols × rows area with the given alignment. The block keeps its internal left-alignment; it is positioned as a unit.

pub fn top_center(
  content: String,
  cols: Int,
  rows: Int,
) -> String

Centre content horizontally, pinned to the top.

Search Document