Skip to content

Commit 995e35c

Browse files
author
Tony Crisci
committed
add i3-debug-console script to examples
1 parent 1fd4ef6 commit 995e35c

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

examples/i3-debug-console.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python3
2+
3+
import i3ipc
4+
from curses import wrapper
5+
from threading import Timer
6+
7+
def con_type_to_text(con):
8+
if con.type != 'con':
9+
return con.type
10+
if len(con.nodes):
11+
return 'container'
12+
else:
13+
return 'view'
14+
15+
def layout_txt(con):
16+
if con.layout == 'splith':
17+
return 'HORIZ'
18+
elif con.layout == 'splitv':
19+
return 'VERT'
20+
else:
21+
return ''
22+
23+
def container_to_text(con, indent):
24+
t = con_type_to_text(con)
25+
txt = (' ' * indent) + '('
26+
txt += t + ' ' + layout_txt(con)
27+
28+
if con.focused:
29+
txt += ' focus'
30+
31+
has_children = len(con.nodes)
32+
33+
for c in con.nodes:
34+
txt += '\n'
35+
txt += container_to_text(c, indent + 4)
36+
37+
if has_children:
38+
txt += '\n' + (' ' * indent)
39+
40+
txt += ')'
41+
42+
return txt
43+
44+
last_txt = ''
45+
46+
def main(stdscr):
47+
ipc = i3ipc.Connection()
48+
49+
def on_event(ipc, e):
50+
txt = ''
51+
for ws in ipc.get_tree().workspaces():
52+
txt += container_to_text(ws, 0) + '\n'
53+
54+
global last_txt
55+
if txt == last_txt:
56+
return
57+
58+
stdscr.clear()
59+
for l in txt:
60+
try:
61+
stdscr.addstr(l)
62+
except Exception:
63+
break
64+
stdscr.refresh()
65+
last_txt = txt
66+
67+
on_window(ipc, None)
68+
69+
ipc.on('window', on_event)
70+
ipc.on('binding', on_event)
71+
ipc.on('workspace', on_event)
72+
73+
ipc.main()
74+
75+
wrapper(main)

0 commit comments

Comments
 (0)