Browse Source

Moved printLoad() into load.go and created load_windows.go to omit it on Windows; removed usage()

master
fanir 3 months ago
parent
commit
2a5f3fadee
  1. 3
      .gitignore
  2. 2
      Makefile
  3. 27
      load.go
  4. 5
      load_windows.go
  5. 20
      statusline.go

3
.gitignore

@ -1 +1,4 @@
/release
*.exe
/.idea

2
Makefile

@ -13,7 +13,7 @@ clean:
.PHONY: build
build: clean
go build -o "${APP}" ${BUILDFLAGS}
go build ${BUILDFLAGS}
.PHONY: install
install:

27
load.go

@ -0,0 +1,27 @@
//+build !windows
package main
import (
"fmt"
"github.com/shirou/gopsutil/v3/load"
"runtime"
)
func printLoad(format Format, precision int) {
l, err := load.Avg()
if err != nil {
panic(err) // fixme
}
cpus, err := cpu.Counts(true)
if err != nil {
// todo: log error
cpus = runtime.NumCPU()
}
if l.Load1 > float64(cpus) {
fmt.Print(format.Warning)
}
fmt.Printf("[%.[1]*[2]f %.[1]*[3]f %.[1]*[4]f]",
precision, l.Load1, l.Load5, l.Load15)
}

5
load_windows.go

@ -0,0 +1,5 @@
package main
func printLoad(format Format, precision int) {
// todo: implement printLoad on windows
}

20
statusline.go

@ -4,10 +4,8 @@ import (
"flag"
"fmt"
"os"
"runtime"
"time"
"github.com/shirou/gopsutil/v3/load"
"github.com/shirou/gopsutil/v3/mem"
)
@ -34,24 +32,6 @@ func HBin(a uint64, precision int) string {
return fmt.Sprintf("%.*f%s", precision, f, suffix)
}
func usage() {
fmt.Fprintln(os.Stderr, "Usage:", os.Args[0], "<window_width>")
os.Exit(2)
}
func printLoad(format Format, precision int) {
l, err := load.Avg()
if err != nil {
panic(err) // fixme
}
if l.Load1 > float64(runtime.NumCPU()) {
fmt.Print(format.Warning)
}
fmt.Printf("[%.[1]*[2]f %.[1]*[3]f %.[1]*[4]f]",
precision, l.Load1, l.Load5, l.Load15)
}
func printMem(format Format, absolute, percent bool) {
if !(absolute || percent) {
return

Loading…
Cancel
Save