Skip to content

Commit 599419e

Browse files
authored
Update repl.py
1 parent b82835e commit 599419e

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

hackerc/repl.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
import tempfile
44
from rich.console import Console
55
from rich.prompt import Prompt
6-
from .parser import parse_hacker_file
6+
from parser import parse_hacker_file
77

88
def run_repl(console, verbose=False):
99
console.print(Panel("Hacker Lang REPL - Type 'exit' to quit", title="REPL", style="bold magenta"))
1010
console.print("Supports: // (system deps), # (libs/include), @ (vars), = (loops), ? (conditionals), & (background), > (cmds), [ ... ], ! (comments)")
11-
11+
1212
lines = []
1313
in_config = False
14-
14+
1515
while True:
1616
try:
1717
if in_config:
1818
prompt = "CONFIG> "
1919
else:
2020
prompt = "> "
2121
line = Prompt.ask(prompt, console=console).strip()
22-
22+
2323
if line.lower() == 'exit':
2424
break
25-
25+
2626
if line == '[':
2727
in_config = True
2828
lines.append(line)
@@ -34,46 +34,46 @@ def run_repl(console, verbose=False):
3434
in_config = False
3535
lines.append(line)
3636
continue
37-
37+
3838
lines.append(line)
39-
39+
4040
if not in_config and line and not line.startswith('!'):
4141
with tempfile.NamedTemporaryFile(mode='w+', suffix='.hacker', delete=False) as temp_hacker:
4242
temp_hacker.write('\n'.join(lines) + '\n')
4343
temp_hacker_path = temp_hacker.name
44-
44+
4545
deps, libs, vars, cmds, includes, errors = parse_hacker_file(temp_hacker_path, verbose, console)
4646
os.unlink(temp_hacker_path)
47-
47+
4848
if errors:
4949
console.print(Panel("\n".join(errors), title="REPL Errors", style="bold red"))
5050
continue
51-
51+
5252
with tempfile.NamedTemporaryFile(mode='w+', suffix='.sh', delete=False) as temp_sh:
5353
temp_sh.write('#!/bin/bash\n')
5454
temp_sh.write('set -e\n')
55-
55+
5656
for var, value in vars.items():
5757
temp_sh.write(f'export {var}="{value}"\n')
58-
58+
5959
for dep in deps:
6060
if dep != "sudo":
6161
temp_sh.write(f"command -v {dep} &> /dev/null || (sudo apt update && sudo apt install -y {dep})\n")
62-
62+
6363
for include in includes:
6464
lib_path = os.path.join(os.path.expanduser("~/.hacker-lang"), "libs", include, "main.hacker")
6565
if os.path.exists(lib_path):
6666
temp_sh.write(f"# Included from {include}\n")
6767
with open(lib_path, 'r') as lib_file:
6868
temp_sh.write(lib_file.read() + "\n")
69-
69+
7070
for cmd in cmds:
7171
temp_sh.write(f"{cmd}\n")
72-
72+
7373
temp_sh_path = temp_sh.name
74-
74+
7575
os.chmod(temp_sh_path, 0o755)
76-
76+
7777
try:
7878
env = os.environ.copy()
7979
env.update(vars)
@@ -84,9 +84,9 @@ def run_repl(console, verbose=False):
8484
console.print(Panel(e.output.strip(), title="Error", style="bold red"))
8585
finally:
8686
os.unlink(temp_sh_path)
87-
87+
8888
except KeyboardInterrupt:
8989
console.print("\n[bold yellow]Use 'exit' to quit REPL[/bold yellow]")
90-
90+
9191
console.print("[bold green]REPL exited[/bold green]")
9292
return True

0 commit comments

Comments
 (0)