varabyte / kotter

A declarative, Kotlin-idiomatic API for writing dynamic console applications.
Apache License 2.0
567 stars 16 forks source link

Handle control C #50

Closed bitspittle closed 3 years ago

bitspittle commented 3 years ago

We should restore the cursor when the user presses Ctrl+C, and probably add handler methods to KonsoleBlock and KonsoleApp that get triggered as well so users can clean up if it happens.

bitspittle commented 3 years ago

Possibly we should create a AbortKonsoleException(val message: String, val errorCode = -1) which we catch in the KonsoleApp, fire all handlers, clear all data (ConcurrentScopedData stopAll?), and then exit with an error code?

bitspittle commented 3 years ago

When done, we should use this in Kobweb#CreateFlow to throw this exception instead of return@konsoleApp

bitspittle commented 3 years ago

The exception idea is bad and I should feel bad :) Often we'll want to abort from run handlers, but at that point we'll be in a different thread.

We probably need something like KonsoleApp#abort which somehow causes the app to exit at that point after cleaning up resources.

bitspittle commented 3 years ago

Closing this issue as we now dispose the konsole app data on Ctrl C, it's probably as good as it's going to get.

Note that #52 is still open for dealing with restoring console state, which we should still definitely do.