Stepper-style wizard for uncommon-route init.
| 320 | |
| 321 | |
| 322 | class InitApp(App): |
| 323 | """Stepper-style wizard for uncommon-route init.""" |
| 324 | |
| 325 | CSS = CSS |
| 326 | TITLE = "uncommon-route init" |
| 327 | BINDINGS = [ |
| 328 | Binding("ctrl+n", "next_step", "Next", priority=True), |
| 329 | Binding("ctrl+p", "prev_step", "Prev", priority=True), |
| 330 | Binding("ctrl+q", "quit", "Quit", priority=True), |
| 331 | ] |
| 332 | |
| 333 | step_index: reactive[int] = reactive(0) |
| 334 | |
| 335 | def __init__( |
| 336 | self, |
| 337 | *, |
| 338 | rc_path: Path, |
| 339 | rc_display: str, |
| 340 | render_exports: Callable[[str, int], list[str]], |
| 341 | start_background_proxy: Callable[..., tuple[bool, str]], |
| 342 | port: int = 8403, |
| 343 | ) -> None: |
| 344 | super().__init__() |
| 345 | self._rc_path = rc_path |
| 346 | self._rc_display = rc_display |
| 347 | self._render_exports = render_exports |
| 348 | self._start_background_proxy = start_background_proxy |
| 349 | self.answers = InitAnswers( |
| 350 | port=port, |
| 351 | connection_choice="commonstack", |
| 352 | upstream_url="https://api.commonstack.ai/v1", |
| 353 | ) |
| 354 | self.applied: bool = False |
| 355 | self.last_result: ApplyResult | None = None |
| 356 | self._lang: str = DEFAULT_LANG |
| 357 | try: |
| 358 | self._existing_upstream = ConnectionsStore().primary().upstream |
| 359 | except Exception: |
| 360 | self._existing_upstream = "" |
| 361 | |
| 362 | def t(self, key: str, **fmt: object) -> str: |
| 363 | return translate(key, self._lang, **fmt) |
| 364 | |
| 365 | # ------------------------------------------------------------------ |
| 366 | # Compose |
| 367 | # ------------------------------------------------------------------ |
| 368 | |
| 369 | def compose(self) -> ComposeResult: |
| 370 | yield Header(show_clock=False) |
| 371 | with Horizontal(): |
| 372 | with Vertical(id="sidebar"): |
| 373 | yield Static(self.t("app.title"), id="sidebar-title") |
| 374 | for i, (_, label_key) in enumerate(STEPS): |
| 375 | yield Static( |
| 376 | f"{i + 1}. {self.t(label_key)}", |
| 377 | id=f"step-row-{i}", |
| 378 | classes="step-row", |
| 379 | ) |