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

Allow executing other programs while Konsole is running #56

Closed
bitspittle opened this issue Sep 15, 2021 · 2 comments
Closed

Allow executing other programs while Konsole is running #56

bitspittle opened this issue Sep 15, 2021 · 2 comments
Labels
enhancement New feature / functionality maybe Not sure if we're going to do this issue or not

Comments

@bitspittle
Copy link
Contributor

For example, maybe an app will want to call git to sync, or some other function that returns output.

Right now, Konsole has taken over System.in, System.out, and System.err - so we may need an escape hatch for when the user wants to say "I'm not in a Konsole block right now, let someone else print stuff for a whiel"

Maybe

konsoleApp {
   konsole { ... }.run()
   konsoleExec("git clone")
   konsole { ... }.run()
}

?

@bitspittle bitspittle added enhancement New feature / functionality maybe Not sure if we're going to do this issue or not labels Sep 17, 2021
@bitspittle
Copy link
Contributor Author

So I experimented with this a bit. It's not hard to do but it's probably not worth putting this into the library itself, because it's easy enough to just exec the process yourself, capture the input stream, and then just add each line into, say, a konsoleList

val output = konsoleListOf<String>()
konsole {
   output.forEach { line -> textLine(line) }
   textLine()
}.run {
   val process = exec("...")
   val reader = BufferedReader(InputStreamReader(process.inputStream))
   while (true) {
       val line = reader.readLine() ?: break
       output.add(line)
  }
}

@bitspittle
Copy link
Contributor Author

We're doing this in Kobweb. See here: https://github.com/varabyte/kobweb/blob/main/cli/kobweb/src/main/kotlin/com/varabyte/kobweb/cli/run/Run.kt#L97

It ends up being easier to just let the application do its own custom thing. Above, we need a reference to the process handles so we can interact with them, which makes me lean towards not trying to wrap this behavior inside Konsole.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature / functionality maybe Not sure if we're going to do this issue or not
Projects
None yet
Development

No branches or pull requests

1 participant