CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-textual

Modern Text User Interface framework for building cross-platform terminal and web applications with Python

Overall
score

93%

Overview
Eval results
Files

task.mdevals/scenario-10/

Background Task Processor

Build a terminal application that processes a list of items in the background while displaying real-time progress and allowing user interaction.

Requirements

Create a Textual application with the following functionality:

Display

The application should display:

  • A label showing the current processing status
  • A progress indicator showing how many items have been processed
  • A button to start processing
  • A button to cancel ongoing processing

Background Processing

When the "Start" button is pressed:

  • Launch a background task that processes 10 items
  • Each item takes 0.5 seconds to process
  • Update the progress after each item is processed
  • Display "Processing item X of 10" during processing
  • Display "Completed!" when all items are processed
  • Display "Cancelled" if processing was cancelled

Cancellation

When the "Cancel" button is pressed:

  • Stop the background processing task
  • Update the status to show cancellation

Error Handling

  • If processing fails, the application should not crash
  • Display "Error occurred" if processing encounters an error

Test Cases

  • Starting processing updates the status label to show "Processing item 1 of 10" @test
  • After processing completes, the status shows "Completed!" @test
  • Clicking cancel during processing updates status to "Cancelled" @test
  • Progress tracking correctly reports 5 out of 10 items after 2.5 seconds @test

Implementation

@generates

API

from textual.app import App, ComposeResult
from textual.widgets import Button, Label, Static
from textual.containers import Container

class ProcessorApp(App):
    """Application that processes items in the background with progress tracking."""

    def compose(self) -> ComposeResult:
        """Create the application layout."""
        pass

    def on_button_pressed(self, event: Button.Pressed) -> None:
        """Handle button press events."""
        pass

    def process_items(self) -> None:
        """Background method that processes items with progress tracking."""
        pass

Dependencies { .dependencies }

textual { .dependency }

Provides the TUI framework for building terminal applications with background task support.

Install with Tessl CLI

npx tessl i tessl/pypi-textual

tile.json