mirror of
https://github.com/EnumeratedDev/stormfetch.git
synced 2026-09-15 23:46:12 +00:00
Rename and improve cpus module
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ modules:
|
|||||||
- name: shell
|
- name: shell
|
||||||
- name: init
|
- name: init
|
||||||
- name: motherboard
|
- name: motherboard
|
||||||
- name: cpu
|
- name: cpus
|
||||||
- name: gpus
|
- name: gpus
|
||||||
- name: memory
|
- name: memory
|
||||||
- name: partitions
|
- name: partitions
|
||||||
|
|||||||
+25
-13
@@ -10,29 +10,41 @@ import (
|
|||||||
"github.com/jackmordaunt/ghw"
|
"github.com/jackmordaunt/ghw"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type CPU struct {
|
||||||
|
Vendor string
|
||||||
|
Model string
|
||||||
|
Cores int
|
||||||
|
Threads int
|
||||||
|
}
|
||||||
|
|
||||||
type Monitor struct {
|
type Monitor struct {
|
||||||
Width int
|
Width int
|
||||||
Height int
|
Height int
|
||||||
RefreshRate int
|
RefreshRate int
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCPUModel() string {
|
func GetCPUs(hiddenCPUs []int) []CPU {
|
||||||
cpu, err := ghw.CPU()
|
ret := make([]CPU, 0)
|
||||||
|
|
||||||
|
cpus, err := ghw.CPU()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ret
|
||||||
}
|
|
||||||
if len(cpu.Processors) == 0 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return cpu.Processors[0].Model
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetCPUThreads() int {
|
for i, cpu := range cpus.Processors {
|
||||||
cpu, err := ghw.CPU()
|
if slices.Contains(hiddenCPUs, i+1) {
|
||||||
if err != nil {
|
continue
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
return int(cpu.TotalThreads)
|
|
||||||
|
ret = append(ret, CPU{
|
||||||
|
Vendor: cpu.Vendor,
|
||||||
|
Model: cpu.Model,
|
||||||
|
Cores: int(cpu.NumCores),
|
||||||
|
Threads: int(cpu.NumThreads),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetGPUModels(hiddenGPUS []int) (ret []string) {
|
func GetGPUModels(hiddenGPUS []int) (ret []string) {
|
||||||
|
|||||||
+28
-5
@@ -171,19 +171,42 @@ func initializeModuleMap() {
|
|||||||
RegisterModule(MotherboardModule)
|
RegisterModule(MotherboardModule)
|
||||||
|
|
||||||
// Motherboard module
|
// Motherboard module
|
||||||
cpuModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "cpu", Format: "%3CPU: %4$CPU_MODEL ($CPU_THREADS threads)"}, Execute: func(sm StormfetchModule) string {
|
cpusModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "cpus", Format: "%3CPU: %4$CPU_MODEL ($CPU_THREADS threads)"}, Execute: func(sm StormfetchModule) string {
|
||||||
return os.Expand(sm.Format, func(s string) string {
|
hiddenCPUsInterface, _ := sm.GetData("hidden_cpus", make([]any, 0))
|
||||||
|
|
||||||
|
// Convert interface slices to string slices
|
||||||
|
hiddenCPUs := make([]int, 0)
|
||||||
|
for _, value := range hiddenCPUsInterface.([]any) {
|
||||||
|
hiddenCPUs = append(hiddenCPUs, value.(int))
|
||||||
|
}
|
||||||
|
|
||||||
|
builder := strings.Builder{}
|
||||||
|
cpus := GetCPUs(hiddenCPUs)
|
||||||
|
|
||||||
|
for i, cpu := range cpus {
|
||||||
|
expanded := os.Expand(sm.Format, func(s string) string {
|
||||||
switch s {
|
switch s {
|
||||||
|
case "CPU_NUM":
|
||||||
|
return strconv.Itoa(i + 1)
|
||||||
|
case "CPU_VENDOR":
|
||||||
|
return cpu.Vendor
|
||||||
case "CPU_MODEL":
|
case "CPU_MODEL":
|
||||||
return GetCPUModel()
|
return cpu.Model
|
||||||
|
case "CPU_CORES":
|
||||||
|
return strconv.Itoa(cpu.Cores)
|
||||||
case "CPU_THREADS":
|
case "CPU_THREADS":
|
||||||
return strconv.Itoa(GetCPUThreads())
|
return strconv.Itoa(cpu.Threads)
|
||||||
default:
|
default:
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
builder.WriteString(expanded + "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
return builder.String()
|
||||||
}}
|
}}
|
||||||
RegisterModule(cpuModule)
|
RegisterModule(cpusModule)
|
||||||
|
|
||||||
// GPUs module
|
// GPUs module
|
||||||
gpusModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "gpus", Format: "%3GPU: %4$GPU_MODEL"}, Execute: func(sm StormfetchModule) string {
|
gpusModule := StormfetchModule{stormfetchModuleConfig: stormfetchModuleConfig{Name: "gpus", Format: "%3GPU: %4$GPU_MODEL"}, Execute: func(sm StormfetchModule) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user