hyprconf2lua 1.4.0__tar.gz → 1.6.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (22) hide show
  1. {hyprconf2lua-1.4.0/src/hyprconf2lua.egg-info → hyprconf2lua-1.6.0}/PKG-INFO +1 -1
  2. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/pyproject.toml +1 -1
  3. hyprconf2lua-1.6.0/src/hyprconf2lua/__init__.py +1 -0
  4. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/codegen.py +110 -36
  5. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/lexer.py +5 -0
  6. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/parser.py +17 -9
  7. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0/src/hyprconf2lua.egg-info}/PKG-INFO +1 -1
  8. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/tests/test_converter.py +97 -0
  9. hyprconf2lua-1.4.0/src/hyprconf2lua/__init__.py +0 -1
  10. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/LICENSE +0 -0
  11. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/README.md +0 -0
  12. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/setup.cfg +0 -0
  13. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/__main__.py +0 -0
  14. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/ast.py +0 -0
  15. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/cli.py +0 -0
  16. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/converter.py +0 -0
  17. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua/mappings.py +0 -0
  18. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua.egg-info/SOURCES.txt +0 -0
  19. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua.egg-info/dependency_links.txt +0 -0
  20. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua.egg-info/entry_points.txt +0 -0
  21. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua.egg-info/requires.txt +0 -0
  22. {hyprconf2lua-1.4.0 → hyprconf2lua-1.6.0}/src/hyprconf2lua.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyprconf2lua
3
- Version: 1.4.0
3
+ Version: 1.6.0
4
4
  Summary: Convert Hyprland hyprlang .conf files to Lua .lua config format (v0.55+)
5
5
  Author: hyprconf2lua contributors
6
6
  License: MIT
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "hyprconf2lua"
7
- version = "1.4.0"
7
+ version = "1.6.0"
8
8
  description = "Convert Hyprland hyprlang .conf files to Lua .lua config format (v0.55+)"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -0,0 +1 @@
1
+ __version__ = "1.6.0"
@@ -1,4 +1,5 @@
1
1
  from __future__ import annotations
2
+ import os
2
3
  import re
3
4
  from typing import Dict, List, Optional
4
5
 
@@ -118,6 +119,38 @@ class Codegen:
118
119
  return "local_var_" + var_name
119
120
  return re.sub(r'\$(\w+)', _repl, val)
120
121
 
122
+ def resolve_val_with_env(self, val: str) -> str:
123
+ def _repl(m: re.Match) -> str:
124
+ var_name = m.group(1)
125
+ if var_name in self.variables:
126
+ return self.variables[var_name]
127
+ if var_name in os.environ:
128
+ return f'os.getenv("{var_name}")'
129
+ return "local_var_" + var_name
130
+ return re.sub(r'\$(\w+)', _repl, val)
131
+
132
+ def resolve_val_exec(self, val: str) -> str:
133
+ def _repl(m: re.Match) -> str:
134
+ var_name = m.group(1)
135
+ if var_name in self.variables:
136
+ return self.variables[var_name]
137
+ if var_name in os.environ:
138
+ return f'os.getenv("{var_name}")'
139
+ return m.group(0)
140
+ return re.sub(r'\$(\w+)', _repl, val)
141
+
142
+ def _build_concat_expr(self, val: str) -> str:
143
+ parts = re.split(r'(os\.getenv\([^)]+\))', val)
144
+ expr_parts = []
145
+ for part in parts:
146
+ if part.startswith("os.getenv("):
147
+ expr_parts.append(part)
148
+ elif part:
149
+ expr_parts.append(self.quote(part))
150
+ if not expr_parts:
151
+ return '""'
152
+ return " .. ".join(expr_parts)
153
+
121
154
  def needs_quotes(self, val: str) -> bool:
122
155
  if not val:
123
156
  return True
@@ -139,10 +172,16 @@ class Codegen:
139
172
  return f'"{escaped}"'
140
173
  return val
141
174
 
175
+ @staticmethod
176
+ def _normalize_key(key: str) -> str:
177
+ return key.replace("-", "_")
178
+
142
179
  def to_lua_val(self, val: str):
143
- val = self.resolve_val(val)
180
+ val = self.resolve_val_with_env(val)
144
181
  if val.startswith("local_var_"):
145
182
  return val[len("local_var_"):]
183
+ if "os.getenv(" in val:
184
+ return self._build_concat_expr(val)
146
185
  if val.lower() in ("true", "on", "yes"):
147
186
  return "true"
148
187
  if val.lower() in ("false", "off", "no"):
@@ -160,7 +199,7 @@ class Codegen:
160
199
  return self.quote(val)
161
200
 
162
201
  def visit_variable(self, stmt: VariableDef):
163
- val = self.resolve_val(stmt.value)
202
+ val = self.resolve_val_with_env(stmt.value)
164
203
  self.variables[stmt.name] = val
165
204
  self.translated_count += 1
166
205
  if stmt.name.upper() == "MAINMOD" or stmt.name == "mainMod":
@@ -179,17 +218,21 @@ class Codegen:
179
218
  self.main_mod_var = name
180
219
  break
181
220
 
221
+ def _exec_lua_expr(self, cmd: str) -> str:
222
+ resolved = self.resolve_val_exec(cmd)
223
+ if resolved.startswith("$") and resolved[1:] in self.variables:
224
+ return resolved[1:]
225
+ if "os.getenv(" in resolved:
226
+ return self._build_concat_expr(resolved)
227
+ return self.quote(resolved)
228
+
182
229
  def emit_pending_execs(self):
183
230
  if self.pending_exec_ones:
184
231
  self.emit("-- Autostart")
185
232
  self.emit('hl.on("hyprland.start", function()')
186
233
  self.indent()
187
234
  for cmd in self.pending_exec_ones:
188
- resolved = self.resolve_val(cmd)
189
- if resolved.startswith("$") and resolved[1:] in self.variables:
190
- self.emit(f"hl.exec_cmd({resolved[1:]})")
191
- else:
192
- self.emit(f"hl.exec_cmd({self.quote(resolved)})")
235
+ self.emit(f"hl.exec_cmd({self._exec_lua_expr(cmd)})")
193
236
  self.dedent()
194
237
  self.emit("end)")
195
238
  self.emit("")
@@ -199,11 +242,7 @@ class Codegen:
199
242
  self.emit('hl.on("config.reloaded", function()')
200
243
  self.indent()
201
244
  for cmd in self.pending_execs:
202
- resolved = self.resolve_val(cmd)
203
- if resolved.startswith("$") and resolved[1:] in self.variables:
204
- self.emit(f"hl.exec_cmd({resolved[1:]})")
205
- else:
206
- self.emit(f"hl.exec_cmd({self.quote(resolved)})")
245
+ self.emit(f"hl.exec_cmd({self._exec_lua_expr(cmd)})")
207
246
  self.dedent()
208
247
  self.emit("end)")
209
248
  self.emit("")
@@ -213,11 +252,7 @@ class Codegen:
213
252
  self.emit('hl.on("hyprland.shutdown", function()')
214
253
  self.indent()
215
254
  for cmd in self.pending_exec_shutdowns:
216
- resolved = self.resolve_val(cmd)
217
- if resolved.startswith("$") and resolved[1:] in self.variables:
218
- self.emit(f"hl.exec_cmd({resolved[1:]})")
219
- else:
220
- self.emit(f"hl.exec_cmd({self.quote(resolved)})")
255
+ self.emit(f"hl.exec_cmd({self._exec_lua_expr(cmd)})")
221
256
  self.dedent()
222
257
  self.emit("end)")
223
258
  self.emit("")
@@ -242,6 +277,9 @@ class Codegen:
242
277
  return f"{{ colors = {{ {', '.join(colors)} }}, angle = {angle} }}"
243
278
 
244
279
  def _emit_directive(self, key: str, values: List[str]):
280
+ if not values or all(not v.strip() for v in values):
281
+ return
282
+ key = self._normalize_key(key)
245
283
  if len(values) == 1 and self._is_gradient(values[0]):
246
284
  self.translated_count += 1
247
285
  self.emit(f"{key} = {self._format_gradient(values[0])},")
@@ -294,8 +332,8 @@ class Codegen:
294
332
  self.passthrough_count += 1
295
333
  self.emit(f"-- Nested subsection {sd.name}:")
296
334
  for ssd in sd.body:
297
- if isinstance(ssd, Directive):
298
- k = ssd.key
335
+ if isinstance(ssd, Directive) and ssd.value and ssd.value[0].strip():
336
+ k = self._normalize_key(ssd.key)
299
337
  vv = self.to_lua_val(ssd.value[0]) if ssd.value else "true"
300
338
  self.emit(f"{k} = {vv},")
301
339
  self.dedent()
@@ -314,7 +352,9 @@ class Codegen:
314
352
  self.emit(f"{name} = {{")
315
353
  self.indent()
316
354
  for d in directives:
317
- key = d.key
355
+ key = self._normalize_key(d.key)
356
+ if not d.value or not d.value[0].strip():
357
+ continue
318
358
  if len(d.value) == 1:
319
359
  val = self.to_lua_val(d.value[0])
320
360
  self.emit(f"{key} = {val},")
@@ -576,7 +616,10 @@ class Codegen:
576
616
  return f'{func}({{ on_monitor = true }})'
577
617
 
578
618
  if dispatcher in ("exec", "execr"):
579
- resolved = self.resolve_val(params[0]) if params else ""
619
+ raw = params[0] if params else ""
620
+ resolved = self.resolve_val_exec(raw)
621
+ if "os.getenv(" in resolved:
622
+ return f'{func}({self._build_concat_expr(resolved)})'
580
623
  return f'{func}({self.quote(resolved)})'
581
624
 
582
625
  args = self.build_dispatcher_args(params, needs_args, func)
@@ -662,6 +705,22 @@ class Codegen:
662
705
  effects = {}
663
706
 
664
707
  for mp in match_params:
708
+ if mp.startswith("match:"):
709
+ rest = mp[len("match:"):].strip()
710
+ m = re.match(r'^([a-zA-Z0-9_-]+)(?:\s*=\s*|\s*:\s*|\s+)(.*)$', rest)
711
+ if m:
712
+ match_key, value = m.groups()
713
+ else:
714
+ match_key = rest
715
+ value = "true"
716
+ if value.lower() == "true":
717
+ match[match_key] = "true"
718
+ elif value.lower() == "false":
719
+ match[match_key] = "false"
720
+ else:
721
+ match[match_key] = self.quote(value)
722
+ continue
723
+
665
724
  colon_idx = mp.find(":")
666
725
  if colon_idx > 0:
667
726
  prefix = mp[:colon_idx].strip()
@@ -731,11 +790,14 @@ class Codegen:
731
790
  self.emit("match = {")
732
791
  self.indent()
733
792
  for k, v in stmt.match.items():
734
- self.emit(f"{k} = {self.quote(v)},")
793
+ self.emit(f"{self._normalize_key(k)} = {self.quote(v)},")
735
794
  self.dedent()
736
795
  self.emit("},")
737
796
 
738
797
  for key, vals in stmt.effects.items():
798
+ key = self._normalize_key(key)
799
+ if not vals or not vals[0].strip():
800
+ continue
739
801
  if len(vals) == 1:
740
802
  parts = vals[0].split()
741
803
  if len(parts) == 1:
@@ -809,30 +871,39 @@ class Codegen:
809
871
  def visit_env(self, stmt: EnvDirective):
810
872
  self.translated_count += 1
811
873
  resolved_name = self.resolve_val(stmt.name)
812
- resolved_val = self.resolve_val(stmt.value)
813
874
  name_q = self.quote(resolved_name)
814
- val_q = self.quote(resolved_val)
815
- self.emit(f"hl.env({name_q}, {val_q})")
875
+ val_expr = self.to_lua_val(stmt.value)
876
+ self.emit(f"hl.env({name_q}, {val_expr})")
877
+
878
+ @staticmethod
879
+ def _sanitize_ident(s: str) -> str:
880
+ return re.sub(r"[^a-zA-Z0-9_]", "_", s)
881
+
882
+ def _source_module_path(self, path: str) -> str:
883
+ p = path.strip()
884
+ for marker in ("/.config/hypr/", "/.config/", "$XDG_CONFIG_HOME/", "$HOME/", "~/"):
885
+ if marker in p:
886
+ p = p.split(marker, 1)[1]
887
+ break
888
+ else:
889
+ p = p.lstrip("/")
890
+ p = p.replace(".conf", "")
891
+ return ".".join(self._sanitize_ident(part) for part in p.split("/") if part)
816
892
 
817
893
  def visit_source(self, stmt: SourceDirective):
818
894
  self.passthrough_count += 1
819
895
  path = stmt.path
820
896
 
821
- lua_path = path.replace(".conf", "")
822
- lua_path = lua_path.replace("~", "os.getenv(\"HOME\")")
823
- lua_path = lua_path.replace("/", ".")
824
-
825
897
  if path.endswith("/*.conf"):
826
898
  self.emit(f'-- source = {path}')
827
899
  self.emit(f"-- NOTE: glob sources need manual handling")
828
900
  self.emit(f"-- Directory contents must be required individually")
829
901
  return
830
902
 
903
+ module = self._source_module_path(path)
904
+ local_name = module.split(".")[-1]
831
905
  self.emit(f'-- source = {path} -> requires manual conversion')
832
-
833
- import os as _os
834
- just_name = _os.path.splitext(_os.path.basename(path))[0]
835
- self.emit(f'-- local {just_name} = require("{just_name}")')
906
+ self.emit(f'-- local {local_name} = require("{module}")')
836
907
  self.emit(f'-- TODO: convert {path} to .lua and use require()')
837
908
 
838
909
  def visit_device(self, stmt: DeviceSection):
@@ -841,8 +912,8 @@ class Codegen:
841
912
  self.indent()
842
913
  self.emit(f'name = {self.quote(stmt.name)},')
843
914
  for d in stmt.body:
844
- if isinstance(d, Directive):
845
- key = d.key
915
+ if isinstance(d, Directive) and d.value and d.value[0].strip():
916
+ key = self._normalize_key(d.key)
846
917
  val = self.to_lua_val(d.value[0]) if d.value else "true"
847
918
  self.emit(f"{key} = {val},")
848
919
  self.dedent()
@@ -937,11 +1008,14 @@ class Codegen:
937
1008
  self.emit("match = {")
938
1009
  self.indent()
939
1010
  for k, v in stmt.match.items():
940
- self.emit(f"{k} = {self.quote(v)},")
1011
+ self.emit(f"{self._normalize_key(k)} = {self.quote(v)},")
941
1012
  self.dedent()
942
1013
  self.emit("},")
943
1014
 
944
1015
  for key, vals in stmt.effects.items():
1016
+ key = self._normalize_key(key)
1017
+ if not vals or not vals[0].strip():
1018
+ continue
945
1019
  if len(vals) == 1:
946
1020
  parts = vals[0].split()
947
1021
  if len(parts) == 1:
@@ -12,8 +12,10 @@ TOKEN_SPECS = [
12
12
  ("COMMA", r","),
13
13
  ("DOT", r"\."),
14
14
  ("COLON", r":"),
15
+ ("SHELL_EXP", r"\$\{[^}\n]*\}"),
15
16
  ("DOLLAR", r"\$"),
16
17
  ("STRING", r'"([^"\\]|\\.)*"'),
18
+ ("CONT", r"\\[ \t]*\n"),
17
19
  ("IDENT", r'[^\s#"={},:!]+'),
18
20
  ("NEWLINE", r"\n"),
19
21
  ("SKIP", r"[ \t]+"),
@@ -59,6 +61,9 @@ def tokenize(source: str) -> List[Token]:
59
61
  line += 1
60
62
  last_line_start = pos + 1
61
63
  tokens.append(Token("NEWLINE", value, line - 1, _col(pos)))
64
+ elif kind == "CONT":
65
+ line += 1
66
+ last_line_start = m.end()
62
67
  elif kind == "SKIP":
63
68
  pass
64
69
  elif kind == "COMMENT":
@@ -137,7 +137,7 @@ class Parser:
137
137
 
138
138
  def parse_value_rest(self) -> str:
139
139
  parts = []
140
- while self.peek().type in ("IDENT", "STRING", "DOLLAR", "DOT", "COLON") or \
140
+ while self.peek().type in ("IDENT", "STRING", "DOLLAR", "SHELL_EXP", "DOT", "COLON") or \
141
141
  (self.peek().type == "EQUALS" and parts):
142
142
  if self.peek().type == "COMMENT":
143
143
  break
@@ -160,14 +160,14 @@ class Parser:
160
160
  result = tokens[0]
161
161
  for t in tokens[1:]:
162
162
  no_space_before = {":", ",", "=", "+", "-", "%", "@", "^", "*", "|", "~"}
163
- no_space_after = {":", ",", "="}
164
- if t in no_space_before or result[-1:] in no_space_after:
163
+ no_space_after = {":", ",", "=", "."}
164
+ if t in no_space_before or result[-1:] in no_space_after or t.startswith(("/", ".")):
165
165
  result += t
166
166
  else:
167
167
  result += " " + t
168
168
  return result.strip()
169
169
 
170
- def parse_comma_values(self) -> List[str]:
170
+ def parse_comma_values(self, keep_string_quotes: bool = False) -> List[str]:
171
171
  values = []
172
172
  current = []
173
173
  while self.peek().type not in ("NEWLINE", "EOF") and \
@@ -200,7 +200,10 @@ class Parser:
200
200
  current.append("$" + var_t.value)
201
201
  else:
202
202
  t = self.advance()
203
- current.append(t.value)
203
+ if keep_string_quotes and t.type == "STRING":
204
+ current.append('"' + t.value + '"')
205
+ else:
206
+ current.append(t.value)
204
207
  remaining = self._join_tokens(current)
205
208
  if remaining:
206
209
  values.append(remaining)
@@ -296,6 +299,8 @@ class Parser:
296
299
  if t.type == "EQUALS":
297
300
  self.advance()
298
301
  values = self.parse_comma_values()
302
+ if not values or all(not v.strip() for v in values):
303
+ return None
299
304
  return Directive(directive, values, line, 0)
300
305
  if t.type == "BLOCK_OPEN":
301
306
  self.advance()
@@ -308,7 +313,7 @@ class Parser:
308
313
  flags = _parse_combined_bind(directive)
309
314
  self.expect("EQUALS")
310
315
  self.skip_newlines()
311
- values = self.parse_comma_values()
316
+ values = self.parse_comma_values(keep_string_quotes=True)
312
317
  if len(values) < 3:
313
318
  raise ParserError(f"bind needs at least 3 arguments (mods, key, dispatcher), got {len(values)}", Token("IDENT", directive, line, 0))
314
319
  mods_str = values[0].strip()
@@ -416,10 +421,10 @@ class Parser:
416
421
 
417
422
  def parse_exec(self, directive: str, line: int) -> ExecDirective:
418
423
  self.expect("EQUALS")
419
- command = self.parse_line_rest()
424
+ command = self.parse_line_rest(keep_string_quotes=True)
420
425
  return ExecDirective(directive, command, line)
421
426
 
422
- def parse_line_rest(self) -> str:
427
+ def parse_line_rest(self, keep_string_quotes: bool = False) -> str:
423
428
  parts = []
424
429
  while self.peek().type not in ("NEWLINE", "EOF", "COMMENT", "BLOCK_CLOSE"):
425
430
  if self.peek().type == "DOLLAR":
@@ -428,7 +433,10 @@ class Parser:
428
433
  parts.append("$" + var_t.value)
429
434
  else:
430
435
  t = self.advance()
431
- parts.append(t.value)
436
+ if keep_string_quotes and t.type == "STRING":
437
+ parts.append('"' + t.value + '"')
438
+ else:
439
+ parts.append(t.value)
432
440
  return self._join_tokens(parts)
433
441
 
434
442
  def parse_animation(self, line: int) -> AnimationDirective:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hyprconf2lua
3
- Version: 1.4.0
3
+ Version: 1.6.0
4
4
  Summary: Convert Hyprland hyprlang .conf files to Lua .lua config format (v0.55+)
5
5
  Author: hyprconf2lua contributors
6
6
  License: MIT
@@ -660,3 +660,100 @@ def test_nested_subsection_in_decoration():
660
660
  assert result.success
661
661
  assert "blur" in result.lua
662
662
  assert "size = 3" in result.lua
663
+
664
+
665
+ def test_windowrule_match_class():
666
+ result = convert("windowrule = workspace special:T silent, match:class ^(T)$\n")
667
+ assert result.success
668
+ assert "class = \"^(T)$\"" in result.lua
669
+ assert "workspace = \"special:T silent\"" in result.lua
670
+
671
+
672
+ def test_windowrule_match_class_with_equals():
673
+ result = convert("windowrule = workspace special:T silent, match:class = ^(T)$\n")
674
+ assert result.success
675
+ assert "class = \"^(T)$\"" in result.lua
676
+ assert "workspace = \"special:T silent\"" in result.lua
677
+
678
+
679
+ def test_windowrule_match_class_complex():
680
+ result = convert("windowrule = workspace special:T silent, match:class ^foo=bar$\n")
681
+ assert result.success
682
+ assert "class = \"^foo=bar$\"" in result.lua
683
+
684
+ result2 = convert("windowrule = workspace special:T silent, match:class:^(T)$\n")
685
+ assert result2.success
686
+ assert "class = \"^(T)$\"" in result2.lua
687
+
688
+
689
+ def test_env_var_resolution():
690
+ result = convert('env = AQ_DRM_DEVICES,$HOME/.config/hypr/cards/intelcard:$HOME/.config/hypr/cards/nvidiacard\n')
691
+ assert result.success
692
+ assert 'os.getenv("HOME")' in result.lua
693
+ assert "local_var_HOME" not in result.lua
694
+
695
+
696
+ def test_hyphen_to_underscore_in_device():
697
+ result = convert('device {\n name = touchpad\n tap-to-click = true\n}\n')
698
+ assert result.success
699
+ assert "tap_to_click" in result.lua
700
+ assert "tap-to-click" not in result.lua
701
+
702
+
703
+ def test_hyphen_to_underscore_in_general():
704
+ result = convert('general {\n no-cursor = true\n}\n')
705
+ assert result.success
706
+ assert "no_cursor" in result.lua
707
+ assert "no-cursor" not in result.lua
708
+
709
+
710
+ def test_leading_dot_float():
711
+ result = convert("input {\n scale = .97\n}\n")
712
+ assert result.success
713
+ assert "scale = .97," in result.lua
714
+ assert '". 97"' not in result.lua
715
+
716
+
717
+ def test_empty_value_skipped():
718
+ result = convert("input {\n kb_layout = es\n kb_variant =\n kb_model =\n}\n")
719
+ assert result.success
720
+ assert "kb_layout" in result.lua
721
+ assert "kb_variant" not in result.lua
722
+ assert "kb_model" not in result.lua
723
+ assert "{ }" not in result.lua
724
+
725
+
726
+ def test_source_filename_hyphens_sanitized():
727
+ result = convert("source = ~/.config/hypr/media-binds.conf\n")
728
+ assert result.success
729
+ assert 'require("media_binds")' in result.lua
730
+ assert "local media-binds" not in result.lua
731
+
732
+
733
+ def test_source_path_mapped_to_module():
734
+ result = convert("source = $HOME/.config/hypr/modules/keybinds.conf\n")
735
+ assert result.success
736
+ assert 'require("modules.keybinds")' in result.lua
737
+
738
+
739
+ def test_shell_brace_expansion():
740
+ result = convert("exec-once = xrdb ${XDG_CONFIG_HOME:-$HOME/.config}/x11/xresources\n")
741
+ assert result.success
742
+ assert "xrdb ${XDG_CONFIG_HOME:-" in result.lua
743
+ assert "os.getenv(\"HOME\")" in result.lua
744
+ assert "/x11/xresources" in result.lua
745
+
746
+
747
+ def test_multiline_exec_continuation():
748
+ src = (
749
+ "bind = ,print, exec, \\\n"
750
+ ' FILE=~/Pictures/screenshot_$(date +%s).png; \\\n'
751
+ ' grim -g "$(slurp)" "$FILE" && wl-copy < "$FILE" && \\\n'
752
+ ' notify-send "Screenshot saved" -i "$FILE"\n'
753
+ )
754
+ result = convert(src)
755
+ assert result.success
756
+ assert 'hl.dsp.exec_cmd("FILE=~/Pictures/screenshot_$(date +%s).png;' in result.lua
757
+ assert '\\"$(slurp)\\"' in result.lua
758
+ assert "$FILE" in result.lua
759
+ assert "local_var_FILE" not in result.lua
@@ -1 +0,0 @@
1
- __version__ = "1.4.0"
File without changes
File without changes
File without changes