Skip to content

Geometry

The dimensions of a terminal-backed Console.

Returned by geometry().

Fields

rows

Height in character cells, or nil if unknown.

Returns: Int?

cols

Width in character cells, or nil if unknown.

Returns: Int?

rows and cols are independently nil: a console may know one dimension without the other. The host console (term.console) always returns a Geometry, never nil itself — see Console.geometry().

let g = term.console.geometry()
if g.cols
  echo $ term.preformat $ "-" * g.cols

Subclassing

Geometry is the interface; reading rows or cols on a bare instance throws UnsupportedError. A Do console that implements geometry() subclasses this to describe itself:

class FixedGeometry: term.Geometry
  pub field rows
  pub field cols

  def (init) self rows cols
    term.Geometry.(init) $self
    self.rows = rows
    self.cols = cols