clean up implicits

This commit is contained in:
Alexander Gehrke 2022-05-23 23:14:55 +02:00
parent 7ab755c540
commit 2b7a4e8d26
2 changed files with 14 additions and 10 deletions

View file

@ -1,7 +1,7 @@
package de.qwertyuiop.copret package de.qwertyuiop.copret
object syntax extends Templates with TerminalSyntax with SlideSyntax: object syntax extends Templates with TerminalSyntax with SlideSyntax:
import Format._ import Format.*
extension (str: String) extension (str: String)
def code(using theme: Theme) = Format.ticks.replaceAllIn(str, m => theme.style("code")("$1").render) def code(using theme: Theme) = Format.ticks.replaceAllIn(str, m => theme.style("code")("$1").render)
def text(using Theme) = Paragraph(str) def text(using Theme) = Paragraph(str)
@ -22,7 +22,7 @@ object syntax extends Templates with TerminalSyntax with SlideSyntax:
def red = fansi.Color.Red(str) def red = fansi.Color.Red(str)
extension (str: fansi.Str) extension (str: fansi.Str)
def text(using Theme) = Paragraph(str) def text(using Theme) = Paragraph(str.toString)
def style(key: String, default: fansi.Attrs)(using theme: Theme) = theme.style(key, default)(str) def style(key: String, default: fansi.Attrs)(using theme: Theme) = theme.style(key, default)(str)
def blue = fansi.Color.Blue(str) def blue = fansi.Color.Blue(str)

View file

@ -1,24 +1,28 @@
package de.qwertyuiop.copret package de.qwertyuiop.copret
import syntax._ import syntax.*
import ammonite.ops.{Path, %, %%, pwd} import ammonite.ops.{Path, %, %%, pwd, ImplicitWd}
trait Templates: trait Templates:
def titleLine(title: String)(implicit theme: Theme) = Paragraph( def titleLine(title: String)(using theme: Theme) = Paragraph(
"\n" + Format.figlet(title, theme.font("titleLine", "pagga")).block.blue + "\n" "\n" + Format.figlet(title, theme.font("titleLine", "pagga")).block.blue + "\n"
) )
def header(implicit theme: Theme) = Meta((p, pos) => { def header(using theme: Theme) = Meta((p, pos) => {
val left = p.meta.getOrElse("author", "") val left = p.meta.getOrElse("author", "")
val center = p.meta.getOrElse("title", "") val center = p.meta.getOrElse("title", "")
val right = s"${pos} / ${p.slides.size - 1}" val right = s"${pos} / ${p.slides.size - 1}"
theme.style("titleLine")(Format.distribute(left, center, right)).text theme.style("titleLine")(Format.distribute(left, center, right)).text
}) })
def slide(title: String)(slides: Slide*) = Group(Clear :: header :: titleLine(title) :: slides.toList) def slide(title: String)(slides: Slide*)(using Theme) = Group(Clear :: header :: titleLine(title) :: slides.toList)
def slide(slides: Slide*) = Group(Clear :: header :: slides.toList) def slide(slides: Slide*)(using Theme) = Group(Clear :: header :: slides.toList)
def markdown(title: String, content: Path) = slide(title)(IncludeMarkdown(content)) def markdown(title: String, content: Path)(using Theme) = slide(title)(
Paragraph(
%%%("/usr/bin/mdcat", "--columns", (columns * 0.8).toInt.toString, content.toString)(using ImplicitWd.implicitCwd).block
)
)
lazy val --- = Paragraph(("═" * columns).yellow) lazy val --- = Paragraph(("═" * columns).yellow.toString)
/* vim:set tw=120: */ /* vim:set tw=120: */