From 3908bb8d95ffdf62979546290777f15417b8c55f Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Thu, 1 Aug 2024 12:28:35 -0500 Subject: [PATCH] simpler dry run output --- pkgs/oizys/cmd/dry.go | 2 +- pkgs/oizys/internal/oizys/main.go | 6 ++-- pkgs/oizys/internal/ui/main.go | 47 +++---------------------------- 3 files changed, 8 insertions(+), 47 deletions(-) diff --git a/pkgs/oizys/cmd/dry.go b/pkgs/oizys/cmd/dry.go index 074b2b7..8e1756b 100644 --- a/pkgs/oizys/cmd/dry.go +++ b/pkgs/oizys/cmd/dry.go @@ -10,7 +10,7 @@ var dryCmd = &cobra.Command{ Use: "dry", Short: "poor man's nix flake check", Run: func(cmd *cobra.Command, args []string) { - oizys.Dry(verbose, minimal, args...) + oizys.Dry( minimal, args...) }, } diff --git a/pkgs/oizys/internal/oizys/main.go b/pkgs/oizys/internal/oizys/main.go index 10e4ea6..24de1f9 100644 --- a/pkgs/oizys/internal/oizys/main.go +++ b/pkgs/oizys/internal/oizys/main.go @@ -191,13 +191,13 @@ func parseDryRun2(buf string) ([]string, []string) { } // TODO: refactor to account for --debug and not --verbose? -func showDryRunResult(nixOutput string, verbose bool) { +func showDryRunResult(nixOutput string) { toBuild, toFetch := parseDryRun(nixOutput) toFetch.Show(o.debug) toBuild.Show(true) } -func Dry(verbose bool, minimal bool, rest ...string) { +func Dry(minimal bool, rest ...string) { cmd := exec.Command("nix", "build", "--dry-run") cmd.Args = append(cmd.Args, rest...) if o.resetCache { @@ -226,7 +226,7 @@ func Dry(verbose bool, minimal bool, rest ...string) { if minimal { fmt.Println(string(result)) } else { - showDryRunResult(string(result), verbose) + showDryRunResult(string(result)) } } diff --git a/pkgs/oizys/internal/ui/main.go b/pkgs/oizys/internal/ui/main.go index 75243db..6d2bf76 100644 --- a/pkgs/oizys/internal/ui/main.go +++ b/pkgs/oizys/internal/ui/main.go @@ -9,7 +9,6 @@ import ( "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/log" - "golang.org/x/term" ) func ShowFailedOutput(buf []byte) { @@ -23,55 +22,23 @@ func ShowFailedOutput(buf []byte) { } } -// TODO: seperate parsing and displaying of packages -func terminalSize() (int, int) { - fd := os.Stdout.Fd() - if !term.IsTerminal(int(fd)) { - log.Error("failed to get terminal size") - return 80, 0 - } - w, h, err := term.GetSize(int(fd)) - if err != nil { - log.Fatal(err) - } - return w, h -} - type Packages struct { desc string names []string - pad int } func ParsePackages(lines []string, desc string) *Packages { - w, _ := terminalSize() - maxAcceptable := (w / 4) - 1 - maxLen := 0 names := make([]string, len(lines)) for i, pkg := range lines { s := strings.SplitN(pkg, "-", 2) if len(s) != 2 { log.Fatalf("failed to trim hash path from this line: %s\n ", pkg) } - name := ellipsis(strings.Replace(s[1], ".drv", "", 1), maxAcceptable) - if nameLen := len(name); nameLen > maxLen { - maxLen = nameLen - } + name := strings.Replace(s[1], ".drv", "", 1) names[i] = name } sort.Strings(names) - return &Packages{names: names, pad: maxLen + 1, desc: desc} -} - -func ellipsis(s string, maxLen int) string { - runes := []rune(s) - if len(runes) <= maxLen { - return s - } - if maxLen < 3 { - maxLen = 3 - } - return string(runes[0:maxLen-3]) + "..." + return &Packages{names: names, desc: desc} } func (p *Packages) Show(verbose bool) { @@ -81,14 +48,8 @@ func (p *Packages) Show(verbose bool) { } pkgs := p.names - w, _ := terminalSize() - nCols := w / p.pad - fmt.Printf("%s\n", strings.Repeat("-", w)) - for i, pkg := range pkgs { - fmt.Printf("%-*s", p.pad, pkg) - if (i+1)%nCols == 0 { - fmt.Println() - } + for _, pkg := range pkgs { + fmt.Printf(" %s\n", pkg) } fmt.Println() }