1919import plain_spec
2020from event_bus import EventBus
2121from module_renderer import ModuleRenderer
22- from partial_rendering import PartialRender , detect_partial_rendering
22+ from partial_rendering import PartialRender , PartialRenderChoice , detect_partial_rendering
2323from plain2code_arguments import parse_arguments
2424from plain2code_console import console
2525from plain2code_events import RenderFailed
@@ -200,12 +200,18 @@ def _check_connection(codeplainAPI: codeplain_api.CodeplainAPI):
200200 )
201201
202202
203- def get_partial_render_choice (plain_module : plain_modules .PlainModule , partial_render : PartialRender | None ) -> str :
203+ def get_partial_render_choice (
204+ plain_module : plain_modules .PlainModule , partial_render : PartialRender | None
205+ ) -> PartialRenderChoice :
206+ choices = dict [str , PartialRenderChoice | None ]()
204207 print ("--- Partial render detected ---" )
205208 print (f"Target module: { plain_module .module_name } " )
206- print (f"Partially rendered module: { partial_render .module .module_name } " )
207- if partial_render .frid is not None :
209+ if partial_render .module .is_module_fully_rendered ():
210+ print (f"Last fully rendered module: { partial_render .module .module_name } " )
211+ else :
212+ print (f"Partially rendered module: { partial_render .module .module_name } " )
208213 print (f"Last fully rendered FRID: { partial_render .frid } " )
214+
209215 if partial_render .spec_change :
210216 print ("Spec change: Yes" )
211217 else :
@@ -216,30 +222,44 @@ def get_partial_render_choice(plain_module: plain_modules.PlainModule, partial_r
216222 else :
217223 print ("Code change: No" )
218224
219- choice_idx = 1
220- options = {f"{ choice_idx } " : "Re-render all" }
225+ choice_idx = 0
226+ first_module = plain_module .all_required_modules [0 ]
227+ choices [f"{ choice_idx } " ] = PartialRenderChoice (
228+ module = first_module ,
229+ frid = None ,
230+ msg = f"Re-render all (start from first module: { first_module .module_name } )" ,
231+ )
221232 choice_idx += 1
222233 if partial_render .frid is not None :
223- options [f"{ choice_idx } " ] = (
224- f"Continue from FRID { partial_render .frid } of module { partial_render .module .module_name } "
234+ next_frid , next_module = plain_module .get_next_frid (partial_render .frid , partial_render .module .module_name )
235+ choices [f"{ choice_idx } " ] = PartialRenderChoice (
236+ module = next_module ,
237+ frid = next_frid ,
238+ msg = f"Continue from FRID { next_frid } of module { next_module .module_name } " ,
225239 )
226240 choice_idx += 1
227241
228242 if partial_render .spec_change :
229- options [f"{ choice_idx } " ] = f"Re-render { partial_render .module .module_name } from start"
243+ choices [f"{ choice_idx } " ] = PartialRenderChoice (
244+ module = partial_render .module , frid = None , msg = f"Re-render { partial_render .module .module_name } from start"
245+ )
230246 choice_idx += 1
231247
232248 if partial_render .code_change :
233- options [f"{ choice_idx } " ] = f"Re-render { partial_render .module .module_name } from start"
249+ choices [f"{ choice_idx } " ] = PartialRenderChoice (
250+ module = partial_render .module , frid = None , msg = f"Re-render { partial_render .module .module_name } from start"
251+ )
234252 choice_idx += 1
235253
236- for key , value in options .items ():
237- print (f"{ key } . { value } " )
254+ choices [f"{ choice_idx } " ] = PartialRenderChoice (module = None , frid = None , msg = "Quit" )
255+ for key , pr_choice in choices .items ():
256+ print (f"{ key } . { pr_choice .msg } " )
238257
239258 while True :
240259 selection = input ("\n Select an option: " ).strip ()
241- if selection in options :
242- return options [selection ]
260+ if selection in choices :
261+ return choices [selection ]
262+
243263 print ("Invalid choice. Please try again." )
244264
245265
@@ -272,12 +292,10 @@ def render(args, run_state: RunState, event_bus: EventBus): # noqa: C901
272292 )
273293
274294 partial_render = detect_partial_rendering (plain_module )
275- print ("Partial render: " , partial_render )
276295 if partial_render is not None :
277296 choice = get_partial_render_choice (plain_module , partial_render )
278- print (f"You selected: { choice } " )
279-
280- exit ()
297+ if choice .module is None and choice .frid is None and choice .msg == "Quit" :
298+ exit ()
281299
282300 module_renderer = ModuleRenderer (
283301 codeplainAPI ,
0 commit comments