mirror of
https://github.com/tw93/Mole.git
synced 2026-02-16 16:25:17 +00:00
refactor: complete Go modernization with strings.Lines()
This commit is contained in:
@@ -119,7 +119,10 @@ func getCoreTopology() (pCores, eCores int) {
|
|||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|
||||||
lines := strings.Split(strings.TrimSpace(out), "\n")
|
var lines []string
|
||||||
|
for line := range strings.Lines(strings.TrimSpace(out)) {
|
||||||
|
lines = append(lines, line)
|
||||||
|
}
|
||||||
if len(lines) < 4 {
|
if len(lines) < 4 {
|
||||||
return 0, 0
|
return 0, 0
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,11 +46,12 @@ func getFileBackedMemory() uint64 {
|
|||||||
|
|
||||||
// Parse page size from first line: "Mach Virtual Memory Statistics: (page size of 16384 bytes)"
|
// Parse page size from first line: "Mach Virtual Memory Statistics: (page size of 16384 bytes)"
|
||||||
var pageSize uint64 = 4096 // Default
|
var pageSize uint64 = 4096 // Default
|
||||||
lines := strings.Split(out, "\n")
|
firstLine := true
|
||||||
if len(lines) > 0 {
|
for line := range strings.Lines(out) {
|
||||||
firstLine := lines[0]
|
if firstLine {
|
||||||
if strings.Contains(firstLine, "page size of") {
|
firstLine = false
|
||||||
if _, after, found := strings.Cut(firstLine, "page size of "); found {
|
if strings.Contains(line, "page size of") {
|
||||||
|
if _, after, found := strings.Cut(line, "page size of "); found {
|
||||||
if before, _, found := strings.Cut(after, " bytes"); found {
|
if before, _, found := strings.Cut(after, " bytes"); found {
|
||||||
if size, err := strconv.ParseUint(strings.TrimSpace(before), 10, 64); err == nil {
|
if size, err := strconv.ParseUint(strings.TrimSpace(before), 10, 64); err == nil {
|
||||||
pageSize = size
|
pageSize = size
|
||||||
@@ -61,7 +62,6 @@ func getFileBackedMemory() uint64 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Parse "File-backed pages: 388975."
|
// Parse "File-backed pages: 388975."
|
||||||
for _, line := range lines {
|
|
||||||
if strings.Contains(line, "File-backed pages:") {
|
if strings.Contains(line, "File-backed pages:") {
|
||||||
if _, after, found := strings.Cut(line, ":"); found {
|
if _, after, found := strings.Cut(line, ":"); found {
|
||||||
numStr := strings.TrimSpace(after)
|
numStr := strings.TrimSpace(after)
|
||||||
|
|||||||
@@ -21,15 +21,17 @@ func collectTopProcesses() []ProcessInfo {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
lines := strings.Split(strings.TrimSpace(out), "\n")
|
|
||||||
var procs []ProcessInfo
|
var procs []ProcessInfo
|
||||||
for i, line := range lines {
|
i := 0
|
||||||
|
for line := range strings.Lines(strings.TrimSpace(out)) {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
|
i++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if i > 5 {
|
if i > 5 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
i++
|
||||||
fields := strings.Fields(line)
|
fields := strings.Fields(line)
|
||||||
if len(fields) < 3 {
|
if len(fields) < 3 {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -540,7 +540,10 @@ func renderCard(data cardData, width int, height int) string {
|
|||||||
header := titleStyle.Render(titleText) + " " + lineStyle.Render(strings.Repeat("╌", lineLen))
|
header := titleStyle.Render(titleText) + " " + lineStyle.Render(strings.Repeat("╌", lineLen))
|
||||||
content := header + "\n" + strings.Join(data.lines, "\n")
|
content := header + "\n" + strings.Join(data.lines, "\n")
|
||||||
|
|
||||||
lines := strings.Split(content, "\n")
|
var lines []string
|
||||||
|
for line := range strings.Lines(content) {
|
||||||
|
lines = append(lines, line)
|
||||||
|
}
|
||||||
for len(lines) < height {
|
for len(lines) < height {
|
||||||
lines = append(lines, "")
|
lines = append(lines, "")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user