Skip to content

Commit c036751

Browse files
committed
revert the alignment change
1 parent bdf0a58 commit c036751

File tree

2 files changed

+10
-37
lines changed

2 files changed

+10
-37
lines changed

crates/chat-cli/src/cli/chat/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,7 +1232,6 @@ impl ChatSession {
12321232
&announcement_with_styling,
12331233
GREETING_BREAK_POINT,
12341234
crate::theme::theme().ui.secondary_text,
1235-
Some(crate::cli::chat::util::ui::TextAlign::Left),
12361235
)?;
12371236

12381237
execute!(self.stderr, style::Print("\n"))?;
@@ -1388,7 +1387,6 @@ impl ChatSession {
13881387
tip,
13891388
GREETING_BREAK_POINT,
13901389
crate::theme::theme().ui.secondary_text,
1391-
None,
13921390
)?;
13931391
}
13941392
}

crates/chat-cli/src/cli/chat/util/ui.rs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,13 @@ use crossterm::{
1616
use eyre::Result;
1717
use strip_ansi_escapes::strip_str;
1818

19-
pub enum TextAlign {
20-
Left,
21-
Center,
22-
}
23-
2419
pub fn draw_box(
2520
output: &mut impl Write,
2621
title: &str,
2722
content: &str,
2823
box_width: usize,
2924
border_color: Color,
30-
align: Option<TextAlign>,
3125
) -> Result<()> {
32-
let align = align.unwrap_or(TextAlign::Center);
3326
let inner_width = box_width - 4; // account for │ and padding
3427

3528
// wrap the single line into multiple lines respecting inner width
@@ -113,37 +106,23 @@ pub fn draw_box(
113106
);
114107
execute!(output, style::Print(top_vertical_border))?;
115108

116-
// Wrapped content with configurable alignment
109+
// Centered wrapped content
117110
for line in wrapped_lines {
118111
let visible_line_len = strip_str(&line).len();
119-
120-
// Calculate padding within the inner content area (box_width - 4)
121-
// This gives us the padding space available after accounting for borders and minimum padding
122-
let available_padding = inner_width.saturating_sub(visible_line_len);
123-
124-
let (left_pad, right_pad) = match align {
125-
TextAlign::Left => {
126-
// Left align: 1 space on left, rest on right
127-
(1, available_padding + 1)
128-
},
129-
TextAlign::Center => {
130-
// Center align: split padding evenly
131-
let left = available_padding / 2 + 1; // +1 for minimum padding
132-
let right = available_padding - available_padding / 2 + 1; // +1 for minimum padding
133-
(left, right)
134-
},
135-
};
136-
137-
let left_padding = " ".repeat(left_pad);
138-
let right_padding = " ".repeat(right_pad);
112+
let left_pad = box_width.saturating_sub(4).saturating_sub(visible_line_len) / 2;
139113

140114
let content = format!(
141-
"{}{}{}{}{}",
115+
"{} {: <pad$}{}{: <rem$} {}",
142116
style::style("│").with(border_color),
143-
left_padding,
117+
"",
144118
line,
145-
right_padding,
119+
"",
146120
style::style("│").with(border_color),
121+
pad = left_pad,
122+
rem = box_width
123+
.saturating_sub(4)
124+
.saturating_sub(left_pad)
125+
.saturating_sub(visible_line_len),
147126
);
148127
execute!(output, style::Print(format!("{}\n", content)))?;
149128
}
@@ -180,7 +159,6 @@ mod tests {
180159
short_tip,
181160
GREETING_BREAK_POINT,
182161
theme().ui.secondary_text,
183-
None,
184162
)
185163
.expect("Failed to draw tip box");
186164

@@ -192,7 +170,6 @@ mod tests {
192170
long_tip,
193171
GREETING_BREAK_POINT,
194172
theme().ui.secondary_text,
195-
None,
196173
)
197174
.expect("Failed to draw tip box");
198175

@@ -209,7 +186,6 @@ mod tests {
209186
long_tip_with_one_long_word.as_str(),
210187
GREETING_BREAK_POINT,
211188
theme().ui.secondary_text,
212-
None,
213189
)
214190
.expect("Failed to draw tip box");
215191
// Test with a long tip with two long words that should wrap
@@ -220,7 +196,6 @@ mod tests {
220196
long_tip_with_two_long_words.as_str(),
221197
GREETING_BREAK_POINT,
222198
theme().ui.secondary_text,
223-
None,
224199
)
225200
.expect("Failed to draw tip box");
226201

0 commit comments

Comments
 (0)