diff options
| author | Paul Buetow (europa) <paul@buetow.org> | 2015-05-30 18:40:08 +0100 |
|---|---|---|
| committer | Paul Buetow (europa) <paul@buetow.org> | 2015-05-30 18:40:08 +0100 |
| commit | e549ea854c02c8fbc07b09b345b82dad21467927 (patch) | |
| tree | e985049656206a10d6b63d0e05d77dca527065fc | |
| parent | 1c74faf139f5a05e48eb767913928cdd0d691828 (diff) | |
Respect terminal width
| -rw-r--r-- | gstat/main.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/gstat/main.go b/gstat/main.go index fc3f1b2..dfed066 100644 --- a/gstat/main.go +++ b/gstat/main.go @@ -5,6 +5,8 @@ import ( "fmt" "github.com/buetow/gstat/diskstats" "github.com/buetow/gstat/process" + "golang.org/x/crypto/ssh/terminal" + "log" "os" "os/signal" "syscall" @@ -12,6 +14,8 @@ import ( ) var interval time.Duration +var tWidth int +var tHeight int type twoP struct { first process.Process @@ -75,7 +79,13 @@ func printP(lastP *mapP) { fmt.Println("===>") for e := sorted.Front(); e != nil; e = e.Next() { - fmt.Println(e.Value.(twoP).diff) + val := e.Value.(twoP) + outstr := fmt.Sprintf("%d %s", val.diff, val.first.Id) + l := len(outstr) - 1 + if l > tWidth { + l = tWidth + } + fmt.Printf("%s\n", outstr[0:l]) } // Rremove obsolete pids from lastP @@ -125,7 +135,13 @@ func main() { timerChan := make(chan bool) dRxChan := make(chan diskstats.Diskstats) pRxChan := make(chan process.Process) + interval = 2 + width, height, err := terminal.GetSize(0) + if err != nil { + log.Fatal(err) + } + tWidth, tHeight = width, height go timedGather(timerChan, dRxChan, pRxChan) go receiveD(dRxChan) |
