Skip to content

Conversation

aibrahim-oai
Copy link
Collaborator

Refactor it to be used in status

Comment on lines 637 to 684
struct CodexCardLayout {
inner_width: usize,
}

impl CodexCardLayout {
fn new(width: u16, max_inner_width: usize) -> Option<Self> {
if width < 4 {
return None;
}
let inner_width = std::cmp::min(width.saturating_sub(2) as usize, max_inner_width);
Some(Self { inner_width })
}

fn inner_width(&self) -> usize {
self.inner_width
}

fn top_border(&self) -> Line<'static> {
vec![Span::from(format!("╭{}╮", "─".repeat(self.inner_width))).dim()].into()
}

fn bottom_border(&self) -> Line<'static> {
vec![Span::from(format!("╰{}╯", "─".repeat(self.inner_width))).dim()].into()
}

fn blank_row(&self) -> Line<'static> {
self.row(Vec::new())
}

fn row(&self, mut content: Vec<Span<'static>>) -> Line<'static> {
let used_width: usize = content
.iter()
.map(|span| UnicodeWidthStr::width(span.content.as_ref()))
.sum();

if used_width < self.inner_width {
let padding = self.inner_width - used_width;
content.push(Span::from(" ".repeat(padding)).dim());
}

let mut spans: Vec<Span<'static>> = Vec::with_capacity(content.len() + 2);
spans.push(Span::from("│").dim());
spans.extend(content);
spans.push(Span::from("│").dim());

Line::from(spans)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be a single function, fn with_border(lines: Vec<Line>) -> Vec<Line>.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this gives us the ability to wrap long lines and handle them differently

.unwrap_or(0);

let mut out = Vec::with_capacity(lines.len() + 2);
out.push(vec![Span::from(format!("╭{}╮", "─".repeat(inner_width))).dim()].into());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need Span::from() here, as .dim() will turn a String into a span.

Comment on lines 871 to 873
if used_width < inner_width {
spans.push(Span::from(" ".repeat(inner_width - used_width)).dim());
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is duplicative with with_border

Comment on lines 904 to 906
model_spans.push(Span::from(" ").dim());
model_spans.push(Span::from(CHANGE_MODEL_HINT_COMMAND).cyan());
model_spans.push(Span::from(CHANGE_MODEL_HINT_EXPLANATION).dim());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
model_spans.push(Span::from(" ").dim());
model_spans.push(Span::from(CHANGE_MODEL_HINT_COMMAND).cyan());
model_spans.push(Span::from(CHANGE_MODEL_HINT_EXPLANATION).dim());
model_spans.push(" ".dim());
model_spans.push(CHANGE_MODEL_HINT_COMMAND.cyan());
model_spans.push(CHANGE_MODEL_HINT_EXPLANATION.dim());

.sum();
let span_count = line.spans.len();
let mut spans: Vec<Span<'static>> = Vec::with_capacity(span_count + 4);
spans.push(Span::from("│").dim());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

”| “.dim()

let mut title_spans: Vec<Span<'static>> = vec![
Span::from("│").dim(),
Span::from(" ").dim(),
let make_row = |spans: Vec<Span<'static>>| Line::from(spans);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make_row is redundant now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? we convert a span to line.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just call Line::from directly

@aibrahim-oai aibrahim-oai enabled auto-merge (squash) September 23, 2025 17:29
@aibrahim-oai aibrahim-oai merged commit c6e8671 into main Sep 23, 2025
19 checks passed
@aibrahim-oai aibrahim-oai deleted the tui-status branch September 23, 2025 17:37
@github-actions github-actions bot locked and limited conversation to collaborators Sep 23, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants