Scoop API

scoop:scoop.platform:0.1.0

src/process/pty.scoop

Selected production source · src/process/pty.scoop

1package scoop.platform.process
3import scoop.platform.system.*
5/**
6 * Launches a child with all standard streams connected to a pseudoterminal. Used by asyncio's
7 * native backends. The caller owns the returned ScoopPlatformPty and must release it through
8 * scoop_platform_pty_close after retiring all native borrows.
9 */
10@Unsafe
11public fun Command.spawnPtyNative(
12 columns: Long,
13 rows: Long,
14 searchPath: Boolean = false
15): Ptr<Unit> {
16 requirePtySize(columns, rows)
17 if (!stdin.isInherited() || !stdout.isInherited() || !stderr.isInherited() || mergeError)
18 throw IllegalArgumentException(Some("pseudoterminal launch owns all standard streams"))
19 return launchProcess("spawn pseudoterminal", searchPath) { packed, path ->
20 val result = packed.spawnPty(path, columns.toInt(), rows.toInt())
21 (result.pty, result.error)
22 }
25private fun Stdio.isInherited(): Boolean = when (this) {
26 case Stdio.Inherit -> true
27 case _ -> false
30/** Validates cell dimensions accepted by the native pseudoterminal on this target. */
31public fun requirePtySize(columns: Long, rows: Long) {
32 val maximum = if (operatingSystem == OperatingSystem.Windows) 32767L else 65535L
33 if (columns <= 0L || rows <= 0L || columns > maximum || rows > maximum)
34 throw IllegalArgumentException(Some("pseudoterminal dimensions out of range"))
37@CLayout
38internal struct NativePtyOpened(val pty: Ptr<Unit>?, val error: Int)