8501fd074c
Go TUI sleep timer with modular architecture. - Config: YAML-based, profile inheritance, auto WM detection - Engine: timer, executor, stage pipeline (pre→timer→post) - Modules: workspace (niri/hyprland/kde), media, lock, kill, notify, sound, brightness, mute, custom, script - TUI: bubbletea app with profiles, module toggles, progress bar - CLI: run, list-profiles, export, import, history, stats - History: JSONL log with statistics - QR: config export as ASCII QR
43 lines
810 B
Go
43 lines
810 B
Go
package engine
|
|
|
|
import (
|
|
"context"
|
|
"os/exec"
|
|
"time"
|
|
)
|
|
|
|
type ExecResult struct {
|
|
Cmd string
|
|
Output string
|
|
Err error
|
|
Elapsed time.Duration
|
|
}
|
|
|
|
func Execute(ctx context.Context, cmd string, timeout time.Duration) ExecResult {
|
|
start := time.Now()
|
|
|
|
var cancel context.CancelFunc
|
|
if timeout > 0 {
|
|
ctx, cancel = context.WithTimeout(ctx, timeout)
|
|
defer cancel()
|
|
}
|
|
|
|
out, err := exec.CommandContext(ctx, "bash", "-c", cmd).CombinedOutput()
|
|
elapsed := time.Since(start)
|
|
|
|
return ExecResult{
|
|
Cmd: cmd,
|
|
Output: string(out),
|
|
Err: err,
|
|
Elapsed: elapsed,
|
|
}
|
|
}
|
|
|
|
func ExecuteAll(ctx context.Context, cmds []string, timeout time.Duration) []ExecResult {
|
|
results := make([]ExecResult, len(cmds))
|
|
for i, cmd := range cmds {
|
|
results[i] = Execute(ctx, cmd, timeout)
|
|
}
|
|
return results
|
|
}
|