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
fcb380e1
Verified
Commit
fcb380e1
authored
Jan 06, 2026
by
Kirill Unitsaev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hyprland/module: optimize the code for working with filesee
parent
3ab504f2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
119 additions
and
58 deletions
+119
-58
hyprland.go
config/hyprland.go
+5
-0
actions.go
hyprland/actions.go
+114
-58
No files found.
config/hyprland.go
0 → 100644
View file @
fcb380e1
package
config
var
HyprlandSkipModules
=
[]
string
{
"hyprland"
,
"hypridle"
,
"hyprlock"
,
"hyprpaper"
,
"hyprsunset"
,
"xdph"
,
}
hyprland/actions.go
View file @
fcb380e1
...
...
@@ -5,7 +5,6 @@ import (
"ximperconf/ui"
"ximperconf/utils"
"bufio"
"context"
"fmt"
"os"
...
...
@@ -28,6 +27,12 @@ type HyprConfigError struct {
Text
string
}
type
HyprModuleInfo
struct
{
Status
string
Available
bool
LineNumber
int
}
func
HyprlandCheck
(
configPath
string
)
([]
HyprConfigError
,
error
)
{
cmd
:=
exec
.
Command
(
"hyprland"
,
"--verify-config"
,
...
...
@@ -117,23 +122,41 @@ func HyprlandGetModuleFile(module string, user bool) string {
return
filepath
.
Join
(
config
.
Env
.
Hyprland
.
SystemModulesDir
,
module
+
".conf"
)
}
func
hyprlandModule
Status
(
module
string
,
user
bool
)
string
{
func
hyprlandModule
Info
(
module
string
,
user
bool
)
HyprModuleInfo
{
sysFile
,
lineFull
,
lineTilde
:=
hyprlandModuleLines
(
module
,
user
)
ModuleAvailable
:=
true
for
_
,
skipModule
:=
range
config
.
HyprlandSkipModules
{
if
module
==
skipModule
{
ModuleAvailable
=
false
}
}
// Конфиг Hyprland отсутствует
if
!
utils
.
FileExists
(
config
.
Env
.
Hyprland
.
Config
)
{
if
utils
.
FileExists
(
sysFile
)
{
return
"unused"
return
HyprModuleInfo
{
Status
:
"unused"
,
Available
:
ModuleAvailable
,
}
}
return
HyprModuleInfo
{
Status
:
"missing"
,
}
return
"missing"
}
f
,
err
:=
os
.
Open
(
config
.
Env
.
Hyprland
.
Config
)
if
err
!=
nil
{
if
utils
.
FileExists
(
sysFile
)
{
return
"unused"
return
HyprModuleInfo
{
Status
:
"unused"
,
Available
:
ModuleAvailable
,
}
}
return
HyprModuleInfo
{
Status
:
"missing"
,
}
return
"missing"
}
defer
f
.
Close
()
...
...
@@ -142,51 +165,72 @@ func hyprlandModuleStatus(module string, user bool) string {
foundActive
:=
false
foundCommented
:=
false
var
LineNumber
int
sc
:=
bufio
.
NewScanner
(
f
)
for
sc
.
Scan
()
{
line
:=
sc
.
Text
()
data
,
_
:=
os
.
ReadFile
(
config
.
Env
.
Hyprland
.
Config
)
lines
:=
strings
.
Split
(
string
(
data
),
"
\n
"
)
for
i
,
line
:=
range
lines
{
trim
:=
strings
.
TrimSpace
(
line
)
if
trim
==
"#"
+
lineFull
||
trim
==
"# "
+
lineFull
||
trim
==
"#"
+
lineTilde
||
trim
==
"# "
+
lineTilde
{
foundCommented
=
true
LineNumber
=
i
continue
}
if
reFull
.
MatchString
(
line
)
||
reTilde
.
MatchString
(
line
)
{
foundActive
=
true
LineNumber
=
i
break
}
}
// подключён, но файла нет
if
foundActive
&&
!
utils
.
FileExists
(
sysFile
)
{
return
"missing"
return
HyprModuleInfo
{
Status
:
"missing"
,
Available
:
ModuleAvailable
,
LineNumber
:
LineNumber
,
}
}
// подключён и файл есть
if
foundActive
&&
utils
.
FileExists
(
sysFile
)
{
return
"enabled"
return
HyprModuleInfo
{
Status
:
"enabled"
,
Available
:
ModuleAvailable
,
LineNumber
:
LineNumber
,
}
}
// закомментирован
if
foundCommented
{
return
"disabled"
return
HyprModuleInfo
{
Status
:
"disabled"
,
Available
:
ModuleAvailable
,
LineNumber
:
LineNumber
,
}
}
// файл есть, но строка отсутствует
if
utils
.
FileExists
(
sysFile
)
&&
!
foundActive
&&
!
foundCommented
{
return
"unused"
return
HyprModuleInfo
{
Status
:
"unused"
,
Available
:
ModuleAvailable
,
}
}
// Файла нет и упоминаний нет
return
"missing"
return
HyprModuleInfo
{
Status
:
"missing"
,
}
}
func
hyprlandModuleStatusStruct
(
module
string
,
user
bool
)
ui
.
ItemStatus
{
status
:=
hyprlandModuleStatus
(
module
,
user
)
info
:=
hyprlandModuleInfo
(
module
,
user
)
switch
s
tatus
{
switch
info
.
S
tatus
{
case
"enabled"
:
return
ui
.
StatusEnabled
case
"disabled"
:
...
...
@@ -200,8 +244,12 @@ func hyprlandModuleStatusStruct(module string, user bool) ui.ItemStatus {
}
func
HyprlandModuleStatusCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
status
:=
hyprlandModuleStatus
(
cmd
.
Args
()
.
Get
(
0
),
cmd
.
Bool
(
"user"
))
fmt
.
Println
(
status
)
info
:=
hyprlandModuleInfo
(
cmd
.
Args
()
.
Get
(
0
),
cmd
.
Bool
(
"user"
))
if
!
info
.
Available
{
color
.
Red
(
"недопустимое название для модуля."
)
return
nil
}
fmt
.
Println
(
info
.
Status
)
return
nil
}
...
...
@@ -243,6 +291,13 @@ func HyprlandModuleCheck(module string, user bool, tmp bool) ([]HyprConfigError,
func
HyprlandModuleCheckCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
moduleinfo
:=
hyprlandModuleInfo
(
cmd
.
Args
()
.
Get
(
0
),
cmd
.
Bool
(
"user"
))
if
!
moduleinfo
.
Available
{
color
.
Red
(
"недопустимое название для модуля."
)
return
nil
}
info
,
err
:=
HyprlandModuleCheck
(
cmd
.
Args
()
.
Get
(
0
),
cmd
.
Bool
(
"user"
),
true
)
if
err
!=
nil
{
...
...
@@ -259,43 +314,44 @@ func HyprlandModuleCheckCommand(ctx context.Context, cmd *cli.Command) error {
func
HyprlandSetModule
(
action
string
,
module
string
,
user
bool
,
onlyNew
bool
)
(
string
,
error
)
{
sysFile
,
lineFull
,
lineTilde
:=
hyprlandModuleLines
(
module
,
user
)
info
:=
hyprlandModuleInfo
(
module
,
user
)
reFull
:=
regexp
.
MustCompile
(
`^\s*#\s*`
+
regexp
.
QuoteMeta
(
lineFull
)
+
`$`
)
reTilde
:=
regexp
.
MustCompile
(
`^\s*#\s*`
+
regexp
.
QuoteMeta
(
lineTilde
)
+
`$`
)
var
out
string
if
!
utils
.
FileExists
(
sysFile
)
{
if
!
info
.
Available
{
return
""
,
fmt
.
Errorf
(
"недопустимое название для модуля."
)
}
if
info
.
Status
==
"missing"
{
return
""
,
fmt
.
Errorf
(
"модуль '%s' не найден: %s"
,
module
,
sysFile
)
}
data
,
_
:=
os
.
ReadFile
(
config
.
Env
.
Hyprland
.
Config
)
lines
:=
strings
.
Split
(
string
(
data
),
"
\n
"
)
changed
:=
false
found
:=
false
switch
action
{
case
"enable"
:
for
i
,
l
:=
range
lines
{
trim
:=
strings
.
TrimSpace
(
l
)
// Уже включён
if
trim
==
lineFull
||
trim
==
lineTilde
{
return
""
,
fmt
.
Errorf
(
"модуль '%s' уже включён"
,
module
)
}
// Уже включён
if
info
.
Status
==
"enabled"
{
return
""
,
fmt
.
Errorf
(
"модуль '%s' уже включён"
,
module
)
}
// Был закомментирован
if
reFull
.
MatchString
(
l
)
||
reTilde
.
MatchString
(
l
)
{
found
=
true
if
onlyNew
{
return
""
,
fmt
.
Errorf
(
"модуль '%s' уже присутствует в конфиге (закомментирован) — пропущено"
,
module
)
}
lines
[
i
]
=
lineFull
changed
=
true
// Был закомментирован
if
info
.
Status
==
"disabled"
{
if
onlyNew
{
return
""
,
fmt
.
Errorf
(
"модуль '%s' уже присутствует в конфиге (закомментирован) — пропущено"
,
module
)
}
lines
[
info
.
LineNumber
]
=
lineFull
changed
=
true
}
// Если модуль нигде не найден — добавляем новую строку
if
!
found
{
if
info
.
Status
==
"unused"
{
lines
=
append
(
lines
,
lineFull
)
changed
=
true
}
...
...
@@ -307,20 +363,17 @@ func HyprlandSetModule(action string, module string, user bool, onlyNew bool) (s
out
=
fmt
.
Sprintf
(
"Модуль '%s' включён"
,
module
)
case
"disable"
:
for
i
,
l
:=
range
lines
{
trim
:=
strings
.
TrimSpace
(
l
)
// Уже выключен
if
reFull
.
MatchString
(
l
)
||
reTilde
.
MatchString
(
l
)
{
return
""
,
fmt
.
Errorf
(
"модуль '%s' уже отключён"
,
module
)
}
// Уже выключен
if
info
.
Status
==
"disabled"
{
return
""
,
fmt
.
Errorf
(
"модуль '%s' уже отключён"
,
module
)
}
// Включён
if
trim
==
lineFull
||
trim
==
lineTilde
{
lines
[
i
]
=
"# "
+
lineFull
out
=
fmt
.
Sprintf
(
"Модуль '%s' отключён"
,
module
)
changed
=
true
}
// Включён
if
info
.
Status
==
"enabled"
{
lines
[
info
.
LineNumber
]
=
"# "
+
lineFull
out
=
fmt
.
Sprintf
(
"Модуль '%s' отключён"
,
module
)
changed
=
true
}
if
!
changed
{
...
...
@@ -328,6 +381,7 @@ func HyprlandSetModule(action string, module string, user bool, onlyNew bool) (s
}
case
"remove"
:
// слайс для строк, которые не нужно удалять
newLines
:=
[]
string
{}
...
...
@@ -399,15 +453,15 @@ func HyprlandModuleDisableCommand(ctx context.Context, cmd *cli.Command) error {
func
HyprlandToggleModuleCommand
(
ctx
context
.
Context
,
cmd
*
cli
.
Command
)
error
{
module
:=
cmd
.
Args
()
.
Get
(
0
)
user
:=
cmd
.
Bool
(
"user"
)
status
:=
hyprlandModuleStatus
(
module
,
user
)
info
:=
hyprlandModuleInfo
(
module
,
user
)
var
msg
string
var
err
error
switch
s
tatus
{
switch
info
.
S
tatus
{
case
"enabled"
:
msg
,
err
=
HyprlandSetModule
(
"disable"
,
module
,
user
,
false
)
case
"disabled"
:
case
"disabled"
,
"unused"
:
msg
,
err
=
HyprlandSetModule
(
"enable"
,
module
,
user
,
false
)
}
...
...
@@ -432,11 +486,6 @@ func hyprlandListModules(user bool, filter string) []string {
if
err
!=
nil
{
return
nil
}
skip
:=
map
[
string
]
bool
{
"hyprland"
:
true
,
"hypridle"
:
true
,
"hyprlock"
:
true
,
"hyprpaper"
:
true
,
"hyprsunset"
:
true
,
"xdph"
:
true
,
}
var
modules
[]
string
for
_
,
e
:=
range
entries
{
...
...
@@ -444,17 +493,18 @@ func hyprlandListModules(user bool, filter string) []string {
continue
}
module
:=
strings
.
TrimSuffix
(
e
.
Name
(),
".conf"
)
if
skip
[
module
]
{
info
:=
hyprlandModuleInfo
(
module
,
user
)
if
!
info
.
Available
{
continue
}
status
:=
hyprlandModuleStatus
(
module
,
user
)
if
filter
==
""
||
filter
==
"all"
{
modules
=
append
(
modules
,
module
)
continue
}
if
s
tatus
==
filter
{
if
info
.
S
tatus
==
filter
{
modules
=
append
(
modules
,
module
)
}
}
...
...
@@ -508,6 +558,12 @@ func HyprlandModuleEditCommand(ctx context.Context, cmd *cli.Command) error {
module
:=
cmd
.
Args
()
.
Get
(
0
)
user
:=
cmd
.
Bool
(
"user"
)
modulefile
:=
HyprlandGetModuleFile
(
module
,
user
)
info
:=
hyprlandModuleInfo
(
module
,
user
)
if
!
info
.
Available
{
color
.
Red
(
"недопустимое название для модуля."
)
return
nil
}
if
!
utils
.
FileExists
(
modulefile
)
{
color
.
Red
(
"Модуль '%s' не найден: %s"
,
module
,
modulefile
)
...
...
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