Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement 'hideInput' on posix systems (#63)
- Loading branch information
1 parent
d7026d5
commit 256f872
Showing
4 changed files
with
52 additions
and
6 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
6 changes: 6 additions & 0 deletions
6
mordant/src/mingwX64Main/kotlin/com/github/ajalt/mordant/internal/tty.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,6 @@ | ||
package com.github.ajalt.mordant.internal | ||
|
||
// hideInput is not currently implemented | ||
internal actual fun ttySetEcho(echo: Boolean) { | ||
|
||
} |
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
30 changes: 30 additions & 0 deletions
30
mordant/src/posixMain/kotlin/com/github/ajalt/mordant/internal/tty.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,30 @@ | ||
package com.github.ajalt.mordant.internal | ||
|
||
import kotlinx.cinterop.* | ||
import platform.posix.* | ||
|
||
@OptIn(UnsafeNumber::class) | ||
internal actual fun ttySetEcho(echo: Boolean) { | ||
updateTermios { | ||
c_lflag = if (echo) { | ||
c_lflag.or(ECHO.convert()) | ||
} else { | ||
c_lflag.and(ECHO.inv().convert()) | ||
} | ||
} | ||
} | ||
|
||
private fun updateTermios(block: termios.() -> Unit) { | ||
memScoped { | ||
val termios = alloc<termios>() | ||
check(tcgetattr(0, termios.ptr) == 0) { | ||
error("tcgetattr() error: $errno") | ||
} | ||
|
||
block(termios) | ||
|
||
check(tcsetattr(0, TCSADRAIN, termios.ptr) == 0) { | ||
error("tcsetattr() error: $errno") | ||
} | ||
} | ||
} |