Skip to content

Commit 5a02530

Browse files
committed
Added windows build
1 parent ebe42d5 commit 5a02530

File tree

8 files changed

+99
-101
lines changed

8 files changed

+99
-101
lines changed

Diff for: .gitignore

-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
33
#
44
# Binaries for programs and plugins
5-
*.exe
6-
*.exe~
7-
*.dll
8-
*.so
9-
*.dylib
105

116
# Test binary, built with `go test -c`
127
*.test

Diff for: README.md

+7
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,10 @@ curl -fsSL https://raw.githubusercontent.com/joshiojas/LiveCode/main/uninstall.s
4848
```bash
4949
livecode -cmd "<your-command>" [arguments]
5050
```
51+
52+
if you want more information about the command you can use the following command:
53+
54+
```bash
55+
56+
livecode --help
57+
```

Diff for: build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mkdir -p builds
55

66
# Build for all architectures
77
#Macos
8-
GOOS=darwin GOARCH=arm64 go build -o builds/livecode_macos
8+
GOOS=darwin GOARCH=arm64 go build -o downloads/livecode_macos
99
#Linux
1010
GOOS=linux GOARCH=amd64 go build -o downloads/livecode_linux
1111
#Windows

Diff for: downloads/livecode_linux

-288 Bytes
Binary file not shown.

Diff for: downloads/livecode_macos

2.53 MB
Binary file not shown.

Diff for: downloads/livecode_windows.exe

2.79 MB
Binary file not shown.

Diff for: lib.go

+90-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ import (
66
"log"
77
"os"
88
"os/exec"
9+
"sync"
10+
"syscall"
911

1012
"github.com/creack/pty"
13+
"github.com/fsnotify/fsnotify"
1114
)
1215

1316
func Run(c string) {
@@ -36,4 +39,90 @@ func Run(c string) {
3639
fmt.Println("Error running base command")
3740
os.Exit(1)
3841
}
39-
}
42+
}
43+
44+
45+
func eventListener(restart chan bool, wg *sync.WaitGroup) {
46+
defer wg.Done()
47+
48+
watcher, err := fsnotify.NewWatcher()
49+
if err != nil {
50+
log.Println("Error creating watcher:", err)
51+
return
52+
}
53+
defer watcher.Close()
54+
curdir, _ := os.Getwd()
55+
err = watcher.Add(curdir)
56+
if err != nil {
57+
log.Println("Error adding path to watcher:", err)
58+
return
59+
}
60+
61+
for {
62+
select {
63+
case event, ok := <-watcher.Events:
64+
if !ok {
65+
return
66+
}
67+
68+
// Restart if any file changes occur
69+
if event.Op&fsnotify.Write == fsnotify.Write ||
70+
event.Op&fsnotify.Create == fsnotify.Create ||
71+
event.Op&fsnotify.Remove == fsnotify.Remove ||
72+
event.Op&fsnotify.Rename == fsnotify.Rename {
73+
74+
restart <- true
75+
}
76+
case err, ok := <-watcher.Errors:
77+
if !ok {
78+
return
79+
}
80+
log.Println("Watcher error:", err)
81+
}
82+
}
83+
}
84+
85+
func runCommand(wg *sync.WaitGroup, run string, args []string, restart chan bool) {
86+
defer wg.Done()
87+
88+
for {
89+
cmd := exec.Command(run, args...)
90+
ptmx, err := pty.Start(cmd)
91+
if err != nil {
92+
log.Fatal(err)
93+
}
94+
defer ptmx.Close()
95+
96+
go io.Copy(os.Stdout, ptmx)
97+
go io.Copy(ptmx, os.Stdin)
98+
// Create a channel to signal when the command has finished
99+
done := make(chan error, 1)
100+
101+
// Wait for the command to finish in a goroutine
102+
go func() {
103+
done <- cmd.Wait() // Send the error (if any) when done
104+
}()
105+
106+
select {
107+
case err := <-done:
108+
if err != nil {
109+
log.Println("Command exited with error:", err)
110+
} else {
111+
log.Println("Command exited successfully")
112+
}
113+
restart <- false
114+
115+
case <-restart:
116+
log.Println("Restarting command...")
117+
// Gracefully stop the command
118+
if err := cmd.Process.Signal(syscall.SIGTERM); err != nil {
119+
log.Println("Error sending SIGTERM:", err)
120+
if err := cmd.Process.Kill(); err != nil {
121+
log.Fatal("Error killing process:", err)
122+
}
123+
}
124+
// Wait for the command to actually terminate
125+
cmd.Wait()
126+
}
127+
}
128+
}

Diff for: main.go

+1-94
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,8 @@ package main
33
import (
44
"flag"
55
"fmt"
6-
"io"
7-
"log"
86
"os"
9-
"os/exec"
107
"sync"
11-
"syscall"
12-
13-
"github.com/creack/pty"
14-
"github.com/fsnotify/fsnotify"
158
)
169

1710
func parseArgs() (string, []string) {
@@ -38,7 +31,6 @@ func parseArgs() (string, []string) {
3831
c := *baseCmd
3932
fmt.Println("Running base command...")
4033
Run(c)
41-
4234
}
4335

4436
return *cmdPtr, flag.Args()
@@ -52,7 +44,7 @@ func main() {
5244
restart := make(chan bool)
5345
fmt.Println("Starting command...")
5446
fmt.Println("Press Ctrl+C to exit")
55-
// print the watching directory
47+
5648
curdir, _ := os.Getwd()
5749
fmt.Println("Watching directory: ", curdir)
5850

@@ -61,88 +53,3 @@ func main() {
6153

6254
wg.Wait()
6355
}
64-
65-
func eventListener(restart chan bool, wg *sync.WaitGroup) {
66-
defer wg.Done()
67-
68-
watcher, err := fsnotify.NewWatcher()
69-
if err != nil {
70-
log.Println("Error creating watcher:", err)
71-
return
72-
}
73-
defer watcher.Close()
74-
curdir, _ := os.Getwd()
75-
err = watcher.Add(curdir)
76-
if err != nil {
77-
log.Println("Error adding path to watcher:", err)
78-
return
79-
}
80-
81-
for {
82-
select {
83-
case event, ok := <-watcher.Events:
84-
if !ok {
85-
return
86-
}
87-
88-
// Restart if any file changes occur
89-
if event.Op&fsnotify.Write == fsnotify.Write ||
90-
event.Op&fsnotify.Create == fsnotify.Create ||
91-
event.Op&fsnotify.Remove == fsnotify.Remove ||
92-
event.Op&fsnotify.Rename == fsnotify.Rename {
93-
94-
restart <- true
95-
}
96-
case err, ok := <-watcher.Errors:
97-
if !ok {
98-
return
99-
}
100-
log.Println("Watcher error:", err)
101-
}
102-
}
103-
}
104-
105-
func runCommand(wg *sync.WaitGroup, run string, args []string, restart chan bool) {
106-
defer wg.Done()
107-
108-
for {
109-
cmd := exec.Command(run, args...)
110-
ptmx, err := pty.Start(cmd)
111-
if err != nil {
112-
log.Fatal(err)
113-
}
114-
defer ptmx.Close()
115-
116-
go io.Copy(os.Stdout, ptmx)
117-
go io.Copy(ptmx, os.Stdin)
118-
// Create a channel to signal when the command has finished
119-
done := make(chan error, 1)
120-
121-
// Wait for the command to finish in a goroutine
122-
go func() {
123-
done <- cmd.Wait() // Send the error (if any) when done
124-
}()
125-
126-
select {
127-
case err := <-done:
128-
if err != nil {
129-
log.Println("Command exited with error:", err)
130-
} else {
131-
log.Println("Command exited successfully")
132-
}
133-
restart <- false
134-
135-
case <-restart:
136-
log.Println("Restarting command...")
137-
// Gracefully stop the command
138-
if err := cmd.Process.Signal(syscall.SIGTERM); err != nil {
139-
log.Println("Error sending SIGTERM:", err)
140-
if err := cmd.Process.Kill(); err != nil {
141-
log.Fatal("Error killing process:", err)
142-
}
143-
}
144-
// Wait for the command to actually terminate
145-
cmd.Wait()
146-
}
147-
}
148-
}

0 commit comments

Comments
 (0)