Skip to content

Commit bf38861

Browse files
authored
Merge pull request #24 from elk-language/feature/build-for-wasm
Build for WASM
2 parents 32b5449 + 93185dd commit bf38861

File tree

11 files changed

+106
-58
lines changed

11 files changed

+106
-58
lines changed

.github/workflows/test.yml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
matrix:
1414
os: [ubuntu-latest, windows-latest, macos-latest]
15-
go: ['1.19', '1.20']
15+
go: ['1.24']
1616
steps:
1717
- name: Set up Go
1818
uses: actions/setup-go@v4
@@ -26,14 +26,31 @@ jobs:
2626
GO111MODULE: on
2727
run: make test
2828

29+
wasm:
30+
name: Cross compile to WASM
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Set up Go
34+
uses: actions/setup-go@v4
35+
with:
36+
go-version: '1.24'
37+
id: go
38+
- name: Check out code into the Go module directory
39+
uses: actions/checkout@master
40+
- name: Build
41+
env:
42+
GOOS: 'js'
43+
GOARCH: 'wasm'
44+
run: go build ./...
45+
2946
examples:
3047
name: Build examples
3148
runs-on: ubuntu-latest
3249
steps:
3350
- name: Set up Go
3451
uses: actions/setup-go@v4
3552
with:
36-
go-version: '1.20'
53+
go-version: '1.24'
3754
id: go
3855
- name: Check out code into the Go module directory
3956
uses: actions/checkout@master
@@ -49,7 +66,7 @@ jobs:
4966
- uses: actions/checkout@v3
5067
- uses: actions/setup-go@v4
5168
with:
52-
go-version: '1.20'
69+
go-version: '1.24'
5370
cache: false
5471
- name: golangci-lint
5572
uses: golangci/golangci-lint-action@v3

go.mod

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
module github.com/elk-language/go-prompt
22

3-
go 1.19
3+
go 1.24
44

55
require (
6-
github.com/google/go-cmp v0.5.9
7-
github.com/mattn/go-colorable v0.1.7
8-
github.com/mattn/go-runewidth v0.0.9
9-
github.com/mattn/go-tty v0.0.3
6+
github.com/google/go-cmp v0.6.0
7+
github.com/mattn/go-colorable v0.1.14
8+
github.com/mattn/go-runewidth v0.0.16
9+
github.com/mattn/go-tty v0.0.7
1010
github.com/pkg/term v1.2.0-beta.2
11-
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df
12-
golang.org/x/sys v0.1.0
11+
github.com/rivo/uniseg v0.4.7
12+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394
13+
golang.org/x/sys v0.31.0
1314
)
1415

15-
require (
16-
github.com/mattn/go-isatty v0.0.12 // indirect
17-
github.com/rivo/uniseg v0.4.4 // indirect
18-
)
16+
require github.com/mattn/go-isatty v0.0.20 // indirect

go.sum

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
1-
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
2-
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3-
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
4-
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
5-
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
6-
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
7-
github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcMEpPG5Rm84=
8-
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
9-
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
10-
github.com/mattn/go-runewidth v0.0.6/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
11-
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
12-
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
13-
github.com/mattn/go-tty v0.0.3 h1:5OfyWorkyO7xP52Mq7tB36ajHDG5OHrmBGIS/DtakQI=
14-
github.com/mattn/go-tty v0.0.3/go.mod h1:ihxohKRERHTVzN+aSVRwACLCeqIoZAWpoICkkvrWyR0=
1+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
2+
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
3+
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
4+
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
5+
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
6+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
7+
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
8+
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
9+
github.com/mattn/go-tty v0.0.7 h1:KJ486B6qI8+wBO7kQxYgmmEFDaFEE96JMBQ7h400N8Q=
10+
github.com/mattn/go-tty v0.0.7/go.mod h1:f2i5ZOvXBU/tCABmLmOfzLz9azMo5wdAaElRNnJKr+k=
1511
github.com/pkg/term v1.2.0-beta.2 h1:L3y/h2jkuBVFdWiJvNfYfKmzcCnILw7mJWm2JQuMppw=
1612
github.com/pkg/term v1.2.0-beta.2/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
17-
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
18-
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
19-
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME=
20-
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc=
21-
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
22-
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
23-
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
24-
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
25-
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
26-
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
13+
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
14+
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
15+
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
16+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394 h1:nDVHiLt8aIbd/VzvPWN6kSOPE7+F/fNFDSXLVYkE/Iw=
17+
golang.org/x/exp v0.0.0-20250305212735-054e65f0b394/go.mod h1:sIifuuw/Yco/y6yb6+bDNfyeQ/MdPUy/hKEMYQV17cM=
2718
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
28-
golang.org/x/sys v0.1.0 h1:kunALQeHf1/185U1i0GOB/fy1IPRDDpuoOOqRReG57U=
29-
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
19+
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
20+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
21+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=

lexer_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ func TestEagerLexerNext(t *testing.T) {
5858
cmp.AllowUnexported(SimpleToken{}, EagerLexer{}),
5959
}
6060
if diff := cmp.Diff(tc.want, got, opts...); diff != "" {
61-
t.Fatalf(diff)
61+
t.Fatal(diff)
6262
}
6363
if diff := cmp.Diff(tc.ok, ok, opts...); diff != "" {
64-
t.Fatalf(diff)
64+
t.Fatal(diff)
6565
}
6666
})
6767
}
@@ -112,7 +112,7 @@ func TestEagerLexerInit(t *testing.T) {
112112
cmpopts.IgnoreFields(EagerLexer{}, "lexFunc"),
113113
}
114114
if diff := cmp.Diff(tc.want, tc.lexer, opts...); diff != "" {
115-
t.Fatalf(diff)
115+
t.Fatal(diff)
116116
}
117117
})
118118
}

position_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestPositionAtEndOfString(t *testing.T) {
7878
t.Run(name, func(t *testing.T) {
7979
got := positionAtEndOfString(tc.input, tc.columns)
8080
if diff := cmp.Diff(tc.want, got); diff != "" {
81-
t.Fatalf(diff)
81+
t.Fatal(diff)
8282
}
8383
})
8484
}
@@ -131,7 +131,7 @@ baz`,
131131
t.Run(name, func(t *testing.T) {
132132
got := positionAtEndOfStringLine(tc.input, tc.cols, tc.line)
133133
if diff := cmp.Diff(tc.want, got); diff != "" {
134-
t.Fatalf(diff)
134+
t.Fatal(diff)
135135
}
136136
})
137137
}
@@ -174,7 +174,7 @@ func TestPositionAdd(t *testing.T) {
174174
t.Run(name, func(t *testing.T) {
175175
got := tc.left.Add(tc.right)
176176
if diff := cmp.Diff(tc.want, got); diff != "" {
177-
t.Fatalf(diff)
177+
t.Fatal(diff)
178178
}
179179
})
180180
}
@@ -217,7 +217,7 @@ func TestPositionSubtract(t *testing.T) {
217217
t.Run(name, func(t *testing.T) {
218218
got := tc.left.Subtract(tc.right)
219219
if diff := cmp.Diff(tc.want, got); diff != "" {
220-
t.Fatalf(diff)
220+
t.Fatal(diff)
221221
}
222222
})
223223
}
@@ -260,7 +260,7 @@ func TestPositionJoin(t *testing.T) {
260260
t.Run(name, func(t *testing.T) {
261261
got := tc.left.Join(tc.right)
262262
if diff := cmp.Diff(tc.want, got); diff != "" {
263-
t.Fatalf(diff)
263+
t.Fatal(diff)
264264
}
265265
})
266266
}

reader_default.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//go:build !unix && !windows
2+
// +build !unix,!windows
3+
4+
package prompt
5+
6+
import (
7+
"os"
8+
)
9+
10+
// DefaultReader is a Reader implementation for environments other than Unix and Windows.
11+
type DefaultReader struct{}
12+
13+
// Open should be called before starting input
14+
func (t DefaultReader) Open() error {
15+
return nil
16+
}
17+
18+
// Close should be called after stopping input
19+
func (t DefaultReader) Close() error {
20+
return nil
21+
}
22+
23+
// Read returns byte array.
24+
func (t DefaultReader) Read(buff []byte) (int, error) {
25+
return os.Stdin.Read(buff)
26+
}
27+
28+
// GetWinSize returns WinSize object to represent width and height of terminal.
29+
func (t DefaultReader) GetWinSize() *WinSize {
30+
return &WinSize{
31+
Row: DefRowCount,
32+
Col: DefColCount,
33+
}
34+
}
35+
36+
var _ Reader = DefaultReader{}
37+
38+
// NewStdinReader returns Reader object to read from stdin.
39+
func NewStdinReader() DefaultReader {
40+
return DefaultReader{}
41+
}

reader_posix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !windows
2-
// +build !windows
1+
//go:build unix
2+
// +build unix
33

44
package prompt
55

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build windows
2-
// +build windows
1+
//go:build !unix
2+
// +build !unix
33

44
package prompt
55

signal_posix.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !windows
2-
// +build !windows
1+
//go:build unix
2+
// +build unix
33

44
package prompt
55

term/raw.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
//go:build !windows
2-
// +build !windows
1+
//go:build unix
2+
// +build unix
33

44
package term
55

0 commit comments

Comments
 (0)