MCPcopy Create free account
hub / github.com/cli/cli / newIOStreams

Function newIOStreams

internal/ghcmd/cmd.go:363–425  ·  view source on GitHub ↗
(cfg gh.Config, invokingAgent agents.AgentName)

Source from the content-addressed store, hash-verified

361}
362
363func newIOStreams(cfg gh.Config, invokingAgent agents.AgentName) *iostreams.IOStreams {
364 io := iostreams.System()
365
366 if _, ghPromptDisabled := os.LookupEnv("GH_PROMPT_DISABLED"); ghPromptDisabled {
367 io.SetNeverPrompt(true)
368 } else if prompt := cfg.Prompt(""); prompt.Value == "disabled" {
369 io.SetNeverPrompt(true)
370 }
371
372 falseyValues := []string{"false", "0", "no", ""}
373
374 accessiblePrompterValue, accessiblePrompterIsSet := os.LookupEnv("GH_ACCESSIBLE_PROMPTER")
375 if accessiblePrompterIsSet {
376 if !slices.Contains(falseyValues, accessiblePrompterValue) {
377 io.SetAccessiblePrompterEnabled(true)
378 }
379 } else if prompt := cfg.AccessiblePrompter(""); prompt.Value == "enabled" {
380 io.SetAccessiblePrompterEnabled(true)
381 }
382
383 experimentalPrompterValue, experimentalPrompterIsSet := os.LookupEnv("GH_EXPERIMENTAL_PROMPTER")
384 if experimentalPrompterIsSet {
385 if !slices.Contains(falseyValues, experimentalPrompterValue) {
386 io.SetExperimentalPrompterEnabled(true)
387 }
388 }
389
390 ghSpinnerDisabledValue, ghSpinnerDisabledIsSet := os.LookupEnv("GH_SPINNER_DISABLED")
391 if ghSpinnerDisabledIsSet {
392 if !slices.Contains(falseyValues, ghSpinnerDisabledValue) {
393 io.SetSpinnerDisabled(true)
394 }
395 } else if invokingAgent != "" {
396 io.SetSpinnerDisabled(true)
397 } else if spinner := cfg.Spinner(""); spinner.Value == "disabled" {
398 io.SetSpinnerDisabled(true)
399 }
400
401 // Pager precedence
402 // 1. GH_PAGER
403 // 2. pager from config
404 // 3. PAGER
405 if ghPager, ghPagerExists := os.LookupEnv("GH_PAGER"); ghPagerExists {
406 io.SetPager(ghPager)
407 } else if pager := cfg.Pager(""); pager.Value != "" {
408 io.SetPager(pager.Value)
409 }
410
411 if ghColorLabels, ghColorLabelsExists := os.LookupEnv("GH_COLOR_LABELS"); ghColorLabelsExists {
412 switch ghColorLabels {
413 case "", "0", "false", "no":
414 io.SetColorLabels(false)
415 default:
416 io.SetColorLabels(true)
417 }
418 } else if prompt := cfg.ColorLabels(""); prompt.Value == "enabled" {
419 io.SetColorLabels(true)
420 }

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