terminal_size

Cross-platform terminal size helpers for MoonBit.

terminal
tty
console
native
windows
macos
linux
moon add justjavac/terminal_size@0.1.5
Download zip
Author
Version
0.1.5
License
MIT
Last updated
2 months ago
Downloads
34
README

#justjavac/terminal_size

Cross-platform terminal size helpers for MoonBit.

///|
test "terminal size api can be called" {
match @terminal_size.terminal_size() {
Some(size) => {
assert_true(size.columns > 0)
assert_true(size.rows > 0)
}
None => ()
}
}

#
Size

pub struct Size {
columns : Int
rows : Int
} derive(Eq,
Debug
)

Visible size of a terminal measured in character cells.

columns is the terminal width and rows is the terminal height. The public API uses a small record so callers can access size.columns and size.rows directly, which is usually more natural in MoonBit than wrapping each dimension in its own numeric newtype.

Values returned by terminal_size() are always positive.
impl Show for Size

#
terminal_size

fn terminal_size() -> Size?

Returns the visible size of the current terminal in character cells.

The function probes the three standard streams in this order: stdout, stderr, then stdin. The first stream that is attached to a terminal and reports a non-zero size wins. If none of the standard streams are attached to a terminal, this function returns None.

The implementation uses platform-native APIs:

  • Windows: GetConsoleScreenBufferInfo
  • Unix-like systems: ioctl(TIOCGWINSZ)

The returned Size describes the visible terminal window, not a scrollback buffer or an off-screen backing store.

Example

test {
match @terminal_size.terminal_size() {
Some(size) => {
assert_true(size.columns > 0)
assert_true(size.rows > 0)
}
None => ()
}
}

Source Files

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io