2022-12-01 12:07:05 +00:00
|
|
|
package com.htmlism.firepower.demo
|
|
|
|
|
2022-12-04 20:40:37 +00:00
|
|
|
import com.htmlism.firepower.demo.asm._
|
|
|
|
import com.htmlism.firepower.demo.str._
|
2022-12-01 11:50:22 +00:00
|
|
|
import zio.*
|
|
|
|
|
|
|
|
import java.io.IOException
|
2022-12-04 20:40:37 +00:00
|
|
|
import com.htmlism.rufio.withzio.*
|
2022-12-01 13:17:33 +00:00
|
|
|
|
2022-12-01 11:50:22 +00:00
|
|
|
object PrintPrograms extends ZIOAppDefault:
|
2022-12-04 18:26:52 +00:00
|
|
|
private def writeLine(file: String)(s: String) =
|
|
|
|
File(s"data/$file.txt")
|
|
|
|
.writeLine(s)
|
|
|
|
|
|
|
|
private val programs =
|
|
|
|
List[(String, String)](
|
2022-12-04 18:59:02 +00:00
|
|
|
"one-line.txt" -> "one line",
|
|
|
|
"two-lines.txt" -> (Line.mkString _)
|
2022-12-04 18:55:33 +00:00
|
|
|
.apply(List("foo", "bar")),
|
2022-12-04 18:59:02 +00:00
|
|
|
"two-paragraphs.txt" -> (Line.mkString _)
|
2022-12-04 18:55:33 +00:00
|
|
|
.compose(Paragraph.mkLines)
|
2022-12-04 19:28:36 +00:00
|
|
|
.apply(
|
|
|
|
List(
|
|
|
|
Paragraph(List("foo", "bar")),
|
|
|
|
Paragraph(List("alpha", "bravo"))
|
|
|
|
)
|
|
|
|
),
|
2022-12-04 18:59:02 +00:00
|
|
|
"annotated-snake.asm" -> (Line.mkString _)
|
|
|
|
.compose(Paragraph.mkLines)
|
2022-12-04 21:56:03 +00:00
|
|
|
.compose((xs: List[AsmBlock]) => xs.map(AsmBlock.toParagraph))
|
2022-12-04 19:28:36 +00:00
|
|
|
.apply(
|
|
|
|
List(
|
|
|
|
CommentBlock.fromMultiline(asciiArt),
|
2022-12-04 21:56:03 +00:00
|
|
|
CommentBlock(List("Change direction: W A S D")),
|
|
|
|
CodeBlock(None, Nil),
|
|
|
|
CodeBlock(Some("labeled"), Nil)
|
2022-12-04 19:28:36 +00:00
|
|
|
)
|
|
|
|
)
|
2022-12-04 18:26:52 +00:00
|
|
|
)
|
2022-12-04 18:01:22 +00:00
|
|
|
|
2022-12-04 18:59:02 +00:00
|
|
|
lazy val asciiArt =
|
|
|
|
""" ___ _ __ ___ __ ___
|
|
|
|
|/ __|_ _ __ _| |_____ / /| __|/ \_ )
|
|
|
|
|\__ \ ' \/ _` | / / -_) _ \__ \ () / /
|
|
|
|
||___/_||_\__,_|_\_\___\___/___/\__/___|""".stripMargin
|
|
|
|
|
2022-12-04 18:26:52 +00:00
|
|
|
def run: Task[Unit] =
|
|
|
|
for {
|
|
|
|
// just a traverse in slow motion...
|
|
|
|
_ <- programs
|
|
|
|
.map { case (f, s) => File(s"data/$f").writeLine(s) }
|
|
|
|
.foldLeft[Task[Unit]](ZIO.unit)((acc, z) => acc *> z)
|
2022-12-04 18:01:22 +00:00
|
|
|
} yield ()
|