Skip to content
This repository was archived by the owner on Apr 25, 2024. It is now read-only.

Commit 3a47f84

Browse files
author
François Guyot
committed
only consider cut nodes
1 parent f2ae17b commit 3a47f84

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

src/pyk/kcfg/tui.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def __init__(
6767
self,
6868
kcfg: KCFG,
6969
kprint: KPrint,
70+
nodes: Iterable[GraphChunk],
7071
minimize: bool = True,
7172
node_printer: Callable[[CTerm], Iterable[str]] | None = None,
7273
id: str = '',
@@ -76,12 +77,7 @@ def __init__(
7677
self._kprint = kprint
7778
self._minimize = minimize
7879
self._node_printer = node_printer
79-
self._nodes = []
80-
kcfg_show = KCFGShow(kprint)
81-
for lseg_id, node_lines in kcfg_show.pretty_segments(
82-
self._kcfg, minimize=self._minimize, node_printer=self._node_printer
83-
):
84-
self._nodes.append(GraphChunk(lseg_id, node_lines))
80+
self._nodes = nodes
8581

8682
def compose(self) -> ComposeResult:
8783
return self._nodes
@@ -284,8 +280,25 @@ def __init__(
284280
self._minimize = minimize
285281
self._hidden_chunks = []
286282
self._buffer = []
287-
self._last_node_idx = 0
283+
288284
# TODO: only take cut nodes
285+
286+
self._nodes = []
287+
kcfg_show = KCFGShow(kprint)
288+
i = 0
289+
for lseg_id, node_lines in kcfg_show.pretty_segments(
290+
self._kcfg, minimize=self._minimize, node_printer=self._node_printer
291+
):
292+
self._nodes.append(GraphChunk(lseg_id, node_lines))
293+
try:
294+
as_id = int(lseg_id)
295+
self._node_ids.append(as_id)
296+
self._node_idx[as_id] = i
297+
i += 1
298+
except:
299+
pass
300+
301+
self._last_node_idx = 0
289302
self._node_ids = list(kcfg._nodes.keys())
290303
self._node_idx = {} # TODO: one-liner for filling this
291304

@@ -305,7 +318,7 @@ def __init__(
305318
def compose(self) -> ComposeResult:
306319
yield Horizontal(
307320
Vertical(
308-
BehaviorView(self._kcfg, self._kprint, node_printer=self._node_printer, id='behavior'),
321+
BehaviorView(self._kcfg, self._kprint, nodes=self._nodes, node_printer=self._node_printer, id='behavior'),
309322
id='navigation',
310323
),
311324
Vertical(NodeView(self._kprint, custom_view=self._custom_view, id='node-view'), id='display'),
@@ -385,7 +398,7 @@ async def action_keystroke(self, key: str) -> None:
385398
else:
386399
match key:
387400
case 'j':
388-
if self._last_idx < len(self._node_ids):
401+
if self._last_idx + 1 < len(self._node_ids):
389402
idx = self._last_idx + 1
390403
node_id = self._node_ids[idx]
391404
self.query_one(f'#{self._selected_chunk}', GraphChunk).set_styles('border: none;')
@@ -406,14 +419,20 @@ async def action_keystroke(self, key: str) -> None:
406419
elif key == 'g':
407420
try:
408421
node_id = self._node_ids[0]
422+
self.query_one(f'#{self._selected_chunk}', GraphChunk).set_styles('border: none;')
423+
self._selected_chunk = "node_" + str(node_id)
409424
self._last_idx = 0
425+
self.query_one(f'#{self._selected_chunk}', GraphChunk).set_styles('border-left: double red;')
410426
self.query_one('#node-view', NodeView).update(self._kcfg.node(node_id), True)
411427
except:
412428
pass
413429
elif key == 'G':
414430
try:
415431
node_id = self._node_ids[-1]
432+
self.query_one(f'#{self._selected_chunk}', GraphChunk).set_styles('border: none;')
433+
self._selected_chunk = "node_" + str(node_id)
416434
self._last_idx = self._node_idx[node_id]
435+
self.query_one(f'#{self._selected_chunk}', GraphChunk).set_styles('border-left: double red;')
417436
self.query_one('#node-view', NodeView).update(self._kcfg.node(node_id), True)
418437
except:
419438
pass

0 commit comments

Comments
 (0)