Skip to content

Commit

Permalink
Started experimenting with interactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Mar 23, 2024
1 parent 47f85a3 commit 3aefe04
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
2 changes: 1 addition & 1 deletion res/build.id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1100
1110
25 changes: 18 additions & 7 deletions src/cli/actions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ case class InitError(initMessage: Message) extends Error(initMessage)

object actions:
object install:
def interactive(force: Boolean, noTabCompletions: Boolean)
def installInteractive(force: Boolean, noTabCompletions: Boolean)
(using DaemonService[?],
Log[Display],
SystemProperties,
Environment,
WorkingDirectory,
HomeDirectory,
Effectful,
FrontEnd,
CliFrontEnd,
Terminal,
Stdio)
: ExitStatus raises UserError =
Expand All @@ -73,10 +73,11 @@ object actions:

if directories.length <= 1 then Installer.install(force) else
info(e"$Italic(Please choose an install location.)")
val menu = SelectMenu(directories, directories.head)
val (target, events2) = menu.ask(terminal.events.stream)
info(e"Installing to $target/${service.scriptName}")
info(Installer.install(force = true, target).communicate)

interactive:
SelectMenu(directories, directories.head).ask: target =>
info(e"Installing to $target/${service.scriptName}")
info(Installer.install(force = true, target).communicate)

if !noTabCompletions then Out.println(TabCompletions.install(force = true).communicate)

Expand Down Expand Up @@ -153,8 +154,18 @@ object actions:
ExitStatus.Ok

object build:
def initialize(directory: Path)(using FrontEnd): ExitStatus raises UserError =
def initialize(directory: Path)(using CliFrontEnd): ExitStatus raises UserError =
given (UserError fixes DismissError) = accede
if (directory / p".fury").exists() then abort(UserError(msg"A build already exists in this directory"))
info(msg"Creating a new build in $directory")

interactive:
info(e"$Italic(Please enter the project name:)")
LineEditor(t"hello-world", 11).ask: choice =>
info(e"You chose $Bold($choice)")
//val (name, events2) = LineEditor(t"hello-world").ask(events)
//info(e"Project has the name $name")

ExitStatus.Ok

def run(target: Target, watch: Boolean, force: Boolean)
Expand Down
7 changes: 3 additions & 4 deletions src/cli/cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,20 +138,19 @@ def main(): Unit =

execute:
frontEnd:
if interactive then actions.install.interactive(force, noTabCompletions)
if interactive then actions.install.installInteractive(force, noTabCompletions)
else actions.install.batch(force, noTabCompletions)

service.shutdown()
ExitStatus.Ok

case Init() :: Nil =>
val dir: Optional[Path] = safely(Dir()).or(safely(workingDirectory))
val discover = Discover()

execute:
frontEnd:
dir.let(actions.build.initialize(_)).or:
val directory = safely(workingDirectory).or:
abort(UserError(msg"The working directory could not be determined."))
actions.build.initialize(directory)

case Config() :: Nil =>
execute:
Expand Down
9 changes: 8 additions & 1 deletion src/cli/clifrontend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import escapade.*
import anticipation.*
import iridescence.*
import gossamer.*
import profanity.*
import rudiments.*
import spectacular.*
import quantitative.*
Expand All @@ -52,7 +53,13 @@ def frontEnd[ResultType](lambda: CliFrontEnd ?=> Terminal ?=> ResultType)(using
safely(frontEnd.render(last = true))
FrontEnd.unregister(frontEnd)

class CliFrontEnd()(using terminal: Terminal) extends FrontEnd:
def interactive[ResultType](using frontEnd: CliFrontEnd)
(block: Stdio ?=> Interactivity[TerminalEvent] ?=> ResultType)
: ResultType =
block(using frontEnd.terminal.stdio)(using frontEnd.terminal)

class CliFrontEnd()(using Terminal) extends FrontEnd:
def terminal = summon[Terminal]
given stdio: Stdio = terminal.stdio
private var dag: Optional[Dag[Target]] = Unset
private var diagram: Optional[DagDiagram[Target]] = Unset
Expand Down
9 changes: 7 additions & 2 deletions src/model/model.scala
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,17 @@ case class ManifestEntry(key: Text, value: Text) derives Debug, CodlEncoder

object Container:
given relabelling: CodlRelabelling[Container] = () =>
Map(t"copies" -> t"copy")
Map(t"insertions" -> t"copy")

case class Insertion(source: WorkPath, destination: WorkPath) derives Debug, CodlEncoder
case class Extraction(source: WorkPath, destination: WorkPath) derives Debug, CodlEncoder

case class Container(id: GoalId, path: WorkPath, insertions: List[Insertion], extractions: List[Extraction])
case class Container
(id: GoalId,
dockerfile: WorkPath,
root: WorkPath,
insertions: List[Insertion],
extractions: List[Extraction])
derives Debug, CodlEncoder

object Exec:
Expand Down

0 comments on commit 3aefe04

Please sign in to comment.