INNER CODE UNIT · Python

refresh_workers

VisionForge-OU/foreman · src/foreman/tui/app.py:193

    def refresh_workers(self) -> None:
        workers = self.app.controller.workers
        lv = self.query_one("#wlist", ListView)
        ids = list(workers.keys())
        if self.selected is None and ids:
            self.selected = ids[0]
        # IMPORTANT: only rebuild the list when the SET of workers changes. Rebuilding
        # (clear + re-append) every tick made the sidebar flicker, wiped the arrow-key
        # highlight, and raced with click handling (Textual looked the clicked item up
        # in a node list we had just cleared → ValueError crash). In steady state we
        # update the existing labels in place instead.
        existing = [item.name for item in lv.children]
        if existing != ids:
            lv.clear()
            for iid in ids:
                lv.append(ListItem(Label(self._worker_label(iid, workers[iid])), name=iid))
            if self.selected in ids:
                lv.index = ids.index(self.selected)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…