tyrus:os
tyrus:os exposes cross-platform information about the operating system the compiled binary is running on: platform, architecture, hostname, kernel release, locale, the line-ending constant, the active user, and standard directories. It is read-only and purely informational, process-level information (pid, cwd(), memoryUsage(), etc.) lives on the built-in process global instead, documented in Environment Variables.
Imports
import { EOL, arch, hostname, language, locale, platform, release, systemName } from "tyrus:os";
import { OsArch, OsPlatform } from "tyrus:os";System Identification
| Export | Signature | Purpose |
|---|---|---|
platform | () => OsPlatform | The target platform. |
arch | () => OsArch | The target CPU architecture. |
EOL | string | The native line-ending constant. |
hostname | () => string | The machine's network hostname. |
release | () => string | The kernel release/build version. |
systemName | () => string | The POSIX-style (uname -s) system name. |
locale | () => string | The current locale tag. |
language | () => string | The current locale's language subtag. |
User and Directories
| Export | Signature | Purpose |
|---|---|---|
userInfo | () => UserInfo | The login, home directory, and shell in one call. |
userName | () => string | The login name. |
whoami | () => string? | The real name (GECOS), not the login. |
homeDir | () => string | The user's home directory. |
cacheDir | () => string | The user's cache directory. |
configDir | () => string | The user's config directory. |
dataDir | () => string | The user's data directory. |
tempDir | () => string | The system's temporary directory. |
desktopDir | () => string? | The user's desktop directory, if any. |
documentsDir | () => string? | The user's documents directory, if any. |
appDataDir | (app: string) => string | An application-specific subdirectory of dataDir. |
Hardware and Performance
| Export | Signature | Purpose |
|---|---|---|
cpus | () => CpuInfo[] | One entry per logical CPU core. |
totalMem | () => u64 | Total system memory, in bytes. |
freeMem | () => u64 | Free system memory, in bytes. |
uptime | () => u64 | Seconds since the system itself last booted. |
loadAvg | () => f64[] | The 1/5/15-minute load averages. |
battery | () => BatteryInfo? | The first battery's info, if any. |
cpuTemp | (unit: string) => f32? | The highest reported sensor temperature. |
Screen and Session
| Export | Signature | Purpose |
|---|---|---|
isDarkMode | () => boolean | Whether the desktop is in dark mode. |
terminalSize | () => [u16, u16]? | The terminal's columns and rows. |
isScreenLocked | () => boolean | Whether the screensaver/lock screen is active. |
isSessionLocked | () => boolean | Whether the current user session is locked. |
preventSleep | () => Result<void, OsError> | Inhibit automatic system/display sleep. |
allowSleep | () => Result<void, OsError> | Reverse preventSleep. |
isScreenLocked/isSessionLocked are best effort and Linux-only for now, false on other platforms, or when the underlying service cannot be reached.
Fonts and Accessibility
| Export | Signature | Purpose |
|---|---|---|
systemFonts | () => FontInfo[] | One entry per font face installed on the system. |
accessibleColorContrast | (fg: Color, bg: Color) => boolean | Whether a color pair meets the WCAG AA contrast ratio. |
Utilities
| Export | Signature | Purpose |
|---|---|---|
hasCapability | (cap: SystemCapability) => boolean | Whether a given capability is available on this system. |
See Interfaces and Enums for the shape of OsPlatform, OsArch, SystemCapability, UserInfo, CpuInfo, BatteryInfo, FontInfo, and Color.
Unresolved values never abort the program
hostname(), release(), systemName(), userName(), and every directory function fall back to "unknown" or an empty string if the operating system does not report a value. locale() and language() fall back to "und", the standard "undetermined locale" subtag. whoami(), desktopDir(), documentsDir(), battery(), and cpuTemp() return an optional type because absence is a normal outcome (a headless system, an account with no real name set, a desktop with no battery, a container with no thermal sensor), none of these functions can fail the program the way a filesystem error does. The one exception is cpuTemp's unit argument: "celsius"/"fahrenheit" are the only valid values, and anything else aborts the program.
Example
import { EOL, arch, hostname, language, locale, platform, release, systemName } from "tyrus:os";
import { OsArch, OsPlatform } from "tyrus:os";
const currentPlatform: OsPlatform = platform();
const currentArch: OsArch = arch();
print(`${systemName()} ${release()} (${hostname()})${EOL}locale ${locale()} (${language()})`);
// "Linux 6.8.0-generic (my-machine)"
// "locale en-US (en)"
if (currentPlatform === OsPlatform.Windows) {
print("running on Windows");
}