@@ -1,7 +1,6 @@ |
| 1 | 1 | """Approval bar widget for command confirmation (Claude Code style).""" |
| 2 | 2 | |
| 3 | 3 | from textual.app import ComposeResult |
| 4 | | -from textual.containers import Horizontal |
| 5 | 4 | from textual.message import Message |
| 6 | 5 | from textual.widgets import Static |
| 7 | 6 | from textual.binding import Binding |
@@ -25,7 +24,8 @@ class ApprovalBar(Widget, can_focus=True): |
| 25 | 24 | |
| 26 | 25 | DEFAULT_CSS = """ |
| 27 | 26 | ApprovalBar { |
| 28 | | - height: 3; |
| 27 | + height: auto; |
| 28 | + max-height: 4; |
| 29 | 29 | display: none; |
| 30 | 30 | padding: 0 1; |
| 31 | 31 | background: $warning 15%; |
@@ -37,31 +37,8 @@ class ApprovalBar(Widget, can_focus=True): |
| 37 | 37 | display: block; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | | - ApprovalBar #approval-container { |
| 40 | + ApprovalBar #approval-content { |
| 41 | 41 | width: 100%; |
| 42 | | - height: 3; |
| 43 | | - } |
| 44 | | - |
| 45 | | - ApprovalBar #approval-tool { |
| 46 | | - color: $warning; |
| 47 | | - text-style: bold; |
| 48 | | - padding-right: 1; |
| 49 | | - } |
| 50 | | - |
| 51 | | - ApprovalBar #approval-preview { |
| 52 | | - color: $text; |
| 53 | | - } |
| 54 | | - |
| 55 | | - ApprovalBar #approval-keys { |
| 56 | | - color: $text-muted; |
| 57 | | - text-align: right; |
| 58 | | - width: auto; |
| 59 | | - dock: right; |
| 60 | | - } |
| 61 | | - |
| 62 | | - ApprovalBar #approval-keys .key { |
| 63 | | - color: $success; |
| 64 | | - text-style: bold; |
| 65 | 42 | } |
| 66 | 43 | """ |
| 67 | 44 | |
@@ -88,13 +65,7 @@ class ApprovalBar(Widget, can_focus=True): |
| 88 | 65 | self.can_focus = True |
| 89 | 66 | |
| 90 | 67 | def compose(self) -> ComposeResult: |
| 91 | | - with Horizontal(id="approval-container"): |
| 92 | | - yield Static("", id="approval-tool") |
| 93 | | - yield Static("", id="approval-preview") |
| 94 | | - yield Static( |
| 95 | | - "[Y]es [n]o [e]dit", |
| 96 | | - id="approval-keys", |
| 97 | | - ) |
| 68 | + yield Static("", id="approval-content") |
| 98 | 69 | |
| 99 | 70 | def show_approval(self, tool_name: str, message: str, details: str = "") -> None: |
| 100 | 71 | """Show the approval bar with a pending action. |
@@ -107,17 +78,14 @@ class ApprovalBar(Widget, can_focus=True): |
| 107 | 78 | self._tool_name = tool_name |
| 108 | 79 | self._full_command = details |
| 109 | 80 | |
| 110 | | - # Update the display |
| 111 | | - tool_label = self.query_one("#approval-tool", Static) |
| 112 | | - preview_label = self.query_one("#approval-preview", Static) |
| 113 | | - |
| 114 | | - tool_label.update(f"[{tool_name}]") |
| 115 | | - |
| 116 | | - # Truncate preview if too long |
| 117 | 81 | preview = details if details else message |
| 118 | | - if len(preview) > 60: |
| 119 | | - preview = preview[:57] + "..." |
| 120 | | - preview_label.update(preview) |
| 82 | + if len(preview) > 70: |
| 83 | + preview = preview[:67] + "..." |
| 84 | + content = self.query_one("#approval-content", Static) |
| 85 | + content.update( |
| 86 | + f"[bold $warning]\\[{tool_name}][/] {preview} " |
| 87 | + f"[bold green]\\[Y][/]es [bold red]\\[n][/]o [bold]\\[e][/]dit" |
| 88 | + ) |
| 121 | 89 | |
| 122 | 90 | # Show the bar |
| 123 | 91 | self.add_class("visible") |