Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d9ce425981 | ||
|
|
069b09e5ec | ||
|
|
8f2afa0441 | ||
|
|
8fa1c6d596 | ||
|
|
12f4dc75f0 | ||
|
|
913fcc34ee | ||
|
|
ac856f4174 | ||
|
|
a5d793926b | ||
|
|
40a94bd001 |
@@ -18,7 +18,7 @@ It is i3bar text generator.
|
||||
|
||||
## How to build it
|
||||
|
||||
This appliction was tested to compile with go v1.24.
|
||||
This application was tested to compile with go v1.24.
|
||||
|
||||
All you need is go lang compiler and gnu make utility. Invoke
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Default text and *block* border colors. If not set #3e78fd is used.
|
||||
"color" : "#3e78fd",
|
||||
|
||||
// Default backbround color. If not set value of #edeceb is used.
|
||||
// Default background color. If not set value of #edeceb is used.
|
||||
"background" : "#000000",
|
||||
|
||||
// Can be omitted, then Liberation Mono will be used.
|
||||
@@ -12,7 +12,7 @@
|
||||
// ‘smaller’ or ‘larger’
|
||||
"font_size": "medium",
|
||||
|
||||
"separator" : {
|
||||
"separator": {
|
||||
"left": {
|
||||
// Set to false if omitted.
|
||||
"enabled": true,
|
||||
@@ -778,6 +778,19 @@
|
||||
"app_buttons": {
|
||||
"enabled": true,
|
||||
|
||||
// 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 net-if block here.
|
||||
"separator": {
|
||||
"left": {
|
||||
@@ -821,31 +834,36 @@
|
||||
// ‘smaller’ or ‘larger’. If omitted set to default font size defined for separator up here.
|
||||
"font_size": "medium"
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
|
||||
// Buttons - application launch "buttons"
|
||||
"apps": [
|
||||
{
|
||||
// Text dispalyed on button
|
||||
// Text displayed on button, pango markup supported.
|
||||
"full_text" : "📂",
|
||||
// Internal name, can be any string, but unique for each app button
|
||||
// Internal name, can be any string, but unique for each app button.
|
||||
"name" : "thunar",
|
||||
// Command itself
|
||||
// Command itself.
|
||||
"cmd" : "thunar",
|
||||
// Array of command args, optional
|
||||
// Array of command args, optional.
|
||||
"args": [ "." ],
|
||||
// Regexp that match with Instance component of WM_CLASS(STRING) of xprop output
|
||||
// Regexp that match with Instance component of WM_CLASS(STRING) of xprop output.
|
||||
"instance": "^thunar$",
|
||||
// Regexp that match with Class component of WM_CLASS(STRING) of xprop output
|
||||
// Regexp that match with Class component of WM_CLASS(STRING) of xprop output.
|
||||
"class": "^Thunar$",
|
||||
// text color in html notation
|
||||
// Text color in html notation.
|
||||
"color": "#ffa500",
|
||||
// background color in html notation
|
||||
// background color in html notation.
|
||||
"background" : "#000000",
|
||||
// border color in html notation
|
||||
// If omitted set to default font defined for app_buttons 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 app_buttons up here.
|
||||
"font_size": "medium",
|
||||
// Border color in html notation.
|
||||
"border": "#666666",
|
||||
// border color if there is at least one window with given Instance and/or Class exist
|
||||
// Border color if there is at least one window with given Instance and/or Class exist.
|
||||
"border_active": "#3e78fd",
|
||||
// Vertical line between objects on bar - if omitted true value is assumed by i3bar, but we set it to false
|
||||
// in that case. It is limitation of golang json parser.
|
||||
|
||||
@@ -192,7 +192,14 @@ func main() {
|
||||
)
|
||||
}
|
||||
|
||||
b.FullText = app.FullText
|
||||
b.FullText = fmt.Sprintf(
|
||||
"<span color='%s' background='%s' font='%s' size='%s'>%s</span>",
|
||||
app.Color,
|
||||
app.Background,
|
||||
app.Font,
|
||||
app.FontSize,
|
||||
app.FullText,
|
||||
)
|
||||
|
||||
if num == len(Conf.Apps) {
|
||||
b.FullText = fmt.Sprintf(
|
||||
@@ -205,8 +212,6 @@ func main() {
|
||||
)
|
||||
}
|
||||
|
||||
b.Background = app.Background
|
||||
b.Color = app.Color
|
||||
b.Instance = app.Instance
|
||||
b.Markup = `pango`
|
||||
b.Separator = app.Separator
|
||||
|
||||
@@ -29,7 +29,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
||||
}
|
||||
|
||||
var (
|
||||
batteries []*battery.Battery = []*battery.Battery{}
|
||||
batteries = []*battery.Battery{}
|
||||
Batts string
|
||||
ch int
|
||||
status string
|
||||
@@ -52,6 +52,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Unable to read file %s: %s", file, err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -65,6 +66,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Unable to read file %s: %s", statusFile, err)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -91,6 +93,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
||||
|
||||
if err != nil {
|
||||
log.Printf("Unable to convert string from file %s to integer", file)
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
@@ -100,9 +103,9 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
batteries, _ = battery.GetAll()
|
||||
// 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.
|
||||
batteries, _ = battery.GetAll()
|
||||
}
|
||||
|
||||
var (
|
||||
|
||||
@@ -21,6 +21,8 @@ type I3BarOutBlock struct {
|
||||
ShortText string `json:"short_text,omitempty"`
|
||||
Color string `json:"color,omitempty"`
|
||||
Background string `json:"background,omitempty"`
|
||||
Font string `json:"font,omitempty"`
|
||||
FontSize string `json:"font_size,omitempty"`
|
||||
Border string `json:"border,omitempty"`
|
||||
BorderTop int `json:"border_top"`
|
||||
BorderRight int `json:"border_right"`
|
||||
@@ -246,6 +248,10 @@ type MyConfig struct {
|
||||
|
||||
AppButtons 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"`
|
||||
} `json:"app_buttons,omitempty"`
|
||||
|
||||
@@ -258,6 +264,8 @@ type MyConfig struct {
|
||||
Class string `json:"class,omitempty"`
|
||||
Color string `json:"color,omitempty"`
|
||||
Background string `json:"background,omitempty"`
|
||||
Font string `json:"font,omitempty"`
|
||||
FontSize string `json:"font_size,omitempty"`
|
||||
Border string `json:"border,omitempty"`
|
||||
BorderActive string `json:"border_active,omitempty"`
|
||||
Separator bool `json:"separator,omitempty"`
|
||||
@@ -464,6 +472,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
|
||||
if sampleConfig.LA.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 == "" {
|
||||
@@ -518,22 +550,6 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
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 == "" {
|
||||
sampleConfig.LA.Separator.Right.Symbol = sampleConfig.Separator.Right.Symbol
|
||||
}
|
||||
@@ -584,6 +600,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
|
||||
if sampleConfig.Mem.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 == "" {
|
||||
@@ -688,6 +728,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
|
||||
if sampleConfig.Clock.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 {
|
||||
@@ -816,6 +880,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
|
||||
if sampleConfig.Battery.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 == "" {
|
||||
@@ -828,6 +916,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
|
||||
if sampleConfig.Battery.SymbolFontSize == "" {
|
||||
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
|
||||
@@ -943,6 +1055,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
|
||||
if sampleConfig.CPUTemp.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 {
|
||||
@@ -1049,11 +1185,35 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
}
|
||||
|
||||
if sampleConfig.Vpn.Font == "" {
|
||||
sampleConfig.Vpn.FontSize = sampleConfig.Font
|
||||
sampleConfig.Vpn.Font = sampleConfig.Font
|
||||
}
|
||||
|
||||
if sampleConfig.Vpn.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
|
||||
@@ -1198,6 +1358,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
|
||||
if sampleConfig.SimpleVolumePa.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 == "" {
|
||||
@@ -1210,6 +1394,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
|
||||
if sampleConfig.SimpleVolumePa.SymbolFontSize == "" {
|
||||
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 {
|
||||
@@ -1370,6 +1578,29 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
|
||||
if sampleConfig.NetIf.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 == "" {
|
||||
@@ -1463,6 +1694,7 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
|
||||
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",
|
||||
)
|
||||
@@ -1484,6 +1716,30 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
|
||||
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 == "" {
|
||||
@@ -1575,6 +1831,45 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
}
|
||||
|
||||
// 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 == "" {
|
||||
sampleConfig.AppButtons.Separator.Left.Color = sampleConfig.Separator.Left.Color
|
||||
@@ -1670,34 +1965,68 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
// app.Instance can be missing.
|
||||
// app.Class can be missing.
|
||||
if app.Name == "" {
|
||||
app.Name = fmt.Sprintf("app%d", num)
|
||||
sampleConfig.Apps[num].Name = fmt.Sprintf("app%d", num)
|
||||
}
|
||||
|
||||
// app.Args can be empty slice. In that case command will be run without aruments.
|
||||
if app.Cmd == "" {
|
||||
app.Cmd = "true"
|
||||
// If command omitted it will be just /usr/bin/true.
|
||||
sampleConfig.Apps[num].Cmd = "true"
|
||||
}
|
||||
|
||||
if app.Color == "" {
|
||||
app.Color = sampleConfig.Color
|
||||
sampleConfig.Apps[num].Color = sampleConfig.AppButtons.Color
|
||||
}
|
||||
|
||||
if app.Background == "" {
|
||||
app.Background = sampleConfig.Background
|
||||
sampleConfig.Apps[num].Background = sampleConfig.AppButtons.Background
|
||||
}
|
||||
|
||||
if app.Font == "" {
|
||||
sampleConfig.Apps[num].Font = sampleConfig.AppButtons.Font
|
||||
}
|
||||
|
||||
if app.FontSize == "" {
|
||||
sampleConfig.Apps[num].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,
|
||||
)
|
||||
|
||||
sampleConfig.Apps[num].FontSize = sampleConfig.AppButtons.FontSize
|
||||
}
|
||||
|
||||
if !matched {
|
||||
log.Printf("Unable to set %s.FontSize, fallback to %s",
|
||||
app.Name,
|
||||
sampleConfig.AppButtons.FontSize,
|
||||
)
|
||||
|
||||
sampleConfig.Apps[num].FontSize = sampleConfig.AppButtons.FontSize
|
||||
}
|
||||
}
|
||||
|
||||
if app.Border == "" {
|
||||
app.Border = sampleConfig.Color
|
||||
sampleConfig.Apps[num].Border = sampleConfig.AppButtons.Color
|
||||
}
|
||||
|
||||
if app.BorderActive == "" {
|
||||
app.BorderActive = sampleConfig.Color
|
||||
sampleConfig.Apps[num].BorderActive = sampleConfig.AppButtons.Color
|
||||
}
|
||||
|
||||
// app.Separator can be omitted, in that case it is false
|
||||
// app.SeparatorBlockWidth can be missing
|
||||
if app.FullText == "" {
|
||||
app.FullText = fmt.Sprintf(" %d ", num)
|
||||
sampleConfig.Apps[num].FullText = fmt.Sprintf(" %d ", num)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
c.Values.Memory.Usedpct = uint64(v.UsedPercent)
|
||||
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
|
||||
}
|
||||
} 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import (
|
||||
func (c *MyConfig) Spawner() {
|
||||
for prg := range c.Channels.RunChan {
|
||||
<-time.After(25 * time.Millisecond)
|
||||
|
||||
devnullR, _ := os.Open(os.DevNull)
|
||||
devnullW, _ := os.OpenFile(os.DevNull, os.O_WRONLY|os.O_APPEND, 0644)
|
||||
|
||||
@@ -68,9 +69,9 @@ func RunProcess(command []string) string {
|
||||
|
||||
switch len(command) {
|
||||
case 1:
|
||||
cmd = exec.Command(command[0], "")
|
||||
cmd = exec.Command(command[0], "") //nolint: gosec
|
||||
default:
|
||||
cmd = exec.Command(command[0], command[1:]...)
|
||||
cmd = exec.Command(command[0], command[1:]...) //nolint: gosec
|
||||
}
|
||||
|
||||
cmd.Dir = "/"
|
||||
@@ -87,11 +88,11 @@ func RunProcess(command []string) string {
|
||||
}
|
||||
|
||||
return ""
|
||||
} else {
|
||||
}
|
||||
|
||||
if stderr.String() != "" {
|
||||
log.Printf("%s: %s", strings.Join(command, " "), stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
return strings.TrimRight(stdout.String(), "\n")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user