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

Function newIOStreams

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

Source from the content-addressed store, hash-verified

388}
389
390func newIOStreams(cfg gh.Config, invokingAgent agents.AgentName) *iostreams.IOStreams {
391 io := iostreams.System()
392
393 if _, ghPromptDisabled := os.LookupEnv("GH_PROMPT_DISABLED"); ghPromptDisabled {
394 io.SetNeverPrompt(true)
395 } else if prompt := cfg.Prompt(""); prompt.Value == "disabled" {
396 io.SetNeverPrompt(true)
397 }
398
399 falseyValues := []string{"false", "0", "no", ""}
400
401 accessiblePrompterValue, accessiblePrompterIsSet := os.LookupEnv("GH_ACCESSIBLE_PROMPTER")
402 if accessiblePrompterIsSet {
403 if !slices.Contains(falseyValues, accessiblePrompterValue) {
404 io.SetAccessiblePrompterEnabled(true)
405 }
406 } else if prompt := cfg.AccessiblePrompter(""); prompt.Value == "enabled" {
407 io.SetAccessiblePrompterEnabled(true)
408 }
409
410 experimentalPrompterValue, experimentalPrompterIsSet := os.LookupEnv("GH_EXPERIMENTAL_PROMPTER")
411 if experimentalPrompterIsSet {
412 if !slices.Contains(falseyValues, experimentalPrompterValue) {
413 io.SetExperimentalPrompterEnabled(true)
414 }
415 }
416
417 ghSpinnerDisabledValue, ghSpinnerDisabledIsSet := os.LookupEnv("GH_SPINNER_DISABLED")
418 if ghSpinnerDisabledIsSet {
419 if !slices.Contains(falseyValues, ghSpinnerDisabledValue) {
420 io.SetSpinnerDisabled(true)
421 }
422 } else if invokingAgent != "" {
423 io.SetSpinnerDisabled(true)
424 } else if spinner := cfg.Spinner(""); spinner.Value == "disabled" {
425 io.SetSpinnerDisabled(true)
426 }
427
428 // Pager precedence
429 // 1. GH_PAGER
430 // 2. pager from config
431 // 3. PAGER
432 if ghPager, ghPagerExists := os.LookupEnv("GH_PAGER"); ghPagerExists {
433 io.SetPager(ghPager)
434 } else if pager := cfg.Pager(""); pager.Value != "" {
435 io.SetPager(pager.Value)
436 }
437
438 if ghColorLabels, ghColorLabelsExists := os.LookupEnv("GH_COLOR_LABELS"); ghColorLabelsExists {
439 switch ghColorLabels {
440 case "", "0", "false", "no":
441 io.SetColorLabels(false)
442 default:
443 io.SetColorLabels(true)
444 }
445 } else if prompt := cfg.ColorLabels(""); prompt.Value == "enabled" {
446 io.SetColorLabels(true)
447 }

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