LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2011 The Go Authors. All rights reserved. | 1 // Copyright 2011 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package ssh | 5 package ssh |
6 | 6 |
7 // A Terminal is capable of parsing and generating virtual terminal | 7 // A Terminal is capable of parsing and generating virtual terminal |
8 // data from an SSH client. | 8 // data from an SSH client. |
9 type Terminal interface { | 9 type Terminal interface { |
10 ReadLine() (line string, err error) | 10 ReadLine() (line string, err error) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 func (ss *ServerTerminal) Write(buf []byte) (n int, err error) { | 45 func (ss *ServerTerminal) Write(buf []byte) (n int, err error) { |
46 return ss.Term.Write(buf) | 46 return ss.Term.Write(buf) |
47 } | 47 } |
48 | 48 |
49 // ReadLine returns a line of input from the terminal. | 49 // ReadLine returns a line of input from the terminal. |
50 func (ss *ServerTerminal) ReadLine() (line string, err error) { | 50 func (ss *ServerTerminal) ReadLine() (line string, err error) { |
51 for { | 51 for { |
52 if line, err = ss.Term.ReadLine(); err == nil { | 52 if line, err = ss.Term.ReadLine(); err == nil { |
53 return | 53 return |
54 } | 54 } |
55 | |
56 req, ok := err.(ChannelRequest) | 55 req, ok := err.(ChannelRequest) |
57 if !ok { | 56 if !ok { |
58 return | 57 return |
59 } | 58 } |
60 | 59 |
61 ok = false | 60 ok = false |
62 switch req.Request { | 61 switch req.Request { |
63 case "pty-req": | 62 case "pty-req": |
64 var width, height int | 63 var width, height int |
65 width, height, ok = parsePtyRequest(req.Payload) | 64 width, height, ok = parsePtyRequest(req.Payload) |
66 ss.Term.SetSize(width, height) | 65 ss.Term.SetSize(width, height) |
67 case "shell": | 66 case "shell": |
68 ok = true | 67 ok = true |
69 if len(req.Payload) > 0 { | 68 if len(req.Payload) > 0 { |
70 // We don't accept any commands, only the defaul
t shell. | 69 // We don't accept any commands, only the defaul
t shell. |
71 ok = false | 70 ok = false |
72 } | 71 } |
73 case "env": | 72 case "env": |
74 ok = true | 73 ok = true |
75 } | 74 } |
76 if req.WantReply { | 75 if req.WantReply { |
77 ss.Channel.AckRequest(ok) | 76 ss.Channel.AckRequest(ok) |
78 } | 77 } |
79 } | 78 } |
80 panic("unreachable") | 79 panic("unreachable") |
81 } | 80 } |
LEFT | RIGHT |