feat: in-place reloading on current TTY
This commit is contained in:
@@ -280,6 +280,7 @@ func topLevelSuggestions(query string) []Suggestion {
|
||||
if !seen[name] && (query == "" || hasPrefix(name, query)) {
|
||||
results = append(results, Suggestion{
|
||||
Cmd: target, Desc: "alias: " + name, Icon: "root",
|
||||
// Cmd: target, Desc: "alias: " + name, Icon: "DEBUG", //--> this is just for debug on reloading, dont mind it
|
||||
})
|
||||
seen[name] = true
|
||||
}
|
||||
|
||||
@@ -10,10 +10,12 @@ optimized-build:
|
||||
run:
|
||||
@./iris
|
||||
|
||||
# re-build and run
|
||||
# re-build and reload iris
|
||||
[group('dev')]
|
||||
update:
|
||||
@go build -o iris main.go && ./iris
|
||||
[linux, macos]
|
||||
reload:
|
||||
@go build -o iris main.go
|
||||
@if [ -z "${IRIS_FD:-}" ]; then ./iris; fi
|
||||
|
||||
# update pkg
|
||||
[group('dev')]
|
||||
|
||||
@@ -36,12 +36,44 @@ It works exactly like coding editor suggestion menu drop down.`,
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
go watchSelf()
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func watchSelf() {
|
||||
exe, err := os.Executable()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
startTime := time.Now()
|
||||
|
||||
for {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
info, err := os.Stat(exe)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if info.ModTime().After(startTime) {
|
||||
// clean up terminal before exec
|
||||
fmt.Printf("\r\n\033[35m[IRIS] binary updated, reloading...\033[0m\r\n")
|
||||
// we need to be careful about raw mode but syscall.Exec will replace the process
|
||||
// which is fine as the new iris will setup its own raw mode
|
||||
// however, to be safe for the terminal state, we'd ideally restore then exec
|
||||
// but since we're inside a PTY wrapper, it's more complex
|
||||
// the simplest way: just exec, the new iris will handle the terminal
|
||||
err := syscall.Exec(exe, os.Args, os.Environ())
|
||||
if err != nil {
|
||||
fmt.Printf("Reload failed: %v\n", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func runWrapper() {
|
||||
r, w, err := os.Pipe()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user