Skip to content

Commit

Permalink
repl: Add cls command to clear screen
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Jul 2, 2019
1 parent 85b336f commit 234f96a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
5 changes: 4 additions & 1 deletion docs/src/content/docs/watch/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ not connected to the file that changed.
if a test run is not in progress.

* `clear`
Delete all coverage info and re-run the test suite
Delete all coverage info and re-run the test suite.

* `cls`
Clear the screen.

## Adding Tests

Expand Down
8 changes: 7 additions & 1 deletion lib/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ class Repl {
return this.exit(cb)
case 'clear':
return this.clear(cb)
case 'cls':
this.repl.output.write('\u001b[2J\u001b[H')
return cb()
default:
return this.help(cb)
}
Expand Down Expand Up @@ -202,6 +205,9 @@ exit
clear
delete all coverage info and re-run the test suite
cls
clear the screen
`)
cb()
}
Expand All @@ -215,7 +221,7 @@ clear
const cmdArg = input.trimLeft().split(' ')
const cmd = cmdArg.shift()
const arg = cmdArg.join(' ').trimLeft()
const commands = ['r', 'u', 'n', 'p', 'c', 'exit', 'clear']
const commands = ['r', 'u', 'n', 'p', 'c', 'exit', 'clear', 'cls']
if (cmd === 'r' || cmd === 'u') {
const d = path.dirname(arg)
const dir = arg.slice(-1) === '/' ? arg : d === '.' ? '' : d + '/'
Expand Down
8 changes: 8 additions & 0 deletions tap-snapshots/test-repl.js-TAP.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Make sure to inspect the output below. Do not ignore changes!
*/
'use strict'
exports[`test/repl.js TAP cls > clear screen 1`] = `
"\\u001b[2J\\u001b[HTAP> "
`

exports[`test/repl.js TAP completer > empty 1`] = `
Array [
Array [
Expand All @@ -15,6 +19,7 @@ Array [
"c",
"exit",
"clear",
"cls",
],
"",
]
Expand Down Expand Up @@ -175,5 +180,8 @@ exit
clear
delete all coverage info and re-run the test suite
cls
clear the screen
TAP>
`
9 changes: 9 additions & 0 deletions test/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,15 @@ t.test('completer', t => {
t.end()
})

t.test('cls', t => {
input.write('cls\n')
setTimeout(() => {
// JSON.stringify it so that it doesn't look gross in patches
t.matchSnapshot(JSON.stringify(output.read()), 'clear screen')
t.end()
})
})

t.test('exit', t => {
repl.repl.emit('SIGINT')
t.matchSnapshot(output.read(), 'output')
Expand Down

0 comments on commit 234f96a

Please sign in to comment.