Skip to content

sidebar

Class info

Classes

Name Children Inherits
PlanPanel
acptui.ui.widgets.sidebar
Every plan of the session that is not removed, kept in sync with the state.
    SideBar
    acptui.ui.widgets.sidebar
    Plan and files, docked at the left of the session screen (hidden until opened).

      🛈 DocStrings

      The sidebar of a session (ctrl+b): the plan and the files, in two sections.

      After toad's sidebar (src/toad/widgets/side_bar.py): collapsible sections, the plan on top (as tall as it needs), the project tree below (the rest of the height), docked at the left. The plan section follows the session's plans live (plan_update and plan removals); the files section is the tree of acptui.ui.widgets.files.

      AUTO_OPEN_WIDTH module-attribute

      AUTO_OPEN_WIDTH = 120
      

      Terminal width from which the sidebar opens by itself for a plan (sidebar = "auto").

      PlanPanel

      Bases: VerticalScroll

      Every plan of the session that is not removed, kept in sync with the state.

      Source code in src/acptui/ui/widgets/sidebar.py
      class PlanPanel(VerticalScroll):
          """Every plan of the session that is not removed, kept in sync with the state."""
      
          DEFAULT_CSS = """
          PlanPanel {
              height: auto;
              max-height: 50vh;
              scrollbar-size-vertical: 1;
              & > PlanView { border: round $secondary 40%; margin: 0; }
              & > #no-plan { color: $text-muted; text-style: italic; padding: 0 1; }
          }
          """
      
          def compose(self) -> ComposeResult:
              yield Static("No plan yet", id="no-plan")
      
          @property
          def views(self) -> list[PlanView]:
              """The plans shown, in order."""
              return list(self.query_children(PlanView))
      
          def show(self, state: SessionState | None) -> None:
              """Show the plans of ``state`` (removed ones go, new ones are added at the end)."""
              plans = list(state.plans.values()) if state is not None else []
              views = {view.entry: view for view in self.views}
              for entry, view in views.items():
                  if entry not in plans:
                      view.remove()
              for entry in plans:
                  if (view := views.get(entry)) is None:
                      self.mount(PlanView(entry, title=""))
                  else:
                      view.refresh_entry()
              self.query_one("#no-plan", Static).display = not plans
      

      views property

      views: list[PlanView]
      

      The plans shown, in order.

      show

      show(state: SessionState | None) -> None
      

      Show the plans of state (removed ones go, new ones are added at the end).

      Source code in src/acptui/ui/widgets/sidebar.py
      def show(self, state: SessionState | None) -> None:
          """Show the plans of ``state`` (removed ones go, new ones are added at the end)."""
          plans = list(state.plans.values()) if state is not None else []
          views = {view.entry: view for view in self.views}
          for entry, view in views.items():
              if entry not in plans:
                  view.remove()
          for entry in plans:
              if (view := views.get(entry)) is None:
                  self.mount(PlanView(entry, title=""))
              else:
                  view.refresh_entry()
          self.query_one("#no-plan", Static).display = not plans
      

      SideBar

      Bases: Vertical

      Plan and files, docked at the left of the session screen (hidden until opened).

      Source code in src/acptui/ui/widgets/sidebar.py
      class SideBar(Vertical):
          """Plan and files, docked at the left of the session screen (hidden until opened)."""
      
          DEFAULT_CSS = """
          SideBar {
              dock: left;
              width: 40;
              max-width: 45%;
              height: 1fr;
              border-right: tall $panel;
              display: none;
              &.-open { display: block; }
              Collapsible {
                  padding: 0;
                  border-top: none;
                  background: transparent;
                  &.-collapsed { height: auto; }
                  & > Contents { padding: 0 0 0 1; }
              }
              #sidebar-plan { height: auto; }
              #sidebar-files { height: 1fr; min-height: 3; }
              #sidebar-files.-collapsed { height: auto; min-height: 1; }
              #sidebar-files > Contents { height: 1fr; }
              FileTree { height: 1fr; background: transparent; }
              #sidebar-hint { color: $text-muted; padding: 0 1; height: 1; }
          }
          """
      
          BINDINGS: ClassVar = [Binding("escape", "leave", "Prompt")]
      
          class Leave(Message):
              """Focus the prompt again (the sidebar stays open)."""
      
          def __init__(self, files: Files) -> None:
              super().__init__(id="sidebar")
              self.files = files
      
          def compose(self) -> ComposeResult:
              with Collapsible(title="Plan", collapsed=False, id="sidebar-plan"):
                  yield PlanPanel()
              with Collapsible(title="Files", collapsed=False, id="sidebar-files"):
                  yield FileTree(self.files)
              yield Static("a: mention · esc: prompt · ctrl+b: hide", id="sidebar-hint")
      
          @property
          def file_tree(self) -> FileTree:
              """The files section's tree."""
              return self.query_one(FileTree)
      
          @property
          def plans(self) -> PlanPanel:
              """The plan section."""
              return self.query_one(PlanPanel)
      
          @property
          def open(self) -> bool:
              """Whether the sidebar is shown."""
              return self.has_class("-open")
      
          def show(self, *, focus: bool = False) -> None:
              """Open the sidebar; ``focus``: move the focus into it (the files, else the plan)."""
              self.add_class("-open")
              if focus:
                  files = self.query_one("#sidebar-files", Collapsible)
                  if files.collapsed:
                      self.query_one("#sidebar-plan CollapsibleTitle").focus()
                  else:
                      self.file_tree.focus()
      
          def hide(self) -> None:
              """Close the sidebar."""
              self.remove_class("-open")
      
          def action_leave(self) -> None:
              """Back to the prompt."""
              self.post_message(self.Leave())
      

      file_tree property

      file_tree: FileTree
      

      The files section's tree.

      open property

      open: bool
      

      Whether the sidebar is shown.

      plans property

      plans: PlanPanel
      

      The plan section.

      Leave

      Bases: Message

      Focus the prompt again (the sidebar stays open).

      Source code in src/acptui/ui/widgets/sidebar.py
      class Leave(Message):
          """Focus the prompt again (the sidebar stays open)."""
      

      action_leave

      action_leave() -> None
      

      Back to the prompt.

      Source code in src/acptui/ui/widgets/sidebar.py
      def action_leave(self) -> None:
          """Back to the prompt."""
          self.post_message(self.Leave())
      

      hide

      hide() -> None
      

      Close the sidebar.

      Source code in src/acptui/ui/widgets/sidebar.py
      def hide(self) -> None:
          """Close the sidebar."""
          self.remove_class("-open")
      

      show

      show(*, focus: bool = False) -> None
      

      Open the sidebar; focus: move the focus into it (the files, else the plan).

      Source code in src/acptui/ui/widgets/sidebar.py
      def show(self, *, focus: bool = False) -> None:
          """Open the sidebar; ``focus``: move the focus into it (the files, else the plan)."""
          self.add_class("-open")
          if focus:
              files = self.query_one("#sidebar-files", Collapsible)
              if files.collapsed:
                  self.query_one("#sidebar-plan CollapsibleTitle").focus()
              else:
                  self.file_tree.focus()