From 517720c72007c993ea01de17302f10c69df712ae Mon Sep 17 00:00:00 2001 From: Alexander Gehrke Date: Wed, 21 Sep 2022 15:47:47 +0200 Subject: [PATCH] Readd incomplete changes, now without missing apply method --- copret/src/slides.scala | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/copret/src/slides.scala b/copret/src/slides.scala index 8cb4dc5..58a8406 100644 --- a/copret/src/slides.scala +++ b/copret/src/slides.scala @@ -126,23 +126,30 @@ case class Pause(millisec: Long) extends Slide case object PauseKey extends Slide case class Meta(contents: (Presentation, Int) => Slide) extends Slide -case class TypedCommand[T](exec: T => String, display: String, cmd: T) extends Slide: +case class TypedCommand[T](exec: T => String, display: String, cmd: T, cmdIsHidden: Boolean, outputIsHidden: Boolean) extends Slide: private lazy val _output = exec(cmd) def output = _output infix def showing (s: String): TypedCommand[T] = TypedCommand(exec, s, cmd) def show() = - prompt() - Terminal.showCursor() - typeCmd() - print(output) - Terminal.hideCursor() + force() + if ! cmdIsHidden then + prompt() + Terminal.showCursor() + typeCmd() + if ! outputIsHidden then + print(output) + if ! cmdIsHidden then + Terminal.hideCursor() def quickShow() = - prompt() - println(display) - print(output) + force() + if ! cmdIsHidden then + prompt() + println(display) + if ! outputIsHidden then + print(output) def prompt() = print(fansi.Color.LightGreen("user@host % ")) def force() = _output @@ -180,6 +187,10 @@ object TypedCommand: def apply(cmd: String*)(using Path): TypedCommand[Vector[String]] = TypedCommand(run, cmd.mkString(" "), cmd.toVector) + def apply[T](exec: T => String, display: String, cmd: T) = + new TypedCommand(exec, display, cmd, false, false) + + def shell(cmd: String*)(using Path): TypedCommand[Vector[String]] = TypedCommand(runShell, cmd.mkString(" "), cmd.toVector)