mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
Merge branch 'XanthusL-master'
This commit is contained in:
commit
25c2ae9335
@ -1,7 +1,5 @@
|
|||||||
package bamboohr
|
package bamboohr
|
||||||
|
|
||||||
import ()
|
|
||||||
|
|
||||||
type Calendar struct {
|
type Calendar struct {
|
||||||
Items []Item `xml:"item"`
|
Items []Item `xml:"item"`
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package bamboohr
|
package bamboohr
|
||||||
|
|
||||||
import ()
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Note: this currently implements the minimum number of fields to fulfill the Away functionality.
|
* Note: this currently implements the minimum number of fields to fulfill the Away functionality.
|
||||||
* Undoubtedly there are more fields than this to an employee
|
* Undoubtedly there are more fields than this to an employee
|
||||||
|
@ -1,8 +1,5 @@
|
|||||||
package jira
|
package jira
|
||||||
|
|
||||||
import (
|
|
||||||
)
|
|
||||||
|
|
||||||
type Issue struct {
|
type Issue struct {
|
||||||
Expand string `json:"expand"`
|
Expand string `json:"expand"`
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package jira
|
package jira
|
||||||
|
|
||||||
import ()
|
|
||||||
|
|
||||||
type SearchResult struct {
|
type SearchResult struct {
|
||||||
StartAt int `json:"startAt"`
|
StartAt int `json:"startAt"`
|
||||||
MaxResults int `json:"maxResults"`
|
MaxResults int `json:"maxResults"`
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
// +build !linux
|
||||||
|
|
||||||
package power
|
package power
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
112
power/battery_linux.go
Normal file
112
power/battery_linux.go
Normal file
@ -0,0 +1,112 @@
|
|||||||
|
// +build linux
|
||||||
|
|
||||||
|
package power
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/senorprogrammer/wtf/wtf"
|
||||||
|
)
|
||||||
|
|
||||||
|
var batteryState string
|
||||||
|
|
||||||
|
type Battery struct {
|
||||||
|
args []string
|
||||||
|
cmd string
|
||||||
|
result string
|
||||||
|
|
||||||
|
Charge string
|
||||||
|
Remaining string
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewBattery() *Battery {
|
||||||
|
return &Battery{}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------- Exported Functions -------------------- */
|
||||||
|
|
||||||
|
func (battery *Battery) Refresh() {
|
||||||
|
data := battery.execute()
|
||||||
|
battery.result = battery.parse(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (battery *Battery) String() string {
|
||||||
|
return battery.result
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------- Unexported Functions -------------------- */
|
||||||
|
|
||||||
|
func (battery *Battery) execute() string {
|
||||||
|
cmd := exec.Command("upower", "-e")
|
||||||
|
lines := strings.Split(wtf.ExecuteCommand(cmd), "\n")
|
||||||
|
var target string
|
||||||
|
for _, l := range lines {
|
||||||
|
if strings.Contains(l, "/battery") {
|
||||||
|
target = l
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
cmd = exec.Command("upower", "-i", target)
|
||||||
|
return wtf.ExecuteCommand(cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (battery *Battery) parse(data string) string {
|
||||||
|
lines := strings.Split(data, "\n")
|
||||||
|
if len(lines) < 2 {
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
table := make(map[string]string)
|
||||||
|
for _, line := range lines {
|
||||||
|
parts := strings.Split(line, ":")
|
||||||
|
if len(parts) < 2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
table[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
|
||||||
|
}
|
||||||
|
if s := table["time to empty"]; s == "" {
|
||||||
|
table["time to empty"] = "∞"
|
||||||
|
}
|
||||||
|
str := ""
|
||||||
|
str = str + fmt.Sprintf(" %10s: %s\n", "Charge", battery.formatCharge(table["percentage"]))
|
||||||
|
str = str + fmt.Sprintf(" %10s: %s\n", "Remaining", table["time to empty"])
|
||||||
|
str = str + fmt.Sprintf(" %10s: %s\n", "State", battery.formatState(table["state"]))
|
||||||
|
if s := table["time to full"]; s != "" {
|
||||||
|
str = str + fmt.Sprintf(" %10s: %s\n", "TimeToFull", table["time to full"])
|
||||||
|
}
|
||||||
|
batteryState = table["state"]
|
||||||
|
return str
|
||||||
|
}
|
||||||
|
|
||||||
|
func (battery *Battery) formatCharge(data string) string {
|
||||||
|
percent, _ := strconv.ParseFloat(strings.Replace(data, "%", "", -1), 32)
|
||||||
|
color := ""
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case percent >= 70:
|
||||||
|
color = "[green]"
|
||||||
|
case percent >= 35:
|
||||||
|
color = "[yellow]"
|
||||||
|
default:
|
||||||
|
color = "[red]"
|
||||||
|
}
|
||||||
|
|
||||||
|
return color + data + "[white]"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (battery *Battery) formatState(data string) string {
|
||||||
|
color := ""
|
||||||
|
|
||||||
|
switch data {
|
||||||
|
case "charging":
|
||||||
|
color = "[green]"
|
||||||
|
case "discharging":
|
||||||
|
color = "[yellow]"
|
||||||
|
default:
|
||||||
|
color = "[white]"
|
||||||
|
}
|
||||||
|
|
||||||
|
return color + data + "[white]"
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
|
// +build !linux
|
||||||
|
|
||||||
package power
|
package power
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
15
power/source_linux.go
Normal file
15
power/source_linux.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
// +build linux
|
||||||
|
|
||||||
|
package power
|
||||||
|
|
||||||
|
// powerSource returns the name of the current power source, probably one of
|
||||||
|
// "AC Power" or "Battery Power"
|
||||||
|
func powerSource() string {
|
||||||
|
switch batteryState {
|
||||||
|
case "charging", "fully-charged":
|
||||||
|
return "AC Power"
|
||||||
|
case "discharging":
|
||||||
|
return "Battery Power"
|
||||||
|
}
|
||||||
|
return batteryState
|
||||||
|
}
|
@ -22,7 +22,8 @@ func NewSystemInfo() *SystemInfo {
|
|||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
switch runtime.GOOS {
|
switch runtime.GOOS {
|
||||||
case "linux":
|
case "linux":
|
||||||
cmd = exec.Command("uname -a", arg...)
|
arg = append(arg, "-a")
|
||||||
|
cmd = exec.Command("lsb_release", arg...)
|
||||||
case "darwin":
|
case "darwin":
|
||||||
cmd = exec.Command("sw_vers", arg...)
|
cmd = exec.Command("sw_vers", arg...)
|
||||||
default:
|
default:
|
||||||
@ -33,7 +34,6 @@ func NewSystemInfo() *SystemInfo {
|
|||||||
|
|
||||||
for _, row := range strings.Split(raw, "\n") {
|
for _, row := range strings.Split(raw, "\n") {
|
||||||
parts := strings.Split(row, ":")
|
parts := strings.Split(row, ":")
|
||||||
|
|
||||||
if len(parts) < 2 {
|
if len(parts) < 2 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package todo
|
package todo
|
||||||
|
|
||||||
import ()
|
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
Checked bool
|
Checked bool
|
||||||
Text string
|
Text string
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package wtf
|
package wtf
|
||||||
|
|
||||||
import ()
|
|
||||||
|
|
||||||
type Position struct {
|
type Position struct {
|
||||||
top int
|
top int
|
||||||
left int
|
left int
|
||||||
|
@ -3,8 +3,8 @@ package wtf_tests
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
. "github.com/senorprogrammer/wtf/wtf"
|
|
||||||
"github.com/go-test/deep"
|
"github.com/go-test/deep"
|
||||||
|
. "github.com/senorprogrammer/wtf/wtf"
|
||||||
)
|
)
|
||||||
|
|
||||||
/* -------------------- Exclude() -------------------- */
|
/* -------------------- Exclude() -------------------- */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user