-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathminecraft-console.py
More file actions
54 lines (45 loc) · 1.46 KB
/
minecraft-console.py
File metadata and controls
54 lines (45 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/python3
import curses
import subprocess
import threading
def run_journalctl(win):
process = subprocess.Popen(['journalctl', '-u', 'minecraft', '--follow'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
line = process.stdout.readline()
if not line:
break
win.addstr(line.decode())
win.refresh()
def input_commands(win):
with open('/run/minecraft.stdin', 'a') as f:
while True:
win.clear()
win.addstr("Enter command (Ctrl-C to exit): ")
curses.echo()
win.move(1, 0)
command = win.getstr().decode()
f.write(command + "\n")
f.flush()
curses.noecho()
win.clear()
def main(stdscr):
try:
curses.curs_set(1)
stdscr.clear()
height, width = stdscr.getmaxyx()
journal_height = int(height * 0.9)
input_height = height - journal_height
journal_win = stdscr.subwin(journal_height, width, 0, 0)
journal_win.scrollok(True)
input_win = stdscr.subwin(input_height, width, journal_height, 0)
thread = threading.Thread(target=run_journalctl, args=(journal_win,))
thread.daemon = True
thread.start()
input_commands(input_win)
except KeyboardInterrupt:
stdscr.clear()
stdscr.refresh()
finally:
curses.endwin()
if __name__ == "__main__":
curses.wrapper(main)