Skip to content

Instantly share code, notes, and snippets.

@spamegg1
Last active September 29, 2025 17:49
Show Gist options
  • Select an option

  • Save spamegg1/af22caa29faba54b4306935e4f77bcc3 to your computer and use it in GitHub Desktop.

Select an option

Save spamegg1/af22caa29faba54b4306935e4f77bcc3 to your computer and use it in GitHub Desktop.
Doodle Reactor, works in SBT on the Terminal, and as a worksheet in Metals, shows pop-up image; but not as `@main` method, neither in Metals nor on Terminal with `scala run ...`
//> using dep org.creativescala::doodle:0.31.0
import cats.effect.unsafe.implicits.global
import concurrent.duration.FiniteDuration
import doodle.reactor.Reactor
import doodle.image.Image
import doodle.core.*
import doodle.syntax.all.*
import doodle.java2d.*
import doodle.core.Color.{deepSkyBlue, red}
val frame = Frame.default
.withSize(600, 600)
.withBackground(deepSkyBlue)
.withTitle("Space Invaders")
.withCenterAtOrigin
val TickRate = FiniteDuration(50, "milliseconds")
val image = Image.square(300).fillColor(red)
// This works with SBT on the Terminal, but not Scala-cli.
// Does not launch the pop-up window of Reactor when run,
// either in Metals (click "run | debug") or Terminal (`scala run reactor.scala`)
@main
def hello: Unit =
Reactor
.init[Int](0)
.withOnTick(identity)
.withRender(_ => image)
.withOnMouseClick((p, w) => w)
.withOnMouseMove((p, w) => w)
.withStop(_ => false)
.withTickRate(TickRate)
.run(frame)
//> using dep org.creativescala::doodle:0.31.0
import cats.effect.unsafe.implicits.global
import concurrent.duration.FiniteDuration
import doodle.reactor.Reactor
import doodle.image.Image
import doodle.core.*
import doodle.syntax.all.*
import doodle.java2d.*
import doodle.core.Color.{deepSkyBlue, red}
val frame = Frame.default
.withSize(600, 600)
.withBackground(deepSkyBlue)
.withTitle("Space Invaders")
.withCenterAtOrigin
val TickRate = FiniteDuration(50, "milliseconds")
val image = Image.square(300).fillColor(red)
// This works just fine in Metals.
Reactor
.init[Int](0)
.withOnTick(identity)
.withRender(_ => image)
.withOnMouseClick((p, w) => w)
.withOnMouseMove((p, w) => w)
.withStop(_ => false)
.withTickRate(TickRate)
.run(frame)
@spamegg1
Copy link
Author

spamegg1 commented Sep 29, 2025

Worksheet works:

Captura de pantalla de 2025-09-29 20-15-08

SBT on the Terminal works:

Captura de pantalla de 2025-09-29 20-46-59

@main method and running does not work:

Terminal:

Captura de pantalla de 2025-09-29 20-23-32

Metals:

Captura de pantalla de 2025-09-29 20-25-04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment