Skip to content

--interactive should not close the terminal after piping Scala code #2185

Open
@bphenriques

Description

@bphenriques

Version(s) 1.0.0

Describe what needs to be done and why
I want to automate a repl that has several libs and imports by default.
My current ammonite setup:

object load {
  def fs2Version(version: String) = {
    repl.load.apply(s"""
      import $$ivy.`co.fs2::fs2-core:$version`
      import $$ivy.`co.fs2::fs2-reactive-streams:$version`
      import $$ivy.`co.fs2::fs2-io:$version`

      import cats.implicits._
      import cats.syntax.all._
      import cats.effect.{IO, Resource}
      import fs2.io.file.{Files, Path}
      import fs2.{Stream, text}

      // For unsafeRunSync
      implicit val runtime = cats.effect.unsafe.IORuntime.global
    """)
  }

  def fs2 = fs2Version("3.3.0")
}

Which makes it very easy to have a quick typelevel repl by calling load.fs2.

I am trying to replace ammonite for scala-cli, so I am exploring existing command line options for the same purpose, however the terminal exits right away.

~ ❯ echo 'import cats.implicits._; import cats.syntax.all._; import cats.effect.{IO, Resource}; import fs2.io.file.{Files, Path}; import fs2.{Stream, text}; implicit val runtime = cats.effect.unsafe.IORuntime.global' | scala-cli repl --scala 2 --toolkit typelevel:latest --interactive
Welcome to Scala 2.13.10 (OpenJDK 64-Bit Server VM, Java 19.0.1).
Type in expressions for evaluation. Or try :help.

scala> import cats.implicits._; import cats.syntax.all._; import cats.effect.{IO, Resource}; import fs2.io.file.{Files, Path}; import fs2.{Stream, text}import cats.implicits._
import cats.syntax.all._
import cats.effect.{IO, Resource}
import fs2.io.file.{Files, Path}
import fs2.{Stream, text}
val runtime: cats.effect.unsafe.IORuntime = IORuntime(cats.effect.unsafe.WorkStealingThreadPool@3dd750ba, cats.effect.unsafe.WorkStealingThreadPool@3dd750ba, IORuntimeConfig(512,1024,true,16,Duration.Inf,true,1 second,10 seconds,0.1))

scala> :quit

I am unsure if this is a bug, but it seems to be. I may be using scala-cli incorrectly, hence my request for feedback.

Is your feature request related to a past ticket or discussion?
AFAIK no.

Describe alternatives you've considered
It won't change much, but I considering moving the Scala code to a file and piping the file to scala-cli.

Metadata

Metadata

Assignees

No one assigned

    Labels

    --interactiveIssues tied to `--interactive` modebugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions