Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
X
ximperconf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
ximperconf
Commits
41a62e06
Verified
Commit
41a62e06
authored
Oct 18, 2025
by
Kirill Unitsaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimize the management of hyprland modules
parent
e1373001
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
74 additions
and
37 deletions
+74
-37
actions.go
hyprland/actions.go
+74
-37
No files found.
hyprland/actions.go
View file @
41a62e06
...
...
@@ -62,38 +62,69 @@ func fileExists(path string) bool {
}
func
hyprlandModuleStatus
(
module
string
,
user
bool
)
string
{
sysFile
:=
hyprlandGetModuleFile
(
module
,
user
)
lineFull
:=
"source = "
+
sysFile
lineTilde
:=
"source = ~"
+
strings
.
TrimPrefix
(
sysFile
,
HomeDir
)
if
!
fileExists
(
sysFile
)
{
fmt
.
Printf
(
"Модуль '%s' не найден: %s"
,
module
,
sysFile
)
os
.
Exit
(
1
)
return
""
}
sysFile
,
lineFull
,
lineTilde
:=
hyprlandModuleLines
(
module
,
user
)
// Конфиг Hyprland отсутствует
if
!
fileExists
(
config
.
Env
.
Hyprland
.
Config
)
{
return
"disabled"
if
fileExists
(
sysFile
)
{
return
"unused"
}
return
"missing"
}
f
,
err
:=
os
.
Open
(
config
.
Env
.
Hyprland
.
Config
)
if
err
!=
nil
{
return
"disabled"
if
fileExists
(
sysFile
)
{
return
"unused"
}
return
"missing"
}
defer
f
.
Close
()
reFull
:=
regexp
.
MustCompile
(
`^\s*`
+
regexp
.
QuoteMeta
(
lineFull
)
+
`(?:\s|$)`
)
reTilde
:=
regexp
.
MustCompile
(
`^\s*`
+
regexp
.
QuoteMeta
(
lineTilde
)
+
`(?:\s|$)`
)
foundActive
:=
false
foundCommented
:=
false
sc
:=
bufio
.
NewScanner
(
f
)
for
sc
.
Scan
()
{
line
:=
sc
.
Text
()
trim
:=
strings
.
TrimSpace
(
line
)
if
trim
==
"#"
+
lineFull
||
trim
==
"# "
+
lineFull
||
trim
==
"#"
+
lineTilde
||
trim
==
"# "
+
lineTilde
{
foundCommented
=
true
continue
}
if
reFull
.
MatchString
(
line
)
||
reTilde
.
MatchString
(
line
)
{
return
"enabled"
foundActive
=
true
break
}
}
return
"disabled"
// подключён, но файла нет
if
foundActive
&&
!
fileExists
(
sysFile
)
{
return
"missing"
}
// подключён и файл есть
if
foundActive
&&
fileExists
(
sysFile
)
{
return
"enabled"
}
// закомментирован
if
foundCommented
{
return
"disabled"
}
// файл есть, но строка отсутствует
if
fileExists
(
sysFile
)
&&
!
foundActive
&&
!
foundCommented
{
return
"unused"
}
// Файла нет и упоминаний нет
return
"missing"
}
func
HyprlandModuleStatusCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
...
...
@@ -103,9 +134,10 @@ func HyprlandModuleStatusCommand(ctx context.Context, cmd *cli.Command) error {
}
func
HyprlandSetModule
(
action
string
,
module
string
,
user
bool
,
onlyNew
bool
)
(
string
,
error
)
{
sysFile
:=
hyprlandGetModuleFile
(
module
,
user
)
lineFull
:=
"source = "
+
sysFile
lineTilde
:=
"source = ~"
+
strings
.
TrimPrefix
(
sysFile
,
HomeDir
)
sysFile
,
lineFull
,
lineTilde
:=
hyprlandModuleLines
(
module
,
user
)
reFull
:=
regexp
.
MustCompile
(
`^\s*#\s*`
+
regexp
.
QuoteMeta
(
lineFull
)
+
`$`
)
reTilde
:=
regexp
.
MustCompile
(
`^\s*#\s*`
+
regexp
.
QuoteMeta
(
lineTilde
)
+
`$`
)
var
out
string
...
...
@@ -133,8 +165,6 @@ func HyprlandSetModule(action string, module string, user bool, onlyNew bool) (s
}
// Был закомментирован
reFull
:=
regexp
.
MustCompile
(
`^\s*#\s*`
+
regexp
.
QuoteMeta
(
lineFull
)
+
`$`
)
reTilde
:=
regexp
.
MustCompile
(
`^\s*#\s*`
+
regexp
.
QuoteMeta
(
lineTilde
)
+
`$`
)
if
reFull
.
MatchString
(
l
)
||
reTilde
.
MatchString
(
l
)
{
found
=
true
if
onlyNew
{
...
...
@@ -163,8 +193,6 @@ func HyprlandSetModule(action string, module string, user bool, onlyNew bool) (s
case
"disable"
:
for
i
,
l
:=
range
lines
{
reFull
:=
regexp
.
MustCompile
(
`^\s*#\s*`
+
regexp
.
QuoteMeta
(
lineFull
)
+
`$`
)
reTilde
:=
regexp
.
MustCompile
(
`^\s*#\s*`
+
regexp
.
QuoteMeta
(
lineTilde
)
+
`$`
)
if
reFull
.
MatchString
(
l
)
||
reTilde
.
MatchString
(
l
)
{
return
""
,
fmt
.
Errorf
(
"модуль '%s' уже отключён"
,
module
)
}
...
...
@@ -257,13 +285,15 @@ func hyprlandListModules(user bool, filter string) []string {
continue
}
status
:=
hyprlandModuleStatus
(
module
,
user
)
if
filter
==
"enabled"
&&
status
!=
"enabled"
{
if
filter
==
""
||
filter
==
"all"
{
modules
=
append
(
modules
,
module
)
continue
}
if
filter
==
"disabled"
&&
status
!=
"disabled"
{
continue
if
status
==
filter
{
modules
=
append
(
modules
,
module
)
}
modules
=
append
(
modules
,
module
)
}
return
modules
}
...
...
@@ -277,22 +307,22 @@ func hyprlandInfoModules(user bool, filter string) {
color
.
Blue
(
"Modules:"
)
statusMap
:=
map
[
string
]
struct
{
symbol
string
color
func
(
format
string
,
a
...
interface
{})
string
}{
"enabled"
:
{
symbol
:
"●"
,
color
:
color
.
GreenString
},
"disabled"
:
{
symbol
:
"○"
,
color
:
color
.
RedString
},
"missing"
:
{
symbol
:
"!"
,
color
:
color
.
YellowString
},
"unused"
:
{
symbol
:
"-"
,
color
:
color
.
HiBlackString
},
}
for
i
,
module
:=
range
modules
{
status
:=
hyprlandModuleStatus
(
module
,
user
)
info
:=
statusMap
[
status
]
coloredStatus
:=
""
coloredModule
:=
""
switch
status
{
case
"enabled"
:
coloredStatus
=
color
.
GreenString
(
"●"
)
coloredModule
=
color
.
GreenString
(
module
)
case
"disabled"
:
coloredStatus
=
color
.
RedString
(
"○"
)
coloredModule
=
color
.
RedString
(
module
)
default
:
coloredStatus
=
color
.
HiBlackString
(
"○"
)
coloredModule
=
color
.
HiBlackString
(
module
)
}
coloredStatus
:=
info
.
color
(
info
.
symbol
)
coloredModule
:=
info
.
color
(
module
)
prefix
:=
"├──"
if
i
==
len
(
modules
)
-
1
{
...
...
@@ -306,3 +336,10 @@ func HyprlandInfoModulesCommand(ctx context.Context, cmd *cli.Command) error {
hyprlandInfoModules
(
cmd
.
Bool
(
"user"
),
cmd
.
String
(
"filter"
))
return
nil
}
func
hyprlandModuleLines
(
module
string
,
user
bool
)
(
sysFile
,
lineFull
,
lineTilde
string
)
{
sysFile
=
hyprlandGetModuleFile
(
module
,
user
)
lineFull
=
"source = "
+
sysFile
lineTilde
=
"source = ~"
+
strings
.
TrimPrefix
(
sysFile
,
HomeDir
)
return
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment