• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang terminal.GetSize函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: newReadProgress

func (cmd CmdCheck) newReadProgress(todo restic.Stat) *restic.Progress {
	if !cmd.global.ShowProgress() {
		return nil
	}

	readProgress := restic.NewProgress(time.Second)

	readProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
		status := fmt.Sprintf("[%s] %s  %d / %d items",
			formatDuration(d),
			formatPercent(s.Blobs, todo.Blobs),
			s.Blobs, todo.Blobs)

		w, _, err := terminal.GetSize(int(os.Stdout.Fd()))
		if err == nil {
			if len(status) > w {
				max := w - len(status) - 4
				status = status[:max] + "... "
			}
		}

		fmt.Printf("\x1b[2K%s\r", status)
	}

	readProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
		fmt.Printf("\nduration: %s\n", formatDuration(d))
	}

	return readProgress
}
开发者ID:marete,项目名称:restic,代码行数:30,代码来源:cmd_check.go


示例2: runAttached

func runAttached(c *cli.Context, app, ps, args, release string) (int, error) {
	fd := os.Stdin.Fd()

	var w, h int

	if terminal.IsTerminal(int(fd)) {
		stdinState, err := terminal.GetState(int(fd))
		if err != nil {
			return -1, err
		}

		defer terminal.Restore(int(fd), stdinState)

		w, h, err = terminal.GetSize(int(fd))
		if err != nil {
			return -1, err
		}
	}

	code, err := rackClient(c).RunProcessAttached(app, ps, args, release, h, w, os.Stdin, os.Stdout)
	if err != nil {
		return -1, err
	}

	return code, nil
}
开发者ID:convox,项目名称:rack,代码行数:26,代码来源:run.go


示例3: SetProgress

func (p *pullProgress) SetProgress(cur, max int, msg string) {
	cols, _, err := terminal.GetSize(0)
	if err != nil {
		format := fmt.Sprintf("%%%dd", len(fmt.Sprintf("%d", max)))
		fmt.Printf(format+"/%d %s\n", cur, max, msg)
	} else {
		if p.first {
			p.first = false
		} else if p.verbose {
			fmt.Printf("\x1b[2A\x1b[K%s\n", p.lastmsg)
		} else {
			fmt.Print("\x1b[2A")
		}
		percent := fmt.Sprintf("%d%%", 100*cur/max)
		ratio := fmt.Sprintf("%d/%d", cur, max)
		progresssize := cols - len(percent) - 2
		psz1 := progresssize * cur / max
		psz2 := progresssize - psz1
		progress := strings.Repeat("#", psz1) + strings.Repeat("-", psz2)
		msglen := cols - len(ratio) - 2
		if len(msg) > msglen {
			msg = msg[:msglen]
		}
		p.lastmsg = fmt.Sprintf("%s %s", ratio, msg)
		fmt.Printf("\x1b[K%s %s\n\x1b[K%s\n", percent, progress, p.lastmsg)
	}
}
开发者ID:mildred,项目名称:doc,代码行数:27,代码来源:pull.go


示例4: newProgressMax

// newProgressMax returns a progress that counts blobs.
func newProgressMax(show bool, max uint64, description string) *restic.Progress {
	if !show {
		return nil
	}

	p := restic.NewProgress()

	p.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
		status := fmt.Sprintf("[%s] %s  %d / %d %s",
			formatDuration(d),
			formatPercent(s.Blobs, max),
			s.Blobs, max, description)

		w, _, err := terminal.GetSize(int(os.Stdout.Fd()))
		if err == nil {
			if len(status) > w {
				max := w - len(status) - 4
				status = status[:max] + "... "
			}
		}

		PrintProgress("%s", status)
	}

	p.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
		fmt.Printf("\n")
	}

	return p
}
开发者ID:ckemper67,项目名称:restic,代码行数:31,代码来源:cmd_prune.go


示例5: String

func (t *Table) String() string {
	if t.Headers == nil && len(t.rows) < 1 {
		return ""
	}
	var ttyWidth int
	terminalFd := int(os.Stdout.Fd())
	if os.Getenv("TSURU_FORCE_WRAP") != "" {
		terminalFd = int(os.Stdin.Fd())
	}
	if terminal.IsTerminal(terminalFd) {
		ttyWidth, _, _ = terminal.GetSize(terminalFd)
	}
	sizes := t.resizeLastColumn(ttyWidth)
	result := t.separator()
	if t.Headers != nil {
		for column, header := range t.Headers {
			result += "| " + header
			result += strings.Repeat(" ", sizes[column]+1-len(header))
		}
		result += "|\n"
		result += t.separator()
	}
	result = t.addRows(t.rows, sizes, result)
	if !t.LineSeparator {
		result += t.separator()
	}
	return result
}
开发者ID:tsuru,项目名称:tsuru,代码行数:28,代码来源:render.go


示例6: newReadProgress

func newReadProgress(gopts GlobalOptions, todo restic.Stat) *restic.Progress {
	if gopts.Quiet {
		return nil
	}

	readProgress := restic.NewProgress()

	readProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
		status := fmt.Sprintf("[%s] %s  %d / %d items",
			formatDuration(d),
			formatPercent(s.Blobs, todo.Blobs),
			s.Blobs, todo.Blobs)

		w, _, err := terminal.GetSize(int(os.Stdout.Fd()))
		if err == nil {
			if len(status) > w {
				max := w - len(status) - 4
				status = status[:max] + "... "
			}
		}

		PrintProgress("%s", status)
	}

	readProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
		fmt.Printf("\nduration: %s\n", formatDuration(d))
	}

	return readProgress
}
开发者ID:ckemper67,项目名称:restic,代码行数:30,代码来源:cmd_check.go


示例7: sendTermSize

func sendTermSize(control *websocket.Conn) error {
	width, height, err := terminal.GetSize(int(syscall.Stdout))
	if err != nil {
		return err
	}

	shared.Debugf("Window size is now: %dx%d", width, height)

	w, err := control.NextWriter(websocket.TextMessage)
	if err != nil {
		return err
	}

	msg := shared.ContainerExecControl{}
	msg.Command = "window-resize"
	msg.Args = make(map[string]string)
	msg.Args["width"] = strconv.Itoa(width)
	msg.Args["height"] = strconv.Itoa(height)

	buf, err := json.Marshal(msg)
	if err != nil {
		return err
	}
	_, err = w.Write(buf)

	w.Close()
	return err
}
开发者ID:rockstar,项目名称:lxd,代码行数:28,代码来源:exec.go


示例8: updateTerminalSize

func updateTerminalSize(term *terminal.Terminal) {
	width, height, err := terminal.GetSize(0)
	if err != nil {
		return
	}
	term.SetSize(width, height)
}
开发者ID:carriercomm,项目名称:pond,代码行数:7,代码来源:cli.go


示例9: GetSize

func GetSize() (int, int, error) {
	w, h, err := terminal.GetSize(int(os.Stdout.Fd()))
	if err != nil {
		return -1, -1, err
	}
	return w, h, nil
}
开发者ID:kildevaeld,项目名称:go-widgets,代码行数:7,代码来源:terminal.go


示例10: OutputWithPty

func (client NativeClient) OutputWithPty(command string) (string, error) {
	session, err := client.session(command)
	if err != nil {
		return "", nil
	}

	fd := int(os.Stdin.Fd())

	termWidth, termHeight, err := terminal.GetSize(fd)
	if err != nil {
		return "", err
	}

	modes := ssh.TerminalModes{
		ssh.ECHO:          0,
		ssh.TTY_OP_ISPEED: 14400,
		ssh.TTY_OP_OSPEED: 14400,
	}

	// request tty -- fixes error with hosts that use
	// "Defaults requiretty" in /etc/sudoers - I'm looking at you RedHat
	if err := session.RequestPty("xterm", termHeight, termWidth, modes); err != nil {
		return "", err
	}

	output, err := session.CombinedOutput(command)
	defer session.Close()

	return string(output), err
}
开发者ID:jkingyens,项目名称:machine,代码行数:30,代码来源:client.go


示例11: connect

func connect(ip string, creds server.Credentials) error {
	config := &ssh.ClientConfig{
		User: creds.Username,
		Auth: []ssh.AuthMethod{
			ssh.Password(creds.Password),
		},
	}
	conn, err := ssh.Dial("tcp", fmt.Sprintf("%s:22", ip), config)
	if err != nil {
		return err
	}
	defer conn.Close()
	// Create a session
	session, err := conn.NewSession()
	defer session.Close()
	if err != nil {
		return err
	}

	fd := int(os.Stdin.Fd())
	oldState, err := terminal.MakeRaw(fd)
	if err != nil {
		return err
	}

	termWidth, termHeight, err := terminal.GetSize(fd)
	defer terminal.Restore(fd, oldState)
	if err != nil {
		return err
	}

	session.Stdout = os.Stdout
	session.Stderr = os.Stderr
	session.Stdin = os.Stdin

	modes := ssh.TerminalModes{
		ssh.ECHO:          1,     // disable echoing
		ssh.TTY_OP_ISPEED: 14400, // input speed = 14.4kbaud
		ssh.TTY_OP_OSPEED: 14400, // output speed = 14.4kbaud
	}
	// Request pseudo terminal
	if err := session.RequestPty("xterm-256color", termHeight, termWidth, modes); err != nil {
		return err
	}
	// Start remote shell
	if err := session.Shell(); err != nil {
		return err
	}

	if err := session.Wait(); err != nil {
		if reflect.TypeOf(err) == reflect.TypeOf(&ssh.ExitError{}) {
			return nil
		} else {
			return err
		}
	}

	return nil
}
开发者ID:mikebeyer,项目名称:clc-cli,代码行数:59,代码来源:ssh.go


示例12: client

func client(user, passwd, ip string) {
	config := &ssh.ClientConfig{
		User: user,
		Auth: []ssh.AuthMethod{
			ssh.Password(passwd),
		},
	}
	client, err := ssh.Dial("tcp", ip, config)
	if err != nil {
		fmt.Println("建立连接: ", err)
		return
	}
	defer client.Close()
	session, err := client.NewSession()
	if err != nil {
		fmt.Println("创建Session出错: ", err)
		return
	}
	defer session.Close()

	fd := int(os.Stdin.Fd())
	oldState, err := terminal.MakeRaw(fd)
	if err != nil {
		fmt.Println("创建文件描述符: ", err)
		return
	}

	session.Stdout = os.Stdout
	session.Stderr = os.Stderr
	session.Stdin = os.Stdin

	termWidth, termHeight, err := terminal.GetSize(fd)
	if err != nil {
		fmt.Println("获取窗口宽高: ", err)
		return
	}
	defer terminal.Restore(fd, oldState)

	modes := ssh.TerminalModes{
		ssh.ECHO:          1,
		ssh.TTY_OP_ISPEED: 14400,
		ssh.TTY_OP_OSPEED: 14400,
	}

	if err := session.RequestPty("xterm-256color", termHeight, termWidth, modes); err != nil {
		fmt.Println("创建终端出错: ", err)
		return
	}
	err = session.Shell()
	if err != nil {
		fmt.Println("执行Shell出错: ", err)
		return
	}
	err = session.Wait()
	if err != nil {
		fmt.Println("执行Wait出错: ", err)
		return
	}
}
开发者ID:czxichen,项目名称:Goprograme,代码行数:59,代码来源:client.go


示例13: newArchiveProgress

func newArchiveProgress(gopts GlobalOptions, todo restic.Stat) *restic.Progress {
	if gopts.Quiet {
		return nil
	}

	archiveProgress := restic.NewProgress()

	var bps, eta uint64
	itemsTodo := todo.Files + todo.Dirs

	archiveProgress.OnUpdate = func(s restic.Stat, d time.Duration, ticker bool) {
		if IsProcessBackground() {
			return
		}

		sec := uint64(d / time.Second)
		if todo.Bytes > 0 && sec > 0 && ticker {
			bps = s.Bytes / sec
			if s.Bytes >= todo.Bytes {
				eta = 0
			} else if bps > 0 {
				eta = (todo.Bytes - s.Bytes) / bps
			}
		}

		itemsDone := s.Files + s.Dirs

		status1 := fmt.Sprintf("[%s] %s  %s/s  %s / %s  %d / %d items  %d errors  ",
			formatDuration(d),
			formatPercent(s.Bytes, todo.Bytes),
			formatBytes(bps),
			formatBytes(s.Bytes), formatBytes(todo.Bytes),
			itemsDone, itemsTodo,
			s.Errors)
		status2 := fmt.Sprintf("ETA %s ", formatSeconds(eta))

		w, _, err := terminal.GetSize(int(os.Stdout.Fd()))
		if err == nil {
			maxlen := w - len(status2) - 1

			if maxlen < 4 {
				status1 = ""
			} else if len(status1) > maxlen {
				status1 = status1[:maxlen-4]
				status1 += "... "
			}
		}

		PrintProgress("%s%s", status1, status2)
	}

	archiveProgress.OnDone = func(s restic.Stat, d time.Duration, ticker bool) {
		fmt.Printf("\nduration: %s, %s\n", formatDuration(d), formatRate(todo.Bytes, d))
	}

	return archiveProgress
}
开发者ID:digitalcrab,项目名称:restic,代码行数:57,代码来源:cmd_backup.go


示例14: updateTerminalSize

func (r *LightRenderer) updateTerminalSize() {
	width, height, err := terminal.GetSize(r.fd())
	if err == nil {
		r.width = width
		r.height = r.maxHeightFunc(height)
	} else {
		r.width = getEnv("COLUMNS", defaultWidth)
		r.height = r.maxHeightFunc(getEnv("LINES", defaultHeight))
	}
}
开发者ID:junegunn,项目名称:fzf,代码行数:10,代码来源:light.go


示例15: ClearLine

// ClearLine creates a platform dependent string to clear the current
// line, so it can be overwritten. ANSI sequences are not supported on
// current windows cmd shell.
func ClearLine() string {
	if runtime.GOOS == "windows" {
		w, _, err := terminal.GetSize(int(os.Stdout.Fd()))
		if err == nil {
			return strings.Repeat(" ", w-1) + "\r"
		}
		return ""
	}
	return "\x1b[2K"
}
开发者ID:restic,项目名称:restic,代码行数:13,代码来源:global.go


示例16: displayJSONMessagesStream

func displayJSONMessagesStream(in io.Reader, out io.Writer) (string, error) {
	var (
		dec        = json.NewDecoder(in)
		ids        = map[string]int{}
		diff       = 0
		fd         = getFd(out)
		isTerminal = terminal.IsTerminal(fd)
		message    = ""
	)

	//oldState, err := terminal.MakeRaw(fd)
	//if err == nil {
	//	defer terminal.Restore(fd, oldState)
	//}
	terminalWidth, terminalHeight, _ = terminal.GetSize(fd)

	for {
		var jm JSONMessage
		if err := dec.Decode(&jm); err != nil {
			if err == io.EOF {
				break
			}
			return "", err
		}

		if jm.ID != "" && (jm.Progress != nil || jm.ProgressMessage != "") {
			line, ok := ids[jm.ID]
			if !ok {
				line = len(ids)
				ids[jm.ID] = line
				if isTerminal {
					fmt.Fprintf(out, "\n")
				}
				diff = 0
			} else {
				diff = len(ids) - line
			}
			if jm.ID != "" && isTerminal {
				// <ESC>[{diff}A = move cursor up diff rows
				fmt.Fprintf(out, "%c[%dA", 27, diff)
			}
		}
		var err error
		message, err = jm.Display(out, isTerminal)
		if jm.ID != "" && isTerminal {
			// <ESC>[{diff}B = move cursor down diff rows
			fmt.Fprintf(out, "%c[%dB", 27, diff)
		}
		if err != nil {
			return "", err
		}
	}
	return message, nil
}
开发者ID:ChengTiesheng,项目名称:talk2docker,代码行数:54,代码来源:stream.go


示例17: height

func (c *Common) height() int {
	if c.Height > 0 {
		return c.Height
	}
	if c.Height < 0 {
		// use screen height - y
		if _, h, err := terminal.GetSize(int(os.Stdin.Fd())); err == nil {
			return h + c.Height
		}
	}
	return DEFAULT_HEIGHT
}
开发者ID:ScriptRock,项目名称:dialog,代码行数:12,代码来源:dialog.go


示例18: NewTextBuffer

func NewTextBuffer() *TextBuffer {
	w, h, err := terminal.GetSize(int(os.Stdout.Fd()))
	if err != nil {
		panic(err)
	}
	stdErr.Printf("Dimensions: (%d, %d)", w, h)
	return &TextBuffer{
		cursor: &Cursor{},
		width:  w,
		height: h,
	}
}
开发者ID:MogeiWang,项目名称:editor,代码行数:12,代码来源:main.go


示例19: width

func (c *Common) width() int {
	if c.Width > 0 {
		return c.Width
	}
	if c.Width < 0 {
		// use screen width - x
		if w, _, err := terminal.GetSize(int(os.Stdin.Fd())); err == nil {
			return w + c.Width
		}
	}
	return DEFAULT_WIDTH
}
开发者ID:ScriptRock,项目名称:dialog,代码行数:12,代码来源:dialog.go


示例20: PrintStory

func PrintStory(story stories.Story) {
	cols, _, err := terminal.GetSize(0)
	if err != nil {
		cols = 128
	}
	cols -= 3

	fmt.Print("NAME: ")
	fmt.Print(story.Name)
	fmt.Println()

	fmt.Print("STATE: ")
	fmt.Print(story.State)
	fmt.Println()

	fmt.Print("OWNER: ")
	fmt.Print(story.Owner.Initials)
	fmt.Println()

	fmt.Println("DESCRIPTION:")
	fmt.Println(story.Description)
	fmt.Println()

	fmt.Print("TYPE: ")
	fmt.Print(story.StoryType)
	fmt.Println()

	fmt.Print("ESTIMATE: ")
	fmt.Print(story.Points)
	fmt.Println()

	fmt.Println("COMMENTS:")
	for _, comment := range story.Comments {
		createdTime, timeErr := time.Parse(time.RFC3339, comment.CreatedAt)
		if timeErr == nil {
			fmt.Println(createdTime.Local().String())
		} else {
			fmt.Println(comment.CreatedAt)
		}
		//fmt.Printf("\t%v\n", strings.Replace(comment.Text[0:int(math.Min(cols-8, float64(len(comment.Text))))], "\n", "\n\t", -1))
		fmt.Printf("> %v\n", strings.Replace(comment.Text, "\n", "\n>> ", -1))
		fmt.Println()
	}

	fmt.Print("LABELS: ")
	labelNames := []string{}
	for _, label := range story.Labels {
		labelNames = append(labelNames, label.Name)
	}
	fmt.Println(strings.Join(labelNames, ","))
	fmt.Println()
}
开发者ID:jonbalbarin,项目名称:tracker,代码行数:52,代码来源:printing.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang terminal.GetState函数代码示例发布时间:2022-05-28
下一篇:
Golang agent.RequestAgentForwarding函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap