当前位置: 首页>>代码示例>>Golang>>正文


Golang terminal.IsTerminal函数代码示例

本文整理汇总了Golang中golang.org/x/crypto/ssh/terminal.IsTerminal函数的典型用法代码示例。如果您正苦于以下问题:Golang IsTerminal函数的具体用法?Golang IsTerminal怎么用?Golang IsTerminal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了IsTerminal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: checkVersion

func (c *CLI) checkVersion() {
	var shouldCheck bool
	var outs io.Writer
	if terminal.IsTerminal(int(os.Stdout.Fd())) {
		outs = os.Stdout
		shouldCheck = true
	} else if terminal.IsTerminal(int(os.Stderr.Fd())) {
		outs = os.Stderr
		shouldCheck = true
	}
	if strings.Contains(c.Version, "dev") {
		shouldCheck = false
	}
	if shouldCheck {
		newVersion, err := c.CheckForUpgrade()
		if err != nil {
			fmt.Fprintf(outs, errize(fmt.Sprintf(
				"Failed checking for upgrade: %s\n",
				err.Error(),
			)))
		}
		if newVersion != nil {
			fmt.Fprintf(outs, heyYou(fmt.Sprintf(
				"You are using an older version (%s; latest: %s) of this client.\nTo upgrade run `%s upgrade`.\n",
				c.Version,
				newVersion.Version,
				c.Name,
			)))
		}
	}
}
开发者ID:eldarion-gondor,项目名称:gondor,代码行数:31,代码来源:cli.go

示例2: performAutoDetections

// performAutoDetections sets options that are set to "auto"
func (o *Options) performAutoDetections(targets []string) {
	if o.ShowFilename == "auto" {
		if len(targets) == 1 {
			fileinfo, err := os.Stat(targets[0])
			if err == nil && fileinfo.IsDir() {
				o.ShowFilename = "on"
			} else {
				o.ShowFilename = "off"
			}
		} else {
			o.ShowFilename = "on"
		}
	}

	if o.Color == "auto" {
		// auto activate colored output only if STDOUT is a terminal
		if o.Output == "" {
			if runtime.GOOS != "windows" && terminal.IsTerminal(int(os.Stdout.Fd())) {
				o.Color = "on"
			} else {
				o.Color = "off"
			}
		} else {
			o.Color = "off"
		}
	}

	if o.GroupByFile {
		if !terminal.IsTerminal(int(os.Stdout.Fd())) {
			o.GroupByFile = false
		}
	}

	if o.Cores == 0 {
		o.Cores = runtime.NumCPU()
	}

	if o.Color == "on" {
		global.termHighlightFilename = fmt.Sprintf("\033[%d;%d;%dm", 1, 35, 49)
		global.termHighlightLineno = fmt.Sprintf("\033[%d;%d;%dm", 1, 32, 49)
		global.termHighlightMatch = fmt.Sprintf("\033[%d;%d;%dm", 1, 31, 49)
		global.termHighlightReset = fmt.Sprintf("\033[%d;%d;%dm", 0, 39, 49)
	} else {
		global.termHighlightFilename = ""
		global.termHighlightLineno = ""
		global.termHighlightMatch = ""
		global.termHighlightReset = ""
	}
}
开发者ID:Rican7,项目名称:sift,代码行数:50,代码来源:options.go

示例3: ttyEscape

func ttyEscape(code string) string {
	if terminal.IsTerminal(syscall.Stdout) {
		return "\x1b[" + code + "m"
	} else {
		return ""
	}
}
开发者ID:hoisie,项目名称:web,代码行数:7,代码来源:ttycolors.go

示例4: NewCanvas

func (cli *CLI) NewCanvas(collection string, filepath string) {
	cli.doAuth()
	var body string

	if filepath != "" {
		//read from file
		fileExists, err := exists(filepath)
		check(err)
		if !fileExists {
			fmt.Printf("File %s not found", filepath)
		}
		bytes, err := ioutil.ReadFile(filepath)
		check(err)
		body = string(bytes)
	} else if !terminal.IsTerminal(int(os.Stdin.Fd())) {
		// read from STDIN if not a terminal
		bytes, err := ioutil.ReadAll(os.Stdin)
		check(err)
		body = string(bytes)
	}

	// default collection to username
	if collection == "" {
		collection = cli.Account.Username
	}

	// make the canvas
	canvas, err := cli.Client.NewCanvas(collection, body)
	check(err)
	canvas.URL = cli.Client.JoinWebUrl(canvas.WebName())
	fmt.Println(canvas.URL)
}
开发者ID:csquared,项目名称:canvas-cli,代码行数:32,代码来源:cli.go

示例5: parseArgs

func parseArgs() {
	// set options
	flag.DurationVar(&option.interval, "interval",
		time.Second, "Measurement interval")
	flag.BoolVar(&option.no_interval_backoff, "no-interval-backoff",
		false, "Disable interval backoff")
	flag.DurationVar(&option.timeout, "timeout",
		time.Second*0, "Measurement timeout")
	flag.DurationVar(&option.start_delay, "start-delay",
		time.Second*0, "Wait time before measurement")
	flag.StringVar(&option.output, "output",
		"-", "Output file name")
	flag.BoolVar(&option.no_cpu, "no-cpu",
		false, "Do not record CPU usage")
	flag.BoolVar(&option.no_disk, "no-disk",
		false, "Do not record disk usage")
	flag.BoolVar(&option.no_net, "no-net",
		false, "Do not record net usage")
	flag.BoolVar(&option.debug, "debug",
		false, "Enable debug mode")
	flag.BoolVar(&option.listDevices, "list-devices",
		false, "List devices and exits")
	flag.StringVar(&option.disks, "disks",
		"", "Disk devices to be monitored")
	flag.StringVar(&option.player_bin, "player-bin",
		"", "Run perfmonger-player to show JSON output")

	flag.Parse()

	if option.player_bin == "" && terminal.IsTerminal(int(os.Stdout.Fd())) &&
		option.output == "-" {
		fmt.Fprintf(os.Stderr, "[recording to data.pgr]\n")
		option.output = "data.pgr"
	}

	if option.disks == "" {
		option.targetDisks = nil
	} else {
		option.targetDisks = new(map[string]bool)
		*option.targetDisks = make(map[string]bool)
		for _, dev := range strings.Split(option.disks, ",") {
			(*option.targetDisks)[dev] = true
		}
	}

	if option.debug {
		os.Stderr.WriteString(
			fmt.Sprintf(
				`== option
  - output   : %s
  - interval : %s
  - debug    : %t
  - remainings: %s
`,
				option.output,
				option.interval.String(),
				option.debug,
				fmt.Sprint(flag.Args())))
	}
}
开发者ID:pazjacket,项目名称:hayamiz-_-perfmonger,代码行数:60,代码来源:perfmonger-recorder.go

示例6: runSave

func runSave(cmd *cobra.Command, args []string) (reterr error) {
	if len(args) == 0 {
		return errors.New("image reference missing")
	}

	output, err := cmd.Flags().GetString("output")
	if err != nil {
		return err
	}

	if output == "-" && terminal.IsTerminal(int(os.Stdout.Fd())) {
		return errors.New("refusing to output to terminal, specify output file")
	}

	client, err := engineapi.NewEnvClient()
	if err != nil {
		return err
	}

	ctx, cancel := context.WithCancel(context.Background())
	callOnSignal(ctx, cancel, syscall.SIGINT)
	defer cancel()

	graphdir, err := cmd.Flags().GetString("graph")
	if err != nil {
		return err
	}

	c, err := buildcache.New(client).Get(ctx, graphdir, args[0])
	if err != nil {
		return err
	}

	if output == "-" {
		_, err := io.Copy(os.Stdout, c)
		return err
	}

	f, err := ioutil.TempFile(filepath.Dir(output), ".buildcache-")
	if err != nil {
		return err
	}
	defer func() {
		if reterr != nil {
			os.RemoveAll(f.Name())
		}
	}()
	if n, err := io.Copy(f, c); err != nil {
		return err
	} else {
		logrus.Debugf("saving: %v", humanize.Bytes(uint64(n)))
	}
	if err := f.Sync(); err != nil {
		return err
	}
	if err := f.Close(); err != nil {
		return err
	}
	return os.Rename(f.Name(), output)
}
开发者ID:concourse,项目名称:docker-image-resource,代码行数:60,代码来源:save.go

示例7: Basic

func (ps passwordStore) Basic(u *url.URL) (string, string) {
	// if it's not a terminal, don't wait on input
	if ps.anonymous || !terminal.IsTerminal(int(os.Stdin.Fd())) {
		return "", ""
	}

	stdin := bufio.NewReader(os.Stdin)
	fmt.Fprintf(os.Stdout, "Enter username: ")

	userIn, err := stdin.ReadBytes('\n')
	if err != nil {
		logrus.Errorf("error processing username input: %s", err)
		return "", ""
	}

	username := strings.TrimSpace(string(userIn))

	fmt.Fprintf(os.Stdout, "Enter password: ")
	passphrase, err := passphrase.GetPassphrase(stdin)
	fmt.Fprintln(os.Stdout)
	if err != nil {
		logrus.Errorf("error processing password input: %s", err)
		return "", ""
	}
	password := strings.TrimSpace(string(passphrase))

	return username, password
}
开发者ID:endophage,项目名称:notary,代码行数:28,代码来源:tuf.go

示例8: rawConnectionFromSerial

func rawConnectionFromSerial() (net.Conn, error) {
	log.Info("opening ttyS0 for backchannel")
	f, err := os.OpenFile(pathPrefix+"/ttyS0", os.O_RDWR|os.O_SYNC|syscall.O_NOCTTY, backchannelMode)
	if err != nil {
		detail := fmt.Errorf("failed to open serial port for backchannel: %s", err)
		log.Error(detail)
		return nil, detail
	}

	// set the provided FDs to raw if it's a termial
	// 0 is the uninitialized value for Fd
	if f.Fd() != 0 && terminal.IsTerminal(int(f.Fd())) {
		log.Debug("setting terminal to raw mode")
		s, err := terminal.MakeRaw(int(f.Fd()))
		if err != nil {
			return nil, err
		}

		log.Infof("s = %#v", s)
	}

	var conn net.Conn

	log.Infof("creating raw connection from ttyS0 (fd=%d)", f.Fd())

	conn, err = serial.NewFileConn(f)
	return conn, err
}
开发者ID:vmware,项目名称:vic,代码行数:28,代码来源:attach_linux.go

示例9: NewScanner

// NewScanner returns a ready-to-use Scanner with configurable settings.
//
// NewScanner also detects if ANSI-mode is available to let the user edit the input line. If it is not available, it falls back to a dumb-mode
// where scanning is using directly a bufio.Scanner using bufio.ScanLines.
//
// Any parameter can be nil in which case the defaults are used (c.f. DefaultScanner).
//
// In order to have a good line editing experience, input should be an *os.File with the same file descriptor as output
func NewScanner(input io.Reader, output io.Writer, onInterrupt func(s *Scanner) (more bool), km Keymap) *Scanner {
	if input == nil {
		input = os.Stdin
	}
	if onInterrupt == nil {
		onInterrupt = defaultOnInterrupt
	}
	if km == nil {
		km = DefaultKeymap()
	}

	s := &Scanner{&Core{input: input, output: devNull, dumb: true}, onInterrupt, km}

	f, ok := input.(*os.File)
	if !ok {
		return s
	}

	if output != nil {
		_, ok := output.(*os.File)
		if !ok {
			return s
		}
	}
	s.output = input.(io.Writer) // does not panic, since *os.File implements io.Writer

	fd := f.Fd()
	s.fd = &fd
	t := os.Getenv("TERM")
	s.dumb = !terminal.IsTerminal(int(fd)) || len(t) == 0 || t == "dumb" || t == "cons25"
	return s
}
开发者ID:jbelke,项目名称:uniline,代码行数:40,代码来源:uniline.go

示例10: doAddPassword

func doAddPassword(args []string) error {
	var plaintext []byte
	var err error

	if len(args) == 1 && terminal.IsTerminal(0) {
		fmt.Printf("Contents for password `%s': ", args[0])
		plaintext, err = terminal.ReadPassword(0)
		if err != nil {
			return err
		}
		fmt.Println()
	} else {
		var f io.Reader
		if len(args) > 1 {
			file, err := os.Open(args[1])
			if err != nil {
				return err
			}
			defer file.Close()
			f = file
		} else {
			f = os.Stdin
		}
		if plaintext, err = ioutil.ReadAll(f); err != nil {
			return err
		}
	}

	if err = config.WritePassword(args[0], string(plaintext)); err != nil {
		return err
	}

	fmt.Printf("Saved password `%s'\n", args[0])
	return nil
}
开发者ID:nelhage,项目名称:pw,代码行数:35,代码来源:commands.go

示例11: edit

func (c *fileCmd) edit(config *lxd.Config, args []string) error {
	if len(args) != 1 {
		return errArgs
	}

	// If stdin isn't a terminal, read text from it
	if !terminal.IsTerminal(int(syscall.Stdin)) {
		return c.push(config, append([]string{os.Stdin.Name()}, args[0]))
	}

	// Create temp file
	f, err := ioutil.TempFile("", "lxd_file_edit_")
	fname := f.Name()
	f.Close()
	os.Remove(fname)
	defer os.Remove(fname)

	// Extract current value
	err = c.pull(config, append([]string{args[0]}, fname))
	if err != nil {
		return err
	}

	_, err = shared.TextEditor(fname, []byte{})
	if err != nil {
		return err
	}

	err = c.push(config, append([]string{fname}, args[0]))
	if err != nil {
		return err
	}

	return nil
}
开发者ID:nehaljwani,项目名称:lxd,代码行数:35,代码来源:file.go

示例12: init

func init() {
	if terminal.IsTerminal(int(os.Stdout.Fd())) {
		ColorReset = "\033[0m"
		ColorGrey = "\033[2m"
		ColorRed = "\033[31m"
		ColorGreen = "\033[32m"
		ColorYellow = "\033[33m"
	}

	Debug = &toggledLogger{
		Logger: log.New(os.Stdout, "", 0),
	}
	Info = &toggledLogger{
		Enabled: true,
		Logger:  log.New(os.Stdout, "", 0),
	}
	Warn = &toggledLogger{
		Enabled: true,
		Logger:  log.New(os.Stderr, "", 0),
	}
	Fatal = &toggledLogger{
		Enabled: true,
		Logger:  log.New(os.Stderr, "", 0),
		prefix:  ColorRed,
		postfix: ColorReset,
	}
}
开发者ID:rfjakob,项目名称:gocryptfs,代码行数:27,代码来源:log.go

示例13: printMasterKey

// printMasterKey - remind the user that he should store the master key in
// a safe place
func printMasterKey(key []byte) {
	if !terminal.IsTerminal(int(os.Stdout.Fd())) {
		// We don't want the master key to end up in a log file
		tlog.Info.Printf("Not running on a terminal, suppressing master key display\n")
		return
	}
	h := hex.EncodeToString(key)
	var hChunked string
	// Try to make it less scary by splitting it up in chunks
	for i := 0; i < len(h); i += 8 {
		hChunked += h[i : i+8]
		if i < 52 {
			hChunked += "-"
		}
		if i == 24 {
			hChunked += "\n    "
		}
	}
	tlog.Info.Printf(`
Your master key is:

    %s

If the gocryptfs.conf file becomes corrupted or you ever forget your password,
there is only one hope for recovery: The master key. Print it to a piece of
paper and store it in a drawer.

`, tlog.ColorGrey+hChunked+tlog.ColorReset)
}
开发者ID:rfjakob,项目名称:gocryptfs,代码行数:31,代码来源:masterkey.go

示例14: doSet

func doSet(config *lxd.Config, args []string) error {
	if len(args) != 4 {
		return errArgs
	}

	// [[lxc config]] set dakara:c1 limits.memory 200000
	remote, container := config.ParseRemoteAndContainer(args[1])
	d, err := lxd.NewClient(config, remote)
	if err != nil {
		return err
	}

	key := args[2]
	value := args[3]

	if !terminal.IsTerminal(int(syscall.Stdin)) && value == "-" {
		buf, err := ioutil.ReadAll(os.Stdin)
		if err != nil {
			return fmt.Errorf("Can't read from stdin: %s", err)
		}
		value = string(buf[:])
	}

	return d.SetContainerConfig(container, key, value)
}
开发者ID:HPCNow,项目名称:lxd,代码行数:25,代码来源:config.go

示例15: Color

func Color(text string, color int) string {
	if terminal.IsTerminal(int(os.Stdout.Fd())) {
		return fmt.Sprintf("\x1b[1;%dm%s\x1b[0m", 30+color, text)
	} else {
		return text
	}
}
开发者ID:snogaraleal,项目名称:gu,代码行数:7,代码来源:term.go


注:本文中的golang.org/x/crypto/ssh/terminal.IsTerminal函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。