Skip to content
This repository was archived by the owner on Jul 27, 2021. It is now read-only.

Clear output the right way (again) #23

Merged
merged 15 commits into from
Feb 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _sandbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export default class MyComponent extends React.Component {
render() {
return <div>Hello</div>
}
}
}
9 changes: 7 additions & 2 deletions src/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const colors = require('./utils/colors');
const chalk = require('chalk');
const stringLength = require('string-length');
const readline = require('readline');

class Debugger {

Expand Down Expand Up @@ -74,8 +75,12 @@ class Debugger {
}

clearConsole () {
if (!this.capturing && this.enabled) {
process.stdout.write(process.platform === 'win32' ? '\x1Bc' : '\x1B[2J\x1B[3J\x1B[H');
if (!this.capturing && this.enabled && process.stdout.isTTY) {
// Fill screen with blank lines. Then move to 0 (beginning of visible part) and clear it
const blank = '\n'.repeat(process.stdout.rows)
console.log(blank)
readline.cursorTo(process.stdout, 0, 0)
readline.clearScreenDown(process.stdout)
}
}

Expand Down