mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-04 10:57:50 +08:00
Add Mac OS X support
This commit is contained in:
parent
d596a4f941
commit
e0212a7353
|
@ -104,7 +104,8 @@ func determineFeature(fname string, mh bool) (fileFeature, error) {
|
|||
return 0, err
|
||||
}
|
||||
|
||||
m := stat.Mode
|
||||
// The type of syscall.Stat_t.Mode is uint32 on Linux and uint16 on Mac
|
||||
m := (uint32)(stat.Mode)
|
||||
|
||||
// Symlink and OrphanedSymlink has highest precedence
|
||||
if is(m, syscall.S_IFLNK) {
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package tty
|
||||
|
||||
/*
|
||||
#include <termios.h>
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
@ -17,11 +21,15 @@ func NewTermiosFromFd(fd int) (*Termios, error) {
|
|||
}
|
||||
|
||||
func (term *Termios) FromFd(fd int) error {
|
||||
return Ioctl(fd, syscall.TCGETS, uintptr(unsafe.Pointer(term)))
|
||||
_, err := C.tcgetattr((C.int)(fd),
|
||||
(*C.struct_termios)(unsafe.Pointer(term)))
|
||||
return err
|
||||
}
|
||||
|
||||
func (term *Termios) ApplyToFd(fd int) error {
|
||||
return Ioctl(fd, syscall.TCSETS, uintptr(unsafe.Pointer(term)))
|
||||
_, err := C.tcsetattr((C.int)(fd), 0,
|
||||
(*C.struct_termios)(unsafe.Pointer(term)))
|
||||
return err
|
||||
}
|
||||
|
||||
func (term *Termios) Copy() *Termios {
|
||||
|
@ -46,9 +54,9 @@ func setFlag(flag *uint32, mask uint32, v bool) {
|
|||
}
|
||||
|
||||
func (term *Termios) SetIcanon(v bool) {
|
||||
setFlag(&term.Lflag, syscall.ICANON, v)
|
||||
setFlag((*uint32)(unsafe.Pointer(&term.Lflag)), syscall.ICANON, v)
|
||||
}
|
||||
|
||||
func (term *Termios) SetEcho(v bool) {
|
||||
setFlag(&term.Lflag, syscall.ECHO, v)
|
||||
setFlag((*uint32)(unsafe.Pointer(&term.Lflag)), syscall.ECHO, v)
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
// Package tty wraps tty ioctls.
|
||||
package tty
|
||||
|
||||
/*
|
||||
#include <termios.h>
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"os"
|
||||
"syscall"
|
||||
|
@ -16,5 +20,6 @@ func Ioctl(fd int, req int, arg uintptr) error {
|
|||
}
|
||||
|
||||
func FlushInput(fd int) error {
|
||||
return Ioctl(fd, TCFLSH, TCIFLUSH)
|
||||
_, err := C.tcflush((C.int)(fd), TCIFLUSH)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -8,13 +8,13 @@ package tty
|
|||
*/
|
||||
import "C"
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
TCFLSH = C.TCFLSH
|
||||
TCIFLUSH = C.TCIFLUSH
|
||||
TIOCGWINSZ = C.TIOCGWINSZ
|
||||
TCIFLUSH = syscall.TCIFLUSH
|
||||
TIOCGWINSZ = syscall.TIOCGWINSZ
|
||||
)
|
||||
|
||||
type Winsize C.struct_winsize
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
// Created by cgo -godefs - DO NOT EDIT
|
||||
// cgo -godefs edit/tty/types.go
|
||||
// cgo -godefs types.go
|
||||
|
||||
package tty
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
TCFLSH = 0x540b
|
||||
TCIFLUSH = 0x0
|
||||
TIOCGWINSZ = 0x5413
|
||||
TCIFLUSH = syscall.TCIFLUSH
|
||||
TIOCGWINSZ = syscall.TIOCGWINSZ
|
||||
)
|
||||
|
||||
type Winsize struct {
|
||||
|
|
|
@ -61,7 +61,3 @@ func (fs *FdSet) Set(fds ...int) {
|
|||
func (fs *FdSet) Zero() {
|
||||
C.fdzero(fs.c())
|
||||
}
|
||||
|
||||
func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *syscall.Timeval) (n int, err error) {
|
||||
return syscall.Select(nfd, r.s(), w.s(), e.s(), timeout)
|
||||
}
|
||||
|
|
9
sys/select_darwin.go
Normal file
9
sys/select_darwin.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
// +build darwin
|
||||
|
||||
package sys
|
||||
|
||||
import "syscall"
|
||||
|
||||
func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *syscall.Timeval) (err error) {
|
||||
return syscall.Select(nfd, r.s(), w.s(), e.s(), timeout)
|
||||
}
|
10
sys/select_linux.go
Normal file
10
sys/select_linux.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
// +build linux
|
||||
|
||||
package sys
|
||||
|
||||
import "syscall"
|
||||
|
||||
func Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *syscall.Timeval) error {
|
||||
_, err := syscall.Select(nfd, r.s(), w.s(), e.s(), timeout)
|
||||
return err
|
||||
}
|
|
@ -43,10 +43,10 @@ func TestSelect(t *testing.T) {
|
|||
syscall.Close(p1[1])
|
||||
syscall.Close(p2[1])
|
||||
}()
|
||||
n, e := Select(maxfd+1, fs, nil, nil, nil)
|
||||
if n < 1 || e != nil {
|
||||
t.Errorf("Select(%v, %v, nil, nil, nil) => (%v, %v), want (>=1, <nil>)",
|
||||
maxfd+1, fs, n, e)
|
||||
e := Select(maxfd+1, fs, nil, nil, nil)
|
||||
if e != nil {
|
||||
t.Errorf("Select(%v, %v, nil, nil, nil) => %v, want <nil>",
|
||||
maxfd+1, fs, e)
|
||||
}
|
||||
syscall.Close(p1[0])
|
||||
syscall.Close(p2[0])
|
||||
|
|
|
@ -62,7 +62,7 @@ func (ar *AsyncReader) run() {
|
|||
|
||||
for {
|
||||
fs.Set(fd, cfd)
|
||||
_, err := sys.Select(maxfd+1, fs, nil, nil, nil)
|
||||
err := sys.Select(maxfd+1, fs, nil, nil, nil)
|
||||
if err != nil {
|
||||
switch err {
|
||||
case syscall.EINTR:
|
||||
|
|
Loading…
Reference in New Issue
Block a user