Skip to content

Commit

Permalink
Merge pull request #35 from StauroDEV/fix-gw-tty
Browse files Browse the repository at this point in the history
fix: disable colors for non tty in ping command
  • Loading branch information
talentlessguy authored May 28, 2024
2 parents 4208f74 + 1a85fd6 commit 6db81f0
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/actions/ping.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import * as colors from 'colorette'
import { isTTY } from '../constants'

let retryCount = 0

const gwOfflineMessage = `😞 Max retries exceeded. Gateway is ${colors.bold(colors.red('Offline'))}.`
const gwOfflineMessage = `😞 Max retries exceeded. Gateway is ${isTTY ? colors.bold(colors.red('Offline')) : 'Offline'}.`

export const pingAction = async (
{ cid, endpoint, options }: {
Expand All @@ -15,7 +16,7 @@ export const pingAction = async (

retryCount++
const url = `https://${cid}.ipfs.${endpoint}`
console.log(`${colors.bold(`[${retryCount}]`)}: Requesting content at ${url}`)
console.log(`${isTTY ? colors.bold(`[${retryCount}]`) : `[${retryCount}]`}: Requesting content at ${url}`)
try {
const response = await fetch(url, { signal: AbortSignal.timeout(timeout), redirect: 'follow' })
if (response.status === 504) {
Expand All @@ -31,7 +32,7 @@ export const pingAction = async (
else {
return console.log(`Gateway status: ${
response.status >= 200 && response.status < 400
? colors.bold(colors.green(`Online ${response.status}`))
? (isTTY ? colors.bold(colors.green(`Online ${response.status}`)) : `Online ${response.status}`)
: response.status
}`)
}
Expand Down

0 comments on commit 6db81f0

Please sign in to comment.