Fix Start command

This commit is contained in:
Alexander Gehrke 2022-05-23 23:54:36 +02:00
parent a6f22e0a08
commit 48680338bf
2 changed files with 22 additions and 12 deletions

View file

@ -15,7 +15,7 @@ case class Presentation(slides: Vector[Slide], meta: Map[String, String] = Map.e
@annotation.tailrec def rec(p: Presentation, pos: Int, action: SlideAction): Unit = @annotation.tailrec def rec(p: Presentation, pos: Int, action: SlideAction): Unit =
action match action match
case Start => case Start =>
executeSlide(p, pos)() executeSlide(p, 0)()
rec(p, 0, waitkey) rec(p, 0, waitkey)
case Next => case Next =>
if pos + 1 < p.slides.size then if pos + 1 < p.slides.size then
@ -61,8 +61,7 @@ case class Presentation(slides: Vector[Slide], meta: Map[String, String] = Map.e
waitkey waitkey
rec(p, pos - 1, QuickNext) rec(p, pos - 1, QuickNext)
case Other(codes) => case Other(codes) =>
Terminal.cursorTo(Terminal.height, 1) Terminal.printStatus(action.show)
println(action.show)
rec(p, pos, waitkey) rec(p, pos, waitkey)
case Quit => case Quit =>
() ()
@ -127,23 +126,30 @@ case class Pause(millisec: Long) extends Slide
case object PauseKey extends Slide case object PauseKey extends Slide
case class Meta(contents: (Presentation, Int) => Slide) 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) private lazy val _output = exec(cmd)
def output = _output def output = _output
infix def showing (s: String): TypedCommand[T] = TypedCommand(exec, s, cmd) infix def showing (s: String): TypedCommand[T] = TypedCommand(exec, s, cmd)
def show() = def show() =
prompt() force()
Terminal.showCursor() if ! cmdIsHidden then
typeCmd() prompt()
print(output) Terminal.showCursor()
Terminal.hideCursor() typeCmd()
if ! outputIsHidden then
print(output)
if ! cmdIsHidden then
Terminal.hideCursor()
def quickShow() = def quickShow() =
prompt() force()
println(display) if ! cmdIsHidden then
print(output) prompt()
println(display)
if ! outputIsHidden then
print(output)
def prompt() = print(fansi.Color.LightGreen("user@host % ")) def prompt() = print(fansi.Color.LightGreen("user@host % "))
def force() = _output def force() = _output

View file

@ -33,6 +33,10 @@ object Terminal:
key += Console.in.read key += Console.in.read
keymap(key.toList) keymap(key.toList)
def printStatus(msg: String): Unit =
cursorTo(height, 1)
print(msg)
def prompt[T](prefix: String, parse: String => T)( def prompt[T](prefix: String, parse: String => T)(
retry: (T, String) => Boolean = (t: T, s: String) => false, retry: (T, String) => Boolean = (t: T, s: String) => false,
error: String => String = in => s"Invalid input: $in" error: String => String = in => s"Invalid input: $in"