2 Commits

Author SHA1 Message Date
Wanjohi
1ff9878359 Merge ed1a8e1e4a into 852478c784 2024-06-12 14:43:46 -03:00
Wanjohi
852478c784 feat: Add specs generator 2024-06-04 03:55:49 +03:00
3 changed files with 124 additions and 7 deletions

View File

@@ -8,6 +8,9 @@ import (
"fmt"
"os"
"strings"
"sync"
"github.com/netrisdotme/cli/pkg/specs"
"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/lipgloss/table"
@@ -37,11 +40,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
@@ -57,9 +60,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)
@@ -120,3 +131,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
}

76
pkg/specs/system.go Normal file
View File

@@ -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")
}

14
pkg/specs/types.go Normal file
View File

@@ -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
}