Skip to content

Commit 09b6e85

Browse files
Josh Hardyclaude
andcommitted
refactor: extract shared helpers in select widget, add tests
- Extract ANSI codes as named constants (BOLD, DIM, etc.) - Factor out write_header, write_title, wrap_lines, write_wrapped helpers shared between Select and Input rendering - Add SelectContext::new()/with_description() builder methods - Add 10 unit tests covering wrap_lines, item_height, and count_items_fitting edge cases - Simplify render_select signature (query terminal size internally) - Apply rustfmt Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 443da54 commit 09b6e85

2 files changed

Lines changed: 295 additions & 241 deletions

File tree

crates/cli/src/commands/strategy_builder/interactive.rs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,14 @@ fn fill_single_field(
424424
if idx < presets.len() {
425425
presets[idx].value.clone()
426426
} else {
427-
select::input(w, &field.name, field.description.as_deref(), None, false, progress)?
427+
select::input(
428+
w,
429+
&field.name,
430+
field.description.as_deref(),
431+
None,
432+
false,
433+
progress,
434+
)?
428435
}
429436
}
430437
_ => select::input(
@@ -467,23 +474,21 @@ async fn fill_deposits(
467474
}
468475

469476
for deposit_cfg in &deployment.deposits {
470-
let (token_display, balance_desc) = match builder
471-
.get_token_info(deposit_cfg.token_key.clone())
472-
.await
473-
{
474-
Ok(info) => {
475-
let balance = builder
476-
.get_account_balance(format!("{}", info.address), owner.to_string())
477-
.await
478-
.ok()
479-
.map(|b| b.formatted_balance().to_string());
480-
let desc = balance
481-
.map(|b| format!("Your balance: {b} {}", info.symbol))
482-
.unwrap_or_default();
483-
(info.symbol.clone(), desc)
484-
}
485-
Err(_) => (deposit_cfg.token_key.clone(), String::new()),
486-
};
477+
let (token_display, balance_desc) =
478+
match builder.get_token_info(deposit_cfg.token_key.clone()).await {
479+
Ok(info) => {
480+
let balance = builder
481+
.get_account_balance(format!("{}", info.address), owner.to_string())
482+
.await
483+
.ok()
484+
.map(|b| b.formatted_balance().to_string());
485+
let desc = balance
486+
.map(|b| format!("Your balance: {b} {}", info.symbol))
487+
.unwrap_or_default();
488+
(info.symbol.clone(), desc)
489+
}
490+
Err(_) => (deposit_cfg.token_key.clone(), String::new()),
491+
};
487492

488493
let presets = builder
489494
.get_deposit_presets(deposit_cfg.token_key.clone())

0 commit comments

Comments
 (0)