oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
73.17k stars 2.68k forks source link

Expose `--clearScreen` for `bun --watch` #3491

Closed cayter closed 1 month ago

cayter commented 1 year ago

What is the problem this feature would solve?

I'm currently using foreman to run multiple processes during development. When using bun --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

flexchar commented 5 months ago

I would like to opt out as it doesn't scroll to the bottom when using Warp.dev terminal.

DesignMonkey commented 5 months ago

+1 - Same problem here - I have to scroll down all the time in Warp

mikemasam commented 5 months ago

+1 - Same problem,

technoplato commented 3 months ago

I hacked something together that works in the meantime because Bun is awesome and we can make simple compromises for excellent tools

demo: 2024-06-05 06 38 41

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))
})
Jarred-Sumner commented 3 months ago

As a temporary workaround, you can set the environment variable BUN_CONFIG_NO_CLEAR_TERMINAL_ON_RELOAD=1

bigopon commented 1 month ago

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.

Jarred-Sumner commented 1 month ago

This was implemented some time ago as --no-clear-screen

bigopon commented 1 month ago

Thanks @Jarred-Sumner , but I want --clear-screen, is there anything like --clear-screen?

bigopon commented 1 month ago

And I just realised I have the opposite problem of the OP, my vscode terminal doesn't clear the screen.

jakebailey commented 3 weeks ago

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.