Skip to content

Commit 375a592

Browse files
committed
final copy
1 parent 9213904 commit 375a592

File tree

3 files changed

+81
-43
lines changed

3 files changed

+81
-43
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,7 @@ impl ChatSession {
12231223
&announcement_with_styling,
12241224
GREETING_BREAK_POINT,
12251225
crate::theme::theme().ui.secondary_text,
1226+
Some(crate::cli::chat::util::ui::TextAlign::Left),
12261227
)?;
12271228

12281229
execute!(self.stderr, style::Print("\n"))?;
@@ -1377,10 +1378,14 @@ impl ChatSession {
13771378
tip,
13781379
GREETING_BREAK_POINT,
13791380
crate::theme::theme().ui.secondary_text,
1381+
None,
13801382
)?;
13811383
}
13821384
}
13831385

1386+
// Show Kiro upgrade announcement before shortcuts (limited to 2 times)
1387+
self.show_kiro_upgrade_announcement(os).await?;
1388+
13841389
// Always show shortcuts and separator
13851390
execute!(
13861391
self.stderr,
@@ -1462,9 +1467,6 @@ impl ChatSession {
14621467
self.conversation.checkpoint_manager = checkpoint_manager;
14631468
}
14641469

1465-
// Show Kiro upgrade announcement (limited to 2 times)
1466-
self.show_kiro_upgrade_announcement(os).await?;
1467-
14681470
if let Some(user_input) = self.initial_input.take() {
14691471
self.inner = Some(ChatState::HandleInput { input: user_input });
14701472
}

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

Lines changed: 73 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,70 @@ use crossterm::{
1616
use eyre::Result;
1717
use strip_ansi_escapes::strip_str;
1818

19+
pub enum TextAlign {
20+
Left,
21+
Center,
22+
}
23+
1924
pub fn draw_box(
2025
output: &mut impl Write,
2126
title: &str,
2227
content: &str,
2328
box_width: usize,
2429
border_color: Color,
30+
align: Option<TextAlign>,
2531
) -> Result<()> {
32+
let align = align.unwrap_or(TextAlign::Center);
2633
let inner_width = box_width - 4; // account for │ and padding
2734

2835
// wrap the single line into multiple lines respecting inner width
2936
// Manually wrap the text by splitting at word boundaries, using visible length for styled text
37+
// First split by newlines to preserve explicit line breaks
3038
let mut wrapped_lines = Vec::new();
31-
let mut line = String::new();
3239

33-
for word in content.split_whitespace() {
34-
let test_line = if line.is_empty() {
35-
word.to_string()
36-
} else {
37-
format!("{} {}", line, word)
38-
};
40+
for paragraph in content.split('\n') {
41+
if paragraph.is_empty() {
42+
// Preserve empty lines
43+
wrapped_lines.push(String::new());
44+
continue;
45+
}
3946

40-
let visible_len = strip_str(&test_line).len();
41-
42-
if visible_len <= inner_width {
43-
line = test_line;
44-
} else {
45-
// Check if the word alone is too long
46-
let word_visible_len = strip_str(word).len();
47-
if word_visible_len >= inner_width {
48-
// Word is too long, we need to break it (but this is rare with styled text)
49-
if !line.is_empty() {
50-
wrapped_lines.push(line);
51-
}
52-
wrapped_lines.push(word.to_string());
53-
line = String::new();
47+
let mut line = String::new();
48+
49+
for word in paragraph.split_whitespace() {
50+
let test_line = if line.is_empty() {
51+
word.to_string()
52+
} else {
53+
format!("{} {}", line, word)
54+
};
55+
56+
let visible_len = strip_str(&test_line).len();
57+
58+
if visible_len <= inner_width {
59+
line = test_line;
5460
} else {
55-
// Start a new line with this word
56-
if !line.is_empty() {
57-
wrapped_lines.push(line);
61+
// Check if the word alone is too long
62+
let word_visible_len = strip_str(word).len();
63+
if word_visible_len >= inner_width {
64+
// Word is too long, we need to break it (but this is rare with styled text)
65+
if !line.is_empty() {
66+
wrapped_lines.push(line);
67+
}
68+
wrapped_lines.push(word.to_string());
69+
line = String::new();
70+
} else {
71+
// Start a new line with this word
72+
if !line.is_empty() {
73+
wrapped_lines.push(line);
74+
}
75+
line = word.to_string();
5876
}
59-
line = word.to_string();
6077
}
6178
}
62-
}
6379

64-
if !line.is_empty() {
65-
wrapped_lines.push(line);
80+
if !line.is_empty() {
81+
wrapped_lines.push(line);
82+
}
6683
}
6784

6885
let top_border = if title.is_empty() {
@@ -96,23 +113,37 @@ pub fn draw_box(
96113
);
97114
execute!(output, style::Print(top_vertical_border))?;
98115

99-
// Centered wrapped content
116+
// Wrapped content with configurable alignment
100117
for line in wrapped_lines {
101118
let visible_line_len = strip_str(&line).len();
102-
let left_pad = box_width.saturating_sub(4).saturating_sub(visible_line_len) / 2;
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);
103139

104140
let content = format!(
105-
"{} {: <pad$}{}{: <rem$} {}",
141+
"{}{}{}{}{}",
106142
style::style("│").with(border_color),
107-
"",
143+
left_padding,
108144
line,
109-
"",
145+
right_padding,
110146
style::style("│").with(border_color),
111-
pad = left_pad,
112-
rem = box_width
113-
.saturating_sub(4)
114-
.saturating_sub(left_pad)
115-
.saturating_sub(visible_line_len),
116147
);
117148
execute!(output, style::Print(format!("{}\n", content)))?;
118149
}
@@ -149,6 +180,7 @@ mod tests {
149180
short_tip,
150181
GREETING_BREAK_POINT,
151182
theme().ui.secondary_text,
183+
None,
152184
)
153185
.expect("Failed to draw tip box");
154186

@@ -160,6 +192,7 @@ mod tests {
160192
long_tip,
161193
GREETING_BREAK_POINT,
162194
theme().ui.secondary_text,
195+
None,
163196
)
164197
.expect("Failed to draw tip box");
165198

@@ -176,6 +209,7 @@ mod tests {
176209
long_tip_with_one_long_word.as_str(),
177210
GREETING_BREAK_POINT,
178211
theme().ui.secondary_text,
212+
None,
179213
)
180214
.expect("Failed to draw tip box");
181215
// Test with a long tip with two long words that should wrap
@@ -186,6 +220,7 @@ mod tests {
186220
long_tip_with_two_long_words.as_str(),
187221
GREETING_BREAK_POINT,
188222
theme().ui.secondary_text,
223+
None,
189224
)
190225
.expect("Failed to draw tip box");
191226

crates/chat-cli/src/constants.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,10 @@ Notes:
223223
/// Announcement text for Kiro CLI upgrade
224224
pub fn kiro_upgrade_announcement() -> String {
225225
format!(
226-
"Q CLI users can now upgrade to the Kiro CLI. Type {} to update today. The Kiro CLI leverages the agentic features of Q CLI and can be used with your existing Q Developer subscription. If you have auto updates enabled for the Q CLI, unless you disable that setting, Q CLI will auto update to Kiro CLI on 11/24. Kiro CLI is licensed as AWS Content under your Agreement and the AWS Intellectual Property License ({}). By updating to Kiro CLI, you agree to the AWS Intellectual Property License.",
226+
"Kiro CLI is the next update of the Q CLI. Your existing Q Developer CLI workflows and subscription continue to work without any changes. You can update to Kiro CLI manually with {} today, or wait for the auto-update on 11/24 to apply the change. To learn more, go to {}.\n\nKiro CLI is licensed under, and by updating to it you agree to, the AWS Intellectual Property License ({}).",
227227
StyledText::command("q update"),
228-
StyledText::command("https://aws.amazon.com/legal/aws-ip-license-terms/")
228+
StyledText::command("kiro.dev/cli/upgrade"),
229+
StyledText::command("kiro.dev/license")
229230
)
230231
}
231232

0 commit comments

Comments
 (0)