@@ -20,12 +20,13 @@ object Watching {
2020 watch : Boolean ,
2121 streams : SystemStreams ,
2222 setIdle : Boolean => Unit ,
23- evaluate : Option [T ] => Result [T ],
23+ evaluate : ( Boolean , Option [T ]) => Result [T ],
2424 colors : Colors
2525 ): (Boolean , T ) = {
2626 var prevState : Option [T ] = None
27+ var enterKeyPressed = false
2728 while (true ) {
28- val Result (watchables, errorOpt, result) = evaluate(prevState)
29+ val Result (watchables, errorOpt, result) = evaluate(enterKeyPressed, prevState)
2930 prevState = Some (result)
3031 errorOpt.foreach(streams.err.println)
3132 if (ringBell) {
@@ -42,8 +43,9 @@ object Watching {
4243 }
4344
4445 val alreadyStale = watchables.exists(! _.validate())
46+ enterKeyPressed = false
4547 if (! alreadyStale) {
46- Watching .watchAndWait(streams, setIdle, streams.in, watchables, colors)
48+ enterKeyPressed = Watching .watchAndWait(streams, setIdle, streams.in, watchables, colors)
4749 }
4850 }
4951 ???
@@ -55,7 +57,7 @@ object Watching {
5557 stdin : InputStream ,
5658 watched : Seq [Watchable ],
5759 colors : Colors
58- ): Unit = {
60+ ): Boolean = {
5961 setIdle(true )
6062 val watchedPaths = watched.collect { case p : Watchable .Path => p.p.path }
6163 val watchedValues = watched.size - watchedPaths.size
@@ -68,21 +70,25 @@ object Watching {
6870 ).toString
6971 )
7072
71- statWatchWait(watched, stdin)
73+ val enterKeyPressed = statWatchWait(watched, stdin)
7274 setIdle(false )
75+ enterKeyPressed
7376 }
7477
75- def statWatchWait (watched : Seq [Watchable ], stdin : InputStream ): Unit = {
78+ // Returns `true` if enter key is pressed to re-run tasks explicitly
79+ def statWatchWait (watched : Seq [Watchable ], stdin : InputStream ): Boolean = {
7680 val buffer = new Array [Byte ](4 * 1024 )
7781
78- @ tailrec def statWatchWait0 (): Unit = {
82+ @ tailrec def statWatchWait0 (): Boolean = {
7983 if (watched.forall(_.validate())) {
80- if (lookForEnterKey()) ()
81- else {
84+ if (lookForEnterKey()) {
85+ mill.main.client.DebugLog .println(" ENTER KEY DETECTED" )
86+ true
87+ } else {
8288 Thread .sleep(100 )
8389 statWatchWait0()
8490 }
85- }
91+ } else false
8692 }
8793
8894 @ tailrec def lookForEnterKey (): Boolean = {
0 commit comments