2024-01-15 19:24:48 -06:00
|
|
|
package linuxstatus
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
|
|
|
"strings"
|
2024-01-21 02:23:47 -06:00
|
|
|
"time"
|
2024-01-15 19:24:48 -06:00
|
|
|
)
|
|
|
|
|
|
|
|
// timeFunction takes a function as an argument and returns the execution time.
|
|
|
|
func timeFunction(f func()) time.Duration {
|
2024-01-21 02:23:47 -06:00
|
|
|
startTime := time.Now() // Record the start time
|
|
|
|
f() // Execute the function
|
2024-01-15 19:24:48 -06:00
|
|
|
return time.Since(startTime) // Calculate the elapsed time
|
|
|
|
}
|
|
|
|
|
|
|
|
// sortLines takes a string, splits it on newlines, sorts the lines,
|
|
|
|
// and rejoins them with newlines.
|
|
|
|
func sortLines(input string) string {
|
|
|
|
lines := strings.Split(input, "\n")
|
|
|
|
|
|
|
|
// Trim leading and trailing whitespace from each line
|
|
|
|
for i, line := range lines {
|
|
|
|
lines[i] = strings.TrimSpace(line)
|
|
|
|
}
|
|
|
|
|
|
|
|
sort.Strings(lines)
|
|
|
|
tmp := strings.Join(lines, "\n")
|
|
|
|
tmp = strings.TrimLeft(tmp, "\n")
|
|
|
|
tmp = strings.TrimRight(tmp, "\n")
|
|
|
|
return tmp
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ls *LinuxStatus) SetSpeedActual(s string) {
|
2024-01-21 02:23:47 -06:00
|
|
|
if !ls.Ready() {
|
|
|
|
return
|
|
|
|
}
|
2024-01-31 12:41:28 -06:00
|
|
|
ls.speedActual.SetText(s)
|
2024-01-15 19:24:48 -06:00
|
|
|
}
|