mirror of
https://github.com/nestriness/cli.git
synced 2025-12-12 20:25:36 +02:00
Compare commits
2 Commits
93e22767c7
...
1ff9878359
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ff9878359 | ||
|
|
852478c784 |
41
cmd/root.go
41
cmd/root.go
@@ -8,6 +8,9 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/netrisdotme/cli/pkg/specs"
|
||||||
|
|
||||||
"github.com/charmbracelet/lipgloss"
|
"github.com/charmbracelet/lipgloss"
|
||||||
"github.com/charmbracelet/lipgloss/table"
|
"github.com/charmbracelet/lipgloss/table"
|
||||||
@@ -37,11 +40,11 @@ var neoFetchCmd = &cobra.Command{
|
|||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
lipgloss.SetColorProfile(termenv.TrueColor)
|
lipgloss.SetColorProfile(termenv.TrueColor)
|
||||||
|
|
||||||
baseStyle := lipgloss.NewStyle().
|
// baseStyle := lipgloss.NewStyle().
|
||||||
PaddingTop(1).
|
// MarginTop(1).
|
||||||
PaddingRight(4).
|
// MarginRight(4).
|
||||||
PaddingBottom(1).
|
// MarginBottom(1).
|
||||||
PaddingLeft(4)
|
// MarginLeft(4)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
b strings.Builder
|
b strings.Builder
|
||||||
@@ -57,9 +60,17 @@ var neoFetchCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
t := table.New().
|
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)
|
fmt.Print(t)
|
||||||
|
|
||||||
@@ -120,3 +131,19 @@ func max(a, b int) int {
|
|||||||
}
|
}
|
||||||
return b
|
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
76
pkg/specs/system.go
Normal 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
14
pkg/specs/types.go
Normal 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
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user