Skip to content

Commit

Permalink
Miscellaneous changes
Browse files Browse the repository at this point in the history
  • Loading branch information
propensive committed Apr 8, 2024
1 parent 7536dfa commit fe4ad5b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 44 deletions.
2 changes: 1 addition & 1 deletion res/build.id
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1612
1626
2 changes: 1 addition & 1 deletion src/cli/actions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ object actions:

val table =
Table[(ProjectId, Definition)]
(Column(e"$Bold(Project)"): (project, definition) =>
(Column(e"$Bold(Project)"): (_, definition) =>
e"${definition.name}",
// definition.website.lay(e"${definition.name}"): website =>
// e"${escapes.link(website, definition.name)}",
Expand Down
29 changes: 4 additions & 25 deletions src/cli/cli.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import iridescence.*, colors.*
import kaleidoscope.*
import nettlesome.*
import parasite.*, threadModels.platform, asyncOptions.cancelOrphans
import profanity.*, terminalOptions.terminalSizeDetection
import profanity.*
import quantitative.*
import rudiments.*, homeDirectories.virtualMachine
import serpentine.*, hierarchies.unixOrWindows
Expand Down Expand Up @@ -121,7 +121,6 @@ def main(): Unit =

supervise:
given logFormat: LogFormat[File, Display] = logFormats.standardColor[File]
given logFormat2: LogFormat[Err.type, Display] = logFormats.standardColor[Err.type]
import filesystemOptions.{createNonexistent, createNonexistentParents}

given Log[Display] =
Expand Down Expand Up @@ -223,24 +222,6 @@ def main(): Unit =

buildTask.await().also(Out.print(t"\e[?25h"))

case Graph() :: Nil =>
val online = Offline().absent

execute:
given (UserError fixes PathError) = accede
given (UserError fixes ConcurrencyError) = accede
given (UserError fixes IoError) = accede
given (UserError fixes NumberError) = accede
given (UserError fixes WorkspaceError) = accede
given (UserError fixes ExecError) = accede
given (UserError fixes VaultError) = accede

internet(online):
val rootWorkspace = Workspace()
given universe: Universe = rootWorkspace.universe()

ExitStatus.Ok

case Universe() :: subcommands =>
val online = Offline().absent
val generation: Optional[Int] = safely(Generation())
Expand All @@ -257,9 +238,7 @@ def main(): Unit =
ExitStatus.Fail(1)

case Shutdown() :: Nil => execute:
frontEnd:
FrontEnd.terminateAll()

FrontEnd.shutdown()
service.shutdown()
ExitStatus.Ok

Expand Down Expand Up @@ -294,7 +273,6 @@ def main(): Unit =
.or(workspace.build.default).let: action =>
workspace.build.actions.where(_.name == action).let: action =>
internet(online):
def abort(): Unit = cancel()
async:
frontEnd:
val buildTask = task(t"build"):
Expand All @@ -303,7 +281,8 @@ def main(): Unit =
daemon:
terminal.events.stream.each:
case Keypress.Escape | Keypress.Ctrl('C') =>
abort()
info(msg"Aborting the build.")
summon[FrontEnd].abort()

case TerminalInfo.WindowSize(rows, cols) =>
summon[FrontEnd].resize(rows, cols)
Expand Down
13 changes: 6 additions & 7 deletions src/cli/clifrontend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import escapade.*
import anticipation.*
import iridescence.*
import gossamer.*
import profanity.*
import rudiments.*
import spectacular.*
import quantitative.*
Expand All @@ -47,16 +46,20 @@ def frontEnd[ResultType](lambda: CliFrontEnd ?=> Terminal ?=> ResultType)
val frontEnd = CliFrontEnd()
FrontEnd.register(frontEnd)
var continue: Boolean = true
val loop = task(t"frontend")(while continue.also(frontEnd.render()) do sleep(50*Milli(Second)))

try lambda(using frontEnd).also { continue = false } finally
val loop = task(t"frontend"):
while continue.also(frontEnd.render()) do sleep(100*Milli(Second))

try lambda(using frontEnd) finally
continue = false
safely(loop.await())
safely(frontEnd.render(last = true))
FrontEnd.unregister(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:
Expand All @@ -69,10 +72,6 @@ class CliFrontEnd()(using Terminal) extends FrontEnd:
private var tooWide: Boolean = false
private val queue: juc.ConcurrentLinkedQueue[Text] = juc.ConcurrentLinkedQueue()

override def abort(): Unit =
info(e"$Bold(Aborting the build.)\e[K")
super.abort()

def resize(rows: Int, cols: Int): Unit = dag.let(setSchedule(_))

def reset(): Unit =
Expand Down
3 changes: 2 additions & 1 deletion src/engine/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ class Builder():
warnings.lint.typeParameterShadow,
warnings.deprecation,
warnings.feature,
warnings.unused(Unused.All),
warnings.implausiblePatterns))
(classpath)
(sourceMap, work.path)
Expand Down Expand Up @@ -763,5 +764,5 @@ extension (basis: Basis)
path.as[File]

val errorRibbon = Ribbon(rgb"#990033", rgb"#CC0033")
val warningRibbon = Ribbon(rgb"#FFCC00", rgb"#FFCC99")
val warningRibbon = Ribbon(rgb"#FF9900", rgb"#FFCC66")
val infoRibbon = Ribbon(rgb"#006666", rgb"#6699CC")
13 changes: 4 additions & 9 deletions src/engine/frontend.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def info[InfoType: Printable](info: InfoType)(using frontEnd: FrontEnd): Unit =

object FrontEnd:
private var frontEnds: Set[FrontEnd] = Set()
private var termination: Optional[Promise[Unit]] = Unset
private val termination: Optional[Promise[Unit]] = Unset

def register(frontEnd: FrontEnd): Unit = synchronized:
frontEnds += frontEnd
Expand All @@ -43,22 +43,17 @@ object FrontEnd:
termination.let: promise =>
if frontEnds.isEmpty then promise.offer(())

def terminateAll(): Unit =
val promise = Promise[Unit]()
termination = promise
frontEnds.each(_.abort())
safely(promise.await(5*Second))
def shutdown(): Unit = synchronized(frontEnds.each(_.abort()))

trait FrontEnd:
protected val active: scc.TrieMap[Target, Double] = scc.TrieMap()
protected val unscheduled: scm.LinkedHashSet[Target] = scm.LinkedHashSet()
private val aborted: Promise[Unit] = Promise()

def setSchedule(diagram: Dag[Target]): Unit
def start(target: Target): Unit = unscheduled.add(target)
def stop(target: Target): Unit = unscheduled.remove(target)
def start(target: Target): Unit = unscheduled.synchronized(unscheduled.add(target))
def stop(target: Target): Unit = unscheduled.synchronized(unscheduled.remove(target))
def info[InfoType: Printable](info: InfoType): Unit

def abort(): Unit = aborted.offer(())
def attend(): Unit = aborted.attend()
def continue: Boolean = !aborted.ready
Expand Down

0 comments on commit fe4ad5b

Please sign in to comment.