提交 8b784766 编写于 作者: J Joe Haddad 提交者: Tim Neutkens

Remove alternate screen usage (#6377)

* Make console output well behaved

* Fix bad rebase
上级 09508ed4
// This file is derived from Jest:
// https://github.com/facebook/jest/blob/d9d501ac342212b8a58ddb23a31518beb7b56f47/packages/jest-util/src/specialChars.ts#L18
const isWindows = process.platform === 'win32'
const isInteractive = process.stderr.isTTY
export function clearConsole() {
if (!isInteractive) {
return
}
process.stderr.write(isWindows ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H')
}
import chalk from 'chalk'
import createStore from 'unistore'
import onExit from 'signal-exit'
import { clearConsole } from './clearConsole'
import readline from 'readline'
import cliCursor from 'cli-cursor'
export type OutputState =
| { bootstrap: true; appUrl: string | null }
......@@ -16,19 +15,11 @@ export type OutputState =
export const store = createStore<OutputState>({ appUrl: null, bootstrap: true })
let registered = false
cliCursor.hide()
process.stdout.write('\n'.repeat(process.stdout.rows || 1))
store.subscribe(state => {
if (!registered) {
registered = true
process.stderr.write('\u001B[?1049h')
onExit(function() {
process.stderr.write('\u001B[?1049l')
})
}
clearConsole()
readline.cursorTo(process.stdout, 0, 0)
readline.clearScreenDown(process.stdout)
if (state.bootstrap) {
console.log(chalk.cyan('Starting the development server ...'))
......
......@@ -60,6 +60,7 @@
"cacache": "^11.0.2",
"case-sensitive-paths-webpack-plugin": "2.1.2",
"chalk": "2.4.2",
"cli-cursor": "2.1.0",
"cross-spawn": "5.1.0",
"del": "3.0.0",
"event-source-polyfill": "0.0.12",
......@@ -82,7 +83,6 @@
"resolve": "1.5.0",
"schema-utils": "1.0.0",
"serialize-javascript": "1.4.0",
"signal-exit": "3.0.2",
"source-map": "0.6.1",
"strip-ansi": "3.0.1",
"styled-jsx": "3.2.1",
......@@ -112,6 +112,7 @@
"@types/babel__template": "7.0.1",
"@types/babel__traverse": "7.0.3",
"@types/case-sensitive-paths-webpack-plugin": "2.1.2",
"@types/cli-cursor": "2.1.0",
"@types/cross-spawn": "6.0.0",
"@types/etag": "1.8.0",
"@types/fresh": "0.5.0",
......@@ -122,7 +123,6 @@
"@types/node-fetch": "2.1.4",
"@types/resolve": "0.0.8",
"@types/rimraf": "2.0.2",
"@types/signal-exit": "3.0.0",
"taskr": "1.1.0",
"typescript": "3.1.6"
},
......
......@@ -1526,6 +1526,13 @@
dependencies:
"@types/webpack" "*"
"@types/cli-cursor@2.1.0":
version "2.1.0"
resolved "https://registry.yarnpkg.com/@types/cli-cursor/-/cli-cursor-2.1.0.tgz#bf293a75efb7bd8a3dd020413ec41cd317e5f128"
integrity sha512-tICz3BCZI/XDB0+qbtHEyFp7JNaL9AP+HCzrH7sRdf6mO9KMnntKlPv8Dhk01nMtCod+4Xh/pjEoJWAr0A0VmQ==
dependencies:
"@types/node" "*"
"@types/cross-spawn@6.0.0":
version "6.0.0"
resolved "https://registry.yarnpkg.com/@types/cross-spawn/-/cross-spawn-6.0.0.tgz#320aaf1d1a12979f1b84fe7a5590a7e860bf3a80"
......@@ -1658,11 +1665,6 @@
"@types/mime" "*"
"@types/node" "*"
"@types/signal-exit@3.0.0":
version "3.0.0"
resolved "https://registry.yarnpkg.com/@types/signal-exit/-/signal-exit-3.0.0.tgz#75e3b17660cf1f6c6cb8557675b4e680e43bbf36"
integrity sha512-MaJ+16SOXz0Z27EMf3d88+B6UDglq1sn140a+5X/ROLkIcEfRq0CPg+1B2efF1GXQn4n+aKH4ti2hHG4Ya+Dzg==
"@types/tapable@*":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@types/tapable/-/tapable-1.0.4.tgz#b4ffc7dc97b498c969b360a41eee247f82616370"
......@@ -3243,6 +3245,13 @@ clean-stack@^1.0.0:
resolved "https://registry.yarnpkg.com/clean-stack/-/clean-stack-1.3.0.tgz#9e821501ae979986c46b1d66d2d432db2fd4ae31"
integrity sha1-noIVAa6XmYbEax1m0tQy2y/UrjE=
cli-cursor@2.1.0, cli-cursor@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
integrity sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=
dependencies:
restore-cursor "^2.0.0"
cli-cursor@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-1.0.2.tgz#64da3f7d56a54412e59794bd62dc35295e8f2987"
......@@ -3250,13 +3259,6 @@ cli-cursor@^1.0.2:
dependencies:
restore-cursor "^1.0.1"
cli-cursor@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/cli-cursor/-/cli-cursor-2.1.0.tgz#b35dac376479facc3e94747d41d0d0f5238ffcb5"
integrity sha1-s12sN2R5+sw+lHR9QdDQ9SOP/LU=
dependencies:
restore-cursor "^2.0.0"
cli-spinners@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/cli-spinners/-/cli-spinners-0.1.2.tgz#bb764d88e185fb9e1e6a2a1f19772318f605e31c"
......@@ -10879,7 +10881,7 @@ shellwords@^0.1.0, shellwords@^0.1.1:
resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b"
integrity sha512-vFwSUfQvqybiICwZY5+DAWIPLKsWO31Q91JSKl3UYv+K5c2QRPzn0qzec6QPu1Qc9eHYItiP3NdJqNVqetYAww==
signal-exit@3.0.2, signal-exit@^3.0.0, signal-exit@^3.0.2:
signal-exit@^3.0.0, signal-exit@^3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d"
integrity sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册