Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
i3going-on
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kevin Lyda
i3going-on
Commits
12bc71ba
Unverified
Commit
12bc71ba
authored
2 years ago
by
Kevin Lyda
Browse files
Options
Downloads
Patches
Plain Diff
Generate from configs.
parent
dc03fb66
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
bar/run.go
+21
-4
21 additions, 4 deletions
bar/run.go
config/config.go
+9
-0
9 additions, 0 deletions
config/config.go
modules/text.go
+10
-12
10 additions, 12 deletions
modules/text.go
with
40 additions
and
16 deletions
bar/run.go
+
21
−
4
View file @
12bc71ba
...
...
@@ -28,20 +28,37 @@ func handleCommands() {
// Run is essentially the main program.
func
Run
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
viper
.
BindPFlags
(
cmd
.
Flags
())
cfg
,
err
:=
config
.
ReadConfig
(
viper
.
GetString
(
"config"
))
if
err
!=
nil
{
// TODO Make a better default
cfg
,
err
=
config
.
ReadConfigStr
(
`---
modules:
- module: text
name: post
params:
text: "post"
color: "#11ff11"
on-click: xdg-open https://mastodon.ie/
- module: date
params:
format: 06-05-04 15:02
on-click: xdg-open https://calendar.google.com/
`
)
cobra
.
CheckErr
(
err
)
}
go
handleCommands
()
fmt
.
Printf
(
`{ "version": 1, "stop_signal": %d, "cont_signal": %d, "click_events": true }`
+
"
\n
"
,
unix
.
SignalNum
(
"SIGSTOP"
),
unix
.
SignalNum
(
"SIGCONT"
))
fmt
.
Println
(
"["
)
separator
:=
"["
for
{
line
:=
make
([]
string
,
0
,
5
)
for
_
,
module
:=
range
cfg
.
Modules
{
line
=
append
(
line
,
module
.
Render
())
}
fmt
.
Printf
(
strings
.
Join
(
line
,
","
))
fmt
.
Printf
(
"%s
\n
[%s]"
,
separator
,
strings
.
Join
(
line
,
","
))
separator
=
","
time
.
Sleep
(
5
*
time
.
Second
)
}
}
This diff is collapsed.
Click to expand it.
config/config.go
+
9
−
0
View file @
12bc71ba
...
...
@@ -2,6 +2,7 @@ package config
import
(
"os"
"strings"
"gitlab.ie.suberic.net/kevin/i3going-on/modules"
"gopkg.in/yaml.v3"
...
...
@@ -12,6 +13,14 @@ type Config struct {
Modules
[]
modules
.
Module
`yaml:"modules"`
}
// ReadConfigStr reads in the config.
func
ReadConfigStr
(
configStr
string
)
(
*
Config
,
error
)
{
configParser
:=
yaml
.
NewDecoder
(
strings
.
NewReader
(
configStr
))
cfg
:=
&
Config
{}
err
:=
configParser
.
Decode
(
&
cfg
)
return
cfg
,
err
}
// ReadConfig reads in the config.
func
ReadConfig
(
configFile
string
)
(
*
Config
,
error
)
{
config
,
err
:=
os
.
Open
(
configFile
)
...
...
This diff is collapsed.
Click to expand it.
modules/text.go
+
10
−
12
View file @
12bc71ba
package
modules
import
(
"fmt"
)
// TextMod module parameters for the text module.
type
TextMod
struct
{
name
string
...
...
@@ -26,18 +30,12 @@ func (t *TextMod) Name() string {
}
// OnClick returns the on-click setting for the module.
func
(
t
*
TextMod
)
Render
()
string
{
{
"name"
:
"color"
,
"full_text"
:
"RED"
,
"color"
:
"#11ff11"
func
(
t
*
TextMod
)
OnClick
()
string
{
return
t
.
onclick
}
// Render renders the module.
func
(
d
*
DateMod
)
Render
()
string
{
now
:=
time
.
Now
()
.
Format
(
d
.
Format
)
return
fmt
.
Sprintf
(
"{
\"
full_text
\"
:
\"
%s
\"
}"
,
)
func
(
t
*
TextMod
)
Render
()
string
{
// TODO: Make color and name optional.
return
fmt
.
Sprintf
(
`{"name": "%s", "full_text": "%s", "color": "%s"}`
,
t
.
name
,
t
.
Text
,
t
.
Color
)
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment