Commit bc181fc799

bc181fc799701f6b12c48b2e2ee91097924905f2

parent: b0a92dd2a6

Unregistered key

Ratakor <ratakor@disroot.org> · 2026-07-25 12:23 UTC
committer: <noreply@github.com>

Fix nix build (#112)

* chore: go mod tidy

Signed-off-by: Ratakor <ratakor@disroot.org>

* chore: go mod vendor

Signed-off-by: Ratakor <ratakor@disroot.org>

---------

Signed-off-by: Ratakor <ratakor@disroot.org>

Layout: unified · split

go.mod +1 −1
@@ -10,6 +10,7 @@ require (
1010 github.com/go-rod/rod v0.116.2
1111 github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
1212 github.com/tr1xem/go-discordrpc v1.0.0
13 golang.org/x/term v0.29.0
1314)
1415
1516require (
@@ -36,7 +37,6 @@ require (
3637 github.com/ysmood/leakless v0.9.0 // indirect
3738 golang.org/x/sync v0.11.0 // indirect
3839 golang.org/x/sys v0.30.0 // indirect
39 golang.org/x/term v0.29.0 // indirect
4040 golang.org/x/text v0.3.8 // indirect
4141 gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
4242)
go.sum +3
@@ -49,8 +49,11 @@ github.com/ysmood/fetchup v0.2.3 h1:ulX+SonA0Vma5zUFXtv52Kzip/xe7aj4vqT5AJwQ+ZQ=
4949github.com/ysmood/fetchup v0.2.3/go.mod h1:xhibcRKziSvol0H1/pj33dnKrYyI2ebIvz5cOOkYGns=
5050github.com/ysmood/goob v0.4.0 h1:HsxXhyLBeGzWXnqVKtmT9qM7EuVs/XOgkX7T6r1o1AQ=
5151github.com/ysmood/goob v0.4.0/go.mod h1:u6yx7ZhS4Exf2MwciFr6nIM8knHQIE22lFpWHnfql18=
52github.com/ysmood/gop v0.2.0 h1:+tFrG0TWPxT6p9ZaZs+VY+opCvHU8/3Fk6BaNv6kqKg=
53github.com/ysmood/gop v0.2.0/go.mod h1:rr5z2z27oGEbyB787hpEcx4ab8cCiPnKxn0SUHt6xzk=
5254github.com/ysmood/got v0.40.0 h1:ZQk1B55zIvS7zflRrkGfPDrPG3d7+JOza1ZkNxcc74Q=
5355github.com/ysmood/got v0.40.0/go.mod h1:W7DdpuX6skL3NszLmAsC5hT7JAhuLZhByVzHTq874Qg=
56github.com/ysmood/gotrace v0.6.0 h1:SyI1d4jclswLhg7SWTL6os3L1WOKeNn/ZtzVQF8QmdY=
5457github.com/ysmood/gotrace v0.6.0/go.mod h1:TzhIG7nHDry5//eYZDYcTzuJLYQIkykJzCRIo4/dzQM=
5558github.com/ysmood/gson v0.7.3 h1:QFkWbTH8MxyUTKPkVWAENJhxqdBa4lYTQWqZCiLG6kE=
5659github.com/ysmood/gson v0.7.3/go.mod h1:3Kzs5zDl21g5F/BlLTNcuAGAYLKt2lV5G8D1zF3RNmg=
vendor/github.com/Microsoft/go-winio/.gitignore added +10
@@ -0,0 +1,10 @@
1.vscode/
2
3*.exe
4
5# testing
6testdata
7
8# go workspaces
9go.work
10go.work.sum
vendor/github.com/charmbracelet/bubbletea/.gitignore added +23
@@ -0,0 +1,23 @@
1.DS_Store
2.envrc
3
4examples/fullscreen/fullscreen
5examples/help/help
6examples/http/http
7examples/list-default/list-default
8examples/list-fancy/list-fancy
9examples/list-simple/list-simple
10examples/mouse/mouse
11examples/pager/pager
12examples/progress-download/color_vortex.blend
13examples/progress-download/progress-download
14examples/simple/simple
15examples/spinner/spinner
16examples/textinput/textinput
17examples/textinputs/textinputs
18examples/views/views
19tutorials/basics/basics
20tutorials/commands/commands
21.idea
22coverage.txt
23dist/
vendor/github.com/charmbracelet/lipgloss/.gitignore added +1
@@ -0,0 +1 @@
1ssh_example_ed25519*
vendor/github.com/erikgeiser/coninput/.gitignore added +15
@@ -0,0 +1,15 @@
1# Binaries for programs and plugins
2*.exe
3*.exe~
4*.dll
5*.so
6*.dylib
7
8# Test binary, built with `go test -c`
9*.test
10
11# Output of the go coverage tool, specifically when used with LiteIDE
12*.out
13
14# Dependency directories (remove the comment below to include it)
15# vendor/
vendor/github.com/go-rod/rod/.gitignore added +9
@@ -0,0 +1,9 @@
1vendor/
2node_modules/
3tmp/
4
5.git
6.dockerignore
7*.out
8*.test
9*.json
vendor/github.com/go-toast/toast/.gitignore added +3
@@ -0,0 +1,3 @@
1.idea/
2vendor/*
3!vendor/vendor.json
vendor/github.com/lucasb-eyer/go-colorful/.gitignore added +101
@@ -0,0 +1,101 @@
1# Created by https://www.toptal.com/developers/gitignore/api/code,go,linux,macos,windows
2# Edit at https://www.toptal.com/developers/gitignore?templates=code,go,linux,macos,windows
3
4### Code ###
5.vscode/*
6!.vscode/tasks.json
7!.vscode/launch.json
8*.code-workspace
9
10### Go ###
11# Binaries for programs and plugins
12*.exe
13*.exe~
14*.dll
15*.so
16*.dylib
17
18# Test binary, built with `go test -c`
19*.test
20
21# Output of the go coverage tool, specifically when used with LiteIDE
22*.out
23
24# Dependency directories (remove the comment below to include it)
25# vendor/
26
27### Go Patch ###
28/vendor/
29/Godeps/
30
31### Linux ###
32*~
33
34# temporary files which can be created if a process still has a handle open of a deleted file
35.fuse_hidden*
36
37# KDE directory preferences
38.directory
39
40# Linux trash folder which might appear on any partition or disk
41.Trash-*
42
43# .nfs files are created when an open file is removed but is still being accessed
44.nfs*
45
46### macOS ###
47# General
48.DS_Store
49.AppleDouble
50.LSOverride
51
52# Icon must end with two \r
53Icon
54
55
56# Thumbnails
57._*
58
59# Files that might appear in the root of a volume
60.DocumentRevisions-V100
61.fseventsd
62.Spotlight-V100
63.TemporaryItems
64.Trashes
65.VolumeIcon.icns
66.com.apple.timemachine.donotpresent
67
68# Directories potentially created on remote AFP share
69.AppleDB
70.AppleDesktop
71Network Trash Folder
72Temporary Items
73.apdisk
74
75### Windows ###
76# Windows thumbnail cache files
77Thumbs.db
78Thumbs.db:encryptable
79ehthumbs.db
80ehthumbs_vista.db
81
82# Dump file
83*.stackdump
84
85# Folder config file
86[Dd]esktop.ini
87
88# Recycle Bin used on file shares
89$RECYCLE.BIN/
90
91# Windows Installer files
92*.cab
93*.msi
94*.msix
95*.msm
96*.msp
97
98# Windows shortcuts
99*.lnk
100
101# End of https://www.toptal.com/developers/gitignore/api/code,go,linux,macos,windows
vendor/github.com/muesli/ansi/.gitignore added +15
@@ -0,0 +1,15 @@
1# Binaries for programs and plugins
2*.exe
3*.exe~
4*.dll
5*.so
6*.dylib
7
8# Test binary, built with `go test -c`
9*.test
10
11# Output of the go coverage tool, specifically when used with LiteIDE
12*.out
13
14# Dependency directories (remove the comment below to include it)
15# vendor/
vendor/github.com/muesli/cancelreader/.gitignore added +15
@@ -0,0 +1,15 @@
1# Binaries for programs and plugins
2*.exe
3*.exe~
4*.dll
5*.so
6*.dylib
7
8# Test binary, built with `go test -c`
9*.test
10
11# Output of the go coverage tool, specifically when used with LiteIDE
12*.out
13
14# Dependency directories (remove the comment below to include it)
15# vendor/
vendor/github.com/muesli/termenv/.gitignore added +15
@@ -0,0 +1,15 @@
1# Binaries for programs and plugins
2*.exe
3*.exe~
4*.dll
5*.so
6*.dylib
7
8# Test binary, built with `go test -c`
9*.test
10
11# Output of the go coverage tool, specifically when used with LiteIDE
12*.out
13
14# Dependency directories (remove the comment below to include it)
15# vendor/
vendor/github.com/nu7hatch/gouuid/.gitignore added +11
@@ -0,0 +1,11 @@
1_obj
2_test
3*.6
4*.out
5_testmain.go
6\#*
7.\#*
8*.log
9_cgo*
10*.o
11*.a
vendor/github.com/tadvi/systray/.gitignore added +12
@@ -0,0 +1,12 @@
1# Binaries for programs and plugins
2*.exe
3*.exe~
4*.dll
5*.so
6*.dylib
7
8# Test binary, build with `go test -c`
9*.test
10
11# Output of the go coverage tool, specifically when used with LiteIDE
12*.out
vendor/github.com/tr1xem/go-discordrpc/internal/ipc/ipc.go +2 −4
@@ -15,11 +15,9 @@ type SocketInterface interface {
1515
1616// GetIpcPath returns the best IPC socket path for the current environment.
1717func GetIpcPath() string {
18 uid := fmt.Sprintf("%d", os.Getuid())
1918 candidates := []string{
20 "/run/user/" + uid + "/.flatpak/dev.vencord.Vesktop/xdg-run",
21 "/run/user/" + uid + "/snap.discord",
22 "/run/user/" + uid + "/.flatpak/com.discordapp.Discord/xdg-run",
19 "/run/user/1000/snap.discord",
20 "/run/user/1000/.flatpak/com.discordapp.Discord/xdg-run",
2321 }
2422
2523 for _, path := range candidates {
vendor/github.com/ysmood/fetchup/.gitignore added +2
@@ -0,0 +1,2 @@
1tmp/
2*.out
\ No newline at end of file
vendor/github.com/ysmood/goob/.gitignore added +1
@@ -0,0 +1 @@
1*.out
\ No newline at end of file
vendor/github.com/ysmood/gson/.gitignore added +2
@@ -0,0 +1,2 @@
1.golangci.yml
2*.out
vendor/github.com/ysmood/leakless/.gitignore added +3
@@ -0,0 +1,3 @@
1dist
2tmp
3coverage.txt
\ No newline at end of file
vendor/golang.org/x/sys/plan9/asm.s added +8
@@ -0,0 +1,8 @@
1// Copyright 2014 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5#include "textflag.h"
6
7TEXT ·use(SB),NOSPLIT,$0
8 RET
vendor/golang.org/x/sys/plan9/asm_plan9_386.s added +30
@@ -0,0 +1,30 @@
1// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5#include "textflag.h"
6
7//
8// System call support for 386, Plan 9
9//
10
11// Just jump to package syscall's implementation for all these functions.
12// The runtime may know about them.
13
14TEXT ·Syscall(SB),NOSPLIT,$0-32
15 JMP syscall·Syscall(SB)
16
17TEXT ·Syscall6(SB),NOSPLIT,$0-44
18 JMP syscall·Syscall6(SB)
19
20TEXT ·RawSyscall(SB),NOSPLIT,$0-28
21 JMP syscall·RawSyscall(SB)
22
23TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
24 JMP syscall·RawSyscall6(SB)
25
26TEXT ·seek(SB),NOSPLIT,$0-36
27 JMP syscall·seek(SB)
28
29TEXT ·exit(SB),NOSPLIT,$4-4
30 JMP syscall·exit(SB)
vendor/golang.org/x/sys/plan9/asm_plan9_amd64.s added +30
@@ -0,0 +1,30 @@
1// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5#include "textflag.h"
6
7//
8// System call support for amd64, Plan 9
9//
10
11// Just jump to package syscall's implementation for all these functions.
12// The runtime may know about them.
13
14TEXT ·Syscall(SB),NOSPLIT,$0-64
15 JMP syscall·Syscall(SB)
16
17TEXT ·Syscall6(SB),NOSPLIT,$0-88
18 JMP syscall·Syscall6(SB)
19
20TEXT ·RawSyscall(SB),NOSPLIT,$0-56
21 JMP syscall·RawSyscall(SB)
22
23TEXT ·RawSyscall6(SB),NOSPLIT,$0-80
24 JMP syscall·RawSyscall6(SB)
25
26TEXT ·seek(SB),NOSPLIT,$0-56
27 JMP syscall·seek(SB)
28
29TEXT ·exit(SB),NOSPLIT,$8-8
30 JMP syscall·exit(SB)
vendor/golang.org/x/sys/plan9/asm_plan9_arm.s added +25
@@ -0,0 +1,25 @@
1// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5#include "textflag.h"
6
7// System call support for plan9 on arm
8
9// Just jump to package syscall's implementation for all these functions.
10// The runtime may know about them.
11
12TEXT ·Syscall(SB),NOSPLIT,$0-32
13 JMP syscall·Syscall(SB)
14
15TEXT ·Syscall6(SB),NOSPLIT,$0-44
16 JMP syscall·Syscall6(SB)
17
18TEXT ·RawSyscall(SB),NOSPLIT,$0-28
19 JMP syscall·RawSyscall(SB)
20
21TEXT ·RawSyscall6(SB),NOSPLIT,$0-40
22 JMP syscall·RawSyscall6(SB)
23
24TEXT ·seek(SB),NOSPLIT,$0-36
25 JMP syscall·exit(SB)
vendor/golang.org/x/sys/plan9/const_plan9.go added +70
@@ -0,0 +1,70 @@
1package plan9
2
3// Plan 9 Constants
4
5// Open modes
6const (
7 O_RDONLY = 0
8 O_WRONLY = 1
9 O_RDWR = 2
10 O_TRUNC = 16
11 O_CLOEXEC = 32
12 O_EXCL = 0x1000
13)
14
15// Rfork flags
16const (
17 RFNAMEG = 1 << 0
18 RFENVG = 1 << 1
19 RFFDG = 1 << 2
20 RFNOTEG = 1 << 3
21 RFPROC = 1 << 4
22 RFMEM = 1 << 5
23 RFNOWAIT = 1 << 6
24 RFCNAMEG = 1 << 10
25 RFCENVG = 1 << 11
26 RFCFDG = 1 << 12
27 RFREND = 1 << 13
28 RFNOMNT = 1 << 14
29)
30
31// Qid.Type bits
32const (
33 QTDIR = 0x80
34 QTAPPEND = 0x40
35 QTEXCL = 0x20
36 QTMOUNT = 0x10
37 QTAUTH = 0x08
38 QTTMP = 0x04
39 QTFILE = 0x00
40)
41
42// Dir.Mode bits
43const (
44 DMDIR = 0x80000000
45 DMAPPEND = 0x40000000
46 DMEXCL = 0x20000000
47 DMMOUNT = 0x10000000
48 DMAUTH = 0x08000000
49 DMTMP = 0x04000000
50 DMREAD = 0x4
51 DMWRITE = 0x2
52 DMEXEC = 0x1
53)
54
55const (
56 STATMAX = 65535
57 ERRMAX = 128
58 STATFIXLEN = 49
59)
60
61// Mount and bind flags
62const (
63 MREPL = 0x0000
64 MBEFORE = 0x0001
65 MAFTER = 0x0002
66 MORDER = 0x0003
67 MCREATE = 0x0004
68 MCACHE = 0x0010
69 MMASK = 0x0017
70)
vendor/golang.org/x/sys/plan9/dir_plan9.go added +212
@@ -0,0 +1,212 @@
1// Copyright 2012 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Plan 9 directory marshalling. See intro(5).
6
7package plan9
8
9import "errors"
10
11var (
12 ErrShortStat = errors.New("stat buffer too short")
13 ErrBadStat = errors.New("malformed stat buffer")
14 ErrBadName = errors.New("bad character in file name")
15)
16
17// A Qid represents a 9P server's unique identification for a file.
18type Qid struct {
19 Path uint64 // the file server's unique identification for the file
20 Vers uint32 // version number for given Path
21 Type uint8 // the type of the file (plan9.QTDIR for example)
22}
23
24// A Dir contains the metadata for a file.
25type Dir struct {
26 // system-modified data
27 Type uint16 // server type
28 Dev uint32 // server subtype
29
30 // file data
31 Qid Qid // unique id from server
32 Mode uint32 // permissions
33 Atime uint32 // last read time
34 Mtime uint32 // last write time
35 Length int64 // file length
36 Name string // last element of path
37 Uid string // owner name
38 Gid string // group name
39 Muid string // last modifier name
40}
41
42var nullDir = Dir{
43 Type: ^uint16(0),
44 Dev: ^uint32(0),
45 Qid: Qid{
46 Path: ^uint64(0),
47 Vers: ^uint32(0),
48 Type: ^uint8(0),
49 },
50 Mode: ^uint32(0),
51 Atime: ^uint32(0),
52 Mtime: ^uint32(0),
53 Length: ^int64(0),
54}
55
56// Null assigns special "don't touch" values to members of d to
57// avoid modifying them during plan9.Wstat.
58func (d *Dir) Null() { *d = nullDir }
59
60// Marshal encodes a 9P stat message corresponding to d into b
61//
62// If there isn't enough space in b for a stat message, ErrShortStat is returned.
63func (d *Dir) Marshal(b []byte) (n int, err error) {
64 n = STATFIXLEN + len(d.Name) + len(d.Uid) + len(d.Gid) + len(d.Muid)
65 if n > len(b) {
66 return n, ErrShortStat
67 }
68
69 for _, c := range d.Name {
70 if c == '/' {
71 return n, ErrBadName
72 }
73 }
74
75 b = pbit16(b, uint16(n)-2)
76 b = pbit16(b, d.Type)
77 b = pbit32(b, d.Dev)
78 b = pbit8(b, d.Qid.Type)
79 b = pbit32(b, d.Qid.Vers)
80 b = pbit64(b, d.Qid.Path)
81 b = pbit32(b, d.Mode)
82 b = pbit32(b, d.Atime)
83 b = pbit32(b, d.Mtime)
84 b = pbit64(b, uint64(d.Length))
85 b = pstring(b, d.Name)
86 b = pstring(b, d.Uid)
87 b = pstring(b, d.Gid)
88 b = pstring(b, d.Muid)
89
90 return n, nil
91}
92
93// UnmarshalDir decodes a single 9P stat message from b and returns the resulting Dir.
94//
95// If b is too small to hold a valid stat message, ErrShortStat is returned.
96//
97// If the stat message itself is invalid, ErrBadStat is returned.
98func UnmarshalDir(b []byte) (*Dir, error) {
99 if len(b) < STATFIXLEN {
100 return nil, ErrShortStat
101 }
102 size, buf := gbit16(b)
103 if len(b) != int(size)+2 {
104 return nil, ErrBadStat
105 }
106 b = buf
107
108 var d Dir
109 d.Type, b = gbit16(b)
110 d.Dev, b = gbit32(b)
111 d.Qid.Type, b = gbit8(b)
112 d.Qid.Vers, b = gbit32(b)
113 d.Qid.Path, b = gbit64(b)
114 d.Mode, b = gbit32(b)
115 d.Atime, b = gbit32(b)
116 d.Mtime, b = gbit32(b)
117
118 n, b := gbit64(b)
119 d.Length = int64(n)
120
121 var ok bool
122 if d.Name, b, ok = gstring(b); !ok {
123 return nil, ErrBadStat
124 }
125 if d.Uid, b, ok = gstring(b); !ok {
126 return nil, ErrBadStat
127 }
128 if d.Gid, b, ok = gstring(b); !ok {
129 return nil, ErrBadStat
130 }
131 if d.Muid, b, ok = gstring(b); !ok {
132 return nil, ErrBadStat
133 }
134
135 return &d, nil
136}
137
138// pbit8 copies the 8-bit number v to b and returns the remaining slice of b.
139func pbit8(b []byte, v uint8) []byte {
140 b[0] = byte(v)
141 return b[1:]
142}
143
144// pbit16 copies the 16-bit number v to b in little-endian order and returns the remaining slice of b.
145func pbit16(b []byte, v uint16) []byte {
146 b[0] = byte(v)
147 b[1] = byte(v >> 8)
148 return b[2:]
149}
150
151// pbit32 copies the 32-bit number v to b in little-endian order and returns the remaining slice of b.
152func pbit32(b []byte, v uint32) []byte {
153 b[0] = byte(v)
154 b[1] = byte(v >> 8)
155 b[2] = byte(v >> 16)
156 b[3] = byte(v >> 24)
157 return b[4:]
158}
159
160// pbit64 copies the 64-bit number v to b in little-endian order and returns the remaining slice of b.
161func pbit64(b []byte, v uint64) []byte {
162 b[0] = byte(v)
163 b[1] = byte(v >> 8)
164 b[2] = byte(v >> 16)
165 b[3] = byte(v >> 24)
166 b[4] = byte(v >> 32)
167 b[5] = byte(v >> 40)
168 b[6] = byte(v >> 48)
169 b[7] = byte(v >> 56)
170 return b[8:]
171}
172
173// pstring copies the string s to b, prepending it with a 16-bit length in little-endian order, and
174// returning the remaining slice of b..
175func pstring(b []byte, s string) []byte {
176 b = pbit16(b, uint16(len(s)))
177 n := copy(b, s)
178 return b[n:]
179}
180
181// gbit8 reads an 8-bit number from b and returns it with the remaining slice of b.
182func gbit8(b []byte) (uint8, []byte) {
183 return uint8(b[0]), b[1:]
184}
185
186// gbit16 reads a 16-bit number in little-endian order from b and returns it with the remaining slice of b.
187func gbit16(b []byte) (uint16, []byte) {
188 return uint16(b[0]) | uint16(b[1])<<8, b[2:]
189}
190
191// gbit32 reads a 32-bit number in little-endian order from b and returns it with the remaining slice of b.
192func gbit32(b []byte) (uint32, []byte) {
193 return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24, b[4:]
194}
195
196// gbit64 reads a 64-bit number in little-endian order from b and returns it with the remaining slice of b.
197func gbit64(b []byte) (uint64, []byte) {
198 lo := uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24
199 hi := uint32(b[4]) | uint32(b[5])<<8 | uint32(b[6])<<16 | uint32(b[7])<<24
200 return uint64(lo) | uint64(hi)<<32, b[8:]
201}
202
203// gstring reads a string from b, prefixed with a 16-bit length in little-endian order.
204// It returns the string with the remaining slice of b and a boolean. If the length is
205// greater than the number of bytes in b, the boolean will be false.
206func gstring(b []byte) (string, []byte, bool) {
207 n, b := gbit16(b)
208 if int(n) > len(b) {
209 return "", b, false
210 }
211 return string(b[:n]), b[n:], true
212}
vendor/golang.org/x/sys/plan9/env_plan9.go added +31
@@ -0,0 +1,31 @@
1// Copyright 2011 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Plan 9 environment variables.
6
7package plan9
8
9import (
10 "syscall"
11)
12
13func Getenv(key string) (value string, found bool) {
14 return syscall.Getenv(key)
15}
16
17func Setenv(key, value string) error {
18 return syscall.Setenv(key, value)
19}
20
21func Clearenv() {
22 syscall.Clearenv()
23}
24
25func Environ() []string {
26 return syscall.Environ()
27}
28
29func Unsetenv(key string) error {
30 return syscall.Unsetenv(key)
31}
vendor/golang.org/x/sys/plan9/errors_plan9.go added +50
@@ -0,0 +1,50 @@
1// Copyright 2011 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package plan9
6
7import "syscall"
8
9// Constants
10const (
11 // Invented values to support what package os expects.
12 O_CREAT = 0x02000
13 O_APPEND = 0x00400
14 O_NOCTTY = 0x00000
15 O_NONBLOCK = 0x00000
16 O_SYNC = 0x00000
17 O_ASYNC = 0x00000
18
19 S_IFMT = 0x1f000
20 S_IFIFO = 0x1000
21 S_IFCHR = 0x2000
22 S_IFDIR = 0x4000
23 S_IFBLK = 0x6000
24 S_IFREG = 0x8000
25 S_IFLNK = 0xa000
26 S_IFSOCK = 0xc000
27)
28
29// Errors
30var (
31 EINVAL = syscall.NewError("bad arg in system call")
32 ENOTDIR = syscall.NewError("not a directory")
33 EISDIR = syscall.NewError("file is a directory")
34 ENOENT = syscall.NewError("file does not exist")
35 EEXIST = syscall.NewError("file already exists")
36 EMFILE = syscall.NewError("no free file descriptors")
37 EIO = syscall.NewError("i/o error")
38 ENAMETOOLONG = syscall.NewError("file name too long")
39 EINTR = syscall.NewError("interrupted")
40 EPERM = syscall.NewError("permission denied")
41 EBUSY = syscall.NewError("no free devices")
42 ETIMEDOUT = syscall.NewError("connection timed out")
43 EPLAN9 = syscall.NewError("not supported by plan 9")
44
45 // The following errors do not correspond to any
46 // Plan 9 system messages. Invented to support
47 // what package os and others expect.
48 EACCES = syscall.NewError("access permission denied")
49 EAFNOSUPPORT = syscall.NewError("address family not supported by protocol")
50)
vendor/golang.org/x/sys/plan9/mkall.sh added +150
@@ -0,0 +1,150 @@
1#!/usr/bin/env bash
2# Copyright 2009 The Go Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style
4# license that can be found in the LICENSE file.
5
6# The plan9 package provides access to the raw system call
7# interface of the underlying operating system. Porting Go to
8# a new architecture/operating system combination requires
9# some manual effort, though there are tools that automate
10# much of the process. The auto-generated files have names
11# beginning with z.
12#
13# This script runs or (given -n) prints suggested commands to generate z files
14# for the current system. Running those commands is not automatic.
15# This script is documentation more than anything else.
16#
17# * asm_${GOOS}_${GOARCH}.s
18#
19# This hand-written assembly file implements system call dispatch.
20# There are three entry points:
21#
22# func Syscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
23# func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr);
24# func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr);
25#
26# The first and second are the standard ones; they differ only in
27# how many arguments can be passed to the kernel.
28# The third is for low-level use by the ForkExec wrapper;
29# unlike the first two, it does not call into the scheduler to
30# let it know that a system call is running.
31#
32# * syscall_${GOOS}.go
33#
34# This hand-written Go file implements system calls that need
35# special handling and lists "//sys" comments giving prototypes
36# for ones that can be auto-generated. Mksyscall reads those
37# comments to generate the stubs.
38#
39# * syscall_${GOOS}_${GOARCH}.go
40#
41# Same as syscall_${GOOS}.go except that it contains code specific
42# to ${GOOS} on one particular architecture.
43#
44# * types_${GOOS}.c
45#
46# This hand-written C file includes standard C headers and then
47# creates typedef or enum names beginning with a dollar sign
48# (use of $ in variable names is a gcc extension). The hardest
49# part about preparing this file is figuring out which headers to
50# include and which symbols need to be #defined to get the
51# actual data structures that pass through to the kernel system calls.
52# Some C libraries present alternate versions for binary compatibility
53# and translate them on the way in and out of system calls, but
54# there is almost always a #define that can get the real ones.
55# See types_darwin.c and types_linux.c for examples.
56#
57# * zerror_${GOOS}_${GOARCH}.go
58#
59# This machine-generated file defines the system's error numbers,
60# error strings, and signal numbers. The generator is "mkerrors.sh".
61# Usually no arguments are needed, but mkerrors.sh will pass its
62# arguments on to godefs.
63#
64# * zsyscall_${GOOS}_${GOARCH}.go
65#
66# Generated by mksyscall.pl; see syscall_${GOOS}.go above.
67#
68# * zsysnum_${GOOS}_${GOARCH}.go
69#
70# Generated by mksysnum_${GOOS}.
71#
72# * ztypes_${GOOS}_${GOARCH}.go
73#
74# Generated by godefs; see types_${GOOS}.c above.
75
76GOOSARCH="${GOOS}_${GOARCH}"
77
78# defaults
79mksyscall="go run mksyscall.go"
80mkerrors="./mkerrors.sh"
81zerrors="zerrors_$GOOSARCH.go"
82mksysctl=""
83zsysctl="zsysctl_$GOOSARCH.go"
84mksysnum=
85mktypes=
86run="sh"
87
88case "$1" in
89-syscalls)
90 for i in zsyscall*go
91 do
92 sed 1q $i | sed 's;^// ;;' | sh > _$i && gofmt < _$i > $i
93 rm _$i
94 done
95 exit 0
96 ;;
97-n)
98 run="cat"
99 shift
100esac
101
102case "$#" in
1030)
104 ;;
105*)
106 echo 'usage: mkall.sh [-n]' 1>&2
107 exit 2
108esac
109
110case "$GOOSARCH" in
111_* | *_ | _)
112 echo 'undefined $GOOS_$GOARCH:' "$GOOSARCH" 1>&2
113 exit 1
114 ;;
115plan9_386)
116 mkerrors=
117 mksyscall="go run mksyscall.go -l32 -plan9 -tags plan9,386"
118 mksysnum="./mksysnum_plan9.sh /n/sources/plan9/sys/src/libc/9syscall/sys.h"
119 mktypes="XXX"
120 ;;
121plan9_amd64)
122 mkerrors=
123 mksyscall="go run mksyscall.go -l32 -plan9 -tags plan9,amd64"
124 mksysnum="./mksysnum_plan9.sh /n/sources/plan9/sys/src/libc/9syscall/sys.h"
125 mktypes="XXX"
126 ;;
127plan9_arm)
128 mkerrors=
129 mksyscall="go run mksyscall.go -l32 -plan9 -tags plan9,arm"
130 mksysnum="./mksysnum_plan9.sh /n/sources/plan9/sys/src/libc/9syscall/sys.h"
131 mktypes="XXX"
132 ;;
133*)
134 echo 'unrecognized $GOOS_$GOARCH: ' "$GOOSARCH" 1>&2
135 exit 1
136 ;;
137esac
138
139(
140 if [ -n "$mkerrors" ]; then echo "$mkerrors |gofmt >$zerrors"; fi
141 case "$GOOS" in
142 plan9)
143 syscall_goos="syscall_$GOOS.go"
144 if [ -n "$mksyscall" ]; then echo "$mksyscall $syscall_goos |gofmt >zsyscall_$GOOSARCH.go"; fi
145 ;;
146 esac
147 if [ -n "$mksysctl" ]; then echo "$mksysctl |gofmt >$zsysctl"; fi
148 if [ -n "$mksysnum" ]; then echo "$mksysnum |gofmt >zsysnum_$GOOSARCH.go"; fi
149 if [ -n "$mktypes" ]; then echo "$mktypes types_$GOOS.go |gofmt >ztypes_$GOOSARCH.go"; fi
150) | $run
vendor/golang.org/x/sys/plan9/mkerrors.sh added +246
@@ -0,0 +1,246 @@
1#!/usr/bin/env bash
2# Copyright 2009 The Go Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style
4# license that can be found in the LICENSE file.
5
6# Generate Go code listing errors and other #defined constant
7# values (ENAMETOOLONG etc.), by asking the preprocessor
8# about the definitions.
9
10unset LANG
11export LC_ALL=C
12export LC_CTYPE=C
13
14CC=${CC:-gcc}
15
16uname=$(uname)
17
18includes='
19#include <sys/types.h>
20#include <sys/file.h>
21#include <fcntl.h>
22#include <dirent.h>
23#include <sys/socket.h>
24#include <netinet/in.h>
25#include <netinet/ip.h>
26#include <netinet/ip6.h>
27#include <netinet/tcp.h>
28#include <errno.h>
29#include <sys/signal.h>
30#include <signal.h>
31#include <sys/resource.h>
32'
33
34ccflags="$@"
35
36# Write go tool cgo -godefs input.
37(
38 echo package plan9
39 echo
40 echo '/*'
41 indirect="includes_$(uname)"
42 echo "${!indirect} $includes"
43 echo '*/'
44 echo 'import "C"'
45 echo
46 echo 'const ('
47
48 # The gcc command line prints all the #defines
49 # it encounters while processing the input
50 echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags |
51 awk '
52 $1 != "#define" || $2 ~ /\(/ || $3 == "" {next}
53
54 $2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers
55 $2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next}
56 $2 ~ /^(SCM_SRCRT)$/ {next}
57 $2 ~ /^(MAP_FAILED)$/ {next}
58
59 $2 !~ /^ETH_/ &&
60 $2 !~ /^EPROC_/ &&
61 $2 !~ /^EQUIV_/ &&
62 $2 !~ /^EXPR_/ &&
63 $2 ~ /^E[A-Z0-9_]+$/ ||
64 $2 ~ /^B[0-9_]+$/ ||
65 $2 ~ /^V[A-Z0-9]+$/ ||
66 $2 ~ /^CS[A-Z0-9]/ ||
67 $2 ~ /^I(SIG|CANON|CRNL|EXTEN|MAXBEL|STRIP|UTF8)$/ ||
68 $2 ~ /^IGN/ ||
69 $2 ~ /^IX(ON|ANY|OFF)$/ ||
70 $2 ~ /^IN(LCR|PCK)$/ ||
71 $2 ~ /(^FLU?SH)|(FLU?SH$)/ ||
72 $2 ~ /^C(LOCAL|READ)$/ ||
73 $2 == "BRKINT" ||
74 $2 == "HUPCL" ||
75 $2 == "PENDIN" ||
76 $2 == "TOSTOP" ||
77 $2 ~ /^PAR/ ||
78 $2 ~ /^SIG[^_]/ ||
79 $2 ~ /^O[CNPFP][A-Z]+[^_][A-Z]+$/ ||
80 $2 ~ /^IN_/ ||
81 $2 ~ /^LOCK_(SH|EX|NB|UN)$/ ||
82 $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|ICMP6|TCP|EVFILT|NOTE|EV|SHUT|PROT|MAP|PACKET|MSG|SCM|MCL|DT|MADV|PR)_/ ||
83 $2 == "ICMPV6_FILTER" ||
84 $2 == "SOMAXCONN" ||
85 $2 == "NAME_MAX" ||
86 $2 == "IFNAMSIZ" ||
87 $2 ~ /^CTL_(MAXNAME|NET|QUERY)$/ ||
88 $2 ~ /^SYSCTL_VERS/ ||
89 $2 ~ /^(MS|MNT)_/ ||
90 $2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ ||
91 $2 ~ /^(O|F|FD|NAME|S|PTRACE|PT)_/ ||
92 $2 ~ /^LINUX_REBOOT_CMD_/ ||
93 $2 ~ /^LINUX_REBOOT_MAGIC[12]$/ ||
94 $2 !~ "NLA_TYPE_MASK" &&
95 $2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P)_/ ||
96 $2 ~ /^SIOC/ ||
97 $2 ~ /^TIOC/ ||
98 $2 !~ "RTF_BITS" &&
99 $2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ ||
100 $2 ~ /^BIOC/ ||
101 $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ ||
102 $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|NOFILE|STACK)|RLIM_INFINITY/ ||
103 $2 ~ /^PRIO_(PROCESS|PGRP|USER)/ ||
104 $2 ~ /^CLONE_[A-Z_]+/ ||
105 $2 !~ /^(BPF_TIMEVAL)$/ &&
106 $2 ~ /^(BPF|DLT)_/ ||
107 $2 !~ "WMESGLEN" &&
108 $2 ~ /^W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", $2, $2)}
109 $2 ~ /^__WCOREFLAG$/ {next}
110 $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)}
111
112 {next}
113 ' | sort
114
115 echo ')'
116) >_const.go
117
118# Pull out the error names for later.
119errors=$(
120 echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
121 awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' |
122 sort
123)
124
125# Pull out the signal names for later.
126signals=$(
127 echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
128 awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' |
129 grep -v 'SIGSTKSIZE\|SIGSTKSZ\|SIGRT' |
130 sort
131)
132
133# Again, writing regexps to a file.
134echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags |
135 awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' |
136 sort >_error.grep
137echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags |
138 awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' |
139 grep -v 'SIGSTKSIZE\|SIGSTKSZ\|SIGRT' |
140 sort >_signal.grep
141
142echo '// mkerrors.sh' "$@"
143echo '// Code generated by the command above; DO NOT EDIT.'
144echo
145go tool cgo -godefs -- "$@" _const.go >_error.out
146cat _error.out | grep -vf _error.grep | grep -vf _signal.grep
147echo
148echo '// Errors'
149echo 'const ('
150cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= Errno(\1)/'
151echo ')'
152
153echo
154echo '// Signals'
155echo 'const ('
156cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= Signal(\1)/'
157echo ')'
158
159# Run C program to print error and syscall strings.
160(
161 echo -E "
162#include <stdio.h>
163#include <stdlib.h>
164#include <errno.h>
165#include <ctype.h>
166#include <string.h>
167#include <signal.h>
168
169#define nelem(x) (sizeof(x)/sizeof((x)[0]))
170
171enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below
172
173int errors[] = {
174"
175 for i in $errors
176 do
177 echo -E ' '$i,
178 done
179
180 echo -E "
181};
182
183int signals[] = {
184"
185 for i in $signals
186 do
187 echo -E ' '$i,
188 done
189
190 # Use -E because on some systems bash builtin interprets \n itself.
191 echo -E '
192};
193
194static int
195intcmp(const void *a, const void *b)
196{
197 return *(int*)a - *(int*)b;
198}
199
200int
201main(void)
202{
203 int i, j, e;
204 char buf[1024], *p;
205
206 printf("\n\n// Error table\n");
207 printf("var errors = [...]string {\n");
208 qsort(errors, nelem(errors), sizeof errors[0], intcmp);
209 for(i=0; i<nelem(errors); i++) {
210 e = errors[i];
211 if(i > 0 && errors[i-1] == e)
212 continue;
213 strcpy(buf, strerror(e));
214 // lowercase first letter: Bad -> bad, but STREAM -> STREAM.
215 if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
216 buf[0] += a - A;
217 printf("\t%d: \"%s\",\n", e, buf);
218 }
219 printf("}\n\n");
220
221 printf("\n\n// Signal table\n");
222 printf("var signals = [...]string {\n");
223 qsort(signals, nelem(signals), sizeof signals[0], intcmp);
224 for(i=0; i<nelem(signals); i++) {
225 e = signals[i];
226 if(i > 0 && signals[i-1] == e)
227 continue;
228 strcpy(buf, strsignal(e));
229 // lowercase first letter: Bad -> bad, but STREAM -> STREAM.
230 if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z)
231 buf[0] += a - A;
232 // cut trailing : number.
233 p = strrchr(buf, ":"[0]);
234 if(p)
235 *p = '\0';
236 printf("\t%d: \"%s\",\n", e, buf);
237 }
238 printf("}\n\n");
239
240 return 0;
241}
242
243'
244) >_errors.c
245
246$CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out
vendor/golang.org/x/sys/plan9/mksysnum_plan9.sh added +23
@@ -0,0 +1,23 @@
1#!/bin/sh
2# Copyright 2009 The Go Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style
4# license that can be found in the LICENSE file.
5
6COMMAND="mksysnum_plan9.sh $@"
7
8cat <<EOF
9// $COMMAND
10// MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT
11
12package plan9
13
14const(
15EOF
16
17SP='[ ]' # space or tab
18sed "s/^#define${SP}\\([A-Z0-9_][A-Z0-9_]*\\)${SP}${SP}*\\([0-9][0-9]*\\)/SYS_\\1=\\2/g" \
19 < $1 | grep -v SYS__
20
21cat <<EOF
22)
23EOF
vendor/golang.org/x/sys/plan9/pwd_go15_plan9.go added +21
@@ -0,0 +1,21 @@
1// Copyright 2015 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build go1.5
6
7package plan9
8
9import "syscall"
10
11func fixwd() {
12 syscall.Fixwd()
13}
14
15func Getwd() (wd string, err error) {
16 return syscall.Getwd()
17}
18
19func Chdir(path string) error {
20 return syscall.Chdir(path)
21}
vendor/golang.org/x/sys/plan9/pwd_plan9.go added +23
@@ -0,0 +1,23 @@
1// Copyright 2015 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build !go1.5
6
7package plan9
8
9func fixwd() {
10}
11
12func Getwd() (wd string, err error) {
13 fd, err := open(".", O_RDONLY)
14 if err != nil {
15 return "", err
16 }
17 defer Close(fd)
18 return Fd2path(fd)
19}
20
21func Chdir(path string) error {
22 return chdir(path)
23}
vendor/golang.org/x/sys/plan9/race.go added +30
@@ -0,0 +1,30 @@
1// Copyright 2012 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build plan9 && race
6
7package plan9
8
9import (
10 "runtime"
11 "unsafe"
12)
13
14const raceenabled = true
15
16func raceAcquire(addr unsafe.Pointer) {
17 runtime.RaceAcquire(addr)
18}
19
20func raceReleaseMerge(addr unsafe.Pointer) {
21 runtime.RaceReleaseMerge(addr)
22}
23
24func raceReadRange(addr unsafe.Pointer, len int) {
25 runtime.RaceReadRange(addr, len)
26}
27
28func raceWriteRange(addr unsafe.Pointer, len int) {
29 runtime.RaceWriteRange(addr, len)
30}
vendor/golang.org/x/sys/plan9/race0.go added +25
@@ -0,0 +1,25 @@
1// Copyright 2012 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build plan9 && !race
6
7package plan9
8
9import (
10 "unsafe"
11)
12
13const raceenabled = false
14
15func raceAcquire(addr unsafe.Pointer) {
16}
17
18func raceReleaseMerge(addr unsafe.Pointer) {
19}
20
21func raceReadRange(addr unsafe.Pointer, len int) {
22}
23
24func raceWriteRange(addr unsafe.Pointer, len int) {
25}
vendor/golang.org/x/sys/plan9/str.go added +22
@@ -0,0 +1,22 @@
1// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build plan9
6
7package plan9
8
9func itoa(val int) string { // do it here rather than with fmt to avoid dependency
10 if val < 0 {
11 return "-" + itoa(-val)
12 }
13 var buf [32]byte // big enough for int64
14 i := len(buf) - 1
15 for val >= 10 {
16 buf[i] = byte(val%10 + '0')
17 i--
18 val /= 10
19 }
20 buf[i] = byte(val + '0')
21 return string(buf[i:])
22}
vendor/golang.org/x/sys/plan9/syscall.go added +109
@@ -0,0 +1,109 @@
1// Copyright 2009 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build plan9
6
7// Package plan9 contains an interface to the low-level operating system
8// primitives. OS details vary depending on the underlying system, and
9// by default, godoc will display the OS-specific documentation for the current
10// system. If you want godoc to display documentation for another
11// system, set $GOOS and $GOARCH to the desired system. For example, if
12// you want to view documentation for freebsd/arm on linux/amd64, set $GOOS
13// to freebsd and $GOARCH to arm.
14//
15// The primary use of this package is inside other packages that provide a more
16// portable interface to the system, such as "os", "time" and "net". Use
17// those packages rather than this one if you can.
18//
19// For details of the functions and data types in this package consult
20// the manuals for the appropriate operating system.
21//
22// These calls return err == nil to indicate success; otherwise
23// err represents an operating system error describing the failure and
24// holds a value of type syscall.ErrorString.
25package plan9 // import "golang.org/x/sys/plan9"
26
27import (
28 "bytes"
29 "strings"
30 "unsafe"
31)
32
33// ByteSliceFromString returns a NUL-terminated slice of bytes
34// containing the text of s. If s contains a NUL byte at any
35// location, it returns (nil, EINVAL).
36func ByteSliceFromString(s string) ([]byte, error) {
37 if strings.IndexByte(s, 0) != -1 {
38 return nil, EINVAL
39 }
40 a := make([]byte, len(s)+1)
41 copy(a, s)
42 return a, nil
43}
44
45// BytePtrFromString returns a pointer to a NUL-terminated array of
46// bytes containing the text of s. If s contains a NUL byte at any
47// location, it returns (nil, EINVAL).
48func BytePtrFromString(s string) (*byte, error) {
49 a, err := ByteSliceFromString(s)
50 if err != nil {
51 return nil, err
52 }
53 return &a[0], nil
54}
55
56// ByteSliceToString returns a string form of the text represented by the slice s, with a terminating NUL and any
57// bytes after the NUL removed.
58func ByteSliceToString(s []byte) string {
59 if i := bytes.IndexByte(s, 0); i != -1 {
60 s = s[:i]
61 }
62 return string(s)
63}
64
65// BytePtrToString takes a pointer to a sequence of text and returns the corresponding string.
66// If the pointer is nil, it returns the empty string. It assumes that the text sequence is terminated
67// at a zero byte; if the zero byte is not present, the program may crash.
68func BytePtrToString(p *byte) string {
69 if p == nil {
70 return ""
71 }
72 if *p == 0 {
73 return ""
74 }
75
76 // Find NUL terminator.
77 n := 0
78 for ptr := unsafe.Pointer(p); *(*byte)(ptr) != 0; n++ {
79 ptr = unsafe.Pointer(uintptr(ptr) + 1)
80 }
81
82 return string(unsafe.Slice(p, n))
83}
84
85// Single-word zero for use when we need a valid pointer to 0 bytes.
86// See mksyscall.pl.
87var _zero uintptr
88
89func (ts *Timespec) Unix() (sec int64, nsec int64) {
90 return int64(ts.Sec), int64(ts.Nsec)
91}
92
93func (tv *Timeval) Unix() (sec int64, nsec int64) {
94 return int64(tv.Sec), int64(tv.Usec) * 1000
95}
96
97func (ts *Timespec) Nano() int64 {
98 return int64(ts.Sec)*1e9 + int64(ts.Nsec)
99}
100
101func (tv *Timeval) Nano() int64 {
102 return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000
103}
104
105// use is a no-op, but the compiler cannot see that it is.
106// Calling use(p) ensures that p is kept live until that point.
107//
108//go:noescape
109func use(p unsafe.Pointer)
vendor/golang.org/x/sys/plan9/syscall_plan9.go added +361
@@ -0,0 +1,361 @@
1// Copyright 2011 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Plan 9 system calls.
6// This file is compiled as ordinary Go code,
7// but it is also input to mksyscall,
8// which parses the //sys lines and generates system call stubs.
9// Note that sometimes we use a lowercase //sys name and
10// wrap it in our own nicer implementation.
11
12package plan9
13
14import (
15 "bytes"
16 "syscall"
17 "unsafe"
18)
19
20// A Note is a string describing a process note.
21// It implements the os.Signal interface.
22type Note string
23
24func (n Note) Signal() {}
25
26func (n Note) String() string {
27 return string(n)
28}
29
30var (
31 Stdin = 0
32 Stdout = 1
33 Stderr = 2
34)
35
36// For testing: clients can set this flag to force
37// creation of IPv6 sockets to return EAFNOSUPPORT.
38var SocketDisableIPv6 bool
39
40func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.ErrorString)
41func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err syscall.ErrorString)
42func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2, err uintptr)
43func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, err uintptr)
44
45func atoi(b []byte) (n uint) {
46 n = 0
47 for i := 0; i < len(b); i++ {
48 n = n*10 + uint(b[i]-'0')
49 }
50 return
51}
52
53func cstring(s []byte) string {
54 i := bytes.IndexByte(s, 0)
55 if i == -1 {
56 i = len(s)
57 }
58 return string(s[:i])
59}
60
61func errstr() string {
62 var buf [ERRMAX]byte
63
64 RawSyscall(SYS_ERRSTR, uintptr(unsafe.Pointer(&buf[0])), uintptr(len(buf)), 0)
65
66 buf[len(buf)-1] = 0
67 return cstring(buf[:])
68}
69
70// Implemented in assembly to import from runtime.
71func exit(code int)
72
73func Exit(code int) { exit(code) }
74
75func readnum(path string) (uint, error) {
76 var b [12]byte
77
78 fd, e := Open(path, O_RDONLY)
79 if e != nil {
80 return 0, e
81 }
82 defer Close(fd)
83
84 n, e := Pread(fd, b[:], 0)
85
86 if e != nil {
87 return 0, e
88 }
89
90 m := 0
91 for ; m < n && b[m] == ' '; m++ {
92 }
93
94 return atoi(b[m : n-1]), nil
95}
96
97func Getpid() (pid int) {
98 n, _ := readnum("#c/pid")
99 return int(n)
100}
101
102func Getppid() (ppid int) {
103 n, _ := readnum("#c/ppid")
104 return int(n)
105}
106
107func Read(fd int, p []byte) (n int, err error) {
108 return Pread(fd, p, -1)
109}
110
111func Write(fd int, p []byte) (n int, err error) {
112 return Pwrite(fd, p, -1)
113}
114
115var ioSync int64
116
117//sys fd2path(fd int, buf []byte) (err error)
118
119func Fd2path(fd int) (path string, err error) {
120 var buf [512]byte
121
122 e := fd2path(fd, buf[:])
123 if e != nil {
124 return "", e
125 }
126 return cstring(buf[:]), nil
127}
128
129//sys pipe(p *[2]int32) (err error)
130
131func Pipe(p []int) (err error) {
132 if len(p) != 2 {
133 return syscall.ErrorString("bad arg in system call")
134 }
135 var pp [2]int32
136 err = pipe(&pp)
137 if err == nil {
138 p[0] = int(pp[0])
139 p[1] = int(pp[1])
140 }
141 return
142}
143
144// Underlying system call writes to newoffset via pointer.
145// Implemented in assembly to avoid allocation.
146func seek(placeholder uintptr, fd int, offset int64, whence int) (newoffset int64, err string)
147
148func Seek(fd int, offset int64, whence int) (newoffset int64, err error) {
149 newoffset, e := seek(0, fd, offset, whence)
150
151 if newoffset == -1 {
152 err = syscall.ErrorString(e)
153 }
154 return
155}
156
157func Mkdir(path string, mode uint32) (err error) {
158 fd, err := Create(path, O_RDONLY, DMDIR|mode)
159
160 if fd != -1 {
161 Close(fd)
162 }
163
164 return
165}
166
167type Waitmsg struct {
168 Pid int
169 Time [3]uint32
170 Msg string
171}
172
173func (w Waitmsg) Exited() bool { return true }
174func (w Waitmsg) Signaled() bool { return false }
175
176func (w Waitmsg) ExitStatus() int {
177 if len(w.Msg) == 0 {
178 // a normal exit returns no message
179 return 0
180 }
181 return 1
182}
183
184//sys await(s []byte) (n int, err error)
185
186func Await(w *Waitmsg) (err error) {
187 var buf [512]byte
188 var f [5][]byte
189
190 n, err := await(buf[:])
191
192 if err != nil || w == nil {
193 return
194 }
195
196 nf := 0
197 p := 0
198 for i := 0; i < n && nf < len(f)-1; i++ {
199 if buf[i] == ' ' {
200 f[nf] = buf[p:i]
201 p = i + 1
202 nf++
203 }
204 }
205 f[nf] = buf[p:]
206 nf++
207
208 if nf != len(f) {
209 return syscall.ErrorString("invalid wait message")
210 }
211 w.Pid = int(atoi(f[0]))
212 w.Time[0] = uint32(atoi(f[1]))
213 w.Time[1] = uint32(atoi(f[2]))
214 w.Time[2] = uint32(atoi(f[3]))
215 w.Msg = cstring(f[4])
216 if w.Msg == "''" {
217 // await() returns '' for no error
218 w.Msg = ""
219 }
220 return
221}
222
223func Unmount(name, old string) (err error) {
224 fixwd()
225 oldp, err := BytePtrFromString(old)
226 if err != nil {
227 return err
228 }
229 oldptr := uintptr(unsafe.Pointer(oldp))
230
231 var r0 uintptr
232 var e syscall.ErrorString
233
234 // bind(2) man page: If name is zero, everything bound or mounted upon old is unbound or unmounted.
235 if name == "" {
236 r0, _, e = Syscall(SYS_UNMOUNT, _zero, oldptr, 0)
237 } else {
238 namep, err := BytePtrFromString(name)
239 if err != nil {
240 return err
241 }
242 r0, _, e = Syscall(SYS_UNMOUNT, uintptr(unsafe.Pointer(namep)), oldptr, 0)
243 }
244
245 if int32(r0) == -1 {
246 err = e
247 }
248 return
249}
250
251func Fchdir(fd int) (err error) {
252 path, err := Fd2path(fd)
253
254 if err != nil {
255 return
256 }
257
258 return Chdir(path)
259}
260
261type Timespec struct {
262 Sec int32
263 Nsec int32
264}
265
266type Timeval struct {
267 Sec int32
268 Usec int32
269}
270
271func NsecToTimeval(nsec int64) (tv Timeval) {
272 nsec += 999 // round up to microsecond
273 tv.Usec = int32(nsec % 1e9 / 1e3)
274 tv.Sec = int32(nsec / 1e9)
275 return
276}
277
278func nsec() int64 {
279 var scratch int64
280
281 r0, _, _ := Syscall(SYS_NSEC, uintptr(unsafe.Pointer(&scratch)), 0, 0)
282 // TODO(aram): remove hack after I fix _nsec in the pc64 kernel.
283 if r0 == 0 {
284 return scratch
285 }
286 return int64(r0)
287}
288
289func Gettimeofday(tv *Timeval) error {
290 nsec := nsec()
291 *tv = NsecToTimeval(nsec)
292 return nil
293}
294
295func Getpagesize() int { return 0x1000 }
296
297func Getegid() (egid int) { return -1 }
298func Geteuid() (euid int) { return -1 }
299func Getgid() (gid int) { return -1 }
300func Getuid() (uid int) { return -1 }
301
302func Getgroups() (gids []int, err error) {
303 return make([]int, 0), nil
304}
305
306//sys open(path string, mode int) (fd int, err error)
307
308func Open(path string, mode int) (fd int, err error) {
309 fixwd()
310 return open(path, mode)
311}
312
313//sys create(path string, mode int, perm uint32) (fd int, err error)
314
315func Create(path string, mode int, perm uint32) (fd int, err error) {
316 fixwd()
317 return create(path, mode, perm)
318}
319
320//sys remove(path string) (err error)
321
322func Remove(path string) error {
323 fixwd()
324 return remove(path)
325}
326
327//sys stat(path string, edir []byte) (n int, err error)
328
329func Stat(path string, edir []byte) (n int, err error) {
330 fixwd()
331 return stat(path, edir)
332}
333
334//sys bind(name string, old string, flag int) (err error)
335
336func Bind(name string, old string, flag int) (err error) {
337 fixwd()
338 return bind(name, old, flag)
339}
340
341//sys mount(fd int, afd int, old string, flag int, aname string) (err error)
342
343func Mount(fd int, afd int, old string, flag int, aname string) (err error) {
344 fixwd()
345 return mount(fd, afd, old, flag, aname)
346}
347
348//sys wstat(path string, edir []byte) (err error)
349
350func Wstat(path string, edir []byte) (err error) {
351 fixwd()
352 return wstat(path, edir)
353}
354
355//sys chdir(path string) (err error)
356//sys Dup(oldfd int, newfd int) (fd int, err error)
357//sys Pread(fd int, p []byte, offset int64) (n int, err error)
358//sys Pwrite(fd int, p []byte, offset int64) (n int, err error)
359//sys Close(fd int) (err error)
360//sys Fstat(fd int, edir []byte) (n int, err error)
361//sys Fwstat(fd int, edir []byte) (err error)
vendor/golang.org/x/sys/plan9/zsyscall_plan9_386.go added +284
@@ -0,0 +1,284 @@
1// go run mksyscall.go -l32 -plan9 -tags plan9,386 syscall_plan9.go
2// Code generated by the command above; see README.md. DO NOT EDIT.
3
4//go:build plan9 && 386
5
6package plan9
7
8import "unsafe"
9
10// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
11
12func fd2path(fd int, buf []byte) (err error) {
13 var _p0 unsafe.Pointer
14 if len(buf) > 0 {
15 _p0 = unsafe.Pointer(&buf[0])
16 } else {
17 _p0 = unsafe.Pointer(&_zero)
18 }
19 r0, _, e1 := Syscall(SYS_FD2PATH, uintptr(fd), uintptr(_p0), uintptr(len(buf)))
20 if int32(r0) == -1 {
21 err = e1
22 }
23 return
24}
25
26// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
27
28func pipe(p *[2]int32) (err error) {
29 r0, _, e1 := Syscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0)
30 if int32(r0) == -1 {
31 err = e1
32 }
33 return
34}
35
36// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
37
38func await(s []byte) (n int, err error) {
39 var _p0 unsafe.Pointer
40 if len(s) > 0 {
41 _p0 = unsafe.Pointer(&s[0])
42 } else {
43 _p0 = unsafe.Pointer(&_zero)
44 }
45 r0, _, e1 := Syscall(SYS_AWAIT, uintptr(_p0), uintptr(len(s)), 0)
46 n = int(r0)
47 if int32(r0) == -1 {
48 err = e1
49 }
50 return
51}
52
53// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
54
55func open(path string, mode int) (fd int, err error) {
56 var _p0 *byte
57 _p0, err = BytePtrFromString(path)
58 if err != nil {
59 return
60 }
61 r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
62 fd = int(r0)
63 if int32(r0) == -1 {
64 err = e1
65 }
66 return
67}
68
69// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
70
71func create(path string, mode int, perm uint32) (fd int, err error) {
72 var _p0 *byte
73 _p0, err = BytePtrFromString(path)
74 if err != nil {
75 return
76 }
77 r0, _, e1 := Syscall(SYS_CREATE, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm))
78 fd = int(r0)
79 if int32(r0) == -1 {
80 err = e1
81 }
82 return
83}
84
85// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
86
87func remove(path string) (err error) {
88 var _p0 *byte
89 _p0, err = BytePtrFromString(path)
90 if err != nil {
91 return
92 }
93 r0, _, e1 := Syscall(SYS_REMOVE, uintptr(unsafe.Pointer(_p0)), 0, 0)
94 if int32(r0) == -1 {
95 err = e1
96 }
97 return
98}
99
100// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
101
102func stat(path string, edir []byte) (n int, err error) {
103 var _p0 *byte
104 _p0, err = BytePtrFromString(path)
105 if err != nil {
106 return
107 }
108 var _p1 unsafe.Pointer
109 if len(edir) > 0 {
110 _p1 = unsafe.Pointer(&edir[0])
111 } else {
112 _p1 = unsafe.Pointer(&_zero)
113 }
114 r0, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
115 n = int(r0)
116 if int32(r0) == -1 {
117 err = e1
118 }
119 return
120}
121
122// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
123
124func bind(name string, old string, flag int) (err error) {
125 var _p0 *byte
126 _p0, err = BytePtrFromString(name)
127 if err != nil {
128 return
129 }
130 var _p1 *byte
131 _p1, err = BytePtrFromString(old)
132 if err != nil {
133 return
134 }
135 r0, _, e1 := Syscall(SYS_BIND, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flag))
136 if int32(r0) == -1 {
137 err = e1
138 }
139 return
140}
141
142// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
143
144func mount(fd int, afd int, old string, flag int, aname string) (err error) {
145 var _p0 *byte
146 _p0, err = BytePtrFromString(old)
147 if err != nil {
148 return
149 }
150 var _p1 *byte
151 _p1, err = BytePtrFromString(aname)
152 if err != nil {
153 return
154 }
155 r0, _, e1 := Syscall6(SYS_MOUNT, uintptr(fd), uintptr(afd), uintptr(unsafe.Pointer(_p0)), uintptr(flag), uintptr(unsafe.Pointer(_p1)), 0)
156 if int32(r0) == -1 {
157 err = e1
158 }
159 return
160}
161
162// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
163
164func wstat(path string, edir []byte) (err error) {
165 var _p0 *byte
166 _p0, err = BytePtrFromString(path)
167 if err != nil {
168 return
169 }
170 var _p1 unsafe.Pointer
171 if len(edir) > 0 {
172 _p1 = unsafe.Pointer(&edir[0])
173 } else {
174 _p1 = unsafe.Pointer(&_zero)
175 }
176 r0, _, e1 := Syscall(SYS_WSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
177 if int32(r0) == -1 {
178 err = e1
179 }
180 return
181}
182
183// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
184
185func chdir(path string) (err error) {
186 var _p0 *byte
187 _p0, err = BytePtrFromString(path)
188 if err != nil {
189 return
190 }
191 r0, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0)
192 if int32(r0) == -1 {
193 err = e1
194 }
195 return
196}
197
198// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
199
200func Dup(oldfd int, newfd int) (fd int, err error) {
201 r0, _, e1 := Syscall(SYS_DUP, uintptr(oldfd), uintptr(newfd), 0)
202 fd = int(r0)
203 if int32(r0) == -1 {
204 err = e1
205 }
206 return
207}
208
209// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
210
211func Pread(fd int, p []byte, offset int64) (n int, err error) {
212 var _p0 unsafe.Pointer
213 if len(p) > 0 {
214 _p0 = unsafe.Pointer(&p[0])
215 } else {
216 _p0 = unsafe.Pointer(&_zero)
217 }
218 r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
219 n = int(r0)
220 if int32(r0) == -1 {
221 err = e1
222 }
223 return
224}
225
226// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
227
228func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
229 var _p0 unsafe.Pointer
230 if len(p) > 0 {
231 _p0 = unsafe.Pointer(&p[0])
232 } else {
233 _p0 = unsafe.Pointer(&_zero)
234 }
235 r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
236 n = int(r0)
237 if int32(r0) == -1 {
238 err = e1
239 }
240 return
241}
242
243// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
244
245func Close(fd int) (err error) {
246 r0, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0)
247 if int32(r0) == -1 {
248 err = e1
249 }
250 return
251}
252
253// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
254
255func Fstat(fd int, edir []byte) (n int, err error) {
256 var _p0 unsafe.Pointer
257 if len(edir) > 0 {
258 _p0 = unsafe.Pointer(&edir[0])
259 } else {
260 _p0 = unsafe.Pointer(&_zero)
261 }
262 r0, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
263 n = int(r0)
264 if int32(r0) == -1 {
265 err = e1
266 }
267 return
268}
269
270// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
271
272func Fwstat(fd int, edir []byte) (err error) {
273 var _p0 unsafe.Pointer
274 if len(edir) > 0 {
275 _p0 = unsafe.Pointer(&edir[0])
276 } else {
277 _p0 = unsafe.Pointer(&_zero)
278 }
279 r0, _, e1 := Syscall(SYS_FWSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
280 if int32(r0) == -1 {
281 err = e1
282 }
283 return
284}
vendor/golang.org/x/sys/plan9/zsyscall_plan9_amd64.go added +284
@@ -0,0 +1,284 @@
1// go run mksyscall.go -l32 -plan9 -tags plan9,amd64 syscall_plan9.go
2// Code generated by the command above; see README.md. DO NOT EDIT.
3
4//go:build plan9 && amd64
5
6package plan9
7
8import "unsafe"
9
10// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
11
12func fd2path(fd int, buf []byte) (err error) {
13 var _p0 unsafe.Pointer
14 if len(buf) > 0 {
15 _p0 = unsafe.Pointer(&buf[0])
16 } else {
17 _p0 = unsafe.Pointer(&_zero)
18 }
19 r0, _, e1 := Syscall(SYS_FD2PATH, uintptr(fd), uintptr(_p0), uintptr(len(buf)))
20 if int32(r0) == -1 {
21 err = e1
22 }
23 return
24}
25
26// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
27
28func pipe(p *[2]int32) (err error) {
29 r0, _, e1 := Syscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0)
30 if int32(r0) == -1 {
31 err = e1
32 }
33 return
34}
35
36// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
37
38func await(s []byte) (n int, err error) {
39 var _p0 unsafe.Pointer
40 if len(s) > 0 {
41 _p0 = unsafe.Pointer(&s[0])
42 } else {
43 _p0 = unsafe.Pointer(&_zero)
44 }
45 r0, _, e1 := Syscall(SYS_AWAIT, uintptr(_p0), uintptr(len(s)), 0)
46 n = int(r0)
47 if int32(r0) == -1 {
48 err = e1
49 }
50 return
51}
52
53// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
54
55func open(path string, mode int) (fd int, err error) {
56 var _p0 *byte
57 _p0, err = BytePtrFromString(path)
58 if err != nil {
59 return
60 }
61 r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
62 fd = int(r0)
63 if int32(r0) == -1 {
64 err = e1
65 }
66 return
67}
68
69// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
70
71func create(path string, mode int, perm uint32) (fd int, err error) {
72 var _p0 *byte
73 _p0, err = BytePtrFromString(path)
74 if err != nil {
75 return
76 }
77 r0, _, e1 := Syscall(SYS_CREATE, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm))
78 fd = int(r0)
79 if int32(r0) == -1 {
80 err = e1
81 }
82 return
83}
84
85// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
86
87func remove(path string) (err error) {
88 var _p0 *byte
89 _p0, err = BytePtrFromString(path)
90 if err != nil {
91 return
92 }
93 r0, _, e1 := Syscall(SYS_REMOVE, uintptr(unsafe.Pointer(_p0)), 0, 0)
94 if int32(r0) == -1 {
95 err = e1
96 }
97 return
98}
99
100// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
101
102func stat(path string, edir []byte) (n int, err error) {
103 var _p0 *byte
104 _p0, err = BytePtrFromString(path)
105 if err != nil {
106 return
107 }
108 var _p1 unsafe.Pointer
109 if len(edir) > 0 {
110 _p1 = unsafe.Pointer(&edir[0])
111 } else {
112 _p1 = unsafe.Pointer(&_zero)
113 }
114 r0, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
115 n = int(r0)
116 if int32(r0) == -1 {
117 err = e1
118 }
119 return
120}
121
122// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
123
124func bind(name string, old string, flag int) (err error) {
125 var _p0 *byte
126 _p0, err = BytePtrFromString(name)
127 if err != nil {
128 return
129 }
130 var _p1 *byte
131 _p1, err = BytePtrFromString(old)
132 if err != nil {
133 return
134 }
135 r0, _, e1 := Syscall(SYS_BIND, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flag))
136 if int32(r0) == -1 {
137 err = e1
138 }
139 return
140}
141
142// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
143
144func mount(fd int, afd int, old string, flag int, aname string) (err error) {
145 var _p0 *byte
146 _p0, err = BytePtrFromString(old)
147 if err != nil {
148 return
149 }
150 var _p1 *byte
151 _p1, err = BytePtrFromString(aname)
152 if err != nil {
153 return
154 }
155 r0, _, e1 := Syscall6(SYS_MOUNT, uintptr(fd), uintptr(afd), uintptr(unsafe.Pointer(_p0)), uintptr(flag), uintptr(unsafe.Pointer(_p1)), 0)
156 if int32(r0) == -1 {
157 err = e1
158 }
159 return
160}
161
162// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
163
164func wstat(path string, edir []byte) (err error) {
165 var _p0 *byte
166 _p0, err = BytePtrFromString(path)
167 if err != nil {
168 return
169 }
170 var _p1 unsafe.Pointer
171 if len(edir) > 0 {
172 _p1 = unsafe.Pointer(&edir[0])
173 } else {
174 _p1 = unsafe.Pointer(&_zero)
175 }
176 r0, _, e1 := Syscall(SYS_WSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
177 if int32(r0) == -1 {
178 err = e1
179 }
180 return
181}
182
183// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
184
185func chdir(path string) (err error) {
186 var _p0 *byte
187 _p0, err = BytePtrFromString(path)
188 if err != nil {
189 return
190 }
191 r0, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0)
192 if int32(r0) == -1 {
193 err = e1
194 }
195 return
196}
197
198// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
199
200func Dup(oldfd int, newfd int) (fd int, err error) {
201 r0, _, e1 := Syscall(SYS_DUP, uintptr(oldfd), uintptr(newfd), 0)
202 fd = int(r0)
203 if int32(r0) == -1 {
204 err = e1
205 }
206 return
207}
208
209// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
210
211func Pread(fd int, p []byte, offset int64) (n int, err error) {
212 var _p0 unsafe.Pointer
213 if len(p) > 0 {
214 _p0 = unsafe.Pointer(&p[0])
215 } else {
216 _p0 = unsafe.Pointer(&_zero)
217 }
218 r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
219 n = int(r0)
220 if int32(r0) == -1 {
221 err = e1
222 }
223 return
224}
225
226// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
227
228func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
229 var _p0 unsafe.Pointer
230 if len(p) > 0 {
231 _p0 = unsafe.Pointer(&p[0])
232 } else {
233 _p0 = unsafe.Pointer(&_zero)
234 }
235 r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
236 n = int(r0)
237 if int32(r0) == -1 {
238 err = e1
239 }
240 return
241}
242
243// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
244
245func Close(fd int) (err error) {
246 r0, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0)
247 if int32(r0) == -1 {
248 err = e1
249 }
250 return
251}
252
253// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
254
255func Fstat(fd int, edir []byte) (n int, err error) {
256 var _p0 unsafe.Pointer
257 if len(edir) > 0 {
258 _p0 = unsafe.Pointer(&edir[0])
259 } else {
260 _p0 = unsafe.Pointer(&_zero)
261 }
262 r0, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
263 n = int(r0)
264 if int32(r0) == -1 {
265 err = e1
266 }
267 return
268}
269
270// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
271
272func Fwstat(fd int, edir []byte) (err error) {
273 var _p0 unsafe.Pointer
274 if len(edir) > 0 {
275 _p0 = unsafe.Pointer(&edir[0])
276 } else {
277 _p0 = unsafe.Pointer(&_zero)
278 }
279 r0, _, e1 := Syscall(SYS_FWSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
280 if int32(r0) == -1 {
281 err = e1
282 }
283 return
284}
vendor/golang.org/x/sys/plan9/zsyscall_plan9_arm.go added +284
@@ -0,0 +1,284 @@
1// go run mksyscall.go -l32 -plan9 -tags plan9,arm syscall_plan9.go
2// Code generated by the command above; see README.md. DO NOT EDIT.
3
4//go:build plan9 && arm
5
6package plan9
7
8import "unsafe"
9
10// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
11
12func fd2path(fd int, buf []byte) (err error) {
13 var _p0 unsafe.Pointer
14 if len(buf) > 0 {
15 _p0 = unsafe.Pointer(&buf[0])
16 } else {
17 _p0 = unsafe.Pointer(&_zero)
18 }
19 r0, _, e1 := Syscall(SYS_FD2PATH, uintptr(fd), uintptr(_p0), uintptr(len(buf)))
20 if int32(r0) == -1 {
21 err = e1
22 }
23 return
24}
25
26// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
27
28func pipe(p *[2]int32) (err error) {
29 r0, _, e1 := Syscall(SYS_PIPE, uintptr(unsafe.Pointer(p)), 0, 0)
30 if int32(r0) == -1 {
31 err = e1
32 }
33 return
34}
35
36// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
37
38func await(s []byte) (n int, err error) {
39 var _p0 unsafe.Pointer
40 if len(s) > 0 {
41 _p0 = unsafe.Pointer(&s[0])
42 } else {
43 _p0 = unsafe.Pointer(&_zero)
44 }
45 r0, _, e1 := Syscall(SYS_AWAIT, uintptr(_p0), uintptr(len(s)), 0)
46 n = int(r0)
47 if int32(r0) == -1 {
48 err = e1
49 }
50 return
51}
52
53// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
54
55func open(path string, mode int) (fd int, err error) {
56 var _p0 *byte
57 _p0, err = BytePtrFromString(path)
58 if err != nil {
59 return
60 }
61 r0, _, e1 := Syscall(SYS_OPEN, uintptr(unsafe.Pointer(_p0)), uintptr(mode), 0)
62 fd = int(r0)
63 if int32(r0) == -1 {
64 err = e1
65 }
66 return
67}
68
69// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
70
71func create(path string, mode int, perm uint32) (fd int, err error) {
72 var _p0 *byte
73 _p0, err = BytePtrFromString(path)
74 if err != nil {
75 return
76 }
77 r0, _, e1 := Syscall(SYS_CREATE, uintptr(unsafe.Pointer(_p0)), uintptr(mode), uintptr(perm))
78 fd = int(r0)
79 if int32(r0) == -1 {
80 err = e1
81 }
82 return
83}
84
85// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
86
87func remove(path string) (err error) {
88 var _p0 *byte
89 _p0, err = BytePtrFromString(path)
90 if err != nil {
91 return
92 }
93 r0, _, e1 := Syscall(SYS_REMOVE, uintptr(unsafe.Pointer(_p0)), 0, 0)
94 if int32(r0) == -1 {
95 err = e1
96 }
97 return
98}
99
100// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
101
102func stat(path string, edir []byte) (n int, err error) {
103 var _p0 *byte
104 _p0, err = BytePtrFromString(path)
105 if err != nil {
106 return
107 }
108 var _p1 unsafe.Pointer
109 if len(edir) > 0 {
110 _p1 = unsafe.Pointer(&edir[0])
111 } else {
112 _p1 = unsafe.Pointer(&_zero)
113 }
114 r0, _, e1 := Syscall(SYS_STAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
115 n = int(r0)
116 if int32(r0) == -1 {
117 err = e1
118 }
119 return
120}
121
122// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
123
124func bind(name string, old string, flag int) (err error) {
125 var _p0 *byte
126 _p0, err = BytePtrFromString(name)
127 if err != nil {
128 return
129 }
130 var _p1 *byte
131 _p1, err = BytePtrFromString(old)
132 if err != nil {
133 return
134 }
135 r0, _, e1 := Syscall(SYS_BIND, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(_p1)), uintptr(flag))
136 if int32(r0) == -1 {
137 err = e1
138 }
139 return
140}
141
142// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
143
144func mount(fd int, afd int, old string, flag int, aname string) (err error) {
145 var _p0 *byte
146 _p0, err = BytePtrFromString(old)
147 if err != nil {
148 return
149 }
150 var _p1 *byte
151 _p1, err = BytePtrFromString(aname)
152 if err != nil {
153 return
154 }
155 r0, _, e1 := Syscall6(SYS_MOUNT, uintptr(fd), uintptr(afd), uintptr(unsafe.Pointer(_p0)), uintptr(flag), uintptr(unsafe.Pointer(_p1)), 0)
156 if int32(r0) == -1 {
157 err = e1
158 }
159 return
160}
161
162// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
163
164func wstat(path string, edir []byte) (err error) {
165 var _p0 *byte
166 _p0, err = BytePtrFromString(path)
167 if err != nil {
168 return
169 }
170 var _p1 unsafe.Pointer
171 if len(edir) > 0 {
172 _p1 = unsafe.Pointer(&edir[0])
173 } else {
174 _p1 = unsafe.Pointer(&_zero)
175 }
176 r0, _, e1 := Syscall(SYS_WSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(_p1), uintptr(len(edir)))
177 if int32(r0) == -1 {
178 err = e1
179 }
180 return
181}
182
183// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
184
185func chdir(path string) (err error) {
186 var _p0 *byte
187 _p0, err = BytePtrFromString(path)
188 if err != nil {
189 return
190 }
191 r0, _, e1 := Syscall(SYS_CHDIR, uintptr(unsafe.Pointer(_p0)), 0, 0)
192 if int32(r0) == -1 {
193 err = e1
194 }
195 return
196}
197
198// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
199
200func Dup(oldfd int, newfd int) (fd int, err error) {
201 r0, _, e1 := Syscall(SYS_DUP, uintptr(oldfd), uintptr(newfd), 0)
202 fd = int(r0)
203 if int32(r0) == -1 {
204 err = e1
205 }
206 return
207}
208
209// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
210
211func Pread(fd int, p []byte, offset int64) (n int, err error) {
212 var _p0 unsafe.Pointer
213 if len(p) > 0 {
214 _p0 = unsafe.Pointer(&p[0])
215 } else {
216 _p0 = unsafe.Pointer(&_zero)
217 }
218 r0, _, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
219 n = int(r0)
220 if int32(r0) == -1 {
221 err = e1
222 }
223 return
224}
225
226// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
227
228func Pwrite(fd int, p []byte, offset int64) (n int, err error) {
229 var _p0 unsafe.Pointer
230 if len(p) > 0 {
231 _p0 = unsafe.Pointer(&p[0])
232 } else {
233 _p0 = unsafe.Pointer(&_zero)
234 }
235 r0, _, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(_p0), uintptr(len(p)), uintptr(offset), uintptr(offset>>32), 0)
236 n = int(r0)
237 if int32(r0) == -1 {
238 err = e1
239 }
240 return
241}
242
243// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
244
245func Close(fd int) (err error) {
246 r0, _, e1 := Syscall(SYS_CLOSE, uintptr(fd), 0, 0)
247 if int32(r0) == -1 {
248 err = e1
249 }
250 return
251}
252
253// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
254
255func Fstat(fd int, edir []byte) (n int, err error) {
256 var _p0 unsafe.Pointer
257 if len(edir) > 0 {
258 _p0 = unsafe.Pointer(&edir[0])
259 } else {
260 _p0 = unsafe.Pointer(&_zero)
261 }
262 r0, _, e1 := Syscall(SYS_FSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
263 n = int(r0)
264 if int32(r0) == -1 {
265 err = e1
266 }
267 return
268}
269
270// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT
271
272func Fwstat(fd int, edir []byte) (err error) {
273 var _p0 unsafe.Pointer
274 if len(edir) > 0 {
275 _p0 = unsafe.Pointer(&edir[0])
276 } else {
277 _p0 = unsafe.Pointer(&_zero)
278 }
279 r0, _, e1 := Syscall(SYS_FWSTAT, uintptr(fd), uintptr(_p0), uintptr(len(edir)))
280 if int32(r0) == -1 {
281 err = e1
282 }
283 return
284}
vendor/golang.org/x/sys/plan9/zsysnum_plan9.go added +49
@@ -0,0 +1,49 @@
1// mksysnum_plan9.sh /opt/plan9/sys/src/libc/9syscall/sys.h
2// MACHINE GENERATED BY THE ABOVE COMMAND; DO NOT EDIT
3
4package plan9
5
6const (
7 SYS_SYSR1 = 0
8 SYS_BIND = 2
9 SYS_CHDIR = 3
10 SYS_CLOSE = 4
11 SYS_DUP = 5
12 SYS_ALARM = 6
13 SYS_EXEC = 7
14 SYS_EXITS = 8
15 SYS_FAUTH = 10
16 SYS_SEGBRK = 12
17 SYS_OPEN = 14
18 SYS_OSEEK = 16
19 SYS_SLEEP = 17
20 SYS_RFORK = 19
21 SYS_PIPE = 21
22 SYS_CREATE = 22
23 SYS_FD2PATH = 23
24 SYS_BRK_ = 24
25 SYS_REMOVE = 25
26 SYS_NOTIFY = 28
27 SYS_NOTED = 29
28 SYS_SEGATTACH = 30
29 SYS_SEGDETACH = 31
30 SYS_SEGFREE = 32
31 SYS_SEGFLUSH = 33
32 SYS_RENDEZVOUS = 34
33 SYS_UNMOUNT = 35
34 SYS_SEMACQUIRE = 37
35 SYS_SEMRELEASE = 38
36 SYS_SEEK = 39
37 SYS_FVERSION = 40
38 SYS_ERRSTR = 41
39 SYS_STAT = 42
40 SYS_FSTAT = 43
41 SYS_WSTAT = 44
42 SYS_FWSTAT = 45
43 SYS_MOUNT = 46
44 SYS_AWAIT = 47
45 SYS_PREAD = 50
46 SYS_PWRITE = 51
47 SYS_TSEMACQUIRE = 52
48 SYS_NSEC = 53
49)
vendor/golang.org/x/sys/unix/.gitignore added +2
@@ -0,0 +1,2 @@
1_obj/
2unix.test
vendor/golang.org/x/term/CONTRIBUTING.md added +26
@@ -0,0 +1,26 @@
1# Contributing to Go
2
3Go is an open source project.
4
5It is the work of hundreds of contributors. We appreciate your help!
6
7## Filing issues
8
9When [filing an issue](https://golang.org/issue/new), make sure to answer these five questions:
10
111. What version of Go are you using (`go version`)?
122. What operating system and processor architecture are you using?
133. What did you do?
144. What did you expect to see?
155. What did you see instead?
16
17General questions should go to the [golang-nuts mailing list](https://groups.google.com/group/golang-nuts) instead of the issue tracker.
18The gophers there will answer or ask you to file an issue if you've tripped over a bug.
19
20## Contributing code
21
22Please read the [Contribution Guidelines](https://golang.org/doc/contribute.html)
23before sending patches.
24
25Unless otherwise noted, the Go source files are distributed under
26the BSD-style license found in the LICENSE file.
vendor/golang.org/x/term/LICENSE added +27
@@ -0,0 +1,27 @@
1Copyright 2009 The Go Authors.
2
3Redistribution and use in source and binary forms, with or without
4modification, are permitted provided that the following conditions are
5met:
6
7 * Redistributions of source code must retain the above copyright
8notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above
10copyright notice, this list of conditions and the following disclaimer
11in the documentation and/or other materials provided with the
12distribution.
13 * Neither the name of Google LLC nor the names of its
14contributors may be used to endorse or promote products derived from
15this software without specific prior written permission.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
vendor/golang.org/x/term/PATENTS added +22
@@ -0,0 +1,22 @@
1Additional IP Rights Grant (Patents)
2
3"This implementation" means the copyrightable works distributed by
4Google as part of the Go project.
5
6Google hereby grants to You a perpetual, worldwide, non-exclusive,
7no-charge, royalty-free, irrevocable (except as stated in this section)
8patent license to make, have made, use, offer to sell, sell, import,
9transfer and otherwise run, modify and propagate the contents of this
10implementation of Go, where such license applies only to those patent
11claims, both currently owned or controlled by Google and acquired in
12the future, licensable by Google that are necessarily infringed by this
13implementation of Go. This grant does not include claims that would be
14infringed only as a consequence of further modification of this
15implementation. If you or your agent or exclusive licensee institute or
16order or agree to the institution of patent litigation against any
17entity (including a cross-claim or counterclaim in a lawsuit) alleging
18that this implementation of Go or any code incorporated within this
19implementation of Go constitutes direct or contributory patent
20infringement, or inducement of patent infringement, then any patent
21rights granted to you under this License for this implementation of Go
22shall terminate as of the date such litigation is filed.
vendor/golang.org/x/term/README.md added +16
@@ -0,0 +1,16 @@
1# Go terminal/console support
2
3[![Go Reference](https://pkg.go.dev/badge/golang.org/x/term.svg)](https://pkg.go.dev/golang.org/x/term)
4
5This repository provides Go terminal and console support packages.
6
7## Report Issues / Send Patches
8
9This repository uses Gerrit for code changes. To learn how to submit changes to
10this repository, see https://go.dev/doc/contribute.
11
12The git repository is https://go.googlesource.com/term.
13
14The main issue tracker for the term repository is located at
15https://go.dev/issues. Prefix your issue with "x/term:" in the
16subject line, so it is easy to find.
vendor/golang.org/x/term/codereview.cfg added +1
@@ -0,0 +1 @@
1issuerepo: golang/go
vendor/golang.org/x/term/term.go added +60
@@ -0,0 +1,60 @@
1// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5// Package term provides support functions for dealing with terminals, as
6// commonly found on UNIX systems.
7//
8// Putting a terminal into raw mode is the most common requirement:
9//
10// oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
11// if err != nil {
12// panic(err)
13// }
14// defer term.Restore(int(os.Stdin.Fd()), oldState)
15//
16// Note that on non-Unix systems os.Stdin.Fd() may not be 0.
17package term
18
19// State contains the state of a terminal.
20type State struct {
21 state
22}
23
24// IsTerminal returns whether the given file descriptor is a terminal.
25func IsTerminal(fd int) bool {
26 return isTerminal(fd)
27}
28
29// MakeRaw puts the terminal connected to the given file descriptor into raw
30// mode and returns the previous state of the terminal so that it can be
31// restored.
32func MakeRaw(fd int) (*State, error) {
33 return makeRaw(fd)
34}
35
36// GetState returns the current state of a terminal which may be useful to
37// restore the terminal after a signal.
38func GetState(fd int) (*State, error) {
39 return getState(fd)
40}
41
42// Restore restores the terminal connected to the given file descriptor to a
43// previous state.
44func Restore(fd int, oldState *State) error {
45 return restore(fd, oldState)
46}
47
48// GetSize returns the visible dimensions of the given terminal.
49//
50// These dimensions don't include any scrollback buffer height.
51func GetSize(fd int) (width, height int, err error) {
52 return getSize(fd)
53}
54
55// ReadPassword reads a line of input from a terminal without local echo. This
56// is commonly used for inputting passwords and other sensitive data. The slice
57// returned does not include the \n.
58func ReadPassword(fd int) ([]byte, error) {
59 return readPassword(fd)
60}
vendor/golang.org/x/term/term_plan9.go added +42
@@ -0,0 +1,42 @@
1// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package term
6
7import (
8 "fmt"
9 "runtime"
10
11 "golang.org/x/sys/plan9"
12)
13
14type state struct{}
15
16func isTerminal(fd int) bool {
17 path, err := plan9.Fd2path(fd)
18 if err != nil {
19 return false
20 }
21 return path == "/dev/cons" || path == "/mnt/term/dev/cons"
22}
23
24func makeRaw(fd int) (*State, error) {
25 return nil, fmt.Errorf("terminal: MakeRaw not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
26}
27
28func getState(fd int) (*State, error) {
29 return nil, fmt.Errorf("terminal: GetState not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
30}
31
32func restore(fd int, state *State) error {
33 return fmt.Errorf("terminal: Restore not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
34}
35
36func getSize(fd int) (width, height int, err error) {
37 return 0, 0, fmt.Errorf("terminal: GetSize not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
38}
39
40func readPassword(fd int) ([]byte, error) {
41 return nil, fmt.Errorf("terminal: ReadPassword not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
42}
vendor/golang.org/x/term/term_unix.go added +91
@@ -0,0 +1,91 @@
1// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris || zos
6
7package term
8
9import (
10 "golang.org/x/sys/unix"
11)
12
13type state struct {
14 termios unix.Termios
15}
16
17func isTerminal(fd int) bool {
18 _, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
19 return err == nil
20}
21
22func makeRaw(fd int) (*State, error) {
23 termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
24 if err != nil {
25 return nil, err
26 }
27
28 oldState := State{state{termios: *termios}}
29
30 // This attempts to replicate the behaviour documented for cfmakeraw in
31 // the termios(3) manpage.
32 termios.Iflag &^= unix.IGNBRK | unix.BRKINT | unix.PARMRK | unix.ISTRIP | unix.INLCR | unix.IGNCR | unix.ICRNL | unix.IXON
33 termios.Oflag &^= unix.OPOST
34 termios.Lflag &^= unix.ECHO | unix.ECHONL | unix.ICANON | unix.ISIG | unix.IEXTEN
35 termios.Cflag &^= unix.CSIZE | unix.PARENB
36 termios.Cflag |= unix.CS8
37 termios.Cc[unix.VMIN] = 1
38 termios.Cc[unix.VTIME] = 0
39 if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, termios); err != nil {
40 return nil, err
41 }
42
43 return &oldState, nil
44}
45
46func getState(fd int) (*State, error) {
47 termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
48 if err != nil {
49 return nil, err
50 }
51
52 return &State{state{termios: *termios}}, nil
53}
54
55func restore(fd int, state *State) error {
56 return unix.IoctlSetTermios(fd, ioctlWriteTermios, &state.termios)
57}
58
59func getSize(fd int) (width, height int, err error) {
60 ws, err := unix.IoctlGetWinsize(fd, unix.TIOCGWINSZ)
61 if err != nil {
62 return 0, 0, err
63 }
64 return int(ws.Col), int(ws.Row), nil
65}
66
67// passwordReader is an io.Reader that reads from a specific file descriptor.
68type passwordReader int
69
70func (r passwordReader) Read(buf []byte) (int, error) {
71 return unix.Read(int(r), buf)
72}
73
74func readPassword(fd int) ([]byte, error) {
75 termios, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
76 if err != nil {
77 return nil, err
78 }
79
80 newState := *termios
81 newState.Lflag &^= unix.ECHO
82 newState.Lflag |= unix.ICANON | unix.ISIG
83 newState.Iflag |= unix.ICRNL
84 if err := unix.IoctlSetTermios(fd, ioctlWriteTermios, &newState); err != nil {
85 return nil, err
86 }
87
88 defer unix.IoctlSetTermios(fd, ioctlWriteTermios, termios)
89
90 return readPasswordLine(passwordReader(fd))
91}
vendor/golang.org/x/term/term_unix_bsd.go added +12
@@ -0,0 +1,12 @@
1// Copyright 2013 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build darwin || dragonfly || freebsd || netbsd || openbsd
6
7package term
8
9import "golang.org/x/sys/unix"
10
11const ioctlReadTermios = unix.TIOCGETA
12const ioctlWriteTermios = unix.TIOCSETA
vendor/golang.org/x/term/term_unix_other.go added +12
@@ -0,0 +1,12 @@
1// Copyright 2021 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build aix || linux || solaris || zos
6
7package term
8
9import "golang.org/x/sys/unix"
10
11const ioctlReadTermios = unix.TCGETS
12const ioctlWriteTermios = unix.TCSETS
vendor/golang.org/x/term/term_unsupported.go added +38
@@ -0,0 +1,38 @@
1// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build !aix && !darwin && !dragonfly && !freebsd && !linux && !netbsd && !openbsd && !zos && !windows && !solaris && !plan9
6
7package term
8
9import (
10 "fmt"
11 "runtime"
12)
13
14type state struct{}
15
16func isTerminal(fd int) bool {
17 return false
18}
19
20func makeRaw(fd int) (*State, error) {
21 return nil, fmt.Errorf("terminal: MakeRaw not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
22}
23
24func getState(fd int) (*State, error) {
25 return nil, fmt.Errorf("terminal: GetState not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
26}
27
28func restore(fd int, state *State) error {
29 return fmt.Errorf("terminal: Restore not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
30}
31
32func getSize(fd int) (width, height int, err error) {
33 return 0, 0, fmt.Errorf("terminal: GetSize not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
34}
35
36func readPassword(fd int) ([]byte, error) {
37 return nil, fmt.Errorf("terminal: ReadPassword not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
38}
vendor/golang.org/x/term/term_windows.go added +80
@@ -0,0 +1,80 @@
1// Copyright 2019 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package term
6
7import (
8 "os"
9
10 "golang.org/x/sys/windows"
11)
12
13type state struct {
14 mode uint32
15}
16
17func isTerminal(fd int) bool {
18 var st uint32
19 err := windows.GetConsoleMode(windows.Handle(fd), &st)
20 return err == nil
21}
22
23func makeRaw(fd int) (*State, error) {
24 var st uint32
25 if err := windows.GetConsoleMode(windows.Handle(fd), &st); err != nil {
26 return nil, err
27 }
28 raw := st &^ (windows.ENABLE_ECHO_INPUT | windows.ENABLE_PROCESSED_INPUT | windows.ENABLE_LINE_INPUT | windows.ENABLE_PROCESSED_OUTPUT)
29 raw |= windows.ENABLE_VIRTUAL_TERMINAL_INPUT
30 if err := windows.SetConsoleMode(windows.Handle(fd), raw); err != nil {
31 return nil, err
32 }
33 return &State{state{st}}, nil
34}
35
36func getState(fd int) (*State, error) {
37 var st uint32
38 if err := windows.GetConsoleMode(windows.Handle(fd), &st); err != nil {
39 return nil, err
40 }
41 return &State{state{st}}, nil
42}
43
44func restore(fd int, state *State) error {
45 return windows.SetConsoleMode(windows.Handle(fd), state.mode)
46}
47
48func getSize(fd int) (width, height int, err error) {
49 var info windows.ConsoleScreenBufferInfo
50 if err := windows.GetConsoleScreenBufferInfo(windows.Handle(fd), &info); err != nil {
51 return 0, 0, err
52 }
53 return int(info.Window.Right - info.Window.Left + 1), int(info.Window.Bottom - info.Window.Top + 1), nil
54}
55
56func readPassword(fd int) ([]byte, error) {
57 var st uint32
58 if err := windows.GetConsoleMode(windows.Handle(fd), &st); err != nil {
59 return nil, err
60 }
61 old := st
62
63 st &^= (windows.ENABLE_ECHO_INPUT | windows.ENABLE_LINE_INPUT)
64 st |= (windows.ENABLE_PROCESSED_OUTPUT | windows.ENABLE_PROCESSED_INPUT)
65 if err := windows.SetConsoleMode(windows.Handle(fd), st); err != nil {
66 return nil, err
67 }
68
69 defer windows.SetConsoleMode(windows.Handle(fd), old)
70
71 var h windows.Handle
72 p, _ := windows.GetCurrentProcess()
73 if err := windows.DuplicateHandle(p, windows.Handle(fd), p, &h, 0, false, windows.DUPLICATE_SAME_ACCESS); err != nil {
74 return nil, err
75 }
76
77 f := os.NewFile(uintptr(h), "stdin")
78 defer f.Close()
79 return readPasswordLine(f)
80}
vendor/golang.org/x/term/terminal.go added +986
@@ -0,0 +1,986 @@
1// Copyright 2011 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package term
6
7import (
8 "bytes"
9 "io"
10 "runtime"
11 "strconv"
12 "sync"
13 "unicode/utf8"
14)
15
16// EscapeCodes contains escape sequences that can be written to the terminal in
17// order to achieve different styles of text.
18type EscapeCodes struct {
19 // Foreground colors
20 Black, Red, Green, Yellow, Blue, Magenta, Cyan, White []byte
21
22 // Reset all attributes
23 Reset []byte
24}
25
26var vt100EscapeCodes = EscapeCodes{
27 Black: []byte{keyEscape, '[', '3', '0', 'm'},
28 Red: []byte{keyEscape, '[', '3', '1', 'm'},
29 Green: []byte{keyEscape, '[', '3', '2', 'm'},
30 Yellow: []byte{keyEscape, '[', '3', '3', 'm'},
31 Blue: []byte{keyEscape, '[', '3', '4', 'm'},
32 Magenta: []byte{keyEscape, '[', '3', '5', 'm'},
33 Cyan: []byte{keyEscape, '[', '3', '6', 'm'},
34 White: []byte{keyEscape, '[', '3', '7', 'm'},
35
36 Reset: []byte{keyEscape, '[', '0', 'm'},
37}
38
39// Terminal contains the state for running a VT100 terminal that is capable of
40// reading lines of input.
41type Terminal struct {
42 // AutoCompleteCallback, if non-null, is called for each keypress with
43 // the full input line and the current position of the cursor (in
44 // bytes, as an index into |line|). If it returns ok=false, the key
45 // press is processed normally. Otherwise it returns a replacement line
46 // and the new cursor position.
47 AutoCompleteCallback func(line string, pos int, key rune) (newLine string, newPos int, ok bool)
48
49 // Escape contains a pointer to the escape codes for this terminal.
50 // It's always a valid pointer, although the escape codes themselves
51 // may be empty if the terminal doesn't support them.
52 Escape *EscapeCodes
53
54 // lock protects the terminal and the state in this object from
55 // concurrent processing of a key press and a Write() call.
56 lock sync.Mutex
57
58 c io.ReadWriter
59 prompt []rune
60
61 // line is the current line being entered.
62 line []rune
63 // pos is the logical position of the cursor in line
64 pos int
65 // echo is true if local echo is enabled
66 echo bool
67 // pasteActive is true iff there is a bracketed paste operation in
68 // progress.
69 pasteActive bool
70
71 // cursorX contains the current X value of the cursor where the left
72 // edge is 0. cursorY contains the row number where the first row of
73 // the current line is 0.
74 cursorX, cursorY int
75 // maxLine is the greatest value of cursorY so far.
76 maxLine int
77
78 termWidth, termHeight int
79
80 // outBuf contains the terminal data to be sent.
81 outBuf []byte
82 // remainder contains the remainder of any partial key sequences after
83 // a read. It aliases into inBuf.
84 remainder []byte
85 inBuf [256]byte
86
87 // history contains previously entered commands so that they can be
88 // accessed with the up and down keys.
89 history stRingBuffer
90 // historyIndex stores the currently accessed history entry, where zero
91 // means the immediately previous entry.
92 historyIndex int
93 // When navigating up and down the history it's possible to return to
94 // the incomplete, initial line. That value is stored in
95 // historyPending.
96 historyPending string
97}
98
99// NewTerminal runs a VT100 terminal on the given ReadWriter. If the ReadWriter is
100// a local terminal, that terminal must first have been put into raw mode.
101// prompt is a string that is written at the start of each input line (i.e.
102// "> ").
103func NewTerminal(c io.ReadWriter, prompt string) *Terminal {
104 return &Terminal{
105 Escape: &vt100EscapeCodes,
106 c: c,
107 prompt: []rune(prompt),
108 termWidth: 80,
109 termHeight: 24,
110 echo: true,
111 historyIndex: -1,
112 }
113}
114
115const (
116 keyCtrlC = 3
117 keyCtrlD = 4
118 keyCtrlU = 21
119 keyEnter = '\r'
120 keyEscape = 27
121 keyBackspace = 127
122 keyUnknown = 0xd800 /* UTF-16 surrogate area */ + iota
123 keyUp
124 keyDown
125 keyLeft
126 keyRight
127 keyAltLeft
128 keyAltRight
129 keyHome
130 keyEnd
131 keyDeleteWord
132 keyDeleteLine
133 keyClearScreen
134 keyPasteStart
135 keyPasteEnd
136)
137
138var (
139 crlf = []byte{'\r', '\n'}
140 pasteStart = []byte{keyEscape, '[', '2', '0', '0', '~'}
141 pasteEnd = []byte{keyEscape, '[', '2', '0', '1', '~'}
142)
143
144// bytesToKey tries to parse a key sequence from b. If successful, it returns
145// the key and the remainder of the input. Otherwise it returns utf8.RuneError.
146func bytesToKey(b []byte, pasteActive bool) (rune, []byte) {
147 if len(b) == 0 {
148 return utf8.RuneError, nil
149 }
150
151 if !pasteActive {
152 switch b[0] {
153 case 1: // ^A
154 return keyHome, b[1:]
155 case 2: // ^B
156 return keyLeft, b[1:]
157 case 5: // ^E
158 return keyEnd, b[1:]
159 case 6: // ^F
160 return keyRight, b[1:]
161 case 8: // ^H
162 return keyBackspace, b[1:]
163 case 11: // ^K
164 return keyDeleteLine, b[1:]
165 case 12: // ^L
166 return keyClearScreen, b[1:]
167 case 23: // ^W
168 return keyDeleteWord, b[1:]
169 case 14: // ^N
170 return keyDown, b[1:]
171 case 16: // ^P
172 return keyUp, b[1:]
173 }
174 }
175
176 if b[0] != keyEscape {
177 if !utf8.FullRune(b) {
178 return utf8.RuneError, b
179 }
180 r, l := utf8.DecodeRune(b)
181 return r, b[l:]
182 }
183
184 if !pasteActive && len(b) >= 3 && b[0] == keyEscape && b[1] == '[' {
185 switch b[2] {
186 case 'A':
187 return keyUp, b[3:]
188 case 'B':
189 return keyDown, b[3:]
190 case 'C':
191 return keyRight, b[3:]
192 case 'D':
193 return keyLeft, b[3:]
194 case 'H':
195 return keyHome, b[3:]
196 case 'F':
197 return keyEnd, b[3:]
198 }
199 }
200
201 if !pasteActive && len(b) >= 6 && b[0] == keyEscape && b[1] == '[' && b[2] == '1' && b[3] == ';' && b[4] == '3' {
202 switch b[5] {
203 case 'C':
204 return keyAltRight, b[6:]
205 case 'D':
206 return keyAltLeft, b[6:]
207 }
208 }
209
210 if !pasteActive && len(b) >= 6 && bytes.Equal(b[:6], pasteStart) {
211 return keyPasteStart, b[6:]
212 }
213
214 if pasteActive && len(b) >= 6 && bytes.Equal(b[:6], pasteEnd) {
215 return keyPasteEnd, b[6:]
216 }
217
218 // If we get here then we have a key that we don't recognise, or a
219 // partial sequence. It's not clear how one should find the end of a
220 // sequence without knowing them all, but it seems that [a-zA-Z~] only
221 // appears at the end of a sequence.
222 for i, c := range b[0:] {
223 if c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '~' {
224 return keyUnknown, b[i+1:]
225 }
226 }
227
228 return utf8.RuneError, b
229}
230
231// queue appends data to the end of t.outBuf
232func (t *Terminal) queue(data []rune) {
233 t.outBuf = append(t.outBuf, []byte(string(data))...)
234}
235
236var space = []rune{' '}
237
238func isPrintable(key rune) bool {
239 isInSurrogateArea := key >= 0xd800 && key <= 0xdbff
240 return key >= 32 && !isInSurrogateArea
241}
242
243// moveCursorToPos appends data to t.outBuf which will move the cursor to the
244// given, logical position in the text.
245func (t *Terminal) moveCursorToPos(pos int) {
246 if !t.echo {
247 return
248 }
249
250 x := visualLength(t.prompt) + pos
251 y := x / t.termWidth
252 x = x % t.termWidth
253
254 up := 0
255 if y < t.cursorY {
256 up = t.cursorY - y
257 }
258
259 down := 0
260 if y > t.cursorY {
261 down = y - t.cursorY
262 }
263
264 left := 0
265 if x < t.cursorX {
266 left = t.cursorX - x
267 }
268
269 right := 0
270 if x > t.cursorX {
271 right = x - t.cursorX
272 }
273
274 t.cursorX = x
275 t.cursorY = y
276 t.move(up, down, left, right)
277}
278
279func (t *Terminal) move(up, down, left, right int) {
280 m := []rune{}
281
282 // 1 unit up can be expressed as ^[[A or ^[A
283 // 5 units up can be expressed as ^[[5A
284
285 if up == 1 {
286 m = append(m, keyEscape, '[', 'A')
287 } else if up > 1 {
288 m = append(m, keyEscape, '[')
289 m = append(m, []rune(strconv.Itoa(up))...)
290 m = append(m, 'A')
291 }
292
293 if down == 1 {
294 m = append(m, keyEscape, '[', 'B')
295 } else if down > 1 {
296 m = append(m, keyEscape, '[')
297 m = append(m, []rune(strconv.Itoa(down))...)
298 m = append(m, 'B')
299 }
300
301 if right == 1 {
302 m = append(m, keyEscape, '[', 'C')
303 } else if right > 1 {
304 m = append(m, keyEscape, '[')
305 m = append(m, []rune(strconv.Itoa(right))...)
306 m = append(m, 'C')
307 }
308
309 if left == 1 {
310 m = append(m, keyEscape, '[', 'D')
311 } else if left > 1 {
312 m = append(m, keyEscape, '[')
313 m = append(m, []rune(strconv.Itoa(left))...)
314 m = append(m, 'D')
315 }
316
317 t.queue(m)
318}
319
320func (t *Terminal) clearLineToRight() {
321 op := []rune{keyEscape, '[', 'K'}
322 t.queue(op)
323}
324
325const maxLineLength = 4096
326
327func (t *Terminal) setLine(newLine []rune, newPos int) {
328 if t.echo {
329 t.moveCursorToPos(0)
330 t.writeLine(newLine)
331 for i := len(newLine); i < len(t.line); i++ {
332 t.writeLine(space)
333 }
334 t.moveCursorToPos(newPos)
335 }
336 t.line = newLine
337 t.pos = newPos
338}
339
340func (t *Terminal) advanceCursor(places int) {
341 t.cursorX += places
342 t.cursorY += t.cursorX / t.termWidth
343 if t.cursorY > t.maxLine {
344 t.maxLine = t.cursorY
345 }
346 t.cursorX = t.cursorX % t.termWidth
347
348 if places > 0 && t.cursorX == 0 {
349 // Normally terminals will advance the current position
350 // when writing a character. But that doesn't happen
351 // for the last character in a line. However, when
352 // writing a character (except a new line) that causes
353 // a line wrap, the position will be advanced two
354 // places.
355 //
356 // So, if we are stopping at the end of a line, we
357 // need to write a newline so that our cursor can be
358 // advanced to the next line.
359 t.outBuf = append(t.outBuf, '\r', '\n')
360 }
361}
362
363func (t *Terminal) eraseNPreviousChars(n int) {
364 if n == 0 {
365 return
366 }
367
368 if t.pos < n {
369 n = t.pos
370 }
371 t.pos -= n
372 t.moveCursorToPos(t.pos)
373
374 copy(t.line[t.pos:], t.line[n+t.pos:])
375 t.line = t.line[:len(t.line)-n]
376 if t.echo {
377 t.writeLine(t.line[t.pos:])
378 for i := 0; i < n; i++ {
379 t.queue(space)
380 }
381 t.advanceCursor(n)
382 t.moveCursorToPos(t.pos)
383 }
384}
385
386// countToLeftWord returns then number of characters from the cursor to the
387// start of the previous word.
388func (t *Terminal) countToLeftWord() int {
389 if t.pos == 0 {
390 return 0
391 }
392
393 pos := t.pos - 1
394 for pos > 0 {
395 if t.line[pos] != ' ' {
396 break
397 }
398 pos--
399 }
400 for pos > 0 {
401 if t.line[pos] == ' ' {
402 pos++
403 break
404 }
405 pos--
406 }
407
408 return t.pos - pos
409}
410
411// countToRightWord returns then number of characters from the cursor to the
412// start of the next word.
413func (t *Terminal) countToRightWord() int {
414 pos := t.pos
415 for pos < len(t.line) {
416 if t.line[pos] == ' ' {
417 break
418 }
419 pos++
420 }
421 for pos < len(t.line) {
422 if t.line[pos] != ' ' {
423 break
424 }
425 pos++
426 }
427 return pos - t.pos
428}
429
430// visualLength returns the number of visible glyphs in s.
431func visualLength(runes []rune) int {
432 inEscapeSeq := false
433 length := 0
434
435 for _, r := range runes {
436 switch {
437 case inEscapeSeq:
438 if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') {
439 inEscapeSeq = false
440 }
441 case r == '\x1b':
442 inEscapeSeq = true
443 default:
444 length++
445 }
446 }
447
448 return length
449}
450
451// handleKey processes the given key and, optionally, returns a line of text
452// that the user has entered.
453func (t *Terminal) handleKey(key rune) (line string, ok bool) {
454 if t.pasteActive && key != keyEnter {
455 t.addKeyToLine(key)
456 return
457 }
458
459 switch key {
460 case keyBackspace:
461 if t.pos == 0 {
462 return
463 }
464 t.eraseNPreviousChars(1)
465 case keyAltLeft:
466 // move left by a word.
467 t.pos -= t.countToLeftWord()
468 t.moveCursorToPos(t.pos)
469 case keyAltRight:
470 // move right by a word.
471 t.pos += t.countToRightWord()
472 t.moveCursorToPos(t.pos)
473 case keyLeft:
474 if t.pos == 0 {
475 return
476 }
477 t.pos--
478 t.moveCursorToPos(t.pos)
479 case keyRight:
480 if t.pos == len(t.line) {
481 return
482 }
483 t.pos++
484 t.moveCursorToPos(t.pos)
485 case keyHome:
486 if t.pos == 0 {
487 return
488 }
489 t.pos = 0
490 t.moveCursorToPos(t.pos)
491 case keyEnd:
492 if t.pos == len(t.line) {
493 return
494 }
495 t.pos = len(t.line)
496 t.moveCursorToPos(t.pos)
497 case keyUp:
498 entry, ok := t.history.NthPreviousEntry(t.historyIndex + 1)
499 if !ok {
500 return "", false
501 }
502 if t.historyIndex == -1 {
503 t.historyPending = string(t.line)
504 }
505 t.historyIndex++
506 runes := []rune(entry)
507 t.setLine(runes, len(runes))
508 case keyDown:
509 switch t.historyIndex {
510 case -1:
511 return
512 case 0:
513 runes := []rune(t.historyPending)
514 t.setLine(runes, len(runes))
515 t.historyIndex--
516 default:
517 entry, ok := t.history.NthPreviousEntry(t.historyIndex - 1)
518 if ok {
519 t.historyIndex--
520 runes := []rune(entry)
521 t.setLine(runes, len(runes))
522 }
523 }
524 case keyEnter:
525 t.moveCursorToPos(len(t.line))
526 t.queue([]rune("\r\n"))
527 line = string(t.line)
528 ok = true
529 t.line = t.line[:0]
530 t.pos = 0
531 t.cursorX = 0
532 t.cursorY = 0
533 t.maxLine = 0
534 case keyDeleteWord:
535 // Delete zero or more spaces and then one or more characters.
536 t.eraseNPreviousChars(t.countToLeftWord())
537 case keyDeleteLine:
538 // Delete everything from the current cursor position to the
539 // end of line.
540 for i := t.pos; i < len(t.line); i++ {
541 t.queue(space)
542 t.advanceCursor(1)
543 }
544 t.line = t.line[:t.pos]
545 t.moveCursorToPos(t.pos)
546 case keyCtrlD:
547 // Erase the character under the current position.
548 // The EOF case when the line is empty is handled in
549 // readLine().
550 if t.pos < len(t.line) {
551 t.pos++
552 t.eraseNPreviousChars(1)
553 }
554 case keyCtrlU:
555 t.eraseNPreviousChars(t.pos)
556 case keyClearScreen:
557 // Erases the screen and moves the cursor to the home position.
558 t.queue([]rune("\x1b[2J\x1b[H"))
559 t.queue(t.prompt)
560 t.cursorX, t.cursorY = 0, 0
561 t.advanceCursor(visualLength(t.prompt))
562 t.setLine(t.line, t.pos)
563 default:
564 if t.AutoCompleteCallback != nil {
565 prefix := string(t.line[:t.pos])
566 suffix := string(t.line[t.pos:])
567
568 t.lock.Unlock()
569 newLine, newPos, completeOk := t.AutoCompleteCallback(prefix+suffix, len(prefix), key)
570 t.lock.Lock()
571
572 if completeOk {
573 t.setLine([]rune(newLine), utf8.RuneCount([]byte(newLine)[:newPos]))
574 return
575 }
576 }
577 if !isPrintable(key) {
578 return
579 }
580 if len(t.line) == maxLineLength {
581 return
582 }
583 t.addKeyToLine(key)
584 }
585 return
586}
587
588// addKeyToLine inserts the given key at the current position in the current
589// line.
590func (t *Terminal) addKeyToLine(key rune) {
591 if len(t.line) == cap(t.line) {
592 newLine := make([]rune, len(t.line), 2*(1+len(t.line)))
593 copy(newLine, t.line)
594 t.line = newLine
595 }
596 t.line = t.line[:len(t.line)+1]
597 copy(t.line[t.pos+1:], t.line[t.pos:])
598 t.line[t.pos] = key
599 if t.echo {
600 t.writeLine(t.line[t.pos:])
601 }
602 t.pos++
603 t.moveCursorToPos(t.pos)
604}
605
606func (t *Terminal) writeLine(line []rune) {
607 for len(line) != 0 {
608 remainingOnLine := t.termWidth - t.cursorX
609 todo := len(line)
610 if todo > remainingOnLine {
611 todo = remainingOnLine
612 }
613 t.queue(line[:todo])
614 t.advanceCursor(visualLength(line[:todo]))
615 line = line[todo:]
616 }
617}
618
619// writeWithCRLF writes buf to w but replaces all occurrences of \n with \r\n.
620func writeWithCRLF(w io.Writer, buf []byte) (n int, err error) {
621 for len(buf) > 0 {
622 i := bytes.IndexByte(buf, '\n')
623 todo := len(buf)
624 if i >= 0 {
625 todo = i
626 }
627
628 var nn int
629 nn, err = w.Write(buf[:todo])
630 n += nn
631 if err != nil {
632 return n, err
633 }
634 buf = buf[todo:]
635
636 if i >= 0 {
637 if _, err = w.Write(crlf); err != nil {
638 return n, err
639 }
640 n++
641 buf = buf[1:]
642 }
643 }
644
645 return n, nil
646}
647
648func (t *Terminal) Write(buf []byte) (n int, err error) {
649 t.lock.Lock()
650 defer t.lock.Unlock()
651
652 if t.cursorX == 0 && t.cursorY == 0 {
653 // This is the easy case: there's nothing on the screen that we
654 // have to move out of the way.
655 return writeWithCRLF(t.c, buf)
656 }
657
658 // We have a prompt and possibly user input on the screen. We
659 // have to clear it first.
660 t.move(0 /* up */, 0 /* down */, t.cursorX /* left */, 0 /* right */)
661 t.cursorX = 0
662 t.clearLineToRight()
663
664 for t.cursorY > 0 {
665 t.move(1 /* up */, 0, 0, 0)
666 t.cursorY--
667 t.clearLineToRight()
668 }
669
670 if _, err = t.c.Write(t.outBuf); err != nil {
671 return
672 }
673 t.outBuf = t.outBuf[:0]
674
675 if n, err = writeWithCRLF(t.c, buf); err != nil {
676 return
677 }
678
679 t.writeLine(t.prompt)
680 if t.echo {
681 t.writeLine(t.line)
682 }
683
684 t.moveCursorToPos(t.pos)
685
686 if _, err = t.c.Write(t.outBuf); err != nil {
687 return
688 }
689 t.outBuf = t.outBuf[:0]
690 return
691}
692
693// ReadPassword temporarily changes the prompt and reads a password, without
694// echo, from the terminal.
695func (t *Terminal) ReadPassword(prompt string) (line string, err error) {
696 t.lock.Lock()
697 defer t.lock.Unlock()
698
699 oldPrompt := t.prompt
700 t.prompt = []rune(prompt)
701 t.echo = false
702
703 line, err = t.readLine()
704
705 t.prompt = oldPrompt
706 t.echo = true
707
708 return
709}
710
711// ReadLine returns a line of input from the terminal.
712func (t *Terminal) ReadLine() (line string, err error) {
713 t.lock.Lock()
714 defer t.lock.Unlock()
715
716 return t.readLine()
717}
718
719func (t *Terminal) readLine() (line string, err error) {
720 // t.lock must be held at this point
721
722 if t.cursorX == 0 && t.cursorY == 0 {
723 t.writeLine(t.prompt)
724 t.c.Write(t.outBuf)
725 t.outBuf = t.outBuf[:0]
726 }
727
728 lineIsPasted := t.pasteActive
729
730 for {
731 rest := t.remainder
732 lineOk := false
733 for !lineOk {
734 var key rune
735 key, rest = bytesToKey(rest, t.pasteActive)
736 if key == utf8.RuneError {
737 break
738 }
739 if !t.pasteActive {
740 if key == keyCtrlD {
741 if len(t.line) == 0 {
742 return "", io.EOF
743 }
744 }
745 if key == keyCtrlC {
746 return "", io.EOF
747 }
748 if key == keyPasteStart {
749 t.pasteActive = true
750 if len(t.line) == 0 {
751 lineIsPasted = true
752 }
753 continue
754 }
755 } else if key == keyPasteEnd {
756 t.pasteActive = false
757 continue
758 }
759 if !t.pasteActive {
760 lineIsPasted = false
761 }
762 line, lineOk = t.handleKey(key)
763 }
764 if len(rest) > 0 {
765 n := copy(t.inBuf[:], rest)
766 t.remainder = t.inBuf[:n]
767 } else {
768 t.remainder = nil
769 }
770 t.c.Write(t.outBuf)
771 t.outBuf = t.outBuf[:0]
772 if lineOk {
773 if t.echo {
774 t.historyIndex = -1
775 t.history.Add(line)
776 }
777 if lineIsPasted {
778 err = ErrPasteIndicator
779 }
780 return
781 }
782
783 // t.remainder is a slice at the beginning of t.inBuf
784 // containing a partial key sequence
785 readBuf := t.inBuf[len(t.remainder):]
786 var n int
787
788 t.lock.Unlock()
789 n, err = t.c.Read(readBuf)
790 t.lock.Lock()
791
792 if err != nil {
793 return
794 }
795
796 t.remainder = t.inBuf[:n+len(t.remainder)]
797 }
798}
799
800// SetPrompt sets the prompt to be used when reading subsequent lines.
801func (t *Terminal) SetPrompt(prompt string) {
802 t.lock.Lock()
803 defer t.lock.Unlock()
804
805 t.prompt = []rune(prompt)
806}
807
808func (t *Terminal) clearAndRepaintLinePlusNPrevious(numPrevLines int) {
809 // Move cursor to column zero at the start of the line.
810 t.move(t.cursorY, 0, t.cursorX, 0)
811 t.cursorX, t.cursorY = 0, 0
812 t.clearLineToRight()
813 for t.cursorY < numPrevLines {
814 // Move down a line
815 t.move(0, 1, 0, 0)
816 t.cursorY++
817 t.clearLineToRight()
818 }
819 // Move back to beginning.
820 t.move(t.cursorY, 0, 0, 0)
821 t.cursorX, t.cursorY = 0, 0
822
823 t.queue(t.prompt)
824 t.advanceCursor(visualLength(t.prompt))
825 t.writeLine(t.line)
826 t.moveCursorToPos(t.pos)
827}
828
829func (t *Terminal) SetSize(width, height int) error {
830 t.lock.Lock()
831 defer t.lock.Unlock()
832
833 if width == 0 {
834 width = 1
835 }
836
837 oldWidth := t.termWidth
838 t.termWidth, t.termHeight = width, height
839
840 switch {
841 case width == oldWidth:
842 // If the width didn't change then nothing else needs to be
843 // done.
844 return nil
845 case len(t.line) == 0 && t.cursorX == 0 && t.cursorY == 0:
846 // If there is nothing on current line and no prompt printed,
847 // just do nothing
848 return nil
849 case width < oldWidth:
850 // Some terminals (e.g. xterm) will truncate lines that were
851 // too long when shinking. Others, (e.g. gnome-terminal) will
852 // attempt to wrap them. For the former, repainting t.maxLine
853 // works great, but that behaviour goes badly wrong in the case
854 // of the latter because they have doubled every full line.
855
856 // We assume that we are working on a terminal that wraps lines
857 // and adjust the cursor position based on every previous line
858 // wrapping and turning into two. This causes the prompt on
859 // xterms to move upwards, which isn't great, but it avoids a
860 // huge mess with gnome-terminal.
861 if t.cursorX >= t.termWidth {
862 t.cursorX = t.termWidth - 1
863 }
864 t.cursorY *= 2
865 t.clearAndRepaintLinePlusNPrevious(t.maxLine * 2)
866 case width > oldWidth:
867 // If the terminal expands then our position calculations will
868 // be wrong in the future because we think the cursor is
869 // |t.pos| chars into the string, but there will be a gap at
870 // the end of any wrapped line.
871 //
872 // But the position will actually be correct until we move, so
873 // we can move back to the beginning and repaint everything.
874 t.clearAndRepaintLinePlusNPrevious(t.maxLine)
875 }
876
877 _, err := t.c.Write(t.outBuf)
878 t.outBuf = t.outBuf[:0]
879 return err
880}
881
882type pasteIndicatorError struct{}
883
884func (pasteIndicatorError) Error() string {
885 return "terminal: ErrPasteIndicator not correctly handled"
886}
887
888// ErrPasteIndicator may be returned from ReadLine as the error, in addition
889// to valid line data. It indicates that bracketed paste mode is enabled and
890// that the returned line consists only of pasted data. Programs may wish to
891// interpret pasted data more literally than typed data.
892var ErrPasteIndicator = pasteIndicatorError{}
893
894// SetBracketedPasteMode requests that the terminal bracket paste operations
895// with markers. Not all terminals support this but, if it is supported, then
896// enabling this mode will stop any autocomplete callback from running due to
897// pastes. Additionally, any lines that are completely pasted will be returned
898// from ReadLine with the error set to ErrPasteIndicator.
899func (t *Terminal) SetBracketedPasteMode(on bool) {
900 if on {
901 io.WriteString(t.c, "\x1b[?2004h")
902 } else {
903 io.WriteString(t.c, "\x1b[?2004l")
904 }
905}
906
907// stRingBuffer is a ring buffer of strings.
908type stRingBuffer struct {
909 // entries contains max elements.
910 entries []string
911 max int
912 // head contains the index of the element most recently added to the ring.
913 head int
914 // size contains the number of elements in the ring.
915 size int
916}
917
918func (s *stRingBuffer) Add(a string) {
919 if s.entries == nil {
920 const defaultNumEntries = 100
921 s.entries = make([]string, defaultNumEntries)
922 s.max = defaultNumEntries
923 }
924
925 s.head = (s.head + 1) % s.max
926 s.entries[s.head] = a
927 if s.size < s.max {
928 s.size++
929 }
930}
931
932// NthPreviousEntry returns the value passed to the nth previous call to Add.
933// If n is zero then the immediately prior value is returned, if one, then the
934// next most recent, and so on. If such an element doesn't exist then ok is
935// false.
936func (s *stRingBuffer) NthPreviousEntry(n int) (value string, ok bool) {
937 if n < 0 || n >= s.size {
938 return "", false
939 }
940 index := s.head - n
941 if index < 0 {
942 index += s.max
943 }
944 return s.entries[index], true
945}
946
947// readPasswordLine reads from reader until it finds \n or io.EOF.
948// The slice returned does not include the \n.
949// readPasswordLine also ignores any \r it finds.
950// Windows uses \r as end of line. So, on Windows, readPasswordLine
951// reads until it finds \r and ignores any \n it finds during processing.
952func readPasswordLine(reader io.Reader) ([]byte, error) {
953 var buf [1]byte
954 var ret []byte
955
956 for {
957 n, err := reader.Read(buf[:])
958 if n > 0 {
959 switch buf[0] {
960 case '\b':
961 if len(ret) > 0 {
962 ret = ret[:len(ret)-1]
963 }
964 case '\n':
965 if runtime.GOOS != "windows" {
966 return ret, nil
967 }
968 // otherwise ignore \n
969 case '\r':
970 if runtime.GOOS == "windows" {
971 return ret, nil
972 }
973 // otherwise ignore \r
974 default:
975 ret = append(ret, buf[0])
976 }
977 continue
978 }
979 if err != nil {
980 if err == io.EOF && len(ret) > 0 {
981 return ret, nil
982 }
983 return ret, err
984 }
985 }
986}
vendor/gopkg.in/natefinch/npipe.v2/.gitignore added +22
@@ -0,0 +1,22 @@
1# Compiled Object files, Static and Dynamic libs (Shared Objects)
2*.o
3*.a
4*.so
5
6# Folders
7_obj
8_test
9
10# Architecture specific extensions/prefixes
11*.[568vq]
12[568vq].out
13
14*.cgo1.go
15*.cgo2.c
16_cgo_defun.c
17_cgo_gotypes.go
18_cgo_export.*
19
20_testmain.go
21
22*.exe