Skip to content

Commit d09d0d5

Browse files
committed
Ask user when the only choice is destruction
1 parent ab39615 commit d09d0d5

3 files changed

Lines changed: 15 additions & 14 deletions

File tree

partial_rendering.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class PartialRenderChoice:
2020
render_range: list[str] | None = None
2121
msg: str | None = None
2222
wipe_later_modules: bool = False
23+
is_desctructive: bool = False
2324

2425

2526
def spec_change(plain_module: PlainModule) -> PlainModule | None:
@@ -78,13 +79,7 @@ def detect_partial_rendering(plain_module: PlainModule) -> PartialRender | None:
7879
return None
7980

8081
if last_rendered_module_name == plain_module.module_name:
81-
if (
82-
last_rendered_frid is None
83-
or plain_spec.get_next_frid(plain_module.plain_source, last_rendered_frid) is not None
84-
):
85-
module = plain_module
86-
else:
87-
return None
82+
module = plain_module
8883
else:
8984
found_module: PlainModule | None = None
9085
for required_module in all_required_modules:
@@ -135,6 +130,7 @@ def get_choices(
135130
render_range=None,
136131
msg=f"Start from module [#5593FF]{partial_render.last_render_module.module_name}[/]",
137132
wipe_later_modules=True,
133+
is_desctructive=False,
138134
)
139135
choice_idx += 1
140136

@@ -169,6 +165,7 @@ def get_choices(
169165
module=next_module,
170166
render_range=None,
171167
msg=f"Start from module [#5593FF]{next_module.module_name}[/]",
168+
is_desctructive=partial_render.last_render_module.module_name == plain_module.module_name,
172169
)
173170
choice_idx += 1
174171

@@ -187,6 +184,7 @@ def get_choices(
187184
render_range=None,
188185
msg=f"Re-render all affected modules ([#5593FF]{', '.join(all_affected_modules)}[/])",
189186
wipe_later_modules=True,
187+
is_desctructive=True,
190188
)
191189
choice_idx += 1
192190

@@ -200,10 +198,9 @@ def get_choices(
200198
render_range=None,
201199
msg=f"Re-render from first module ([#5593FF]{first_module.module_name}[/])",
202200
wipe_later_modules=True,
201+
is_desctructive=True,
203202
)
204203
choice_idx += 1
205204

206205
choices[str(choice_idx)] = PartialRenderChoice(module=None, render_range=None, msg="Quit")
207-
print(choices)
208-
209206
return choices

plain2code.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,14 @@ def render(args, run_state: RunState, event_bus: EventBus): # noqa: C901
186186
partial_render = detect_partial_rendering(plain_module)
187187
if partial_render is not None:
188188
choices = get_choices(plain_module, partial_render, args.force_render)
189-
if len(choices) > 2:
189+
ask_user = True
190+
partial_render_choice = None
191+
if len(choices) <= 2:
192+
# Last choice is Quit, first choice is the only other actionable choice
193+
partial_render_choice = choices[list(choices.keys())[0]]
194+
ask_user = partial_render_choice.is_desctructive
195+
196+
if ask_user:
190197
app = PartialRenderTUI(
191198
plain_module,
192199
partial_render,
@@ -202,9 +209,6 @@ def render(args, run_state: RunState, event_bus: EventBus): # noqa: C901
202209
and partial_render_choice.msg == "Quit"
203210
):
204211
sys.exit(0)
205-
else:
206-
# Last choice is Quit, first choice is the only other actionable choice
207-
partial_render_choice = choices[list(choices.keys())[0]]
208212

209213
if partial_render_choice is not None and render_range is not None:
210214
raise Exception("Partial rendering and render range cannot be used together")

tui/partial_render_tui.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def on_mount(self) -> None:
128128
lv.focus()
129129

130130
def _register_expandable(self, label: Label, prefix: str, full_text: str) -> None:
131-
first_line = full_text[:20]
131+
first_line = full_text[:100]
132132
short = f"{prefix} {first_line} [#888](ctrl+o to expand)[/]"
133133
full = f"{prefix} {full_text} [#888](ctrl+o to collapse)[/]"
134134
label.update(short)

0 commit comments

Comments
 (0)