Closed cayter closed 1 month ago
I would like to opt out as it doesn't scroll to the bottom when using Warp.dev terminal.
+1 - Same problem here - I have to scroll down all the time in Warp
+1 - Same problem,
I hacked something together that works in the meantime because Bun is awesome and we can make simple compromises for excellent tools
demo:
Obviously, this is a super hack, but it works for me right now until one adds the watch option to clear the screen.
Note that you will have to change the terminal listed in the script if you're not using the standard terminal. I don't know how this would work with the in-IDE terminal either.
Here's the code:
import { exec } from 'child_process'
// Define the AppleScript to clear the terminal
const appleScript = `
tell application "Terminal"
activate
tell application "System Events"
keystroke "k" using {command down}
end tell
end tell
`
// Function to execute the AppleScript
export function clearTerminal() {
return new Promise((resolve, reject) => {
exec(`osascript -e '${appleScript}'`, (error, stdout, stderr) => {
if (error) {
reject(`Error executing AppleScript: ${error}`)
return
}
if (stderr) {
reject(`Error output: ${stderr}`)
return
}
resolve(`Output: ${stdout}`)
})
})
}
Here is how to use the code. From my experience, a timeout of about 70 ms is required:
beforeEach(async () => {
await clearTerminal()
await new Promise((resolve) => setTimeout(resolve, 70))
})
As a temporary workaround, you can set the environment variable BUN_CONFIG_NO_CLEAR_TERMINAL_ON_RELOAD=1
Having the following in the preload script is working for me
import { beforeAll } from 'bun:test';
beforeAll(() => {
function clearScreen() {
try { process.stdout.write('\x1Bc'); } catch {}
}
clearScreen();
});
at least it seems to be enough for what I need.
This was implemented some time ago as --no-clear-screen
Thanks @Jarred-Sumner , but I want --clear-screen
, is there anything like --clear-screen
?
And I just realised I have the opposite problem of the OP, my vscode terminal doesn't clear the screen.
This probably deserves another bug, but TS as of version 5.6 uses "\x1B[2J\x1B[3J\x1B[H"
as the screen clearing string, which seems to work consistently across all terminals/OSs. I've stuck process.stdout.write("\x1B[2J\x1B[3J\x1B[H");
at the top of my own bun scripts I've been running with --watch
in the meantime.
What is the problem this feature would solve?
I'm currently using
foreman
to run multiple processes during development. When usingbun --watch
as 1 of the processes, it clears the other processes stderr/stdout which leads to us not knowing what's wrong with the other processes.What is the feature you are proposing to solve the problem?
Expose
--clearScreen
to allow users opt-out.What alternatives have you considered?
No response