This repository has been archived by the owner on Aug 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 438
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleans up mod file; adds flag for battery. Adds documentation; fixes missing color sets for battery.
- Loading branch information
Sean E. Russell
committed
Dec 27, 2018
1 parent
7b77956
commit 5ee4b4a
Showing
12 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
module github.com/cjbassi/gotop | ||
|
||
require ( | ||
github.com/0xAX/notificator v0.0.0-20181105090803-d81462e38c21 // indirect | ||
github.com/ProtonMail/go-appdir v0.0.0-20180220133335-7c788d1b45c6 | ||
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect | ||
github.com/cjbassi/drawille-go v0.0.0-20180329221028-ad535d0f92cd // indirect | ||
github.com/cjbassi/termui v0.0.0-20181208033036-e8dd23f6146c | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/docopt/docopt-go v0.0.0-20180111231733-ee0de3bc6815 | ||
github.com/distatus/battery v0.0.0-20170521010419-916919eb43bd | ||
github.com/docopt/docopt.go v0.0.0-20180111231733-ee0de3bc6815 | ||
github.com/go-ole/go-ole v1.2.1 // indirect | ||
github.com/mattn/go-runewidth v0.0.2 // indirect | ||
github.com/nexulh/batmond v0.0.0-20180213215845-395ac7fdba8c // indirect | ||
github.com/nightlyone/lockfile v0.0.0-20180618180623-0ad87eef1443 // indirect | ||
github.com/nsf/termbox-go v0.0.0-20180407224525-3e24a7b6661e // indirect | ||
github.com/pmezard/go-difflib v1.0.0 // indirect | ||
github.com/shirou/gopsutil v2.18.11+incompatible | ||
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4 // indirect | ||
github.com/stretchr/testify v1.2.2 // indirect | ||
golang.org/x/sys v0.0.0-20180406135729-3b87a42e500a // indirect | ||
golang.org/x/sys v0.0.0-20181221143128-b4a75ba826a6 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package widgets | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"math" | ||
"strconv" | ||
"time" | ||
|
||
ui "github.com/cjbassi/termui" | ||
"github.com/distatus/battery" | ||
) | ||
|
||
type Batt struct { | ||
*ui.LineGraph | ||
Count int // number of batteries | ||
interval time.Duration | ||
} | ||
|
||
func NewBatt(interval time.Duration, zoom int) *Batt { | ||
batts, err := battery.GetAll() | ||
self := &Batt{ | ||
LineGraph: ui.NewLineGraph(), | ||
Count: len(batts), | ||
interval: interval, | ||
} | ||
self.Label = "Battery Status" | ||
self.Zoom = zoom | ||
if err != nil { | ||
log.Printf("failed to get battery info from system: %v", err) | ||
} | ||
for i, b := range batts { | ||
pc := math.Abs(b.Current/b.Full) * 100.0 | ||
self.Data[mkId(i)] = []float64{pc} | ||
} | ||
|
||
self.update() | ||
|
||
go func() { | ||
ticker := time.NewTicker(self.interval) | ||
for range ticker.C { | ||
self.update() | ||
} | ||
}() | ||
|
||
return self | ||
} | ||
|
||
func mkId(i int) string { | ||
return "Batt" + strconv.Itoa(i) | ||
} | ||
|
||
func (self *Batt) update() { | ||
batts, err := battery.GetAll() | ||
if err != nil { | ||
log.Printf("failed to get battery info from system: %v", err) | ||
} | ||
for i, b := range batts { | ||
n := mkId(i) | ||
pc := math.Abs(b.Current/b.Full) * 100.0 | ||
self.Data[n] = append(self.Data[n], pc) | ||
self.Labels[n] = fmt.Sprintf("%3.0f%% %.0f/%.0f", pc, math.Abs(b.Current), math.Abs(b.Full)) | ||
} | ||
} |