scoop:scoop.platform:0.1.0
src/process/pty.scoop
Selected production source · src/process/pty.scoop
1
package scoop.platform.process3
import scoop.platform.system.*5
/**6
* Launches a child with all standard streams connected to a pseudoterminal. Used by asyncio's7
* native backends. The caller owns the returned ScoopPlatformPty and must release it through8
* scoop_platform_pty_close after retiring all native borrows.9
*/10
@Unsafe11
public fun Command.spawnPtyNative(12
columns: Long,13
rows: Long,14
searchPath: Boolean = false15
): 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
}23
}25
private fun Stdio.isInherited(): Boolean = when (this) {26
case Stdio.Inherit -> true27
case _ -> false28
}30
/** Validates cell dimensions accepted by the native pseudoterminal on this target. */31
public fun requirePtySize(columns: Long, rows: Long) {32
val maximum = if (operatingSystem == OperatingSystem.Windows) 32767L else 65535L33
if (columns <= 0L || rows <= 0L || columns > maximum || rows > maximum)34
throw IllegalArgumentException(Some("pseudoterminal dimensions out of range"))35
}37
@CLayout38
internal struct NativePtyOpened(val pty: Ptr<Unit>?, val error: Int)