Fix Start
command
This commit is contained in:
parent
a6f22e0a08
commit
48680338bf
|
@ -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 =
|
||||
action match
|
||||
case Start =>
|
||||
executeSlide(p, pos)()
|
||||
executeSlide(p, 0)()
|
||||
rec(p, 0, waitkey)
|
||||
case Next =>
|
||||
if pos + 1 < p.slides.size then
|
||||
|
@ -61,8 +61,7 @@ case class Presentation(slides: Vector[Slide], meta: Map[String, String] = Map.e
|
|||
waitkey
|
||||
rec(p, pos - 1, QuickNext)
|
||||
case Other(codes) =>
|
||||
Terminal.cursorTo(Terminal.height, 1)
|
||||
println(action.show)
|
||||
Terminal.printStatus(action.show)
|
||||
rec(p, pos, waitkey)
|
||||
case Quit =>
|
||||
()
|
||||
|
@ -127,22 +126,29 @@ 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() =
|
||||
force()
|
||||
if ! cmdIsHidden then
|
||||
prompt()
|
||||
Terminal.showCursor()
|
||||
typeCmd()
|
||||
if ! outputIsHidden then
|
||||
print(output)
|
||||
if ! cmdIsHidden then
|
||||
Terminal.hideCursor()
|
||||
|
||||
def quickShow() =
|
||||
force()
|
||||
if ! cmdIsHidden then
|
||||
prompt()
|
||||
println(display)
|
||||
if ! outputIsHidden then
|
||||
print(output)
|
||||
|
||||
def prompt() = print(fansi.Color.LightGreen("user@host % "))
|
||||
|
|
|
@ -33,6 +33,10 @@ object Terminal:
|
|||
key += Console.in.read
|
||||
keymap(key.toList)
|
||||
|
||||
def printStatus(msg: String): Unit =
|
||||
cursorTo(height, 1)
|
||||
print(msg)
|
||||
|
||||
def prompt[T](prefix: String, parse: String => T)(
|
||||
retry: (T, String) => Boolean = (t: T, s: String) => false,
|
||||
error: String => String = in => s"Invalid input: $in"
|
||||
|
|
Loading…
Reference in a new issue