-
Notifications
You must be signed in to change notification settings - Fork 452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Pty.TerminalModes #131
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,19 @@ import ( | |
"golang.org/x/crypto/ssh" | ||
) | ||
|
||
type ptyRequestMsg struct { | ||
Term string | ||
Columns uint32 | ||
Rows uint32 | ||
Width uint32 | ||
Height uint32 | ||
Modelist string | ||
} | ||
|
||
const ( | ||
ttyOPEND = 0 | ||
) | ||
|
||
func generateSigner() (ssh.Signer, error) { | ||
key, err := rsa.GenerateKey(rand.Reader, 2048) | ||
if err != nil { | ||
|
@@ -17,26 +30,42 @@ func generateSigner() (ssh.Signer, error) { | |
} | ||
|
||
func parsePtyRequest(s []byte) (pty Pty, ok bool) { | ||
term, s, ok := parseString(s) | ||
if !ok { | ||
return | ||
} | ||
width32, s, ok := parseUint32(s) | ||
if !ok { | ||
return | ||
reqMsg := &ptyRequestMsg{} | ||
err := ssh.Unmarshal(s, reqMsg) | ||
if err != nil { | ||
return Pty{}, false | ||
} | ||
height32, _, ok := parseUint32(s) | ||
if !ok { | ||
return | ||
|
||
modes := []byte(reqMsg.Modelist) | ||
|
||
mode := struct { | ||
Key uint8 | ||
Val uint32 | ||
}{} | ||
|
||
termModes := make(ssh.TerminalModes, 0) | ||
for { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The description on how terminal modes are actually passed can be found here: https://tools.ietf.org/html/rfc4254#section-8 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if I understand what you mean. Do you mean to set terminal modes to |
||
if len(modes) < 1 || modes[0] == ttyOPEND || len(modes) < 5 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This actually handles 2 different conditions - I'd argue |
||
break | ||
} | ||
b := modes[:5] | ||
err = ssh.Unmarshal(b, &mode) | ||
if err != nil { | ||
return Pty{}, false | ||
} | ||
termModes[mode.Key] = mode.Val | ||
modes = modes[6:] | ||
} | ||
|
||
pty = Pty{ | ||
Term: term, | ||
Term: reqMsg.Term, | ||
Window: Window{ | ||
Width: int(width32), | ||
Height: int(height32), | ||
Width: int(reqMsg.Columns), | ||
Height: int(reqMsg.Rows), | ||
}, | ||
Termmodes: termModes, | ||
} | ||
return | ||
return pty, true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are already implicitly returned because of the named params. Please either switch back to the implicit return or remove the variable names from the function definition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👌 |
||
} | ||
|
||
func parseWinchRequest(s []byte) (win Window, ok bool) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like it needs a gofmt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry, I forgot it. I will modify this.