Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check environment for stty location #74

Merged
merged 1 commit into from
Oct 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

### Fixed
- Terminal detection would sometimes incorrectly identify the process as running in IntelliJ [(#72)](https://github.com/ajalt/mordant/issues/72)
- `updateTerminalSize` would sometimes fail to find the `stty` command [(#66)](https://github.com/ajalt/mordant/issues/66)

## 2.0.0-beta7
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,21 @@ internal actual class AtomicInt actual constructor(initial: Int) {
// We have to shell out to another program on JVM, which takes ~10ms for stty and ~100ms for powershell
internal actual fun terminalSizeDetectionIsFast(): Boolean = false

internal actual fun getTerminalSize(timeoutMs: Long): Pair<Int, Int>? {
val process = try {
val cmd = when {
isWindows() -> ProcessBuilder("powershell.exe",
"-noprofile",
"-command",
"\$host.ui.rawui")
else -> ProcessBuilder("stty", "size")
}
cmd.redirectInput(ProcessBuilder.Redirect.INHERIT)
private fun runCommand(vararg args: String): Process? {
return try {
ProcessBuilder(*args)
.redirectInput(ProcessBuilder.Redirect.INHERIT)
.start()
} catch (e: IOException) {
return null
null
}
}
internal actual fun getTerminalSize(timeoutMs: Long): Pair<Int, Int>? {
val process = when {
isWindows() -> runCommand("powershell.exe", "-noprofile", "-command", "\$host.ui.rawui")
// Try running stty both directly and via env, since neither one works on all systems
else -> runCommand("stty", "size") ?: runCommand("/use/bin/env", "stty", "size")
} ?: return null
try {
if (!process.waitFor(timeoutMs, TimeUnit.MILLISECONDS)) {
return null
Expand Down