Skip to content

Commit

Permalink
fix: erase scrollback when clearing the screen (scalacenter#2267)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpodsiad authored Feb 9, 2024
1 parent bc910fa commit 00b715a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion frontend/src/main/scala/bloop/engine/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ object Interpreter {
}

if (!bloop.util.CrossPlatform.isWindows)
state.logger.info("\u001b[H\u001b[2J")
state.logger.info(bloop.util.Console.clearCommand)

// Force the first execution before relying on the file watching task
fg(state).flatMap(newState => watcher.watch(newState, fg))
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/main/scala/bloop/io/SourceWatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ final class SourceWatcher private (
def runAction(state: State, events: Seq[DirectoryChangeEvent]): Task[State] = {
// Windows is not supported for now
if (!bloop.util.CrossPlatform.isWindows)
logger.info("\u001b[H\u001b[2J") // Clean terminal before acting on the event action
logger.info(bloop.util.Console.clearCommand)
events.foreach(e => logger.debug(s"A ${e.eventType()} in ${e.path()} has triggered an event"))
action(state)
}
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/main/scala/bloop/util/Console.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package bloop.util

object Console {
private val escape = "\u001b["
private val cursorHome = "H"
private val eraseScreen = "2J"
private val eraseScrollbar = "3J"

val clearCommand: String = escape + cursorHome + escape + eraseScreen + escape + eraseScrollbar
}

0 comments on commit 00b715a

Please sign in to comment.