本文整理汇总了Golang中github.com/kr/pty.Getsize函数的典型用法代码示例。如果您正苦于以下问题:Golang Getsize函数的具体用法?Golang Getsize怎么用?Golang Getsize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Getsize函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
var width int
var flag uint
args := os.Args[1:]
for len(args) > 0 && len(args[0]) > 0 && args[0][0] == '-' {
if len(args[0]) > 1 {
width, _ = strconv.Atoi(args[0][1:])
} else {
flag |= colwriter.BreakOnColon
}
args = args[1:]
}
if width < 1 {
_, width, _ = pty.Getsize(os.Stdout)
}
if width < 1 {
width = 80
}
w := colwriter.NewWriter(os.Stdout, width, flag)
if len(args) > 0 {
for _, s := range args {
if f, err := os.Open(s); err == nil {
copyin(w, f)
f.Close()
} else {
log.Println(err)
}
}
} else {
copyin(w, os.Stdin)
}
}
开发者ID:hellrider42,项目名称:ShortLinkRestApi,代码行数:33,代码来源:mc.go
示例2: main
func main() {
heightInt, widthInt, _ := pty.Getsize(os.Stdout)
var width uint
var height uint
// The three subtracted lines is to have room for command, file name and prompt after explosion
flag.UintVar(&width, "w", uint(widthInt), "Maximum width of output in number of columns")
flag.UintVar(&height, "h", uint((heightInt-3)*2), "Maximum height of output in number of half lines")
flag.Usage = func() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] [file | - ...]\n\n", os.Args[0])
fmt.Fprintln(os.Stderr, " Specify \"-\" or just noting to read from stdin.")
fmt.Fprintln(os.Stderr)
fmt.Fprintln(os.Stderr, "Options:")
flag.PrintDefaults()
}
flag.Parse()
filenames := flag.Args()
if len(filenames) == 0 {
fmt.Println("stdin:")
sourceImage, _, err := image.Decode(os.Stdin)
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
} else {
printImage(sourceImage, width, height)
}
} else {
for i, filename := range filenames {
if i > 0 {
fmt.Println()
}
var file *os.File
var err error
if filename == "-" {
fmt.Println("stdin:")
file = os.Stdin
} else {
fmt.Printf("%s:\n", filename)
file, err = os.Open(filename)
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
continue
}
}
sourceImage, _, err := image.Decode(file)
_ = file.Close()
if err != nil {
fmt.Fprintln(os.Stderr, "Error:", err)
continue
}
printImage(sourceImage, width, height)
}
}
}
开发者ID:Tenzer,项目名称:explosion,代码行数:59,代码来源:explosion.go
示例3: printSize
func printSize() {
rows, cols, err := pty.Getsize(os.Stdin)
if err != nil {
log.Fatalln("failed to get window size:", err)
}
fmt.Printf("rows: %d, cols: %d\n", rows, cols)
}
开发者ID:julz,项目名称:garden-runc,代码行数:8,代码来源:main.go
示例4: Hijack
func Hijack(c *cli.Context) {
target := returnTarget(c.GlobalString("target"))
insecure := c.GlobalBool("insecure")
stepType := c.String("step-type")
stepName := c.String("step-name")
check := c.String("check")
pipelineName := c.String("pipeline")
jobName := c.String("job")
buildName := c.String("build")
path, args := remoteCommand(c.Args())
privileged := true
fingerprint := containerFingerprint{
pipelineName: pipelineName,
jobName: jobName,
buildName: buildName,
stepName: stepName,
stepType: stepType,
checkName: check,
}
reqGenerator := rata.NewRequestGenerator(target, atc.Routes)
tlsConfig := &tls.Config{InsecureSkipVerify: insecure}
transport := &http.Transport{
TLSClientConfig: tlsConfig,
}
client := &http.Client{Transport: transport}
reqValues := locateContainer(client, reqGenerator, fingerprint)
var ttySpec *atc.HijackTTYSpec
rows, cols, err := pty.Getsize(os.Stdin)
if err == nil {
ttySpec = &atc.HijackTTYSpec{
WindowSize: atc.HijackWindowSize{
Columns: cols,
Rows: rows,
},
}
}
spec := atc.HijackProcessSpec{
Path: path,
Args: args,
Env: []string{"TERM=" + os.Getenv("TERM")},
User: "root",
Privileged: privileged,
TTY: ttySpec,
}
hijackReq := constructRequest(reqGenerator, spec, reqValues)
hijackResult := performHijack(hijackReq, tlsConfig)
os.Exit(hijackResult)
}
开发者ID:simonjjones,项目名称:fly,代码行数:57,代码来源:hijack.go
示例5: sendSize
func sendSize(enc *json.Encoder) {
rows, cols, err := pty.Getsize(os.Stdin)
if err == nil {
enc.Encode(atc.HijackInput{
TTYSpec: &atc.HijackTTYSpec{
WindowSize: atc.HijackWindowSize{
Columns: cols,
Rows: rows,
},
},
})
}
}
开发者ID:simonjjones,项目名称:fly,代码行数:13,代码来源:hijack.go
示例6: Getsize
func Getsize(file *os.File) (int, int, error) {
return pty.Getsize(file)
}
开发者ID:aemengo,项目名称:fly,代码行数:3,代码来源:pty_unix.go
示例7: main
//.........这里部分代码省略.........
failIf(err)
process, err := container.Attach(pid, garden.ProcessIO{
Stdin: os.Stdin,
Stdout: os.Stdout,
Stderr: os.Stderr,
})
failIf(err)
_, err = process.Wait()
failIf(err)
},
},
{
Name: "shell",
Usage: "open a shell inside the running container",
Flags: []cli.Flag{
cli.StringFlag{
Name: "user, u",
Usage: "user to open shell as",
},
},
BashComplete: handleComplete,
Action: func(c *cli.Context) {
container, err := client(c).Lookup(handle(c))
failIf(err)
term, err := term.Open(os.Stdin.Name())
failIf(err)
err = term.SetRaw()
failIf(err)
rows, cols, err := pty.Getsize(os.Stdin)
failIf(err)
process, err := container.Run(garden.ProcessSpec{
User: c.String("user"),
Path: "/bin/sh",
Args: []string{"-l"},
Env: []string{"TERM=" + os.Getenv("TERM")},
TTY: &garden.TTYSpec{
WindowSize: &garden.WindowSize{
Rows: rows,
Columns: cols,
},
},
}, garden.ProcessIO{
Stdin: term,
Stdout: term,
Stderr: term,
})
if err != nil {
term.Restore()
failIf(err)
}
resized := make(chan os.Signal, 10)
signal.Notify(resized, syscall.SIGWINCH)
go func() {
for {
<-resized
rows, cols, err := pty.Getsize(os.Stdin)
if err == nil {
开发者ID:vito,项目名称:gaol,代码行数:67,代码来源:gaol.go
注:本文中的github.com/kr/pty.Getsize函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论