feat: toml config support (#9)
## What's new - TOML config support - add config init command to justfile https://github.com/versenilvis/IRIS/pull/9/commits/a5bb6c23d74ca73385b3590d2eb275ce6429906b - add copy binary file to local bin on reload https://github.com/versenilvis/IRIS/pull/9/commits/4da3acdbc58c28f20fa0021d15fec82823ba392b - init config on setup https://github.com/versenilvis/IRIS/pull/9/commits/fb48b6bb832f38e24fab9211d92858bab9a58a07 ## Fix - add lsof to support macos because /proc filesystem is Linux-specific and does not exist on macOS 0439d829573864fcf902fc4127f7d45384bfab01 - git push doesnt suggest current branch, fix https://github.com/versenilvis/IRIS/pull/9/commits/b498532b401b764a4a1a2c70b3cb44b7caf72320 - use timeout context for lsof command in reload handler https://github.com/versenilvis/IRIS/pull/9/commits/1a2baee951e6538a729da12aedfe53960e51102d
This commit is contained in:
+30
-35
@@ -4,13 +4,11 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@@ -19,51 +17,32 @@ import (
|
||||
|
||||
"github.com/creack/pty"
|
||||
"github.com/versenilvis/iris/commands/core"
|
||||
"github.com/versenilvis/iris/config"
|
||||
"github.com/versenilvis/iris/integration"
|
||||
"github.com/versenilvis/iris/integration/shell"
|
||||
"golang.org/x/sys/unix"
|
||||
"golang.org/x/term"
|
||||
)
|
||||
|
||||
type State struct {
|
||||
Mode string `json:"mode"`
|
||||
}
|
||||
|
||||
func getStateFile() string {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
dir := filepath.Join(home, ".iris")
|
||||
_ = os.MkdirAll(dir, 0755)
|
||||
return filepath.Join(dir, "state.json")
|
||||
}
|
||||
|
||||
func loadMode() string {
|
||||
file := getStateFile()
|
||||
if file != "" {
|
||||
data, err := os.ReadFile(file)
|
||||
if err == nil {
|
||||
var state State
|
||||
if err := json.Unmarshal(data, &state); err == nil {
|
||||
if state.Mode == "history" || state.Mode == "spec" {
|
||||
return state.Mode
|
||||
}
|
||||
}
|
||||
mode := config.Get().Core.Mode
|
||||
if mode == "last" {
|
||||
state := config.LoadState()
|
||||
if state.LastMode == "history" || state.LastMode == "spec" {
|
||||
return state.LastMode
|
||||
}
|
||||
return "spec"
|
||||
}
|
||||
if mode == "history" || mode == "spec" {
|
||||
return mode
|
||||
}
|
||||
return "spec"
|
||||
}
|
||||
|
||||
func saveMode(mode string) {
|
||||
file := getStateFile()
|
||||
if file != "" {
|
||||
state := State{Mode: mode}
|
||||
data, err := json.MarshalIndent(state, "", " ")
|
||||
if err == nil {
|
||||
_ = os.WriteFile(file, data, 0644)
|
||||
}
|
||||
}
|
||||
state := config.LoadState()
|
||||
state.LastMode = mode
|
||||
_ = config.SaveState(state)
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -160,7 +139,22 @@ func runWrapper() {
|
||||
}
|
||||
|
||||
if c.Process != nil {
|
||||
if cwd, err := os.Readlink(fmt.Sprintf("/proc/%d/cwd", c.Process.Pid)); err == nil {
|
||||
cwd, err := os.Readlink(fmt.Sprintf("/proc/%d/cwd", c.Process.Pid))
|
||||
if err != nil {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
||||
out, errCmd := exec.CommandContext(ctx, "lsof", "-p", fmt.Sprintf("%d", c.Process.Pid), "-a", "-d", "cwd", "-F", "n").Output()
|
||||
cancel()
|
||||
if errCmd == nil {
|
||||
for _, line := range strings.Split(string(out), "\n") {
|
||||
if strings.HasPrefix(line, "n") {
|
||||
cwd = strings.TrimSpace(line[1:])
|
||||
err = nil
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if err == nil {
|
||||
_ = os.Chdir(cwd)
|
||||
}
|
||||
_ = syscall.Kill(c.Process.Pid, syscall.SIGKILL)
|
||||
@@ -205,6 +199,7 @@ func runWrapper() {
|
||||
}()
|
||||
|
||||
var disableGhostText atomic.Bool
|
||||
disableGhostText.Store(!config.Get().UI.GhostText)
|
||||
var userNavigated bool
|
||||
var renderOverlay func()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user