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.
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
| Member | Meaning |
|---|---|
Linux | Linux |
MacOS | macOS |
Windows | Windows |
Other | Any other target |
OsArch Members
| Member | Meaning |
|---|---|
X86_64 | 64-bit x86 |
Aarch64 | 64-bit ARM |
X86 | 32-bit x86 |
Arm | 32-bit ARM |
Other | Any other target |
NotifyUrgency
NotifyUrgency is NotifyOptions's urgency field, passed to notify().
NotifyUrgency Members
| Member | Meaning |
|---|---|
Low | Low priority, the desktop environment may not show it at all in "do not disturb" mode. |
Normal | Default priority. |
Critical | High 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
| Member | Meaning |
|---|---|
Notification | Whether a desktop notification could plausibly be shown. |
Clipboard | Whether the system clipboard can be reached. |
Battery | Whether this machine reports at least one battery. |
DarkMode | Whether the desktop's dark-mode setting is queryable at all. |
ScreenLock | Whether the screensaver/lock-screen state is queryable at all (Linux only). |
SessionLock | Whether the session-lock state is queryable at all (Linux only). |
SleepPrevention | Whether preventSleep()/allowSleep() would actually work. |
Fonts | Whether systemFonts() would return anything. |
UserInfo
UserInfo is returned by userInfo(): the active user's login, home directory, and shell in one call.
import { UserInfo, userInfo } from "tyrus:os";
const info: UserInfo = userInfo();
print(info.username);
print(info.homedir);
print(info.shell);UserInfo Fields
| Field | Type | Meaning |
|---|---|---|
username | string | The login name (same as userName()). |
homedir | string | The home directory (same as homeDir()). |
shell | string | The user's default shell. |
CpuInfo
CpuInfo is the element type of the array returned by cpus(): one entry per logical CPU core.
import { CpuInfo, cpus } from "tyrus:os";
const cores: CpuInfo[] = cpus();
print(`${cores.length} cores, ${cores[0].model}`);CpuInfo Fields
| Field | Type | Meaning |
|---|---|---|
model | string | The CPU model name (e.g. "Intel(R) Core(TM) i5-10400F CPU @ 2.90GHz"). |
speed | u32 | The core's frequency, in MHz. |
BatteryInfo
BatteryInfo is returned by battery().
import { BatteryInfo, battery } from "tyrus:os";
const info: BatteryInfo? = battery();
if (info) {
print(`${info.level * 100.0}%, charging: ${info.charging}`);
}BatteryInfo Fields
| Field | Type | Meaning |
|---|---|---|
level | f32 | State of charge, from 0.0 to 1.0. |
charging | boolean | Whether the battery is currently charging. |
timeToFull | u32? | Seconds until full, absent unless currently charging. |
timeToEmpty | u32? | 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.
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
| Field | Type | Meaning |
|---|---|---|
name | string | The adapter's name (e.g. "eth0", "en0", "Wi-Fi"). |
address | string | The local IP address. |
netmask | string | The subnet mask for address. |
family | string | Either "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
| Field | Type | Meaning |
|---|---|---|
code | string | A stable, machine-readable identifier (e.g. "ERR_OS_NO_HANDLER"). |
message | string | A 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
| Field | Type | Meaning |
|---|---|---|
icon | string? | The name or path of an icon to show alongside the notification. |
urgency | NotifyUrgency? | See NotifyUrgency. Defaults to Normal. |
timeout | u32? | 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.
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
| Field | Type | Meaning |
|---|---|---|
name | string | The face's primary family name. |
style | string | Either "normal", "italic", or "oblique". |
path | string | The 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
| Field | Type | Meaning |
|---|---|---|
r | u8 | The red channel, 0 to 255. |
g | u8 | The green channel, 0 to 255. |
b | u8 | The blue channel, 0 to 255. |
