mirror of
https://github.com/openai/codex.git
synced 2026-11-25 07:23:22 +00:00
1 parent
d7482510b1
commit
b53889aed5
7 files changed
+10
-393
No files matched your search
@@ -3,7 +3,6 @@ use std::path::PathBuf;
|
||||
|
||||
use crate::app_event_sender::AppEventSender;
|
||||
use crate::bottom_pane::queued_user_messages::QueuedUserMessages;
|
||||
use crate::bottom_pane::unified_exec_footer::UnifiedExecFooter;
|
||||
use crate::render::renderable::FlexRenderable;
|
||||
use crate::render::renderable::Renderable;
|
||||
use crate::render::renderable::RenderableItem;
|
||||
@@ -41,7 +40,6 @@ mod queued_user_messages;
|
||||
mod scroll_state;
|
||||
mod selection_popup_common;
|
||||
mod textarea;
|
||||
mod unified_exec_footer;
|
||||
pub(crate) use feedback_view::FeedbackNoteView;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
@@ -78,8 +76,6 @@ pub(crate) struct BottomPane {
|
||||
|
||||
/// Inline status indicator shown above the composer while a task is running.
|
||||
status: Option<StatusIndicatorWidget>,
|
||||
/// Unified exec session summary shown above the composer.
|
||||
unified_exec_footer: UnifiedExecFooter,
|
||||
/// Queued user messages to show above the composer while a turn is running.
|
||||
queued_user_messages: QueuedUserMessages,
|
||||
context_window_percent: Option<i64>,
|
||||
@@ -127,7 +123,6 @@ impl BottomPane {
|
||||
is_task_running: false,
|
||||
ctrl_c_quit_hint: false,
|
||||
status: None,
|
||||
unified_exec_footer: UnifiedExecFooter::new(),
|
||||
queued_user_messages: QueuedUserMessages::new(),
|
||||
esc_backtrack_hint: false,
|
||||
animations_enabled,
|
||||
@@ -398,12 +393,6 @@ impl BottomPane {
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
pub(crate) fn set_unified_exec_sessions(&mut self, sessions: Vec<String>) {
|
||||
if self.unified_exec_footer.set_sessions(sessions) {
|
||||
self.request_redraw();
|
||||
}
|
||||
}
|
||||
|
||||
/// Update custom prompts available for the slash popup.
|
||||
pub(crate) fn set_custom_prompts(&mut self, prompts: Vec<CustomPrompt>) {
|
||||
self.composer.set_custom_prompts(prompts);
|
||||
@@ -534,14 +523,8 @@ impl BottomPane {
|
||||
if let Some(status) = &self.status {
|
||||
flex.push(0, RenderableItem::Borrowed(status));
|
||||
}
|
||||
if !self.unified_exec_footer.is_empty() {
|
||||
flex.push(0, RenderableItem::Borrowed(&self.unified_exec_footer));
|
||||
}
|
||||
flex.push(1, RenderableItem::Borrowed(&self.queued_user_messages));
|
||||
if self.status.is_some()
|
||||
|| !self.unified_exec_footer.is_empty()
|
||||
|| !self.queued_user_messages.messages.is_empty()
|
||||
{
|
||||
if self.status.is_some() || !self.queued_user_messages.messages.is_empty() {
|
||||
flex.push(0, RenderableItem::Owned("".into()));
|
||||
}
|
||||
let mut flex2 = FlexRenderable::new();
|
||||
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/unified_exec_footer.rs
|
||||
expression: "format!(\"{buf:?}\")"
|
||||
---
|
||||
Buffer {
|
||||
area: Rect { x: 0, y: 0, width: 50, height: 2 },
|
||||
content: [
|
||||
"Background terminal running: echo hello · rg "foo"",
|
||||
" src · 1 more running ",
|
||||
],
|
||||
styles: [
|
||||
x: 0, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
|
||||
x: 28, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 29, y: 0, fg: Cyan, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 39, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
|
||||
x: 42, y: 0, fg: Cyan, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 0, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 29, y: 1, fg: Cyan, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 32, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
|
||||
x: 49, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
]
|
||||
}
|
||||
-21
@@ -1,21 +0,0 @@
|
||||
---
|
||||
source: tui/src/bottom_pane/unified_exec_footer.rs
|
||||
expression: "format!(\"{buf:?}\")"
|
||||
---
|
||||
Buffer {
|
||||
area: Rect { x: 0, y: 0, width: 50, height: 2 },
|
||||
content: [
|
||||
"Background terminal running: echo hello · rg "foo"",
|
||||
" src ",
|
||||
],
|
||||
styles: [
|
||||
x: 0, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
|
||||
x: 28, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 29, y: 0, fg: Cyan, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 39, y: 0, fg: Reset, bg: Reset, underline: Reset, modifier: DIM,
|
||||
x: 42, y: 0, fg: Cyan, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 0, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 29, y: 1, fg: Cyan, bg: Reset, underline: Reset, modifier: NONE,
|
||||
x: 32, y: 1, fg: Reset, bg: Reset, underline: Reset, modifier: NONE,
|
||||
]
|
||||
}
|
||||
@@ -1,125 +0,0 @@
|
||||
use ratatui::buffer::Buffer;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::style::Stylize;
|
||||
use ratatui::text::Line;
|
||||
use ratatui::widgets::Paragraph;
|
||||
|
||||
use crate::render::renderable::Renderable;
|
||||
use crate::text_formatting::truncate_text;
|
||||
use crate::wrapping::RtOptions;
|
||||
use crate::wrapping::word_wrap_lines;
|
||||
|
||||
const MAX_SESSION_LABEL_GRAPHEMES: usize = 48;
|
||||
const MAX_VISIBLE_SESSIONS: usize = 2;
|
||||
|
||||
pub(crate) struct UnifiedExecFooter {
|
||||
sessions: Vec<String>,
|
||||
}
|
||||
|
||||
impl UnifiedExecFooter {
|
||||
pub(crate) fn new() -> Self {
|
||||
Self {
|
||||
sessions: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn set_sessions(&mut self, sessions: Vec<String>) -> bool {
|
||||
if self.sessions == sessions {
|
||||
return false;
|
||||
}
|
||||
self.sessions = sessions;
|
||||
true
|
||||
}
|
||||
|
||||
pub(crate) fn is_empty(&self) -> bool {
|
||||
self.sessions.is_empty()
|
||||
}
|
||||
|
||||
fn render_lines(&self, width: u16) -> Vec<Line<'static>> {
|
||||
if self.sessions.is_empty() || width < 4 {
|
||||
return Vec::new();
|
||||
}
|
||||
|
||||
let label = "Background terminal running:";
|
||||
let mut spans = Vec::new();
|
||||
spans.push(label.dim());
|
||||
spans.push(" ".into());
|
||||
|
||||
let visible = self.sessions.iter().take(MAX_VISIBLE_SESSIONS);
|
||||
let mut visible_count = 0usize;
|
||||
for (idx, command) in visible.enumerate() {
|
||||
if idx > 0 {
|
||||
spans.push(" · ".dim());
|
||||
}
|
||||
let truncated = truncate_text(command, MAX_SESSION_LABEL_GRAPHEMES);
|
||||
spans.push(truncated.cyan());
|
||||
visible_count += 1;
|
||||
}
|
||||
|
||||
let remaining = self.sessions.len().saturating_sub(visible_count);
|
||||
if remaining > 0 {
|
||||
spans.push(" · ".dim());
|
||||
spans.push(format!("{remaining} more running").dim());
|
||||
}
|
||||
|
||||
let indent = " ".repeat(label.len() + 1);
|
||||
let line = Line::from(spans);
|
||||
word_wrap_lines(
|
||||
std::iter::once(line),
|
||||
RtOptions::new(width as usize).subsequent_indent(Line::from(indent).dim()),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl Renderable for UnifiedExecFooter {
|
||||
fn render(&self, area: Rect, buf: &mut Buffer) {
|
||||
if area.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
Paragraph::new(self.render_lines(area.width)).render(area, buf);
|
||||
}
|
||||
|
||||
fn desired_height(&self, width: u16) -> u16 {
|
||||
self.render_lines(width).len() as u16
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use insta::assert_snapshot;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn desired_height_empty() {
|
||||
let footer = UnifiedExecFooter::new();
|
||||
assert_eq!(footer.desired_height(40), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_two_sessions() {
|
||||
let mut footer = UnifiedExecFooter::new();
|
||||
footer.set_sessions(vec!["echo hello".to_string(), "rg \"foo\" src".to_string()]);
|
||||
let width = 50;
|
||||
let height = footer.desired_height(width);
|
||||
let mut buf = Buffer::empty(Rect::new(0, 0, width, height));
|
||||
footer.render(Rect::new(0, 0, width, height), &mut buf);
|
||||
assert_snapshot!("render_two_sessions", format!("{buf:?}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_more_sessions() {
|
||||
let mut footer = UnifiedExecFooter::new();
|
||||
footer.set_sessions(vec![
|
||||
"echo hello".to_string(),
|
||||
"rg \"foo\" src".to_string(),
|
||||
"cat README.md".to_string(),
|
||||
]);
|
||||
let width = 50;
|
||||
let height = footer.desired_height(width);
|
||||
let mut buf = Buffer::empty(Rect::new(0, 0, width, height));
|
||||
footer.render(Rect::new(0, 0, width, height), &mut buf);
|
||||
assert_snapshot!("render_more_sessions", format!("{buf:?}"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user