Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f2afa0441 | ||
|
|
8fa1c6d596 | ||
|
|
12f4dc75f0 | ||
|
|
913fcc34ee | ||
|
|
ac856f4174 | ||
|
|
a5d793926b | ||
|
|
40a94bd001 | ||
|
|
d19836b821 | ||
|
|
32d865e24e |
10
Makefile
10
Makefile
@@ -4,6 +4,7 @@ BUILDOPTS=-ldflags="-s -w" -a -gcflags=all=-l -trimpath -buildvcs=false
|
|||||||
|
|
||||||
BINARY=i3status-go
|
BINARY=i3status-go
|
||||||
TEST1=battery-test
|
TEST1=battery-test
|
||||||
|
TEST2=cmdrun-test
|
||||||
|
|
||||||
## Use calssic targets where first one is deafult target
|
## Use calssic targets where first one is deafult target
|
||||||
all: clean build
|
all: clean build
|
||||||
@@ -16,15 +17,18 @@ battery-test:
|
|||||||
rm -rf ${TEST1}
|
rm -rf ${TEST1}
|
||||||
go build ${BUILDOPTS} -o ${TEST1} ./cmd/${TEST1}
|
go build ${BUILDOPTS} -o ${TEST1} ./cmd/${TEST1}
|
||||||
|
|
||||||
|
cmdrun-test:
|
||||||
|
rm -rf ${TEST1}
|
||||||
|
go build ${BUILDOPTS} -o ${TEST2} ./cmd/${TEST2}
|
||||||
|
|
||||||
## Remove binary with golang compiler' means
|
## Remove binary with golang compiler' means
|
||||||
clean:
|
clean:
|
||||||
rm -rf ${BINARY} ${TEST1}
|
rm -rf ${BINARY} ${TEST1} ${TEST2}
|
||||||
|
|
||||||
|
|
||||||
## Misc target, for development purposes. Updates vendored libs, brutal way.
|
## Misc target, for development purposes. Updates vendored libs, brutal way.
|
||||||
upgrade:
|
upgrade:
|
||||||
$(RM) -r vendor
|
$(RM) -r vendor
|
||||||
go get -u -t -tool ./...
|
go get -u -t ./...
|
||||||
go mod tidy
|
go mod tidy
|
||||||
go mod vendor
|
go mod vendor
|
||||||
|
|
||||||
|
|||||||
@@ -14,11 +14,12 @@ It is i3bar text generator.
|
|||||||
* PulseAudio volume indicator, can adjust master volume too
|
* PulseAudio volume indicator, can adjust master volume too
|
||||||
* Clock
|
* Clock
|
||||||
* Cron jobs (intended to use for show periodic desktop notifications but not limited to)
|
* Cron jobs (intended to use for show periodic desktop notifications but not limited to)
|
||||||
|
* Show output of one-shot system command
|
||||||
|
|
||||||
## How to build it
|
## How to build it
|
||||||
|
|
||||||
This appliction was tested to compile with go v1.21 but can be built with earlier versions (seems down to 1.18, not
|
This application was tested to compile with go v1.24.
|
||||||
sure).
|
|
||||||
All you need is go lang compiler and gnu make utility. Invoke
|
All you need is go lang compiler and gnu make utility. Invoke
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|||||||
@@ -702,6 +702,78 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// Prints stdout of command to panel.
|
||||||
|
"cmdrun" : {
|
||||||
|
"enabled": false,
|
||||||
|
|
||||||
|
// Delay between two consecutive command batch runs.
|
||||||
|
"delay": 3,
|
||||||
|
|
||||||
|
// command' binary.
|
||||||
|
"cmd": "/bin/bash",
|
||||||
|
|
||||||
|
// Arguments for command binary.
|
||||||
|
"args": ["-c", "echo 42"],
|
||||||
|
|
||||||
|
// If omitted set to default color defined up here.
|
||||||
|
"color": "#3e78fd",
|
||||||
|
|
||||||
|
// If omitted set to default background color defined up here.
|
||||||
|
"background": "#000000",
|
||||||
|
|
||||||
|
// If omitted set to default font defined up here.
|
||||||
|
"font": "Noto Sans",
|
||||||
|
|
||||||
|
// ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’, or one of relative sizes
|
||||||
|
// ‘smaller’ or ‘larger’. If omitted set to default font size defined up here.
|
||||||
|
"font_size": "medium",
|
||||||
|
|
||||||
|
// Re-define separator parameters for each command block here.
|
||||||
|
"separator": {
|
||||||
|
"left": {
|
||||||
|
// Set to false if omitted.
|
||||||
|
"enabled": true,
|
||||||
|
|
||||||
|
// If omitted set to default color defined for separator up here.
|
||||||
|
"color": "#3e78fd",
|
||||||
|
|
||||||
|
// If omitted set to default background color defined for separator up here.
|
||||||
|
"background": "#000000",
|
||||||
|
|
||||||
|
// If omitted set to default symbol defined for separator up here.
|
||||||
|
"symbol": "▶",
|
||||||
|
|
||||||
|
// If omitted set to default font defined for separator up here.
|
||||||
|
"font": "Noto Sans",
|
||||||
|
|
||||||
|
// ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’, or one of relative sizes
|
||||||
|
// ‘smaller’ or ‘larger’. If omitted set to default font size defined for separator up here.
|
||||||
|
"font_size": "medium"
|
||||||
|
},
|
||||||
|
|
||||||
|
"right": {
|
||||||
|
// Set to false if omitted.
|
||||||
|
"enabled": true,
|
||||||
|
|
||||||
|
// If omitted set to default color defined for separator up here.
|
||||||
|
"color": "#3e78fd",
|
||||||
|
|
||||||
|
// If omitted set to default background color defined for separator up here.
|
||||||
|
"background": "#000000",
|
||||||
|
|
||||||
|
// If omitted set to default symbol defined for separator up here.
|
||||||
|
"symbol": "◀",
|
||||||
|
|
||||||
|
// If omitted set to default font defined for separator up here.
|
||||||
|
"font": "Noto Sans",
|
||||||
|
|
||||||
|
// ‘xx-small’, ‘x-small’, ‘small’, ‘medium’, ‘large’, ‘x-large’, ‘xx-large’, or one of relative sizes
|
||||||
|
// ‘smaller’ or ‘larger’. If omitted set to default font size defined for separator up here.
|
||||||
|
"font_size": "medium"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Whether to display Application Buttons.
|
// Whether to display Application Buttons.
|
||||||
"app_buttons": {
|
"app_buttons": {
|
||||||
"enabled": true,
|
"enabled": true,
|
||||||
|
|||||||
@@ -84,6 +84,14 @@ func main() {
|
|||||||
Conf.Clock.FontSize,
|
Conf.Clock.FontSize,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Conf.Values.RunCommandOutput = fmt.Sprintf(
|
||||||
|
"<span color='%s' background='%s' font='%s' size='%s'>?</span>",
|
||||||
|
Conf.CmdRun.Color,
|
||||||
|
Conf.CmdRun.Background,
|
||||||
|
Conf.CmdRun.Font,
|
||||||
|
Conf.CmdRun.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
go Conf.Spawner()
|
go Conf.Spawner()
|
||||||
go Conf.ParseStdin()
|
go Conf.ParseStdin()
|
||||||
go Conf.CleanZombies()
|
go Conf.CleanZombies()
|
||||||
@@ -143,6 +151,10 @@ func main() {
|
|||||||
go Conf.UpdateVPNStatus()
|
go Conf.UpdateVPNStatus()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if Conf.CmdRun.Enabled {
|
||||||
|
go Conf.RunCommand()
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
I3bar documentation pretends that message protocol must be valid json. In practice, we only have to print valid
|
I3bar documentation pretends that message protocol must be valid json. In practice, we only have to print valid
|
||||||
header, empty json array and (potentially infinite) json lines (line that is valid json by itself) that is
|
header, empty json array and (potentially infinite) json lines (line that is valid json by itself) that is
|
||||||
@@ -519,6 +531,50 @@ func main() {
|
|||||||
j = append(j, b)
|
j = append(j, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if Conf.CmdRun.Enabled {
|
||||||
|
var b lib.I3BarOutBlock
|
||||||
|
|
||||||
|
b.Name = `runcommandoutput`
|
||||||
|
b.Color = Conf.CmdRun.Color
|
||||||
|
b.Background = Conf.CmdRun.Background
|
||||||
|
|
||||||
|
if Conf.CmdRun.Separator.Left.Enabled {
|
||||||
|
b.FullText = fmt.Sprintf(
|
||||||
|
"<span color='%s' background='%s' font='%s' size='%s'>%s</span>",
|
||||||
|
Conf.CmdRun.Separator.Left.Color,
|
||||||
|
Conf.CmdRun.Separator.Left.Background,
|
||||||
|
Conf.CmdRun.Separator.Left.Font,
|
||||||
|
Conf.CmdRun.Separator.Left.FontSize,
|
||||||
|
Conf.CmdRun.Separator.Left.Symbol,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.FullText += fmt.Sprintf(
|
||||||
|
"<span color='%s' background='%s' font='%s' size='%s'>%s</span>",
|
||||||
|
Conf.CmdRun.Color,
|
||||||
|
Conf.CmdRun.Background,
|
||||||
|
Conf.CmdRun.Font,
|
||||||
|
Conf.CmdRun.FontSize,
|
||||||
|
Conf.Values.RunCommandOutput,
|
||||||
|
)
|
||||||
|
|
||||||
|
if Conf.CmdRun.Separator.Right.Enabled {
|
||||||
|
b.FullText += fmt.Sprintf(
|
||||||
|
"<span color='%s' background='%s' font='%s' size='%s'>%s</span>",
|
||||||
|
Conf.CmdRun.Separator.Right.Color,
|
||||||
|
Conf.CmdRun.Separator.Right.Background,
|
||||||
|
Conf.CmdRun.Separator.Right.Font,
|
||||||
|
Conf.CmdRun.Separator.Right.FontSize,
|
||||||
|
Conf.CmdRun.Separator.Right.Symbol,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Markup = "pango"
|
||||||
|
b.Separator = false
|
||||||
|
|
||||||
|
j = append(j, b)
|
||||||
|
}
|
||||||
|
|
||||||
if Conf.Clock.Enabled {
|
if Conf.Clock.Enabled {
|
||||||
var b lib.I3BarOutBlock
|
var b lib.I3BarOutBlock
|
||||||
|
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
/home/eleksir/git/i3status-go/cmd/i3status-go/default-config.json
|
../cmd/i3status-go/default-config.json
|
||||||
@@ -29,7 +29,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
batteries []*battery.Battery = []*battery.Battery{}
|
batteries = []*battery.Battery{}
|
||||||
Batts string
|
Batts string
|
||||||
ch int
|
ch int
|
||||||
status string
|
status string
|
||||||
@@ -52,6 +52,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to read file %s: %s", file, err)
|
log.Printf("Unable to read file %s: %s", file, err)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,6 +66,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to read file %s: %s", statusFile, err)
|
log.Printf("Unable to read file %s: %s", statusFile, err)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +93,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Unable to convert string from file %s to integer", file)
|
log.Printf("Unable to convert string from file %s to integer", file)
|
||||||
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,9 +103,9 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
batteries, _ = battery.GetAll()
|
|
||||||
// In theory, this module should give for each entry its separate err, but in practice it gives
|
// In theory, this module should give for each entry its separate err, but in practice it gives
|
||||||
// one single err for all entries, so we cannot detemine whist exatly entry errored.
|
// one single err for all entries, so we cannot detemine whist exatly entry errored.
|
||||||
|
batteries, _ = battery.GetAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -59,16 +59,17 @@ type Separator struct {
|
|||||||
|
|
||||||
type MyConfig struct {
|
type MyConfig struct {
|
||||||
Values struct {
|
Values struct {
|
||||||
PrintOutput bool
|
PrintOutput bool
|
||||||
CPUTemperature int64
|
CPUTemperature int64
|
||||||
BatteryString string
|
BatteryString string
|
||||||
ClockTime string
|
ClockTime string
|
||||||
IfStatus string
|
IfStatus string
|
||||||
VPNStatus string
|
VPNStatus string
|
||||||
Memory Mem
|
Memory Mem
|
||||||
La string
|
La string
|
||||||
PA *p.Client
|
PA *p.Client
|
||||||
SoundVolume string
|
SoundVolume string
|
||||||
|
RunCommandOutput string
|
||||||
}
|
}
|
||||||
|
|
||||||
Channels struct {
|
Channels struct {
|
||||||
@@ -231,9 +232,25 @@ type MyConfig struct {
|
|||||||
} `json:"tasks,omitempty"`
|
} `json:"tasks,omitempty"`
|
||||||
} `json:"cron,omitempty"`
|
} `json:"cron,omitempty"`
|
||||||
|
|
||||||
|
CmdRun struct {
|
||||||
|
Enabled bool `json:"enabled,omitempty"`
|
||||||
|
Color string `json:"color,omitempty"`
|
||||||
|
Background string `json:"background,omitempty"`
|
||||||
|
Font string `json:"font,omitempty"`
|
||||||
|
FontSize string `json:"font_size,omitempty"`
|
||||||
|
Separator Separator `json:"separator,omitempty"`
|
||||||
|
Cmd string `json:"cmd,omitempty"`
|
||||||
|
Delay int `json:"delay,omitempty"`
|
||||||
|
Args []string `json:"args,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
AppButtons struct {
|
AppButtons struct {
|
||||||
Enabled bool `json:"enabled,omitempty"`
|
Enabled bool `json:"enabled,omitempty"`
|
||||||
Separator Separator `json:"separator,omitempty"`
|
Color string `json:"color,omitempty"`
|
||||||
|
Background string `json:"background,omitempty"`
|
||||||
|
Font string `json:"font,omitempty"`
|
||||||
|
FontSize string `json:"font_size,omitempty"`
|
||||||
|
Separator Separator `json:"separator,omitempty"`
|
||||||
} `json:"app_buttons,omitempty"`
|
} `json:"app_buttons,omitempty"`
|
||||||
|
|
||||||
Apps []struct {
|
Apps []struct {
|
||||||
@@ -245,6 +262,8 @@ type MyConfig struct {
|
|||||||
Class string `json:"class,omitempty"`
|
Class string `json:"class,omitempty"`
|
||||||
Color string `json:"color,omitempty"`
|
Color string `json:"color,omitempty"`
|
||||||
Background string `json:"background,omitempty"`
|
Background string `json:"background,omitempty"`
|
||||||
|
Font string `json:"font,omitempty"`
|
||||||
|
FontSize string `json:"font_size,omitempty"`
|
||||||
Border string `json:"border,omitempty"`
|
Border string `json:"border,omitempty"`
|
||||||
BorderActive string `json:"border_active,omitempty"`
|
BorderActive string `json:"border_active,omitempty"`
|
||||||
Separator bool `json:"separator,omitempty"`
|
Separator bool `json:"separator,omitempty"`
|
||||||
@@ -451,6 +470,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
|
|
||||||
if sampleConfig.LA.FontSize == "" {
|
if sampleConfig.LA.FontSize == "" {
|
||||||
sampleConfig.LA.FontSize = sampleConfig.FontSize
|
sampleConfig.LA.FontSize = sampleConfig.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.LA.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.LA.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.LA.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.LA.FontSize, fallback to %s",
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.LA.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.LA.Separator.Left.Color == "" {
|
if sampleConfig.LA.Separator.Left.Color == "" {
|
||||||
@@ -505,22 +548,6 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
sampleConfig.LA.Separator.Right.Background = sampleConfig.Separator.Right.Background
|
sampleConfig.LA.Separator.Right.Background = sampleConfig.Separator.Right.Background
|
||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.LA.Separator.Right.Font == "" {
|
|
||||||
sampleConfig.LA.Separator.Right.Font = sampleConfig.Separator.Right.Font
|
|
||||||
}
|
|
||||||
|
|
||||||
if sampleConfig.LA.Separator.Right.FontSize == "" {
|
|
||||||
sampleConfig.LA.Separator.Right.FontSize = sampleConfig.Separator.Right.FontSize
|
|
||||||
}
|
|
||||||
|
|
||||||
if sampleConfig.LA.Separator.Right.Color == "" {
|
|
||||||
sampleConfig.LA.Separator.Right.Color = sampleConfig.Separator.Right.Color
|
|
||||||
}
|
|
||||||
|
|
||||||
if sampleConfig.LA.Separator.Right.Background == "" {
|
|
||||||
sampleConfig.LA.Separator.Right.Background = sampleConfig.Separator.Right.Background
|
|
||||||
}
|
|
||||||
|
|
||||||
if sampleConfig.LA.Separator.Right.Symbol == "" {
|
if sampleConfig.LA.Separator.Right.Symbol == "" {
|
||||||
sampleConfig.LA.Separator.Right.Symbol = sampleConfig.Separator.Right.Symbol
|
sampleConfig.LA.Separator.Right.Symbol = sampleConfig.Separator.Right.Symbol
|
||||||
}
|
}
|
||||||
@@ -571,6 +598,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
|
|
||||||
if sampleConfig.Mem.FontSize == "" {
|
if sampleConfig.Mem.FontSize == "" {
|
||||||
sampleConfig.Mem.FontSize = sampleConfig.FontSize
|
sampleConfig.Mem.FontSize = sampleConfig.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.Mem.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.Mem.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.Mem.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.Mem.FontSize, fallback to %s",
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.Mem.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.Mem.Separator.Left.Color == "" {
|
if sampleConfig.Mem.Separator.Left.Color == "" {
|
||||||
@@ -675,6 +726,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
|
|
||||||
if sampleConfig.Clock.FontSize == "" {
|
if sampleConfig.Clock.FontSize == "" {
|
||||||
sampleConfig.Clock.FontSize = sampleConfig.FontSize
|
sampleConfig.Clock.FontSize = sampleConfig.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.Clock.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.Clock.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.Clock.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.Clock.FontSize, fallback to %s",
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.Clock.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.Clock.Separator.Left.Enabled {
|
if sampleConfig.Clock.Separator.Left.Enabled {
|
||||||
@@ -803,6 +878,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
|
|
||||||
if sampleConfig.Battery.FontSize == "" {
|
if sampleConfig.Battery.FontSize == "" {
|
||||||
sampleConfig.Battery.FontSize = sampleConfig.FontSize
|
sampleConfig.Battery.FontSize = sampleConfig.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.Battery.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.Battery.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.Battery.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.Battery.FontSize, fallback to %s",
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.Battery.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.Battery.Symbol == "" {
|
if sampleConfig.Battery.Symbol == "" {
|
||||||
@@ -815,6 +914,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
|
|
||||||
if sampleConfig.Battery.SymbolFontSize == "" {
|
if sampleConfig.Battery.SymbolFontSize == "" {
|
||||||
sampleConfig.Battery.SymbolFontSize = sampleConfig.Battery.FontSize
|
sampleConfig.Battery.SymbolFontSize = sampleConfig.Battery.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.Battery.SymbolFontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.Battery.SymbolFontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.Battery.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.Battery.SymbolFontSize = sampleConfig.Battery.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.Battery.SymbolFontSize, fallback to %s",
|
||||||
|
sampleConfig.Battery.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.Battery.SymbolFontSize = sampleConfig.Battery.FontSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sampleConfig.Battery.ChargeColor.Full will be empty string if not set
|
// sampleConfig.Battery.ChargeColor.Full will be empty string if not set
|
||||||
@@ -930,6 +1053,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
|
|
||||||
if sampleConfig.CPUTemp.FontSize == "" {
|
if sampleConfig.CPUTemp.FontSize == "" {
|
||||||
sampleConfig.CPUTemp.FontSize = sampleConfig.FontSize
|
sampleConfig.CPUTemp.FontSize = sampleConfig.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.CPUTemp.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.CPUTemp.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.CPUTemp.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.CPUTemp.FontSize, fallback to %s",
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.CPUTemp.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.CPUTemp.Separator.Left.Enabled {
|
if sampleConfig.CPUTemp.Separator.Left.Enabled {
|
||||||
@@ -1036,11 +1183,35 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.Vpn.Font == "" {
|
if sampleConfig.Vpn.Font == "" {
|
||||||
sampleConfig.Vpn.FontSize = sampleConfig.Font
|
sampleConfig.Vpn.Font = sampleConfig.Font
|
||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.Vpn.FontSize == "" {
|
if sampleConfig.Vpn.FontSize == "" {
|
||||||
sampleConfig.Vpn.FontSize = sampleConfig.FontSize
|
sampleConfig.Vpn.FontSize = sampleConfig.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.Vpn.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.Vpn.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.Vpn.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.Vpn.FontSize, fallback to %s",
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.Vpn.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check status file at least once per 3 seconds
|
// Check status file at least once per 3 seconds
|
||||||
@@ -1185,6 +1356,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
|
|
||||||
if sampleConfig.SimpleVolumePa.FontSize == "" {
|
if sampleConfig.SimpleVolumePa.FontSize == "" {
|
||||||
sampleConfig.SimpleVolumePa.FontSize = sampleConfig.FontSize
|
sampleConfig.SimpleVolumePa.FontSize = sampleConfig.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.SimpleVolumePa.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.SimpleVolumePa.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.SimpleVolumePa.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.SimpleVolumePa.FontSize, fallback to %s",
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.SimpleVolumePa.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.SimpleVolumePa.Symbol == "" {
|
if sampleConfig.SimpleVolumePa.Symbol == "" {
|
||||||
@@ -1197,6 +1392,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
|
|
||||||
if sampleConfig.SimpleVolumePa.SymbolFontSize == "" {
|
if sampleConfig.SimpleVolumePa.SymbolFontSize == "" {
|
||||||
sampleConfig.SimpleVolumePa.SymbolFontSize = sampleConfig.SimpleVolumePa.FontSize
|
sampleConfig.SimpleVolumePa.SymbolFontSize = sampleConfig.SimpleVolumePa.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.SimpleVolumePa.SymbolFontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.SimpleVolumePa.SymbolFontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.SimpleVolumePa.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.SimpleVolumePa.SymbolFontSize = sampleConfig.SimpleVolumePa.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.SimpleVolumePa.SymbolFontSize, fallback to %s",
|
||||||
|
sampleConfig.SimpleVolumePa.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.SimpleVolumePa.SymbolFontSize = sampleConfig.SimpleVolumePa.FontSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.SimpleVolumePa.Step == 0 {
|
if sampleConfig.SimpleVolumePa.Step == 0 {
|
||||||
@@ -1357,6 +1576,29 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
|
|
||||||
if sampleConfig.NetIf.FontSize == "" {
|
if sampleConfig.NetIf.FontSize == "" {
|
||||||
sampleConfig.NetIf.FontSize = sampleConfig.FontSize
|
sampleConfig.NetIf.FontSize = sampleConfig.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.NetIf.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.NetIf.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.NetIf.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf("Unable to set sampleConfig.NetIf.FontSize, fallback to %s",
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.NetIf.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if sampleConfig.NetIf.Separator.Left.Color == "" {
|
if sampleConfig.NetIf.Separator.Left.Color == "" {
|
||||||
@@ -1446,7 +1688,186 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// sampleConfig.CmdRun.Enabled will false if not set in config
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Cmd == "" && sampleConfig.CmdRun.Enabled {
|
||||||
|
sampleConfig.CmdRun.Enabled = false
|
||||||
|
|
||||||
|
log.Print(
|
||||||
|
"Setting sampleConfig.CmdRun.Enabled to false because sampleConfig.CmdRun.Cmd is not set",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// sampleConfig.CmdRun.Args can be empty
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Color == "" {
|
||||||
|
sampleConfig.CmdRun.Color = sampleConfig.Color
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Background == "" {
|
||||||
|
sampleConfig.CmdRun.Background = sampleConfig.Background
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Font == "" {
|
||||||
|
sampleConfig.CmdRun.Font = sampleConfig.Font
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.FontSize == "" {
|
||||||
|
sampleConfig.CmdRun.FontSize = sampleConfig.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.CmdRun.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.CmdRun.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.CmdRun.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.CmdRun.FontSize, fallback to %s",
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.CmdRun.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Separator.Left.Color == "" {
|
||||||
|
sampleConfig.CmdRun.Separator.Left.Color = sampleConfig.Separator.Left.Color
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Separator.Left.Background == "" {
|
||||||
|
sampleConfig.CmdRun.Separator.Left.Background = sampleConfig.Separator.Left.Background
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Separator.Left.Symbol == "" {
|
||||||
|
sampleConfig.CmdRun.Separator.Left.Symbol = sampleConfig.Separator.Left.Symbol
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Separator.Left.Font == "" {
|
||||||
|
sampleConfig.CmdRun.Separator.Left.Font = sampleConfig.Separator.Left.Font
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Separator.Left.FontSize == "" {
|
||||||
|
sampleConfig.CmdRun.Separator.Left.FontSize = sampleConfig.Separator.Left.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.CmdRun.Separator.Left.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.CmdRun.Separator.Left.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.Separator.Left.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.CmdRun.Separator.Left.FontSize = sampleConfig.Separator.Left.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.CmdRun.Separator.Left.FontSize, fallback to %s",
|
||||||
|
sampleConfig.Separator.Left.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.CmdRun.Separator.Left.FontSize = sampleConfig.Separator.Left.FontSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Separator.Right.Color == "" {
|
||||||
|
sampleConfig.CmdRun.Separator.Right.Color = sampleConfig.Separator.Right.Color
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Separator.Right.Background == "" {
|
||||||
|
sampleConfig.CmdRun.Separator.Right.Background = sampleConfig.Separator.Right.Background
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Separator.Right.Symbol == "" {
|
||||||
|
sampleConfig.CmdRun.Separator.Right.Symbol = sampleConfig.Separator.Right.Symbol
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Separator.Right.Font == "" {
|
||||||
|
sampleConfig.CmdRun.Separator.Right.Font = sampleConfig.Separator.Right.Font
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.CmdRun.Separator.Right.FontSize == "" {
|
||||||
|
sampleConfig.CmdRun.Separator.Right.FontSize = sampleConfig.Separator.Right.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.CmdRun.Separator.Right.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.CmdRun.Separator.Right.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.Separator.Right.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.CmdRun.Separator.Right.FontSize = sampleConfig.Separator.Right.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.CmdRun.Separator.Right.FontSize, fallback to %s",
|
||||||
|
sampleConfig.Separator.Right.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.CmdRun.Separator.Right.FontSize = sampleConfig.Separator.Right.FontSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// sampleConfig.AppButtons.Enabled will false if not set in config
|
// sampleConfig.AppButtons.Enabled will false if not set in config
|
||||||
|
if sampleConfig.AppButtons.Color == "" {
|
||||||
|
sampleConfig.AppButtons.Color = sampleConfig.Color
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.AppButtons.Background == "" {
|
||||||
|
sampleConfig.AppButtons.Background = sampleConfig.Background
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.AppButtons.Font == "" {
|
||||||
|
sampleConfig.AppButtons.Font = sampleConfig.Font
|
||||||
|
}
|
||||||
|
|
||||||
|
if sampleConfig.AppButtons.FontSize == "" {
|
||||||
|
sampleConfig.AppButtons.FontSize = sampleConfig.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
sampleConfig.AppButtons.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.AppButtons.FontSize: %s, fallback to %s",
|
||||||
|
err,
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.AppButtons.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set sampleConfig.AppButtons.FontSize, fallback to %s",
|
||||||
|
sampleConfig.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
sampleConfig.AppButtons.FontSize = sampleConfig.FontSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if sampleConfig.AppButtons.Separator.Left.Color == "" {
|
if sampleConfig.AppButtons.Separator.Left.Color == "" {
|
||||||
sampleConfig.AppButtons.Separator.Left.Color = sampleConfig.Separator.Left.Color
|
sampleConfig.AppButtons.Separator.Left.Color = sampleConfig.Separator.Left.Color
|
||||||
@@ -1547,23 +1968,57 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
|||||||
|
|
||||||
// app.Args can be empty slice. In that case command will be run without aruments.
|
// app.Args can be empty slice. In that case command will be run without aruments.
|
||||||
if app.Cmd == "" {
|
if app.Cmd == "" {
|
||||||
|
// If command omitted it will be just /usr/bin/true.
|
||||||
app.Cmd = "true"
|
app.Cmd = "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.Color == "" {
|
if app.Color == "" {
|
||||||
app.Color = sampleConfig.Color
|
app.Color = sampleConfig.AppButtons.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.Background == "" {
|
if app.Background == "" {
|
||||||
app.Background = sampleConfig.Background
|
app.Background = sampleConfig.AppButtons.Background
|
||||||
|
}
|
||||||
|
|
||||||
|
if app.Font == "" {
|
||||||
|
app.Font = sampleConfig.AppButtons.Font
|
||||||
|
}
|
||||||
|
|
||||||
|
if app.FontSize == "" {
|
||||||
|
app.FontSize = sampleConfig.AppButtons.FontSize
|
||||||
|
} else {
|
||||||
|
matched, err := regexp.MatchString(
|
||||||
|
`^(xx-small|x-small|small|medium|large|x-large|xx-large|smaller|larger)$`,
|
||||||
|
app.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf(
|
||||||
|
"Unable to set %s.FontSize: %s, fallback to %s",
|
||||||
|
app.Name,
|
||||||
|
err,
|
||||||
|
sampleConfig.AppButtons.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
app.FontSize = sampleConfig.AppButtons.FontSize
|
||||||
|
}
|
||||||
|
|
||||||
|
if !matched {
|
||||||
|
log.Printf("Unable to set %s.FontSize, fallback to %s",
|
||||||
|
app.Name,
|
||||||
|
sampleConfig.AppButtons.FontSize,
|
||||||
|
)
|
||||||
|
|
||||||
|
app.FontSize = sampleConfig.AppButtons.FontSize
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.Border == "" {
|
if app.Border == "" {
|
||||||
app.Border = sampleConfig.Color
|
app.Border = sampleConfig.AppButtons.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
if app.BorderActive == "" {
|
if app.BorderActive == "" {
|
||||||
app.BorderActive = sampleConfig.Color
|
app.BorderActive = sampleConfig.AppButtons.Color
|
||||||
}
|
}
|
||||||
|
|
||||||
// app.Separator can be omitted, in that case it is false
|
// app.Separator can be omitted, in that case it is false
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ func (c *MyConfig) UpdateMemStats() {
|
|||||||
if c.Values.Memory.Usedpct != uint64(v.UsedPercent) || c.Values.Memory.Shared != v.Shared/1024/1024 || c.Values.Memory.Swap != v.SwapTotal-v.SwapFree {
|
if c.Values.Memory.Usedpct != uint64(v.UsedPercent) || c.Values.Memory.Shared != v.Shared/1024/1024 || c.Values.Memory.Swap != v.SwapTotal-v.SwapFree {
|
||||||
c.Values.Memory.Usedpct = uint64(v.UsedPercent)
|
c.Values.Memory.Usedpct = uint64(v.UsedPercent)
|
||||||
c.Values.Memory.Shared = v.Shared / 1024 / 1024
|
c.Values.Memory.Shared = v.Shared / 1024 / 1024
|
||||||
c.Values.Memory.Swap = sw.Used
|
c.Values.Memory.Swap = sw.Used / 1024 / 1024
|
||||||
c.Channels.UpdateReady <- true
|
c.Channels.UpdateReady <- true
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
41
internal/lib/runcommand.go
Normal file
41
internal/lib/runcommand.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package lib
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// RunCommands gets list of commands runs them sequentally and conacatenates their output.
|
||||||
|
func (c *MyConfig) RunCommand() {
|
||||||
|
var (
|
||||||
|
InitialDelay = 100 * time.Millisecond
|
||||||
|
LoopIterationDelay = time.Duration(c.CmdRun.Delay) * time.Second
|
||||||
|
Delay = InitialDelay
|
||||||
|
ticker = time.NewTicker(Delay)
|
||||||
|
)
|
||||||
|
|
||||||
|
for range ticker.C {
|
||||||
|
if Delay == InitialDelay {
|
||||||
|
Delay = LoopIterationDelay
|
||||||
|
ticker.Reset(Delay)
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
outputString string
|
||||||
|
command = []string{c.CmdRun.Cmd}
|
||||||
|
)
|
||||||
|
|
||||||
|
if len(c.CmdRun.Args) > 0 {
|
||||||
|
command = append(command, c.CmdRun.Args...)
|
||||||
|
}
|
||||||
|
|
||||||
|
outputString += RunProcess(command)
|
||||||
|
|
||||||
|
log.Println(c.Values.RunCommandOutput)
|
||||||
|
|
||||||
|
if c.Values.RunCommandOutput != outputString {
|
||||||
|
c.Values.RunCommandOutput = outputString
|
||||||
|
c.Channels.UpdateReady <- true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package lib
|
package lib
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@@ -12,6 +14,7 @@ import (
|
|||||||
func (c *MyConfig) Spawner() {
|
func (c *MyConfig) Spawner() {
|
||||||
for prg := range c.Channels.RunChan {
|
for prg := range c.Channels.RunChan {
|
||||||
<-time.After(25 * time.Millisecond)
|
<-time.After(25 * time.Millisecond)
|
||||||
|
|
||||||
devnullR, _ := os.Open(os.DevNull)
|
devnullR, _ := os.Open(os.DevNull)
|
||||||
devnullW, _ := os.OpenFile(os.DevNull, os.O_WRONLY|os.O_APPEND, 0644)
|
devnullW, _ := os.OpenFile(os.DevNull, os.O_WRONLY|os.O_APPEND, 0644)
|
||||||
|
|
||||||
@@ -55,3 +58,41 @@ func (c *MyConfig) CleanZombies() {
|
|||||||
time.Sleep(1 * time.Minute)
|
time.Sleep(1 * time.Minute)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RunProcess runs given command and returns contens of command stdout. On error prints error on stderr and returns
|
||||||
|
// empty syting.
|
||||||
|
func RunProcess(command []string) string {
|
||||||
|
var (
|
||||||
|
cmd *exec.Cmd
|
||||||
|
stdout, stderr bytes.Buffer
|
||||||
|
)
|
||||||
|
|
||||||
|
switch len(command) {
|
||||||
|
case 1:
|
||||||
|
cmd = exec.Command(command[0], "") //nolint: gosec
|
||||||
|
default:
|
||||||
|
cmd = exec.Command(command[0], command[1:]...) //nolint: gosec
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Dir = "/"
|
||||||
|
cmd.Stdout = &stdout
|
||||||
|
cmd.Stderr = &stderr
|
||||||
|
|
||||||
|
err := cmd.Run()
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if stdout.String() != "" {
|
||||||
|
log.Printf("Unable to run '%s': %s, %s", strings.Join(command, " "), err, stdout.String())
|
||||||
|
} else {
|
||||||
|
log.Printf("Unable to run '%s': %s", strings.Join(command, " "), err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
if stderr.String() != "" {
|
||||||
|
log.Printf("%s: %s", strings.Join(command, " "), stderr.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.TrimRight(stdout.String(), "\n")
|
||||||
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ func (c *MyConfig) UpdateVPNStatus() {
|
|||||||
func (c *MyConfig) VPNTCPCheck() bool {
|
func (c *MyConfig) VPNTCPCheck() bool {
|
||||||
conn, err := net.DialTimeout(
|
conn, err := net.DialTimeout(
|
||||||
"tcp",
|
"tcp",
|
||||||
fmt.Sprintf("%s:%d", c.Vpn.TCPCheck.Host, c.Vpn.TCPCheck.Port),
|
fmt.Sprintf("%s:%d", c.Vpn.TCPCheck.Host, c.Vpn.TCPCheck.Port), //nolint: hostport
|
||||||
time.Second*time.Duration(c.Vpn.TCPCheck.Timeout),
|
time.Second*time.Duration(c.Vpn.TCPCheck.Timeout),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user