MCPcopy
hub / github.com/cli/cli / newIOStreams

Function newIOStreams

internal/ghcmd/cmd.go:349–409  ·  view source on GitHub ↗
(cfg gh.Config)

Source from the content-addressed store, hash-verified

347}
348
349func newIOStreams(cfg gh.Config) *iostreams.IOStreams {
350 io := iostreams.System()
351
352 if _, ghPromptDisabled := os.LookupEnv("GH_PROMPT_DISABLED"); ghPromptDisabled {
353 io.SetNeverPrompt(true)
354 } else if prompt := cfg.Prompt(""); prompt.Value == "disabled" {
355 io.SetNeverPrompt(true)
356 }
357
358 falseyValues := []string{"false", "0", "no", ""}
359
360 accessiblePrompterValue, accessiblePrompterIsSet := os.LookupEnv("GH_ACCESSIBLE_PROMPTER")
361 if accessiblePrompterIsSet {
362 if !slices.Contains(falseyValues, accessiblePrompterValue) {
363 io.SetAccessiblePrompterEnabled(true)
364 }
365 } else if prompt := cfg.AccessiblePrompter(""); prompt.Value == "enabled" {
366 io.SetAccessiblePrompterEnabled(true)
367 }
368
369 experimentalPrompterValue, experimentalPrompterIsSet := os.LookupEnv("GH_EXPERIMENTAL_PROMPTER")
370 if experimentalPrompterIsSet {
371 if !slices.Contains(falseyValues, experimentalPrompterValue) {
372 io.SetExperimentalPrompterEnabled(true)
373 }
374 }
375
376 ghSpinnerDisabledValue, ghSpinnerDisabledIsSet := os.LookupEnv("GH_SPINNER_DISABLED")
377 if ghSpinnerDisabledIsSet {
378 if !slices.Contains(falseyValues, ghSpinnerDisabledValue) {
379 io.SetSpinnerDisabled(true)
380 }
381 } else if spinnerDisabled := cfg.Spinner(""); spinnerDisabled.Value == "disabled" {
382 io.SetSpinnerDisabled(true)
383 }
384
385 // Pager precedence
386 // 1. GH_PAGER
387 // 2. pager from config
388 // 3. PAGER
389 if ghPager, ghPagerExists := os.LookupEnv("GH_PAGER"); ghPagerExists {
390 io.SetPager(ghPager)
391 } else if pager := cfg.Pager(""); pager.Value != "" {
392 io.SetPager(pager.Value)
393 }
394
395 if ghColorLabels, ghColorLabelsExists := os.LookupEnv("GH_COLOR_LABELS"); ghColorLabelsExists {
396 switch ghColorLabels {
397 case "", "0", "false", "no":
398 io.SetColorLabels(false)
399 default:
400 io.SetColorLabels(true)
401 }
402 } else if prompt := cfg.ColorLabels(""); prompt.Value == "enabled" {
403 io.SetColorLabels(true)
404 }
405
406 io.SetAccessibleColorsEnabled(xcolor.IsAccessibleColorsEnabled())

Callers 6

MainFunction · 0.85
Test_newIOStreams_pagerFunction · 0.85
Test_newIOStreams_promptFunction · 0.85

Calls 14

SystemFunction · 0.92
SetNeverPromptMethod · 0.80
ContainsMethod · 0.80
SetSpinnerDisabledMethod · 0.80
SetPagerMethod · 0.80
SetColorLabelsMethod · 0.80
PromptMethod · 0.65
AccessiblePrompterMethod · 0.65
SpinnerMethod · 0.65