Merge lp:~dave-cheney/goetveld/001-add-darwin-termios-support into lp:~niemeyer/goetveld/trunk

Proposed by Dave Cheney
Status: Needs review
Proposed branch: lp:~dave-cheney/goetveld/001-add-darwin-termios-support
Merge into: lp:~niemeyer/goetveld/trunk
Diff against target: 79 lines (+63/-1)
2 files modified
terminal_darwin.go (+62/-0)
terminal_linux.go (+1/-1)
To merge this branch: bzr merge lp:~dave-cheney/goetveld/001-add-darwin-termios-support
Reviewer Review Type Date Requested Status
Gustavo Niemeyer Pending
Review via email: mp+126137@code.launchpad.net

Description of the change

Add minimal darwin support.

To post a comment you must log in.
Revision history for this message
Dave Cheney (dave-cheney) wrote :

Please take a look.

Unmerged revisions

40. By Dave Cheney

add darwin termios support

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'terminal_darwin.go'
2--- terminal_darwin.go 1970-01-01 00:00:00 +0000
3+++ terminal_darwin.go 2012-09-25 02:25:21 +0000
4@@ -0,0 +1,62 @@
5+// Copyright 2011 The Go Authors. All rights reserved.
6+// Use of this source code is governed by a BSD-style
7+// license that can be found in the LICENSE file.
8+
9+package rietveld
10+
11+import (
12+ "io"
13+ "syscall"
14+ "unsafe"
15+)
16+
17+const (
18+ syscall_TCGETS = 0x40487413
19+ syscall_TCSETS = 0x80487414
20+)
21+
22+// This was copied from package exp/terminal
23+
24+// readPassword reads a line of input from a terminal without local echo. This
25+// is commonly used for inputting passwords and other sensitive data. The slice
26+// returned does not include the \n.
27+func readPassword(fd uintptr) ([]byte, error) {
28+ var oldState syscall.Termios
29+ if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(syscall_TCGETS), uintptr(unsafe.Pointer(&oldState)), 0, 0, 0); e != 0 {
30+ return nil, syscall.Errno(e)
31+ }
32+
33+ newState := oldState
34+ newState.Lflag &^= syscall.ECHO
35+ if _, _, e := syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(syscall_TCSETS), uintptr(unsafe.Pointer(&newState)), 0, 0, 0); e != 0 {
36+ return nil, syscall.Errno(e)
37+ }
38+
39+ defer func() {
40+ syscall.Syscall6(syscall.SYS_IOCTL, fd, uintptr(syscall_TCSETS), uintptr(unsafe.Pointer(&oldState)), 0, 0, 0)
41+ }()
42+
43+ var buf [16]byte
44+ var ret []byte
45+ for {
46+ n, errno := syscall.Read(int(fd), buf[:])
47+ if errno != nil {
48+ return nil, errno
49+ }
50+ if n == 0 {
51+ if len(ret) == 0 {
52+ return nil, io.EOF
53+ }
54+ break
55+ }
56+ if buf[n-1] == '\n' {
57+ n--
58+ }
59+ ret = append(ret, buf[:n]...)
60+ if n < len(buf) {
61+ break
62+ }
63+ }
64+
65+ return ret, nil
66+}
67
68=== renamed file 'terminal.go' => 'terminal_linux.go'
69--- terminal.go 2012-02-21 18:47:37 +0000
70+++ terminal_linux.go 2012-09-25 02:25:21 +0000
71@@ -12,7 +12,7 @@
72
73 // This was copied from package exp/terminal
74
75-// ReadPassword reads a line of input from a terminal without local echo. This
76+// readPassword reads a line of input from a terminal without local echo. This
77 // is commonly used for inputting passwords and other sensitive data. The slice
78 // returned does not include the \n.
79 func readPassword(fd uintptr) ([]byte, error) {

Subscribers

People subscribed via source and target branches

to all changes: