Skip to content

Commit

Permalink
If stderr isn’t a tty don’t do control sequences
Browse files Browse the repository at this point in the history
note: only by default
  • Loading branch information
mxcl committed Jun 6, 2023
1 parent 5dba2b1 commit a486cfa
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/hooks/useConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,20 @@ export function ConfigDefault(flags?: Flags, arg0 = Deno.execPath(), env = Deno.
PATH
} = env

// we only output color & control sequences to stderr
const isTTY = () => Deno.isatty(Deno.stderr.rid)

return {
...defaults,
arg0: new Path(arg0),
UserAgent: `tea.cli/${useVersion()}`,
logger: {
prefix: undefined,
color: getColor(env)
color: getColor(env, isTTY)
},
modifiers: {
dryrun: flags?.dryrun ?? false,
verbosity: flags?.verbosity ?? getVerbosity(env),
verbosity: flags?.verbosity ?? getVerbosity(env, isTTY()),
json: flags?.json ?? false,
keepGoing: flags?.keepGoing ?? false,
},
Expand Down Expand Up @@ -115,7 +118,7 @@ export enum Verbosity {
trace = 3
}

function getVerbosity(env: Record<string, string>): Verbosity {
function getVerbosity(env: Record<string, string>, sequences_ok: boolean): Verbosity {
const { DEBUG, GITHUB_ACTIONS, RUNNER_DEBUG, VERBOSE, CI } = env

if (DEBUG == '1') return Verbosity.debug
Expand All @@ -124,17 +127,15 @@ function getVerbosity(env: Record<string, string>): Verbosity {
const verbosity = flatmap(VERBOSE, parseInt)
if (isNumber(verbosity)) {
return verbosity
} else if (parseBool(CI)) {
} else if (parseBool(CI) || !sequences_ok) {
// prevents dumping 100s of lines of download progress
return Verbosity.quiet
} else {
return Verbosity.normal
}
}

function getColor(env: Record<string, string>) {
const isTTY = () => Deno.isatty(Deno.stdout.rid) && Deno.isatty(Deno.stdout.rid)

function getColor(env: Record<string, string>, isTTY: () => boolean) {
if ((env.CLICOLOR ?? '1') != '0' && isTTY()){
//https://bixense.com/clicolors/
return true
Expand Down

0 comments on commit a486cfa

Please sign in to comment.