Skip to content
This repository has been archived by the owner on Aug 30, 2024. It is now read-only.

Commit

Permalink
add to markdown raw and json output
Browse files Browse the repository at this point in the history
  • Loading branch information
abs3ntdev committed Jan 5, 2023
1 parent 90eb853 commit a768168
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 111 deletions.
Empty file added main
Empty file.
7 changes: 7 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ func filterBinds(configValues *reader.ConfigValues, flags *flags.Flags) []*reade
func markdownHandler(configValues *reader.ConfigValues, flags *flags.Flags) error {
md := keybindsToMarkdown(configValues.Binds)
out := ""
for _, val := range configValues.Keywords {
out += fmt.Sprintf("#### $%s = %s", val.Name, val.Value)
}
out += "\n"
out += "| Keybind | Dispatcher | Command | Comments |\n"
out += "|---------|------------|---------|----------|\n"
for _, row := range md {
Expand Down Expand Up @@ -138,6 +142,9 @@ func rawHandler(configValues *reader.ConfigValues, flags *flags.Flags) error {
}
out += "\n"
}
for _, key := range configValues.Keywords {
out += fmt.Sprintf("$%s = %s\n", key.Name, key.Value)
}
fmt.Print(out)
if flags.Output != "" {
err := os.WriteFile(flags.Output, []byte(out), 0o644)
Expand Down
6 changes: 3 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestMarkdown(t *testing.T) {
flags.ConfigPath = "test/hyprland.conf"
flags.Output = "test/markdown.md"
flags.Markdown = true
configValues, err := reader.ReadHyprlandConfig(flags.ConfigPath)
configValues, err := reader.ReadHyprlandConfig(flags)
if err != nil {
t.Errorf(err.Error())
}
Expand All @@ -28,7 +28,7 @@ func TestJson(t *testing.T) {
flags.ConfigPath = "test/hyprland.conf"
flags.Output = "test/out.json"
flags.Json = true
configValues, err := reader.ReadHyprlandConfig(flags.ConfigPath)
configValues, err := reader.ReadHyprlandConfig(flags)
if err != nil {
t.Errorf(err.Error())
}
Expand All @@ -43,7 +43,7 @@ func TestRaw(t *testing.T) {
flags.ConfigPath = "test/hyprland.conf"
flags.Output = "test/out"
flags.Json = true
configValues, err := reader.ReadHyprlandConfig(flags.ConfigPath)
configValues, err := reader.ReadHyprlandConfig(flags)
if err != nil {
t.Errorf(err.Error())
}
Expand Down
19 changes: 19 additions & 0 deletions reader/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ type Setting struct {
SubCategories []Setting
}

type Keyword struct {
Name string
Value string
}

type Keybind struct {
BindType string
Bind string
Expand All @@ -37,6 +42,7 @@ type ConfigValues struct {
Settings Settings `json:",omitempty"`
AutoStart []*Exec `json:",omitempty"`
Binds []*Keybind `json:",omitempty"`
Keywords []*Keyword `json:",omitempty"`
}

// Read Hyprland configuration file and return lines that start with bind= and bindm=
Expand Down Expand Up @@ -69,6 +75,7 @@ func ReadHyprlandConfig(flags *flags.Flags) (*ConfigValues, error) {

var binds []*Keybind
var autostart []*Exec
var keywords []*Keyword

for scanner.Scan() {
line := scanner.Text()
Expand All @@ -81,6 +88,8 @@ func ReadHyprlandConfig(flags *flags.Flags) (*ConfigValues, error) {
switch {
case strings.HasPrefix(line, "bind"):
binds = append(binds, makeBind(line))
case strings.HasPrefix(line, "$"):
keywords = append(keywords, makeKeyword(line))
case strings.HasPrefix(line, "exec"):
if flags.AutoStart {
autostart = append(autostart, makeExec(line))
Expand All @@ -95,6 +104,7 @@ func ReadHyprlandConfig(flags *flags.Flags) (*ConfigValues, error) {
Settings: settings,
Binds: binds,
AutoStart: autostart,
Keywords: keywords,
}
return configValues, nil
}
Expand Down Expand Up @@ -126,6 +136,15 @@ func makeExec(line string) *Exec {
return exec
}

func makeKeyword(line string) *Keyword {
split := strings.SplitN(line, "=", 2)
keyword := &Keyword{
Name: strings.TrimSpace(strings.TrimPrefix(split[0], "$")),
Value: strings.TrimSpace(split[1]),
}
return keyword
}

func makeBind(bind string) *Keybind {
split := strings.SplitN(bind, "=", 2)
keyBind := &Keybind{
Expand Down
51 changes: 8 additions & 43 deletions test/out
Original file line number Diff line number Diff line change
@@ -1,43 +1,8 @@
bind = $mainMod Q exec kitty #
bind = $mainMod C killactive #
bind = $mainMod M exit #
bind = $mainMod E exec dolphin #
bind = $mainMod V togglefloating #
bind = $mainMod R exec wofi --show drun #
bind = $mainMod P pseudo #dwindle
bind = $mainMod J togglesplit #dwindle
input {
kb_layout = us
follow_mouse = 1
sensitivity = 0#-1.0-1.0,0meansnomodification.
touchpad {
natural_scroll = no
}
}
general {
layout = dwindle
gaps_in = 5
gaps_out = 20
border_size = 2
col.active_border = rgba(1affffee)
col.inactive_border = rgba(595959aa)
}
decoration {
blur = yes
shadow_render_power = 3
col.shadow = rgba(1a1a1aee)
shadow_range = 4
rounding = 10
blur_size = 3
blur_passes = 1
blur_new_optimizations = on
drop_shadow = yes
}
animation {
enabled = yes
bezier = myBezier,0.05,0.9,0.1,1.05
animation = workspaces,1,6,default
}
gestures {
workspace_swipe = off
}
bind = $mainMod Q exec kitty
bind = $mainMod C killactive
bind = $mainMod M exit
bind = $mainMod E exec dolphin
bind = $mainMod V togglefloating
bind = $mainMod R exec wofi --show drun
bind = $mainMod P pseudo #dwindle
bind = $mainMod J togglesplit #dwindle
67 changes: 2 additions & 65 deletions test/out.json
Original file line number Diff line number Diff line change
@@ -1,67 +1,5 @@
{
"Settings": [
{
"Name": "input",
"Settings": {
"follow_mouse": "1",
"kb_layout": "us",
"sensitivity": "0#-1.0-1.0,0meansnomodification."
},
"SubCategories": [
{
"Name": "touchpad",
"Settings": {
"natural_scroll": "no"
},
"SubCategories": null
}
]
},
{
"Name": "general",
"Settings": {
"border_size": "2",
"col.active_border": "rgba(1affffee)",
"col.inactive_border": "rgba(595959aa)",
"gaps_in": "5",
"gaps_out": "20",
"layout": "dwindle"
},
"SubCategories": null
},
{
"Name": "decoration",
"Settings": {
"blur": "yes",
"blur_new_optimizations": "on",
"blur_passes": "1",
"blur_size": "3",
"col.shadow": "rgba(1a1a1aee)",
"drop_shadow": "yes",
"rounding": "10",
"shadow_range": "4",
"shadow_render_power": "3"
},
"SubCategories": null
},
{
"Name": "animation",
"Settings": {
"animation": "workspaces,1,6,default",
"bezier": "myBezier,0.05,0.9,0.1,1.05",
"enabled": "yes"
},
"SubCategories": null
},
{
"Name": "gestures",
"Settings": {
"workspace_swipe": "off"
},
"SubCategories": null
}
],
"KeyboardBinds": [
"Binds": [
{
"BindType": "bind",
"Bind": "$mainMod Q",
Expand Down Expand Up @@ -118,6 +56,5 @@
"Command": "",
"Comments": "dwindle"
}
],
"MouseBinds": null
]
}

0 comments on commit a768168

Please sign in to comment.