本文整理汇总了Golang中golang.org/x/crypto/ssh/terminal.GetSize函数的典型用法代码示例。如果您正苦于以下问题:Golang GetSize函数的具体用法?Golang GetSize怎么用?Golang GetSize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GetSize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
}
示例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
}
示例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)
}
}
示例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
}
示例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
}
示例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
}
示例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
}
示例8: updateTerminalSize
func updateTerminalSize(term *terminal.Terminal) {
width, height, err := terminal.GetSize(0)
if err != nil {
return
}
term.SetSize(width, height)
}
示例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
}
示例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
}
示例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
}
示例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
}
}
示例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
}
示例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))
}
}
示例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"
}