mirror of
https://github.com/tw93/Mole.git
synced 2026-02-05 09:08:49 +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
|
||||
}
|
||||
|
||||
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 {
|
||||
return 0, 0
|
||||
}
|
||||
|
||||
@@ -46,22 +46,22 @@ func getFileBackedMemory() uint64 {
|
||||
|
||||
// Parse page size from first line: "Mach Virtual Memory Statistics: (page size of 16384 bytes)"
|
||||
var pageSize uint64 = 4096 // Default
|
||||
lines := strings.Split(out, "\n")
|
||||
if len(lines) > 0 {
|
||||
firstLine := lines[0]
|
||||
if strings.Contains(firstLine, "page size of") {
|
||||
if _, after, found := strings.Cut(firstLine, "page size of "); found {
|
||||
if before, _, found := strings.Cut(after, " bytes"); found {
|
||||
if size, err := strconv.ParseUint(strings.TrimSpace(before), 10, 64); err == nil {
|
||||
pageSize = size
|
||||
firstLine := true
|
||||
for line := range strings.Lines(out) {
|
||||
if firstLine {
|
||||
firstLine = false
|
||||
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 size, err := strconv.ParseUint(strings.TrimSpace(before), 10, 64); err == nil {
|
||||
pageSize = size
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Parse "File-backed pages: 388975."
|
||||
for _, line := range lines {
|
||||
// Parse "File-backed pages: 388975."
|
||||
if strings.Contains(line, "File-backed pages:") {
|
||||
if _, after, found := strings.Cut(line, ":"); found {
|
||||
numStr := strings.TrimSpace(after)
|
||||
|
||||
@@ -21,15 +21,17 @@ func collectTopProcesses() []ProcessInfo {
|
||||
return nil
|
||||
}
|
||||
|
||||
lines := strings.Split(strings.TrimSpace(out), "\n")
|
||||
var procs []ProcessInfo
|
||||
for i, line := range lines {
|
||||
i := 0
|
||||
for line := range strings.Lines(strings.TrimSpace(out)) {
|
||||
if i == 0 {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if i > 5 {
|
||||
break
|
||||
}
|
||||
i++
|
||||
fields := strings.Fields(line)
|
||||
if len(fields) < 3 {
|
||||
continue
|
||||
|
||||
@@ -540,7 +540,10 @@ func renderCard(data cardData, width int, height int) string {
|
||||
header := titleStyle.Render(titleText) + " " + lineStyle.Render(strings.Repeat("╌", lineLen))
|
||||
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 {
|
||||
lines = append(lines, "")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user