Skip to content

Interfaces and Enums ​

tyrus:os exports four native enums and eight native interfaces.

Interfaces must be imported by name

Unlike the enums below, UserInfo, CpuInfo, BatteryInfo, NetworkInterface, OsError, NotifyOptions, FontInfo, and Color are not available until the file imports them explicitly, import { CpuInfo, cpus } from "tyrus:os";, not just cpus. This applies even without writing the type name in an annotation: const cores = cpus(); cores[0].model still requires CpuInfo to be imported, since resolving .model needs its field list.

OsPlatform and OsArch ​

OsPlatform and OsArch are returned by platform() and arch(). Both reflect the target this binary was compiled for, not a runtime guess.

tyrus
import { arch, platform } from "tyrus:os";
import { OsArch, OsPlatform } from "tyrus:os";

const currentPlatform: OsPlatform = platform();
const currentArch: OsArch = arch();

print(currentPlatform === OsPlatform.Linux);
print(currentArch === OsArch.X86_64);

OsPlatform Members ​

MemberMeaning
LinuxLinux
MacOSmacOS
WindowsWindows
OtherAny other target

OsArch Members ​

MemberMeaning
X86_6464-bit x86
Aarch6464-bit ARM
X8632-bit x86
Arm32-bit ARM
OtherAny other target

NotifyUrgency ​

NotifyUrgency is NotifyOptions's urgency field, passed to notify().

NotifyUrgency Members ​

MemberMeaning
LowLow priority, the desktop environment may not show it at all in "do not disturb" mode.
NormalDefault priority.
CriticalHigh priority, some desktop environments keep it on screen until dismissed.

SystemCapability ​

SystemCapability is hasCapability()'s argument type: each member answers "can I find out?"/"would this work?" for one corner of tyrus:os, without triggering the real effect.

SystemCapability Members ​

MemberMeaning
NotificationWhether a desktop notification could plausibly be shown.
ClipboardWhether the system clipboard can be reached.
BatteryWhether this machine reports at least one battery.
DarkModeWhether the desktop's dark-mode setting is queryable at all.
ScreenLockWhether the screensaver/lock-screen state is queryable at all (Linux only).
SessionLockWhether the session-lock state is queryable at all (Linux only).
SleepPreventionWhether preventSleep()/allowSleep() would actually work.
FontsWhether systemFonts() would return anything.

UserInfo ​

UserInfo is returned by userInfo(): the active user's login, home directory, and shell in one call.

tyrus
import { UserInfo, userInfo } from "tyrus:os";

const info: UserInfo = userInfo();
print(info.username);
print(info.homedir);
print(info.shell);

UserInfo Fields ​

FieldTypeMeaning
usernamestringThe login name (same as userName()).
homedirstringThe home directory (same as homeDir()).
shellstringThe user's default shell.

CpuInfo ​

CpuInfo is the element type of the array returned by cpus(): one entry per logical CPU core.

tyrus
import { CpuInfo, cpus } from "tyrus:os";

const cores: CpuInfo[] = cpus();
print(`${cores.length} cores, ${cores[0].model}`);

CpuInfo Fields ​

FieldTypeMeaning
modelstringThe CPU model name (e.g. "Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz").
speedu32The core's frequency, in MHz.

BatteryInfo ​

BatteryInfo is returned by battery().

tyrus
import { BatteryInfo, battery } from "tyrus:os";

const info: BatteryInfo? = battery();
if (info) {
    print(`${info.level * 100.0}%, charging: ${info.charging}`);
}

BatteryInfo Fields ​

FieldTypeMeaning
levelf32State of charge, from 0.0 to 1.0.
chargingbooleanWhether the battery is currently charging.
timeToFullu32?Seconds until full, absent unless currently charging.
timeToEmptyu32?Seconds until empty, absent unless currently discharging.

NetworkInterface ​

NetworkInterface is the element type of the array returned in the Ok variant by networkInterfaces(): one entry per local IP address, so an adapter with both an IPv4 and an IPv6 address contributes two entries.

tyrus
import { NetworkInterface, OsError, networkInterfaces } from "tyrus:os";

const result: Result<NetworkInterface[], OsError> = networkInterfaces();
match (result) {
    Ok(interfaces) => { print(`${interfaces.length} address(es)`); }
    Err(error) => { printError(error.code); }
}

NetworkInterface Fields ​

FieldTypeMeaning
namestringThe adapter's name (e.g. "eth0", "en0", "Wi-Fi").
addressstringThe local IP address.
netmaskstringThe subnet mask for address.
familystringEither "IPv4" or "IPv6".

OsError ​

OsError is returned in the Err variant by openUrl(), trash(), preventSleep(), allowSleep() and networkInterfaces() when an operation fails, with a stable, structured code and a human-readable message.

OsError is an Error: a catch (error) without an annotation receives it, and error is OsError narrows the binding to it, with every field of OsError.

OsError Fields ​

FieldTypeMeaning
codestringA stable, machine-readable identifier (e.g. "ERR_OS_NO_HANDLER").
messagestringA human-readable description of what went wrong.

NotifyOptions ​

NotifyOptions is notify()'s optional third argument. Every field is optional; an omitted field uses the platform's own default.

NotifyOptions Fields ​

FieldTypeMeaning
iconstring?The name or path of an icon to show alongside the notification.
urgencyNotifyUrgency?See NotifyUrgency. Defaults to Normal.
timeoutu32?How long the notification stays visible, in milliseconds, before the desktop environment dismisses it automatically.

FontInfo ​

FontInfo is the element type of the array returned by systemFonts(): one entry per font face, so a family with regular/bold/italic/bold-italic variants contributes one entry per variant.

tyrus
import { FontInfo, systemFonts } from "tyrus:os";

const fonts: FontInfo[] = systemFonts();
print(`${fonts.length} faces installed`);
if (fonts.length > 0) {
    print(`${fonts[0].name} (${fonts[0].style})`);
}

FontInfo Fields ​

FieldTypeMeaning
namestringThe face's primary family name.
stylestringEither "normal", "italic", or "oblique".
pathstringThe font file's path, or an empty string for a font embedded in memory rather than backed by a file.

Color ​

Color is accessibleColorContrast()'s argument type, built as a plain object literal, the same way NotifyOptions is.

Color Fields ​

FieldTypeMeaning
ru8The red channel, 0 to 255.
gu8The green channel, 0 to 255.
bu8The blue channel, 0 to 255.