Skip to content

Commit

Permalink
Add custom handling for SIGINT (i.e. Ctrl C)
Browse files Browse the repository at this point in the history
This should allow windows users to Ctrl-C just like their
*nix bretheren have been able to do forever.
  • Loading branch information
bitspittle committed Jan 31, 2023
1 parent 344d6b6 commit 3b35dce
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import kotlinx.coroutines.currentCoroutineContext
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.isActive
import org.jline.terminal.Terminal.Signal
import org.jline.terminal.TerminalBuilder
import org.jline.utils.InfoCmp
import java.io.IOException
import java.io.OutputStream
import java.io.PrintStream
import kotlin.system.exitProcess

/**
* A [Terminal] implementation which interacts directly with the underlying system terminal.
Expand All @@ -31,6 +33,10 @@ class SystemTerminal : Terminal {
// Swallow keypresses - instead, we will handle them
enterRawMode()

// Handle Ctrl-C ourselves, because Windows otherwise swallows it
// See also: https://github.com/jline/jline3/issues/822
handle(Signal.INT) { exitProcess(130) } // 130 == 128+2, where 2 == SIGINT

val disabledPrintStream = PrintStream(object : OutputStream() {
override fun write(b: Int) = Unit
})
Expand Down

0 comments on commit 3b35dce

Please sign in to comment.