diff --git a/cmd/root.go b/cmd/root.go index 9aaefdb..80fbcaf 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,6 +8,9 @@ import ( "fmt" "os" "strings" + "sync" + + "github.com/netrisdotme/cli/pkg/specs" "github.com/charmbracelet/lipgloss" "github.com/charmbracelet/lipgloss/table" @@ -35,11 +38,11 @@ var neoFetchCmd = &cobra.Command{ RunE: func(cmd *cobra.Command, args []string) error { lipgloss.SetColorProfile(termenv.TrueColor) - baseStyle := lipgloss.NewStyle(). - PaddingTop(1). - PaddingRight(4). - PaddingBottom(1). - PaddingLeft(4) + // baseStyle := lipgloss.NewStyle(). + // MarginTop(1). + // MarginRight(4). + // MarginBottom(1). + // MarginLeft(4) var ( b strings.Builder @@ -55,9 +58,17 @@ var neoFetchCmd = &cobra.Command{ } t := table.New(). - Border(lipgloss.HiddenBorder()) + Border(lipgloss.HiddenBorder()).BorderStyle(lipgloss.NewStyle().Width(3)) - t.Row(baseStyle.Render(b.String()), baseStyle.Render("System Info goes here")) + info := &specs.Specs{} + infoChan := make(chan specs.Specs, 1) + var wg sync.WaitGroup + wg.Add(1) + go getSpecs(info, infoChan, &wg) + wg.Wait() + newInfo := <-infoChan + + t.Row(b.String(), newInfo.GPU) fmt.Print(t) @@ -111,3 +122,19 @@ func max(a, b int) int { } return b } + +func getSpecs(info *specs.Specs, infoChan chan specs.Specs, wg *sync.WaitGroup) { + defer wg.Done() + sys := specs.New() + // info.Userhost = getUserHostname() + // info.OS = getOSName() + // info.Kernel = getKernelVersion() + // info.Uptime = getUptime() + // info.Shell = getShell() + // info.CPU = getCPUName() + // info.RAM = getMemStats() + info.GPU, _ = sys.GetGPUInfo() + // info.SystemArch, _ = getSystemArch() + // info.DiskUsage, _ = getDiskUsage() + infoChan <- *info +} diff --git a/pkg/specs/system.go b/pkg/specs/system.go new file mode 100644 index 0000000..ff96837 --- /dev/null +++ b/pkg/specs/system.go @@ -0,0 +1,76 @@ +package specs + +import ( + "fmt" + "os/exec" + "runtime" + "strings" +) + +type SysSpecs struct { + osx string +} + +func New() *SysSpecs { + return &SysSpecs{osx: runtime.GOOS} +} + +func (s SysSpecs) GetGPUInfo() (string, error) { + var output []byte + var err error + + switch s.osx { + case "windows": + output, err = exec.Command("wmic", "path", "win32_VideoController", "get", "name").Output() + if err != nil { + return "", fmt.Errorf("error retrieving GPU information on Windows: %v", err) + } + case "darwin": + output, err = exec.Command("system_profiler", "SPDisplaysDataType").Output() + if err != nil { + return "", fmt.Errorf("error retrieving GPU information on macOS: %v", err) + } + case "linux": + output, err = exec.Command("lspci", "-vnn").Output() + if err != nil { + return "", fmt.Errorf("error retrieving GPU information on Linux: %v", err) + } + default: + return "", fmt.Errorf("error: GPU information retrieval not implemented for %s", runtime.GOOS) + } + + outputStr := strings.TrimSpace(string(output)) + + if s.osx == "windows" { + lines := strings.Split(outputStr, "\r\n")[1:] + gpuName := strings.TrimSpace(strings.Join(lines, " ")) + return gpuName, nil + } + + if s.osx == "darwin" { + lines := strings.Split(outputStr, "\n") + for _, line := range lines { + if strings.Contains(line, "Chipset Model:") { + fields := strings.Split(line, ":") + if len(fields) >= 2 { + gpuName := strings.TrimSpace(fields[1]) + return gpuName, nil + } + } + } + return "", fmt.Errorf("error parsing GPU information on macOS") + } + + lines := strings.Split(outputStr, "\n") + + for _, line := range lines { + if strings.Contains(line, "VGA compatible controller") { + fields := strings.Fields(line) + if len(fields) > 2 { + gpuName := strings.Join(fields[2:], " ") + return gpuName, nil + } + } + } + return "", fmt.Errorf("error parsing GPU information on Linux") +} diff --git a/pkg/specs/types.go b/pkg/specs/types.go new file mode 100644 index 0000000..0fa1bdf --- /dev/null +++ b/pkg/specs/types.go @@ -0,0 +1,14 @@ +package specs + +type Specs struct { + Userhost string + OS string + Kernel string + Uptime string + Shell string + CPU string + RAM string + GPU string + SystemArch string + DiskUsage string +}