From 1aca0f2f46cc7d69c00b9b430db39c236dd15582 Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Wed, 31 Jan 2024 11:40:27 -0500 Subject: [PATCH] Split out termios modification --- .../src/linuxX64Main/kotlin/TermiosUtil.linuxX64.kt | 8 ++++++++ .../src/macosX64Main/kotlin/TermiosUtil.macosX64.kt | 9 +++++++++ ksrpc-sockets/src/nativeMain/kotlin/TermiosUtil.kt | 4 +++- 3 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 ksrpc-sockets/src/linuxX64Main/kotlin/TermiosUtil.linuxX64.kt create mode 100644 ksrpc-sockets/src/macosX64Main/kotlin/TermiosUtil.macosX64.kt diff --git a/ksrpc-sockets/src/linuxX64Main/kotlin/TermiosUtil.linuxX64.kt b/ksrpc-sockets/src/linuxX64Main/kotlin/TermiosUtil.linuxX64.kt new file mode 100644 index 00000000..194df364 --- /dev/null +++ b/ksrpc-sockets/src/linuxX64Main/kotlin/TermiosUtil.linuxX64.kt @@ -0,0 +1,8 @@ +package com.monkopedia.ksrpc.sockets + +import platform.posix.ICANON +import platform.posix.termios + +actual fun termios.setICanon() { + c_lflag = c_lflag and ICANON.inv().toUInt() +} \ No newline at end of file diff --git a/ksrpc-sockets/src/macosX64Main/kotlin/TermiosUtil.macosX64.kt b/ksrpc-sockets/src/macosX64Main/kotlin/TermiosUtil.macosX64.kt new file mode 100644 index 00000000..68beb734 --- /dev/null +++ b/ksrpc-sockets/src/macosX64Main/kotlin/TermiosUtil.macosX64.kt @@ -0,0 +1,9 @@ +package com.monkopedia.ksrpc.sockets + +import platform.posix.ICANON +import platform.posix.termios + +actual fun termios.setICanon() { + c_lflag = c_lflag and ICANON.inv().toUInt() +} + diff --git a/ksrpc-sockets/src/nativeMain/kotlin/TermiosUtil.kt b/ksrpc-sockets/src/nativeMain/kotlin/TermiosUtil.kt index c36a81a9..b70953d2 100644 --- a/ksrpc-sockets/src/nativeMain/kotlin/TermiosUtil.kt +++ b/ksrpc-sockets/src/nativeMain/kotlin/TermiosUtil.kt @@ -53,11 +53,13 @@ fun initTermios(fd: Int = STDIN_FILENO, old: CPointer) { val current = alloc().ptr tcgetattr(fd, old) memcpy(current, old, sizeOf().toULong()) - current.pointed.c_lflag = current.pointed.c_lflag and ICANON.inv().toUInt() + current.pointed.setICanon() tcsetattr(fd, TCSANOW, current) } } +expect fun termios.setICanon() + fun resetTermios(fd: Int = STDIN_FILENO, old: CPointer) { tcsetattr(fd, TCSANOW, old) }