use super::{
Action, PLACEHOLDER_COLOR, Session, measure_text_width, ratatui_color_from_ansi, ratatui_style_from_inline,
};
use crate::tui::config::constants::ui;
use crate::tui::ui::tui::types::InlineTextStyle;
use anstyle::{Color as AnsiColorEnum, Effects};
use ratatui::{
buffer::Buffer,
prelude::*,
widgets::{Block, Padding, Paragraph, Wrap},
};
mod helpers;
mod tokenizer;
pub(crate) use helpers::{InputWidgetData, should_track_compact_paste, status_requires_shimmer};
use helpers::{
byte_index_to_char_index, char_index_to_byte_index, compact_image_label, compact_image_placeholders,
compact_paste_range_preview, display_width_for_char_range, generic_large_input_preview,
inline_prompt_suggestion_suffix, render_fake_cursor,
};
pub(super) use tokenizer::{InputToken, InputTokenKind, tokenize_input};
fn paint_pre_wrapped_text(text: &Text<'static>, area: Rect, buf: &mut Buffer, base: Style) {
for (row, line) in text.lines.iter().take(usize::from(area.height)).enumerate() {
let y = area.y + row as u16;
let mut x = area.x;
for span in &line.spans {
if x >= area.right() {
break;
}
let merged = base.patch(span.style);
let (end_x, _) =
buf.set_stringn(x, y, span.content.as_ref(), area.right().saturating_sub(x) as usize, merged);
x = end_x;
}
}
}
fn paint_pre_wrapped_line(line: &Line<'static>, area: Rect, buf: &mut Buffer, base: Style) {
if area.width == 0 || area.height == 0 {
return;
}
let mut x = area.x;
let y = area.y;
for span in &line.spans {
if x >= area.right() {
break;
}
let merged = base.patch(span.style);
let (end_x, _) = buf.set_stringn(x, y, span.content.as_ref(), area.right().saturating_sub(x) as usize, merged);
x = end_x;
}
}
use tui_shimmer::shimmer_spans_with_style_at_phase;
use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};
use super::utils::line_truncation::truncate_line_with_ellipsis_if_overflow;
pub(super) struct InputRender {
pub(super) text: Text<'static>,
pub(super) cursor_x: u16,
pub(super) cursor_y: u16,
}
#[derive(Default)]
pub(super) struct InputStatusLine {
pub(super) line: Line<'static>,
pub(super) background_hits: Vec<(u16, u16)>,
pub(super) progress_start: u16,
pub(super) progress_columns: u16,
}
pub(super) struct CompactInputPreview {
pub(super) before: String,
pub(super) placeholder: String,
pub(super) after_lines: Vec<String>,
}
impl CompactInputPreview {
fn line_count(&self) -> usize {
self.after_lines.len().max(1)
}
}
#[derive(Default)]
pub(super) struct InputLineBuffer {
pub(super) prefix: String,
pub(super) text: String,
pub(super) prefix_width: u16,
pub(super) text_width: u16,
pub(super) char_start: usize,
}
impl InputLineBuffer {
fn new(prefix: String, prefix_width: u16, char_start: usize) -> Self {
Self {
prefix,
text: String::new(),
prefix_width,
text_width: 0,
char_start,
}
}
}
pub(super) struct InputLayout {
pub(super) buffers: Vec<InputLineBuffer>,
pub(super) cursor_line_idx: usize,
pub(super) cursor_column: u16,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) struct InputVisualGeometry {
pub(crate) total_rows: usize,
pub(crate) cursor_row: usize,
}
const SHELL_MODE_BORDER_TITLE: &str = " ! Shell mode ";
const SHELL_MODE_STATUS_HINT: &str = "Shell mode (!): direct command execution";
impl Session {
pub(super) fn queued_input_status_text(&self) -> Option<String> {
let pending = self.queued_inputs.len();
if pending == 0 || !self.is_running_activity() || self.copy_notification_text().is_some() {
return None;
}
if pending == 1 {
const PREVIEW_CHARS: usize = 40;
let entry = &self.queued_inputs[0];
let flattened = entry.replace(['\r', '\n'], " ");
let trimmed = flattened.trim();
let preview: String = trimmed.chars().take(PREVIEW_CHARS).collect();
let ellipsis = if trimmed.chars().count() > PREVIEW_CHARS {
"…"
} else {
""
};
return Some(format!("Queued: {preview}{ellipsis} — runs after this turn"));
}
Some(format!("{pending} turns queued — running after this turn"))
}
#[cfg_attr(feature = "profiling", hotpath::measure)]
pub(crate) fn render_input(&mut self, frame: &mut Frame<'_>, area: Rect) {
if area.height == 0 {
self.set_input_area(None);
self.set_background_indicator_hits(Vec::new());
return;
}
let mut input_area = area;
let mut status_area = None;
if area.height > ui::INLINE_INPUT_STATUS_HEIGHT {
let block_height = area.height.saturating_sub(ui::INLINE_INPUT_STATUS_HEIGHT);
input_area.height = block_height.max(1);
status_area = Some(Rect::new(area.x, area.y + block_height, area.width, ui::INLINE_INPUT_STATUS_HEIGHT));
}
let background_style = self.styles.input_background_style();
let shell_mode_title = self.shell_mode_border_title();
let active_subagent_title = self.active_subagent_input_title();
let active_subagent_border_style = self.active_subagent_input_border_style();
let mut block = if shell_mode_title.is_some() || active_subagent_title.is_some() {
Block::bordered()
} else {
Block::new()
};
block = block.style(background_style).padding(self.input_block_padding());
if shell_mode_title.is_some() || active_subagent_title.is_some() {
block = block.border_set(super::terminal_capabilities::get_border_set()).border_style(
active_subagent_border_style.unwrap_or_else(|| self.styles.accent_style().add_modifier(Modifier::BOLD)),
);
}
if let Some(title) = shell_mode_title {
block = block.title_top(Line::from(title).left_aligned());
}
if let Some(title) = active_subagent_title {
block = block.title_top(title);
}
let inner = block.inner(input_area);
self.set_input_area(Some(inner));
let input_render = self.build_input_render(inner.width, inner.height);
frame.render_widget(block, input_area);
{
let buf = frame.buffer_mut();
buf.set_style(inner, background_style);
paint_pre_wrapped_text(&input_render.text, inner, buf, background_style);
}
self.apply_input_selection_highlight(frame.buffer_mut(), inner);
if self.fullscreen.interaction.copy_on_select && self.input_manager.selection_needs_copy() {
let _ = self.copy_input_selection_to_clipboard();
}
if self.cursor_should_be_visible() && inner.width > 0 && inner.height > 0 {
let cursor_x = input_render.cursor_x.min(inner.width.saturating_sub(1)).saturating_add(inner.x);
let cursor_y = input_render
.cursor_y
.min(inner.height.saturating_sub(1))
.saturating_add(inner.y);
if self.use_fake_cursor() {
render_fake_cursor(frame.buffer_mut(), cursor_x, cursor_y);
} else {
frame.set_cursor_position(Position::new(cursor_x, cursor_y));
}
}
if let Some(status_area) = status_area {
let status = self.build_input_status_line(status_area.width).unwrap_or_default();
{
let buf = frame.buffer_mut();
buf.set_style(status_area, self.styles.default_style());
paint_pre_wrapped_line(&status.line, status_area, buf, self.styles.default_style());
}
if status.progress_columns > 0 {
let feedback_area =
Rect::new(status_area.x + status.progress_start, status_area.y, status.progress_columns, 1);
self.set_progress_feedback_area(feedback_area.intersection(frame.area()));
}
let hits = status
.background_hits
.into_iter()
.map(|(start, end)| {
Rect::new(status_area.x.saturating_add(start), status_area.y, end.saturating_sub(start), 1)
})
.collect();
self.set_background_indicator_hits(hits);
} else {
self.set_background_indicator_hits(Vec::new());
}
}
pub(crate) fn desired_input_lines(&self, inner_width: u16) -> u16 {
if inner_width == 0 {
return 1;
}
if self.input_compact_mode && self.input_manager.cursor() == self.input_manager.content().len() {
if let Some(preview) = self.input_compact_preview() {
return preview.line_count().min(ui::INLINE_INPUT_MAX_LINES.max(1)) as u16;
}
if self.input_compact_placeholder().is_some() {
return 1;
}
}
if self.input_manager.content().is_empty() {
return 1;
}
let prompt_width = UnicodeWidthStr::width(self.prompt_prefix.as_str()) as u16;
let prompt_display_width = prompt_width.min(inner_width);
let layout = self.input_layout(inner_width, prompt_display_width);
let line_count = layout.buffers.len().max(1);
let capped = line_count.min(ui::INLINE_INPUT_MAX_LINES.max(1));
capped as u16
}
pub(crate) fn apply_input_height(&mut self, height: u16) {
let resolved = height.max(Self::input_block_height_for_lines(1));
if self.input_height != resolved {
self.input_height = resolved;
self.recalculate_transcript_rows();
}
}
pub(crate) fn input_block_height_for_lines(lines: u16) -> u16 {
lines.max(1).saturating_add(ui::INLINE_INPUT_PADDING_VERTICAL.saturating_mul(2))
}
pub(crate) fn input_block_extra_height(&self) -> u16 {
if self.active_subagent_input_title().is_some() && !self.input_uses_shell_prefix() {
2
} else {
0
}
}
fn input_layout(&self, width: u16, prompt_display_width: u16) -> InputLayout {
let indent_prefix = " ".repeat(prompt_display_width as usize);
let mut buffers = vec![InputLineBuffer::new(
self.prompt_prefix.clone(),
prompt_display_width,
0,
)];
let secure_prompt_active = self.secure_prompt_active();
let mut cursor_line_idx = 0usize;
let mut cursor_column = prompt_display_width;
let input_content = self.input_manager.content();
let cursor_pos = self.input_manager.cursor();
let mut cursor_set = cursor_pos == 0;
let mut char_idx: usize = 0;
for (idx, ch) in input_content.char_indices() {
if !cursor_set
&& cursor_pos == idx
&& let Some(current) = buffers.last()
{
cursor_line_idx = buffers.len() - 1;
cursor_column = current.prefix_width + current.text_width;
cursor_set = true;
}
if ch == '\n' {
let end = idx + ch.len_utf8();
char_idx += 1;
buffers.push(InputLineBuffer::new(indent_prefix.clone(), prompt_display_width, char_idx));
if !cursor_set && cursor_pos == end {
cursor_line_idx = buffers.len() - 1;
cursor_column = prompt_display_width;
cursor_set = true;
}
continue;
}
let display_ch = if secure_prompt_active { '•' } else { ch };
let char_width = UnicodeWidthChar::width(display_ch).unwrap_or(0) as u16;
if let Some(current) = buffers.last_mut() {
let capacity = width.saturating_sub(current.prefix_width);
if capacity > 0 && current.text_width + char_width > capacity && !current.text.is_empty() {
buffers.push(InputLineBuffer::new(indent_prefix.clone(), prompt_display_width, char_idx));
}
}
if let Some(current) = buffers.last_mut() {
current.text.push(display_ch);
current.text_width = current.text_width.saturating_add(char_width);
}
char_idx += 1;
let end = idx + ch.len_utf8();
if !cursor_set
&& cursor_pos == end
&& let Some(current) = buffers.last()
{
cursor_line_idx = buffers.len() - 1;
cursor_column = current.prefix_width + current.text_width;
cursor_set = true;
}
}
if !cursor_set && let Some(current) = buffers.last() {
cursor_line_idx = buffers.len() - 1;
cursor_column = current.prefix_width + current.text_width;
}
InputLayout { buffers, cursor_line_idx, cursor_column }
}
pub(super) fn visible_input_window(&self, width: u16, height: u16) -> (InputLayout, usize, usize) {
let prompt_width = UnicodeWidthStr::width(self.prompt_prefix.as_str()) as u16;
let prompt_display_width = prompt_width.min(width);
let layout = self.input_layout(width, prompt_display_width);
let total_lines = layout.buffers.len();
let visible_limit = height.max(1).min(ui::INLINE_INPUT_MAX_LINES as u16) as usize;
let mut start = total_lines.saturating_sub(visible_limit);
if layout.cursor_line_idx < start {
start = layout.cursor_line_idx.saturating_sub(visible_limit - 1);
}
let end = (start + visible_limit).min(total_lines);
(layout, start, end)
}
pub(crate) fn input_visual_geometry(&self) -> Option<InputVisualGeometry> {
let area = self.input_area()?;
if area.width == 0 {
return None;
}
let prompt_width = UnicodeWidthStr::width(self.prompt_prefix.as_str()) as u16;
let layout = self.input_layout(area.width, prompt_width.min(area.width));
Some(InputVisualGeometry {
total_rows: layout.buffers.len().max(1),
cursor_row: layout.cursor_line_idx,
})
}
pub(crate) fn is_multi_row_composer(&self) -> bool {
match self.input_visual_geometry() {
Some(geometry) => geometry.total_rows > 1,
None => !self.input_manager.is_single_line(),
}
}
pub(crate) fn move_cursor_up_within_visual(&mut self) -> bool {
self.move_cursor_visual_rows(-1)
}
pub(crate) fn move_cursor_down_within_visual(&mut self) -> bool {
self.move_cursor_visual_rows(1)
}
fn move_cursor_visual_rows(&mut self, delta: isize) -> bool {
let area = match self.input_area() {
Some(area) if area.width > 0 => area,
_ => return false,
};
let prompt_width = UnicodeWidthStr::width(self.prompt_prefix.as_str()) as u16;
let layout = self.input_layout(area.width, prompt_width.min(area.width));
let total = layout.buffers.len();
if total == 0 {
return false;
}
let current = layout.cursor_line_idx.min(total - 1);
let Some(target_idx) = current.checked_add_signed(delta) else {
return false;
};
if target_idx >= total || target_idx == current {
return false;
}
let desired = layout.cursor_column.saturating_sub(layout.buffers[current].prefix_width);
let target = &layout.buffers[target_idx];
let mut acc = 0u16;
let mut offset = 0usize;
for ch in target.text.chars() {
if acc >= desired {
break;
}
acc = acc.saturating_add(UnicodeWidthChar::width(ch).unwrap_or(0) as u16);
offset += 1;
}
let char_index = target.char_start.saturating_add(offset);
self.input_manager
.set_cursor(char_index_to_byte_index(self.input_manager.content(), char_index));
true
}
#[cfg(test)]
pub(super) fn build_input_render_for_test(&mut self, width: u16, height: u16) -> InputRender {
self.build_input_render(width, height)
}
fn apply_input_selection_highlight(&self, buf: &mut Buffer, area: Rect) {
let Some((selection_start, selection_end)) = self.input_manager.selection_range() else {
return;
};
if area.width == 0 || area.height == 0 || selection_start == selection_end {
return;
}
let (layout, start, end) = self.visible_input_window(area.width, area.height);
let selection_start_char = byte_index_to_char_index(self.input_manager.content(), selection_start);
let selection_end_char = byte_index_to_char_index(self.input_manager.content(), selection_end);
for (row_offset, buffer) in layout.buffers[start..end].iter().enumerate() {
let line_char_start = buffer.char_start;
let line_char_end = buffer.char_start + buffer.text.chars().count();
let highlight_start = selection_start_char.max(line_char_start);
let highlight_end = selection_end_char.min(line_char_end);
if highlight_start >= highlight_end {
continue;
}
let local_start = highlight_start.saturating_sub(line_char_start);
let local_end = highlight_end.saturating_sub(line_char_start);
let start_x = area
.x
.saturating_add(buffer.prefix_width)
.saturating_add(display_width_for_char_range(&buffer.text, local_start));
let end_x = area
.x
.saturating_add(buffer.prefix_width)
.saturating_add(display_width_for_char_range(&buffer.text, local_end));
let y = area.y.saturating_add(row_offset as u16);
for x in start_x..end_x.min(area.x.saturating_add(area.width)) {
if let Some(cell) = buf.cell_mut((x, y)) {
let mut style = cell.style();
style = style.add_modifier(Modifier::REVERSED);
cell.set_style(style);
if cell.symbol().is_empty() {
cell.set_symbol(" ");
}
}
}
}
}
pub(crate) fn cursor_index_for_input_point(&self, column: u16, row: u16) -> Option<usize> {
let area = self.input_area()?;
if row < area.y
|| row >= area.y.saturating_add(area.height)
|| column < area.x
|| column >= area.x.saturating_add(area.width)
{
return None;
}
if self.input_compact_mode
&& self.input_manager.cursor() == self.input_manager.content().len()
&& self.input_compact_placeholder().is_some()
{
return Some(self.input_manager.content().len());
}
let relative_row = row.saturating_sub(area.y);
let relative_column = column.saturating_sub(area.x);
let (layout, start, end) = self.visible_input_window(area.width, area.height);
if start >= end {
return Some(0);
}
let line_index = (start + usize::from(relative_row)).min(end.saturating_sub(1));
let buffer = layout.buffers.get(line_index)?;
if relative_column <= buffer.prefix_width {
return Some(char_index_to_byte_index(self.input_manager.content(), buffer.char_start));
}
let target_width = relative_column.saturating_sub(buffer.prefix_width);
let mut consumed_width = 0u16;
let mut char_offset = 0usize;
for ch in buffer.text.chars() {
let ch_width = UnicodeWidthChar::width(ch).unwrap_or(0) as u16;
let next_width = consumed_width.saturating_add(ch_width);
if target_width < next_width {
break;
}
consumed_width = next_width;
char_offset += 1;
}
let char_index = buffer.char_start.saturating_add(char_offset);
Some(char_index_to_byte_index(self.input_manager.content(), char_index))
}
pub(crate) fn input_compact_placeholder(&self) -> Option<String> {
let content = self.input_manager.content();
let trimmed = content.trim();
if trimmed.is_empty() {
return None;
}
if let Some(label) = compact_image_label(trimmed) {
return Some(format!("[Image: {label}]"));
}
if let Some(preview) = self.input_compact_preview() {
return Some(preview.placeholder);
}
if let Some(compact) = compact_image_placeholders(content) {
if compact.chars().count() >= ui::INLINE_INPUT_COMPACT_CHAR_THRESHOLD {
let char_count = content.chars().count();
return Some(format!("[Pasted Content {char_count} chars]"));
}
return Some(compact);
}
None
}
pub(super) fn input_compact_preview(&self) -> Option<CompactInputPreview> {
let content = self.input_manager.content();
if let Some(preview) = compact_paste_range_preview(content, self.input_manager.compact_paste_range()) {
return Some(preview);
}
generic_large_input_preview(content, self.input_manager.attachments().len())
}
pub(crate) fn visible_inline_prompt_suggestion_suffix(&self) -> Option<String> {
if !self.input_enabled
|| self.has_active_overlay()
|| self.input_compact_mode
|| self.input_manager.cursor() != self.input_manager.content().len()
{
return None;
}
let suggestion = self.inline_prompt_suggestion.suggestion.as_deref()?;
inline_prompt_suggestion_suffix(self.input_manager.content(), suggestion)
}
pub(crate) fn render_input_status_line(&self, width: u16) -> Option<Line<'static>> {
self.render_input_status_line_with_hit(width).map(|(line, _hits)| line)
}
pub(crate) fn render_input_status_line_with_hit(&self, width: u16) -> Option<(Line<'static>, Vec<(u16, u16)>)> {
self.build_input_status_line(width)
.map(|status| (status.line, status.background_hits))
}
fn input_uses_shell_prefix(&self) -> bool {
self.input_manager.content().trim_start().starts_with('!')
}
pub(crate) fn input_block_padding(&self) -> Padding {
if self.input_uses_shell_prefix() {
Padding::new(0, 0, 0, 0)
} else {
Padding::new(
ui::INLINE_INPUT_PADDING_HORIZONTAL,
ui::INLINE_INPUT_PADDING_HORIZONTAL,
ui::INLINE_INPUT_PADDING_VERTICAL,
ui::INLINE_INPUT_PADDING_VERTICAL,
)
}
}
pub(crate) fn shell_mode_border_title(&self) -> Option<&'static str> {
self.input_uses_shell_prefix().then_some(SHELL_MODE_BORDER_TITLE)
}
pub(crate) fn active_subagent_input_title(&self) -> Option<Line<'static>> {
let badge = self.header_context.subagent_badges.first()?;
let hidden = self.header_context.subagent_badges.len().saturating_sub(1);
let label = if hidden == 0 {
badge.text.clone()
} else {
format!("{} +{}", badge.text, hidden)
};
let mut style = ratatui_style_from_inline(&badge.style, self.theme.foreground);
if badge.full_background {
style = style.add_modifier(Modifier::BOLD);
}
Some(Line::from(Span::styled(format!(" {label} "), style)).right_aligned())
}
fn active_subagent_input_border_style(&self) -> Option<Style> {
if let Some(color_style) =
super::super::style::agent_color_style(self.header_context.primary_agent_color.as_deref(), Color::Magenta)
.fg
{
return Some(self.styles.accent_style().fg(color_style).add_modifier(Modifier::BOLD));
}
let badge = self.header_context.subagent_badges.first()?;
let mut title_style = ratatui_style_from_inline(&badge.style, self.theme.foreground);
if badge.full_background {
title_style = title_style.add_modifier(Modifier::BOLD);
}
let color = if badge.full_background {
title_style.bg.or(title_style.fg)
} else {
title_style.fg.or(title_style.bg)
}?;
Some(self.styles.accent_style().fg(color).add_modifier(Modifier::BOLD))
}
fn primary_mode_name(&self) -> Option<&str> {
self.header_context
.primary_agent
.as_deref()
.map(str::trim)
.filter(|name| !name.is_empty())
}
fn primary_mode_color(&self) -> Option<Color> {
self.primary_mode_name()?;
let fallback = self.theme.primary.map(ratatui_color_from_ansi).unwrap_or(Color::LightMagenta);
super::super::style::agent_color_style(self.header_context.primary_agent_color.as_deref(), fallback).fg
}
pub(super) fn primary_mode_pill(&self) -> Option<(String, Style)> {
let name = self.primary_mode_name()?;
let color = self.primary_mode_color()?;
let label = super::header::primary_agent_header_label(Some(name));
let style = Style::default().fg(color).add_modifier(Modifier::BOLD);
Some((format!("• {label}"), style))
}
pub(super) fn shell_mode_status_hint(&self) -> Option<&'static str> {
self.input_uses_shell_prefix().then_some(SHELL_MODE_STATUS_HINT)
}
pub(super) fn local_agents_input_status_hint(&self) -> Option<String> {
if self.input_uses_shell_prefix() || !self.input_manager.content().trim().is_empty() {
return self.foreground_pty_background_hint();
}
if !self.has_local_agents() {
return self.foreground_pty_background_hint();
}
Some(format!("↓ or Alt+S local agents · {} background", self.background_shortcut_label()))
}
pub(super) fn append_background_hint_spans(
spans: &mut Vec<Span<'static>>,
hint: &str,
key_label: &str,
dim_style: Style,
key_style: Style,
label_style: Style,
) -> Option<(u16, u16)> {
let mut appended_width = 0_u16;
let mut key_hit: Option<(u16, u16)> = None;
let mut push = |spans: &mut Vec<Span<'static>>, text: &str, style: Style, mark: bool| {
let width = measure_text_width(text);
let start = appended_width;
let end = appended_width.saturating_add(width);
if mark {
key_hit = Some(match key_hit {
Some((s, e)) => (s.min(start), e.max(end)),
None => (start, end),
});
}
appended_width = end;
spans.push(Span::styled(text.to_owned(), style));
};
if let Some(prefix) = hint.strip_suffix(" background")
&& prefix == key_label
{
if !spans.is_empty() {
push(spans, " · ", dim_style, false);
}
push(spans, key_label, key_style, true);
push(spans, " background", label_style, true);
return key_hit;
}
if let Some(rest) = hint.strip_prefix("↓ or Alt+S local agents · ")
&& let Some(prefix) = rest.strip_suffix(" background")
&& prefix == key_label
{
if !spans.is_empty() {
push(spans, " · ", dim_style, false);
}
push(spans, "↓ or ", label_style, false);
push(spans, "Alt+S", key_style, false);
push(spans, " local agents", label_style, false);
push(spans, " · ", dim_style, false);
push(spans, key_label, key_style, true);
push(spans, " background", label_style, true);
return key_hit;
}
if !spans.is_empty() {
push(spans, " · ", dim_style, false);
}
push(spans, hint, dim_style, false);
key_hit
}
pub(super) fn build_scroll_indicator(&self) -> Option<String> {
if !self.user_scrolled {
return None;
}
let pending = self.pending_new_messages.min(self.scroll_manager.offset());
let total = self.transcript_rows.max(1) as usize;
let top = self.scroll_manager.offset().saturating_add(1).min(total);
let mut label = if pending > 0 {
format!("↓ {} new", pending)
} else {
format!("↑ {}/{}", top, total)
};
if self.should_show_jump_to_last_change() {
let key_label = self.primary_binding_label(Action::JumpToLastChange).unwrap_or("Ctrl+End");
label.push_str(&format!(" · ⤓ Jump to last change [{key_label}]"));
}
Some(label)
}
pub(super) fn create_git_status_spans(&self, text: &str, default_style: Style) -> Vec<Span<'static>> {
let text = text.trim_prefix(ui::HEADER_GIT_PREFIX).trim_start();
if let Some((branch_part, indicator_part)) = text.rsplit_once(" | ") {
let mut spans = Vec::new();
let branch_trim = branch_part.trim_end();
if !branch_trim.is_empty() {
spans.push(Span::styled(branch_trim.to_owned(), default_style));
}
spans.push(Span::raw(" "));
let indicator_trim = indicator_part.trim();
let indicator_style = if indicator_trim == ui::HEADER_GIT_DIRTY_SUFFIX {
Style::default().fg(Color::Red).add_modifier(Modifier::BOLD)
} else if indicator_trim == ui::HEADER_GIT_CLEAN_SUFFIX {
Style::default().fg(Color::Green).add_modifier(Modifier::BOLD)
} else {
self.styles.accent_style().add_modifier(Modifier::BOLD)
};
spans.push(Span::styled(indicator_trim.to_owned(), indicator_style));
spans
} else {
vec![Span::styled(text.to_owned(), default_style)]
}
}
fn cursor_should_be_visible(&self) -> bool {
let loading_state = self.is_running_activity() || self.has_status_spinner();
self.cursor_visible && (self.input_enabled || loading_state)
}
fn use_fake_cursor(&self) -> bool {
self.has_status_spinner()
}
fn secure_prompt_active(&self) -> bool {
self.modal_state().and_then(|modal| modal.secure_prompt.as_ref()).is_some()
}
pub(crate) fn build_input_widget_data(&self, width: u16, height: u16) -> InputWidgetData {
let input_render = self.build_input_render_uncached(width, height);
let background_style = self.styles.input_background_style();
InputWidgetData {
text: input_render.text,
cursor_x: input_render.cursor_x,
cursor_y: input_render.cursor_y,
cursor_should_be_visible: self.cursor_should_be_visible(),
use_fake_cursor: self.use_fake_cursor(),
background_style,
default_style: self.styles.default_style(),
}
}
pub(crate) fn build_input_status_widget_data(&self, width: u16) -> Option<Vec<Span<'static>>> {
self.render_input_status_line(width).map(|line| line.spans)
}
}
#[cfg(test)]
mod input_highlight_tests;