-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
89 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ant/src/macosArm64Main/kotlin/com/github/ajalt/mordant/internal/MppInternal.macosArm64.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.ajalt.mordant.internal | ||
|
||
import com.github.ajalt.mordant.terminal.TerminalInterface | ||
import com.github.ajalt.mordant.terminal.terminalinterface.TerminalInterfaceNativeCopyPasted | ||
|
||
internal actual fun getStandardTerminalInterface(): TerminalInterface { | ||
return TerminalInterfaceNativeCopyPasted() | ||
} |
File renamed without changes.
6 changes: 0 additions & 6 deletions
6
mordant/src/macosMain/kotlin/com/github/ajalt/mordant/internal/MppInternal.macos.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
package com.github.ajalt.mordant.internal | ||
|
||
import com.github.ajalt.mordant.terminal.TerminalInterface | ||
import com.github.ajalt.mordant.terminal.terminalinterface.TerminalInterfaceNativeCopyPasted | ||
|
||
internal actual fun testsHaveFileSystem(): Boolean = true | ||
internal actual fun getStandardTerminalInterface(): TerminalInterface { | ||
return TerminalInterfaceNativeCopyPasted() | ||
} |
8 changes: 8 additions & 0 deletions
8
mordant/src/macosX64Main/kotlin/com/github/ajalt/mordant/internal/MppInternal.macosX64.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.github.ajalt.mordant.internal | ||
|
||
import com.github.ajalt.mordant.terminal.TerminalInterface | ||
import com.github.ajalt.mordant.terminal.terminalinterface.TerminalInterfaceNativeCopyPasted | ||
|
||
internal actual fun getStandardTerminalInterface(): TerminalInterface { | ||
return TerminalInterfaceNativeCopyPasted() | ||
} |
72 changes: 72 additions & 0 deletions
72
.../com/github/ajalt/mordant/terminal/terminalinterface/TerminalInterface.native.macosX64.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.github.ajalt.mordant.terminal.terminalinterface | ||
|
||
import com.github.ajalt.mordant.rendering.Size | ||
import kotlinx.cinterop.* | ||
import platform.posix.* | ||
|
||
// XXX: The source code for this file is identical between linux and the various apple targets, but | ||
// they have different bit widths for some fields, so the compileMetadata task fails if we don't use | ||
// separate files. Hopefully some day there will be solution that doesn't require copy-pasting. | ||
|
||
internal class TerminalInterfaceNativeCopyPasted : TerminalInterfaceNativePosix() { | ||
override val termiosConstants: TermiosConstants = TermiosConstants( | ||
VTIME = VTIME, | ||
VMIN = VMIN, | ||
INPCK = INPCK.convert(), | ||
ISTRIP = ISTRIP.convert(), | ||
INLCR = INLCR.convert(), | ||
IGNCR = IGNCR.convert(), | ||
ICRNL = ICRNL.convert(), | ||
IXON = IXON.convert(), | ||
OPOST = OPOST.convert(), | ||
CS8 = CS8.convert(), | ||
ISIG = ISIG.convert(), | ||
ICANON = ICANON.convert(), | ||
ECHO = ECHO.convert(), | ||
IEXTEN = IEXTEN.convert(), | ||
) | ||
|
||
override fun readIntoBuffer(c: ByteVar): Long { | ||
return read(platform.posix.STDIN_FILENO, c.ptr, 1u).convert() | ||
} | ||
|
||
override fun getTerminalSize(): Size? = memScoped { | ||
val size = alloc<winsize>() | ||
if (ioctl(STDIN_FILENO, TIOCGWINSZ.convert(), size) < 0) { | ||
null | ||
} else { | ||
Size(width = size.ws_col.toInt(), height = size.ws_row.toInt()) | ||
} | ||
} | ||
|
||
override fun getStdinTermios(): Termios = memScoped { | ||
val termios = alloc<termios>() | ||
if (tcgetattr(platform.posix.STDIN_FILENO, termios.ptr) != 0) { | ||
throw RuntimeException("Error reading terminal attributes") | ||
} | ||
return Termios( | ||
iflag = termios.c_iflag.convert(), | ||
oflag = termios.c_oflag.convert(), | ||
cflag = termios.c_cflag.convert(), | ||
lflag = termios.c_lflag.convert(), | ||
cc = ByteArray(NCCS) { termios.c_cc[it].convert() }, | ||
) | ||
} | ||
|
||
override fun setStdinTermios(termios: Termios) = memScoped { | ||
val nativeTermios = alloc<termios>() | ||
// different platforms have different fields in termios, so we need to read the current | ||
// struct before we set the fields we care about. | ||
if (tcgetattr(platform.posix.STDIN_FILENO, nativeTermios.ptr) != 0) { | ||
throw RuntimeException("Error reading terminal attributes") | ||
} | ||
nativeTermios.c_iflag = termios.iflag.convert() | ||
nativeTermios.c_oflag = termios.oflag.convert() | ||
nativeTermios.c_cflag = termios.cflag.convert() | ||
nativeTermios.c_lflag = termios.lflag.convert() | ||
repeat(NCCS) { nativeTermios.c_cc[it] = termios.cc[it].convert<UByte>() } | ||
if (tcsetattr(platform.posix.STDIN_FILENO, TCSADRAIN, nativeTermios.ptr) != 0) { | ||
throw RuntimeException("Error setting terminal attributes") | ||
} | ||
} | ||
} |