Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions plain2code.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def render(args, run_state: RunState, codeplain_api, event_bus: EventBus): # no
unittests_script=args.unittests_script,
conformance_tests_script=args.conformance_tests_script,
prepare_environment_script=args.prepare_environment_script,
state_machine_version=system_config.client_version,
css_path="styles.css",
)
result = app.run()
Expand Down
2 changes: 1 addition & 1 deletion render_machine/actions/render_functional_requirement.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def execute(self, render_context: RenderContext, _previous_action_payload: Any |
if render_context.verbose:
msg = "-------------------------------------\n"
msg += f"Module: {render_context.module_name}\n"
msg += f"Rendering functional requirement {render_context.frid_context.frid}"
msg += f"Rendering functionality {render_context.frid_context.frid}"
if render_context.frid_context.functional_requirement_render_attempts > 1:
msg += f", attempt number {render_context.frid_context.functional_requirement_render_attempts}/{MAX_CODE_GENERATION_RETRIES}."
msg += f"\n{render_context.frid_context.functional_requirement_text}\n"
Expand Down
154 changes: 56 additions & 98 deletions tui/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def compose(self):


class ScriptOutputType(str, Enum):
UNIT_TEST_OUTPUT_TEXT = "Unit tests: "
CONFORMANCE_TEST_OUTPUT_TEXT = "Conformance tests: "
UNIT_TEST_OUTPUT_TEXT = "Unit tests output: "
CONFORMANCE_TEST_OUTPUT_TEXT = "Conformance tests output: "
TESTING_ENVIRONMENT_OUTPUT_TEXT = "Testing environment preparation execution output: "

@staticmethod
Expand Down Expand Up @@ -232,70 +232,45 @@ async def clear_substates(self):


class RenderingInfoBox(Vertical):
"""Container with ASCII border for module and functionality information."""
"""Responsive container for module and functionality information."""

def __init__(self, **kwargs):
super().__init__(**kwargs)
self.module_text = ""
self.functionality_text = ""
self.module_widget: Static | None = None
self.functionality_widget: Static | None = None

def update_module(self, text: str) -> None:
"""Update the module name and refresh the display."""
"""Update the module name display."""
self.module_text = text
self._refresh_content()

def update_functionality(self, text: str) -> None:
"""Update the functionality text and refresh the display."""
"""Update the functionality text display."""
self.functionality_text = text
self._refresh_content()

def _refresh_content(self) -> None:
"""Refresh the content of the box."""
try:
widget = self.query_one("#rendering-info-content", Static)
# Calculate the width needed for the border
lines = []
if self.module_text:
lines.append(f" {self.module_text}")
if self.functionality_text:
lines.append(f" {self.functionality_text}")

if not lines:
widget.update("")
return

# Find the longest line to determine border width
max_width = max(len(line) for line in lines) if lines else 40
border_width = max(max_width + 2, 42) # At least 42 chars wide

# Build the bordered box with title
title = " Currently rendering "
top_border = "┌[#FFFFFF]" + title + "[/#FFFFFF]" + "─" * (border_width - len(title)) + "┐"
bottom_border = "└" + "─" * border_width + "┘"

content_lines = [top_border]
# Add top padding (empty line)
content_lines.append(f"│{' ' * border_width}│")
for line in lines:
padding = border_width - len(line)
content_lines.append(f"│{line}{' ' * padding}│")
# Add bottom padding (empty line)
content_lines.append(f"│{' ' * border_width}│")
content_lines.append(bottom_border)

widget.update("\n".join(content_lines))
except Exception:
pass
"""Refresh text inside the box."""
if self.module_widget is not None:
self.module_widget.update(self.module_text or "")
if self.functionality_widget is not None:
self.functionality_widget.update(self.functionality_text or "")

def on_mount(self) -> None:
"""Initialize the box with empty state on mount."""
# Set default empty labels
"""Initialize default labels on mount."""
self.module_text = "Module: "
self.functionality_text = "Functionality:"
self._refresh_content()

def compose(self):
yield Static("", id="rendering-info-content", classes="rendering-info-box")
self.module_widget = Static(self.module_text, classes="rendering-info-row")
self.functionality_widget = Static(self.functionality_text, classes="rendering-info-row")
yield Static("module status", classes="rendering-info-title")
with Vertical(classes="rendering-info-box"):
yield self.module_widget
yield self.functionality_widget


class TestScriptsContainer(Vertical):
Expand All @@ -315,6 +290,9 @@ def __init__(
self.unit_test_text = ScriptOutputType.UNIT_TEST_OUTPUT_TEXT.value
self.conformance_test_text = ScriptOutputType.CONFORMANCE_TEST_OUTPUT_TEXT.value
self.testing_env_text = ScriptOutputType.TESTING_ENVIRONMENT_OUTPUT_TEXT.value
self.unit_widget: Static | None = None
self.conformance_widget: Static | None = None
self.testing_widget: Static | None = None

def update_unit_test(self, text: str) -> None:
"""Update unit test output and refresh."""
Expand All @@ -332,52 +310,30 @@ def update_testing_env(self, text: str) -> None:
self._refresh_content()

def _refresh_content(self) -> None:
"""Refresh the bordered box content."""
try:
widget = self.query_one("#test-scripts-content", Static)

# Collect lines to display
lines = []
if self.show_unit_test:
lines.append(f" {self.unit_test_text}")
if self.show_conformance_test:
lines.append(f" {self.conformance_test_text}")
if self.show_testing_env:
lines.append(f" {self.testing_env_text}")

if not lines:
widget.update("")
return

# Find the longest line to determine border width
max_width = max(len(line) for line in lines)
border_width = max(max_width + 2, 80) # Minimum width of 80 chars

# Build the bordered box with title
title = " Latest test scripts "
top_border = "┌[#FFFFFF]" + title + "[/#FFFFFF]" + "─" * (border_width - len(title)) + "┐"
bottom_border = "└" + "─" * border_width + "┘"

content_lines = [top_border]
# Add top padding (empty line)
content_lines.append(f"│{' ' * border_width}│")
for line in lines:
padding = border_width - len(line)
content_lines.append(f"│{line}{' ' * padding}│")
# Add bottom padding (empty line)
content_lines.append(f"│{' ' * border_width}│")
content_lines.append(bottom_border)

widget.update("\n".join(content_lines))
except Exception:
pass
"""Refresh the test script rows."""
if self.unit_widget is not None:
self.unit_widget.update(self.unit_test_text)
self.unit_widget.display = self.show_unit_test
if self.conformance_widget is not None:
self.conformance_widget.update(self.conformance_test_text)
self.conformance_widget.display = self.show_conformance_test
if self.testing_widget is not None:
self.testing_widget.update(self.testing_env_text)
self.testing_widget.display = self.show_testing_env

def on_mount(self) -> None:
"""Initialize the box on mount."""
self._refresh_content()

def compose(self):
yield Static("", id="test-scripts-content", classes="test-scripts-box")
yield Static("testing status", classes="test-scripts-title")
with Vertical(classes="test-scripts-box"):
self.unit_widget = Static(self.unit_test_text, classes="test-script-row")
self.conformance_widget = Static(self.conformance_test_text, classes="test-script-row")
self.testing_widget = Static(self.testing_env_text, classes="test-script-row")
yield self.unit_widget
yield self.conformance_widget
yield self.testing_widget


class FRIDProgress(Vertical):
Expand Down Expand Up @@ -422,24 +378,26 @@ def on_mount(self) -> None:

def compose(self):
yield RenderingInfoBox()
yield ProgressItem(
self.IMPLEMENTING_FUNCTIONALITY_TEXT,
id=TUIComponents.FRID_PROGRESS_RENDER_FR.value,
)
if self.unittests_script is not None:
yield Static("rendering status", classes="frid-state-machine-title")
with Vertical(classes="frid-state-machine-box"):
yield ProgressItem(
self.UNIT_TEST_VALIDATION_TEXT,
id=TUIComponents.FRID_PROGRESS_UNIT_TEST.value,
self.IMPLEMENTING_FUNCTIONALITY_TEXT,
id=TUIComponents.FRID_PROGRESS_RENDER_FR.value,
)
yield ProgressItem(
self.REFACTORING_TEXT,
id=TUIComponents.FRID_PROGRESS_REFACTORING.value,
)
if self.conformance_tests_script is not None:
if self.unittests_script is not None:
yield ProgressItem(
self.UNIT_TEST_VALIDATION_TEXT,
id=TUIComponents.FRID_PROGRESS_UNIT_TEST.value,
)
yield ProgressItem(
self.CONFORMANCE_TEST_VALIDATION_TEXT,
id=TUIComponents.FRID_PROGRESS_CONFORMANCE_TEST.value,
self.REFACTORING_TEXT,
id=TUIComponents.FRID_PROGRESS_REFACTORING.value,
)
if self.conformance_tests_script is not None:
yield ProgressItem(
self.CONFORMANCE_TEST_VALIDATION_TEXT,
id=TUIComponents.FRID_PROGRESS_CONFORMANCE_TEST.value,
)


class LogEntry(Vertical):
Expand Down
7 changes: 3 additions & 4 deletions tui/plain2code_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def __init__(
unittests_script: str,
conformance_tests_script: str,
prepare_environment_script: str,
state_machine_version: str,
**kwargs,
):
super().__init__(**kwargs)
Expand All @@ -76,6 +77,7 @@ def __init__(
self.unittests_script: Optional[str] = unittests_script
self.conformance_tests_script: Optional[str] = conformance_tests_script
self.prepare_environment_script: Optional[str] = prepare_environment_script
self.state_machine_version = state_machine_version

# Initialize state handlers
self._state_handlers: dict[str, StateHandler] = {
Expand Down Expand Up @@ -175,10 +177,7 @@ def compose(self) -> ComposeResult:
with Vertical(id=TUIComponents.DASHBOARD_VIEW.value):
with VerticalScroll():
yield Static(
"┌────────────────────────────────────────────────────────────────┐\n"
"│ [#E0FF6E]*codeplain[/#E0FF6E] │ how to get started │\n"
"│ [#888888](v0.5.0)[/#888888] │ [#888888]Use ctrl + l to see the logs for debuging[/#888888] │\n"
"└────────────────────────────────────────────────────────────────┘",
f"[#FFFFFF]*codeplain[/#FFFFFF] [#888888](v{self.state_machine_version})[/#888888]\n",
id="codeplain-header",
classes="codeplain-header",
)
Expand Down
47 changes: 38 additions & 9 deletions tui/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ Screen {
margin: 0 2;
}

/* Codeplain Header Box */
/* Codeplain Header Box - *codeplain (version)*/
#codeplain-header {
dock: top;
margin: 1 2;
margin: 1 0;
width: auto;
height: auto;
}
Expand All @@ -34,13 +34,10 @@ We might need those at some point, so just commenting them out for now.
margin-left: 2;
margin-right: 2;
height: auto;
color: grey;
}

#render-status-widget {
margin: 0 3;
height: auto;
color: #4D4D4D;
}

#render-status-widget.success {
Expand All @@ -56,15 +53,31 @@ We might need those at some point, so just commenting them out for now.
height: auto;
}

/* Rendering Info Box */
/* Module Status */
RenderingInfoBox {
height: auto;
margin: 1 0;
}

/* Module Status box border */
.rendering-info-box {
height: auto;
border: solid #888;
padding: 0 1;
}

.rendering-info-row {
color: #FFF;
}

.rendering-info-title {
color: #888;
margin-bottom: 0;
}

.frid-state-machine-title {
color: #888;
margin-bottom: 0;
}

ProgressItem {
Expand Down Expand Up @@ -98,28 +111,44 @@ ProgressItem {
}

#frid-progress-header {
margin-bottom: 1;
margin-left: 2;
margin-right: 2;
color: #4D4D4D;
color: #FFF;
}

#render-module-name-widget {
margin-left: 2;
margin-right: 2;
color: #4D4D4D;
color: #FFF;
}

TestScriptsContainer {
margin: 1 0;
height: auto;
}

/* Latest script output container */
.test-scripts-box {
height: auto;
color: #888;
border: solid #888;
padding: 0 1;
}

.test-scripts-title {
color: #888;
margin-bottom: 0;
}

.test-script-row {
color: #FFF;
}

/* State machine container border */
.frid-state-machine-box {
border: solid #888;
padding: 0 1;
}
#unit-test-script-output-widget,
#conformance-tests-script-output-widget,
#testing-environment-script-output-widget {
Expand Down