-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: remove ansi-escapes
#13471
Closed
Closed
chore: remove ansi-escapes
#13471
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
packages/jest-util/src/__tests__/__snapshots__/ansiEscapes.test.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`ansiEscapes allows passing an argument to cursorDown function 1`] = ` | ||
"<moveCursorDownBy2Rows> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes allows passing an argument to cursorUp function 1`] = ` | ||
"<moveCursorUpBy2Rows> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes allows passing arguments to cursorTo function 1`] = ` | ||
"<moveCursorToRow3Column12> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes clearTerminal sequence 1`] = ` | ||
"<clearTerminal> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes cursorToFirstColumn sequence 1`] = ` | ||
"<moveCursorToColumn1> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes eraseLine sequence 1`] = ` | ||
"<eraseLine> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes eraseScreenDown sequence 1`] = ` | ||
"<eraseScreenDown> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes hideCursor sequence 1`] = ` | ||
"<hideCursor> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes restoreCursorPosition sequence 1`] = ` | ||
"<restoreCursorPosition> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes restoreCursorPosition sequence on Terminal App 1`] = ` | ||
"<restoreCursorPosition> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes returns cursorDown sequence 1`] = ` | ||
"<moveCursorDownBy1Row> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes returns cursorUp sequence 1`] = ` | ||
"<moveCursorUpBy1Row> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes saveCursorPosition sequence 1`] = ` | ||
"<saveCursorPosition> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes saveCursorPosition sequence on Terminal App 1`] = ` | ||
"<saveCursorPosition> | ||
" | ||
`; | ||
|
||
exports[`ansiEscapes showCursor sequence 1`] = ` | ||
"<showCursor> | ||
" | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import * as ansiEscapes from '../ansiEscapes'; | ||
|
||
const oldTermProgram = process.env.TERM_PROGRAM; | ||
|
||
afterEach(() => { | ||
process.env.TERM_PROGRAM = oldTermProgram; | ||
}); | ||
|
||
describe('ansiEscapes', () => { | ||
test('clearTerminal sequence', () => { | ||
expect(ansiEscapes.clearTerminal).toMatchSnapshot(); | ||
}); | ||
|
||
test('returns cursorUp sequence', () => { | ||
expect(ansiEscapes.cursorUp()).toMatchSnapshot(); | ||
}); | ||
|
||
test('allows passing an argument to cursorUp function', () => { | ||
expect(ansiEscapes.cursorUp(2)).toMatchSnapshot(); | ||
}); | ||
|
||
test('returns cursorDown sequence', () => { | ||
expect(ansiEscapes.cursorDown()).toMatchSnapshot(); | ||
}); | ||
|
||
test('allows passing an argument to cursorDown function', () => { | ||
expect(ansiEscapes.cursorDown(2)).toMatchSnapshot(); | ||
}); | ||
|
||
test('cursorToFirstColumn sequence', () => { | ||
expect(ansiEscapes.cursorToFirstColumn).toMatchSnapshot(); | ||
}); | ||
|
||
test('allows passing arguments to cursorTo function', () => { | ||
expect(ansiEscapes.cursorTo(3, 12)).toMatchSnapshot(); | ||
}); | ||
|
||
test('eraseScreenDown sequence', () => { | ||
expect(ansiEscapes.eraseScreenDown).toMatchSnapshot(); | ||
}); | ||
|
||
test('eraseLine sequence', () => { | ||
expect(ansiEscapes.eraseLine).toMatchSnapshot(); | ||
}); | ||
|
||
test('saveCursorPosition sequence', () => { | ||
expect(ansiEscapes.saveCursorPosition).toMatchSnapshot(); | ||
}); | ||
|
||
test('saveCursorPosition sequence on Terminal App', () => { | ||
process.env.TERM_PROGRAM = 'Apple_Terminal'; | ||
|
||
expect(ansiEscapes.saveCursorPosition).toMatchSnapshot(); | ||
}); | ||
|
||
test('restoreCursorPosition sequence', () => { | ||
expect(ansiEscapes.restoreCursorPosition).toMatchSnapshot(); | ||
}); | ||
|
||
test('restoreCursorPosition sequence on Terminal App', () => { | ||
process.env.TERM_PROGRAM = 'Apple_Terminal'; | ||
|
||
expect(ansiEscapes.restoreCursorPosition).toMatchSnapshot(); | ||
}); | ||
|
||
test('hideCursor sequence', () => { | ||
expect(ansiEscapes.hideCursor).toMatchSnapshot(); | ||
}); | ||
|
||
test('showCursor sequence', () => { | ||
expect(ansiEscapes.showCursor).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// Reference: https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences | ||
|
||
const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal'; | ||
const isWindows = process.platform === 'win32'; | ||
|
||
export const clearTerminal = isWindows | ||
? '\x1b[2J\x1b[0f' | ||
: '\x1b[2J\x1b[3J\x1b[H'; | ||
|
||
export const cursorUp = (rows = 1): string => `\x1b[${rows}A`; | ||
export const cursorDown = (rows = 1): string => `\x1b[${rows}B`; | ||
|
||
export const cursorToFirstColumn = '\x1b[G'; | ||
|
||
export const cursorTo = (row: number, column: number): string => | ||
`\x1b[${row};${column}H`; | ||
|
||
export const eraseScreenDown = '\x1b[J'; | ||
|
||
export const eraseLine = '\x1b[2K'; | ||
|
||
export const saveCursorPosition = isTerminalApp ? '\x1b7' : '\x1b[s'; | ||
export const restoreCursorPosition = isTerminalApp ? '\x1b8' : '\x1b[u'; | ||
|
||
export const hideCursor = '\x1b[?25l'; | ||
export const showCursor = '\x1b[?25h'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more idea. Additionally
jest-watcher
could also exposeansiEscapes
so that plugins could use this implementation as well.