Split core and TUI crates
This commit is contained in:
190
crates/tele-tui/src/ui/modals/account_switcher.rs
Normal file
190
crates/tele-tui/src/ui/modals/account_switcher.rs
Normal file
@@ -0,0 +1,190 @@
|
||||
//! Account switcher modal
|
||||
//!
|
||||
//! Renders a centered popup with account list (SelectAccount) or
|
||||
//! new account name input (AddAccount).
|
||||
|
||||
use crate::app::{AccountSwitcherState, App};
|
||||
use crate::tdlib::TdClientTrait;
|
||||
use ratatui::{
|
||||
layout::Rect,
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Clear, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
|
||||
/// Renders the account switcher modal overlay.
|
||||
pub fn render<T: TdClientTrait>(f: &mut Frame, area: Rect, app: &App<T>) {
|
||||
let Some(state) = &app.account_switcher else {
|
||||
return;
|
||||
};
|
||||
|
||||
match state {
|
||||
AccountSwitcherState::SelectAccount { accounts, selected_index, current_account } => {
|
||||
render_select_account(f, area, accounts, *selected_index, current_account);
|
||||
}
|
||||
AccountSwitcherState::AddAccount { name_input, cursor_position, error } => {
|
||||
render_add_account(f, area, name_input, *cursor_position, error.as_deref());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn render_select_account(
|
||||
f: &mut Frame,
|
||||
area: Rect,
|
||||
accounts: &[crate::accounts::AccountProfile],
|
||||
selected_index: usize,
|
||||
current_account: &str,
|
||||
) {
|
||||
let mut lines: Vec<Line> = Vec::new();
|
||||
lines.push(Line::from(""));
|
||||
|
||||
for (idx, account) in accounts.iter().enumerate() {
|
||||
let is_selected = idx == selected_index;
|
||||
let is_current = account.name == current_account;
|
||||
|
||||
let marker = if is_current { "● " } else { " " };
|
||||
let suffix = if is_current { " (текущий)" } else { "" };
|
||||
let display = format!("{}{} ({}){}", marker, account.name, account.display_name, suffix);
|
||||
|
||||
let style = if is_selected {
|
||||
Style::default()
|
||||
.fg(Color::Yellow)
|
||||
.add_modifier(Modifier::BOLD)
|
||||
} else if is_current {
|
||||
Style::default().fg(Color::Green)
|
||||
} else {
|
||||
Style::default().fg(Color::White)
|
||||
};
|
||||
|
||||
lines.push(Line::from(Span::styled(format!(" {}", display), style)));
|
||||
}
|
||||
|
||||
// Separator
|
||||
lines.push(Line::from(Span::styled(
|
||||
" ──────────────────────",
|
||||
Style::default().fg(Color::DarkGray),
|
||||
)));
|
||||
|
||||
// Add account item
|
||||
let add_selected = selected_index == accounts.len();
|
||||
let add_style = if add_selected {
|
||||
Style::default()
|
||||
.fg(Color::Yellow)
|
||||
.add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(Color::Cyan)
|
||||
};
|
||||
lines.push(Line::from(Span::styled(" + Добавить аккаунт", add_style)));
|
||||
|
||||
lines.push(Line::from(""));
|
||||
|
||||
// Help bar
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" j/k ", Style::default().fg(Color::Yellow)),
|
||||
Span::styled("Nav", Style::default().fg(Color::DarkGray)),
|
||||
Span::raw(" "),
|
||||
Span::styled(" Enter ", Style::default().fg(Color::Green)),
|
||||
Span::styled("Select", Style::default().fg(Color::DarkGray)),
|
||||
Span::raw(" "),
|
||||
Span::styled(" a ", Style::default().fg(Color::Cyan)),
|
||||
Span::styled("Add", Style::default().fg(Color::DarkGray)),
|
||||
Span::raw(" "),
|
||||
Span::styled(" Esc ", Style::default().fg(Color::Red)),
|
||||
Span::styled("Close", Style::default().fg(Color::DarkGray)),
|
||||
]));
|
||||
|
||||
// Calculate dynamic height: header(3) + accounts + separator(1) + add(1) + empty(1) + help(1) + footer(1)
|
||||
let content_height = (accounts.len() as u16) + 7;
|
||||
let height = content_height.min(area.height.saturating_sub(4));
|
||||
let width = 40u16.min(area.width.saturating_sub(4));
|
||||
|
||||
let x = area.x + (area.width.saturating_sub(width)) / 2;
|
||||
let y = area.y + (area.height.saturating_sub(height)) / 2;
|
||||
let modal_area = Rect::new(x, y, width, height);
|
||||
|
||||
f.render_widget(Clear, modal_area);
|
||||
|
||||
let modal = Paragraph::new(lines).block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Color::Cyan))
|
||||
.title(" АККАУНТЫ ")
|
||||
.title_style(
|
||||
Style::default()
|
||||
.fg(Color::Cyan)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
);
|
||||
|
||||
f.render_widget(modal, modal_area);
|
||||
}
|
||||
|
||||
fn render_add_account(
|
||||
f: &mut Frame,
|
||||
area: Rect,
|
||||
name_input: &str,
|
||||
_cursor_position: usize,
|
||||
error: Option<&str>,
|
||||
) {
|
||||
let mut lines: Vec<Line> = Vec::new();
|
||||
lines.push(Line::from(""));
|
||||
|
||||
// Input field
|
||||
let input_display = if name_input.is_empty() {
|
||||
Span::styled("_", Style::default().fg(Color::DarkGray))
|
||||
} else {
|
||||
Span::styled(format!("{}_", name_input), Style::default().fg(Color::White))
|
||||
};
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" Имя: ", Style::default().fg(Color::Cyan)),
|
||||
input_display,
|
||||
]));
|
||||
|
||||
// Hint
|
||||
lines.push(Line::from(Span::styled(
|
||||
" (a-z, 0-9, -, _)",
|
||||
Style::default().fg(Color::DarkGray),
|
||||
)));
|
||||
|
||||
lines.push(Line::from(""));
|
||||
|
||||
// Error
|
||||
if let Some(err) = error {
|
||||
lines.push(Line::from(Span::styled(format!(" {}", err), Style::default().fg(Color::Red))));
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
|
||||
// Help bar
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" Enter ", Style::default().fg(Color::Green)),
|
||||
Span::styled("Create", Style::default().fg(Color::DarkGray)),
|
||||
Span::raw(" "),
|
||||
Span::styled(" Esc ", Style::default().fg(Color::Red)),
|
||||
Span::styled("Back", Style::default().fg(Color::DarkGray)),
|
||||
]));
|
||||
|
||||
let height = if error.is_some() { 10 } else { 8 };
|
||||
let height = (height as u16).min(area.height.saturating_sub(4));
|
||||
let width = 40u16.min(area.width.saturating_sub(4));
|
||||
|
||||
let x = area.x + (area.width.saturating_sub(width)) / 2;
|
||||
let y = area.y + (area.height.saturating_sub(height)) / 2;
|
||||
let modal_area = Rect::new(x, y, width, height);
|
||||
|
||||
f.render_widget(Clear, modal_area);
|
||||
|
||||
let modal = Paragraph::new(lines).block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Color::Cyan))
|
||||
.title(" НОВЫЙ АККАУНТ ")
|
||||
.title_style(
|
||||
Style::default()
|
||||
.fg(Color::Cyan)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
);
|
||||
|
||||
f.render_widget(modal, modal_area);
|
||||
}
|
||||
8
crates/tele-tui/src/ui/modals/delete_confirm.rs
Normal file
8
crates/tele-tui/src/ui/modals/delete_confirm.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
//! Delete confirmation modal
|
||||
|
||||
use ratatui::{layout::Rect, Frame};
|
||||
|
||||
/// Renders delete confirmation modal
|
||||
pub fn render(f: &mut Frame, area: Rect) {
|
||||
crate::ui::components::modal::render_delete_confirm_modal(f, area);
|
||||
}
|
||||
178
crates/tele-tui/src/ui/modals/image_viewer.rs
Normal file
178
crates/tele-tui/src/ui/modals/image_viewer.rs
Normal file
@@ -0,0 +1,178 @@
|
||||
//! Модальное окно для полноэкранного просмотра изображений.
|
||||
//!
|
||||
//! Поддерживает:
|
||||
//! - Автоматическое масштабирование с сохранением aspect ratio
|
||||
//! - Максимизация по ширине/высоте терминала
|
||||
//! - Затемнение фона
|
||||
//! - Hotkeys: Esc/q для закрытия, ←/→ для навигации между фото
|
||||
|
||||
use crate::app::App;
|
||||
use crate::tdlib::r#trait::TdClientTrait;
|
||||
use crate::tdlib::ImageModalState;
|
||||
use ratatui::{
|
||||
layout::{Alignment, Rect},
|
||||
style::{Color, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Clear, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
use ratatui_image::StatefulImage;
|
||||
|
||||
/// Рендерит модальное окно с полноэкранным изображением
|
||||
pub fn render<T: TdClientTrait>(f: &mut Frame, app: &mut App<T>, modal_state: &ImageModalState) {
|
||||
let area = f.area();
|
||||
|
||||
// Затемняем весь фон
|
||||
f.render_widget(Clear, area);
|
||||
f.render_widget(Block::default().style(Style::default().bg(Color::Black)), area);
|
||||
|
||||
// Резервируем место для подсказок (2 строки внизу)
|
||||
let image_area_height = area.height.saturating_sub(2);
|
||||
|
||||
// Вычисляем размер изображения с сохранением aspect ratio
|
||||
let (img_width, img_height) = calculate_modal_size(
|
||||
modal_state.photo_width,
|
||||
modal_state.photo_height,
|
||||
area.width,
|
||||
image_area_height,
|
||||
);
|
||||
|
||||
// Центрируем изображение
|
||||
let img_x = (area.width.saturating_sub(img_width)) / 2;
|
||||
let img_y = (image_area_height.saturating_sub(img_height)) / 2;
|
||||
let img_rect = Rect::new(img_x, img_y, img_width, img_height);
|
||||
|
||||
// Рендерим изображение (используем modal_renderer для высокого качества)
|
||||
if let Some(renderer) = &mut app.modal_image_renderer {
|
||||
// Проверяем есть ли протокол уже в кеше
|
||||
if let Some(protocol) = renderer.get_protocol(&modal_state.message_id) {
|
||||
// Протокол готов - рендерим изображение (iTerm2/Sixel - высокое качество)
|
||||
f.render_stateful_widget(StatefulImage::default(), img_rect, protocol);
|
||||
} else {
|
||||
// Протокола нет - показываем индикатор загрузки
|
||||
let loading_text = vec![
|
||||
Line::from(""),
|
||||
Line::from(Span::styled(
|
||||
"⏳ Загрузка изображения...",
|
||||
Style::default().fg(Color::Gray),
|
||||
)),
|
||||
Line::from(""),
|
||||
Line::from(Span::styled(
|
||||
"(декодирование в высоком качестве)",
|
||||
Style::default().fg(Color::DarkGray),
|
||||
)),
|
||||
];
|
||||
let loading = Paragraph::new(loading_text)
|
||||
.alignment(Alignment::Center)
|
||||
.block(Block::default());
|
||||
f.render_widget(loading, img_rect);
|
||||
|
||||
// Загружаем изображение (может занять время для iTerm2/Sixel)
|
||||
let _ = renderer.load_image(modal_state.message_id, &modal_state.photo_path);
|
||||
|
||||
// Триггерим перерисовку для показа загруженного изображения
|
||||
app.needs_redraw = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Подсказки внизу
|
||||
let hint = "[Esc/q] Закрыть [←/→] Пред/След фото";
|
||||
let hint_y = area.height.saturating_sub(1);
|
||||
let hint_rect = Rect::new(0, hint_y, area.width, 1);
|
||||
f.render_widget(
|
||||
Paragraph::new(Span::styled(hint, Style::default().fg(Color::Gray)))
|
||||
.alignment(Alignment::Center),
|
||||
hint_rect,
|
||||
);
|
||||
|
||||
// Информация о размере (опционально)
|
||||
let info = format!(
|
||||
"{}x{} | {:.1}%",
|
||||
modal_state.photo_width,
|
||||
modal_state.photo_height,
|
||||
(img_width as f64 / modal_state.photo_width as f64) * 100.0
|
||||
);
|
||||
let info_y = area.height.saturating_sub(2);
|
||||
let info_rect = Rect::new(0, info_y, area.width, 1);
|
||||
f.render_widget(
|
||||
Paragraph::new(Span::styled(info, Style::default().fg(Color::DarkGray)))
|
||||
.alignment(Alignment::Center),
|
||||
info_rect,
|
||||
);
|
||||
}
|
||||
|
||||
/// Вычисляет размер изображения для модалки с сохранением aspect ratio.
|
||||
///
|
||||
/// # Логика масштабирования:
|
||||
/// - Если изображение меньше терминала → показываем как есть
|
||||
/// - Если ширина больше → масштабируем по ширине
|
||||
/// - Если высота больше → масштабируем по высоте
|
||||
/// - Сохраняем aspect ratio
|
||||
fn calculate_modal_size(
|
||||
img_width: i32,
|
||||
img_height: i32,
|
||||
term_width: u16,
|
||||
term_height: u16,
|
||||
) -> (u16, u16) {
|
||||
let aspect_ratio = img_width as f64 / img_height as f64;
|
||||
|
||||
// Если изображение помещается целиком
|
||||
if img_width <= term_width as i32 && img_height <= term_height as i32 {
|
||||
return (img_width as u16, img_height as u16);
|
||||
}
|
||||
|
||||
// Начинаем с максимального размера терминала
|
||||
let mut width = term_width as f64;
|
||||
let mut height = term_height as f64;
|
||||
|
||||
// Подгоняем по aspect ratio
|
||||
let term_aspect = width / height;
|
||||
|
||||
if term_aspect > aspect_ratio {
|
||||
// Терминал шире → ограничены по высоте
|
||||
width = height * aspect_ratio;
|
||||
} else {
|
||||
// Терминал выше → ограничены по ширине
|
||||
height = width / aspect_ratio;
|
||||
}
|
||||
|
||||
(width as u16, height as u16)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_calculate_modal_size_fits() {
|
||||
// Изображение помещается целиком
|
||||
let (w, h) = calculate_modal_size(50, 30, 100, 50);
|
||||
assert_eq!(w, 50);
|
||||
assert_eq!(h, 30);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_calculate_modal_size_scale_width() {
|
||||
// Ограничены по ширине (изображение шире терминала)
|
||||
let (w, h) = calculate_modal_size(200, 100, 100, 100);
|
||||
assert_eq!(w, 100);
|
||||
assert_eq!(h, 50); // aspect ratio 2:1
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_calculate_modal_size_scale_height() {
|
||||
// Ограничены по высоте (изображение выше терминала)
|
||||
let (w, h) = calculate_modal_size(100, 200, 100, 100);
|
||||
assert_eq!(w, 50); // aspect ratio 1:2
|
||||
assert_eq!(h, 100);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_calculate_modal_size_aspect_ratio() {
|
||||
// Проверка сохранения aspect ratio
|
||||
let (w, h) = calculate_modal_size(1920, 1080, 100, 100);
|
||||
let aspect = w as f64 / h as f64;
|
||||
let expected_aspect = 1920.0 / 1080.0;
|
||||
assert!((aspect - expected_aspect).abs() < 0.01);
|
||||
}
|
||||
}
|
||||
27
crates/tele-tui/src/ui/modals/mod.rs
Normal file
27
crates/tele-tui/src/ui/modals/mod.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
//! Modal dialog rendering modules
|
||||
//!
|
||||
//! Contains UI rendering for various modal dialogs:
|
||||
//! - account_switcher: Account switcher modal (global overlay)
|
||||
//! - delete_confirm: Delete confirmation modal
|
||||
//! - reaction_picker: Emoji reaction picker modal
|
||||
//! - search: Message search modal
|
||||
//! - pinned: Pinned messages viewer modal
|
||||
//! - image_viewer: Full-screen image viewer modal (images feature)
|
||||
|
||||
pub mod account_switcher;
|
||||
pub mod delete_confirm;
|
||||
pub mod pinned;
|
||||
pub mod reaction_picker;
|
||||
pub mod search;
|
||||
|
||||
#[cfg(feature = "images")]
|
||||
pub mod image_viewer;
|
||||
|
||||
pub use account_switcher::render as render_account_switcher;
|
||||
pub use delete_confirm::render as render_delete_confirm;
|
||||
pub use pinned::render as render_pinned;
|
||||
pub use reaction_picker::render as render_reaction_picker;
|
||||
pub use search::render as render_search;
|
||||
|
||||
#[cfg(feature = "images")]
|
||||
pub use image_viewer::render as render_image_viewer;
|
||||
91
crates/tele-tui/src/ui/modals/pinned.rs
Normal file
91
crates/tele-tui/src/ui/modals/pinned.rs
Normal file
@@ -0,0 +1,91 @@
|
||||
//! Pinned messages viewer modal
|
||||
|
||||
use crate::app::App;
|
||||
use crate::tdlib::TdClientTrait;
|
||||
use crate::ui::components::{calculate_scroll_offset, render_help_bar, render_message_item};
|
||||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
|
||||
/// Renders pinned messages mode
|
||||
pub fn render<T: TdClientTrait>(f: &mut Frame, area: Rect, app: &App<T>) {
|
||||
// Извлекаем данные из ChatState
|
||||
let (messages, selected_index) =
|
||||
if let crate::app::ChatState::PinnedMessages { messages, selected_index } = &app.chat_state
|
||||
{
|
||||
(messages.as_slice(), *selected_index)
|
||||
} else {
|
||||
return; // Некорректное состояние
|
||||
};
|
||||
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Length(3), // Header
|
||||
Constraint::Min(0), // Pinned messages list
|
||||
Constraint::Length(3), // Help bar
|
||||
])
|
||||
.split(area);
|
||||
|
||||
// Header
|
||||
let total = messages.len();
|
||||
let current = selected_index + 1;
|
||||
let header_text = format!("📌 ЗАКРЕПЛЁННЫЕ ({}/{})", current, total);
|
||||
let header = Paragraph::new(header_text)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Color::Magenta)),
|
||||
)
|
||||
.style(
|
||||
Style::default()
|
||||
.fg(Color::Magenta)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
);
|
||||
f.render_widget(header, chunks[0]);
|
||||
|
||||
// Pinned messages list
|
||||
let content_width = chunks[1].width.saturating_sub(2) as usize;
|
||||
let mut lines: Vec<Line> = Vec::new();
|
||||
|
||||
for (idx, msg) in messages.iter().enumerate() {
|
||||
if idx > 0 {
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
lines.extend(render_message_item(msg, idx == selected_index, content_width, 3));
|
||||
}
|
||||
|
||||
if lines.is_empty() {
|
||||
lines.push(Line::from(Span::styled(
|
||||
"Нет закреплённых сообщений",
|
||||
Style::default().fg(Color::Gray),
|
||||
)));
|
||||
}
|
||||
|
||||
// Скролл к выбранному сообщению
|
||||
let scroll_offset = calculate_scroll_offset(selected_index, 5, chunks[1].height);
|
||||
|
||||
let messages_widget = Paragraph::new(lines)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Color::Magenta)),
|
||||
)
|
||||
.scroll((scroll_offset, 0));
|
||||
f.render_widget(messages_widget, chunks[1]);
|
||||
|
||||
// Help bar
|
||||
let help = render_help_bar(
|
||||
&[
|
||||
("↑↓", "навигация", Color::Yellow),
|
||||
("Enter", "перейти", Color::Green),
|
||||
("Esc", "выход", Color::Red),
|
||||
],
|
||||
Color::Magenta,
|
||||
);
|
||||
f.render_widget(help, chunks[2]);
|
||||
}
|
||||
8
crates/tele-tui/src/ui/modals/reaction_picker.rs
Normal file
8
crates/tele-tui/src/ui/modals/reaction_picker.rs
Normal file
@@ -0,0 +1,8 @@
|
||||
//! Reaction picker modal
|
||||
|
||||
use ratatui::{layout::Rect, Frame};
|
||||
|
||||
/// Renders emoji reaction picker modal
|
||||
pub fn render(f: &mut Frame, area: Rect, available_reactions: &[String], selected_index: usize) {
|
||||
crate::ui::components::render_emoji_picker(f, area, available_reactions, selected_index);
|
||||
}
|
||||
110
crates/tele-tui/src/ui/modals/search.rs
Normal file
110
crates/tele-tui/src/ui/modals/search.rs
Normal file
@@ -0,0 +1,110 @@
|
||||
//! Message search modal
|
||||
|
||||
use crate::app::App;
|
||||
use crate::tdlib::TdClientTrait;
|
||||
use crate::ui::components::{calculate_scroll_offset, render_help_bar, render_message_item};
|
||||
use ratatui::{
|
||||
layout::{Constraint, Direction, Layout, Rect},
|
||||
style::{Color, Modifier, Style},
|
||||
text::{Line, Span},
|
||||
widgets::{Block, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
|
||||
/// Renders message search mode
|
||||
pub fn render<T: TdClientTrait>(f: &mut Frame, area: Rect, app: &App<T>) {
|
||||
// Извлекаем данные из ChatState
|
||||
let (query, results, selected_index) =
|
||||
if let crate::app::ChatState::SearchInChat { query, results, selected_index } =
|
||||
&app.chat_state
|
||||
{
|
||||
(query.as_str(), results.as_slice(), *selected_index)
|
||||
} else {
|
||||
return; // Некорректное состояние, не рендерим
|
||||
};
|
||||
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([
|
||||
Constraint::Length(3), // Search input
|
||||
Constraint::Min(0), // Search results
|
||||
Constraint::Length(3), // Help bar
|
||||
])
|
||||
.split(area);
|
||||
|
||||
// Search input
|
||||
let total = results.len();
|
||||
let current = if total > 0 { selected_index + 1 } else { 0 };
|
||||
|
||||
let input_line = if query.is_empty() {
|
||||
Line::from(vec![
|
||||
Span::styled("🔍 ", Style::default().fg(Color::Yellow)),
|
||||
Span::styled("█", Style::default().fg(Color::Yellow)),
|
||||
Span::styled(" Введите текст для поиска...", Style::default().fg(Color::Gray)),
|
||||
])
|
||||
} else {
|
||||
Line::from(vec![
|
||||
Span::styled("🔍 ", Style::default().fg(Color::Yellow)),
|
||||
Span::styled(query, Style::default().fg(Color::White)),
|
||||
Span::styled("█", Style::default().fg(Color::Yellow)),
|
||||
Span::styled(format!(" ({}/{})", current, total), Style::default().fg(Color::Gray)),
|
||||
])
|
||||
};
|
||||
|
||||
let search_input = Paragraph::new(input_line).block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Color::Yellow))
|
||||
.title(" Поиск по сообщениям ")
|
||||
.title_style(
|
||||
Style::default()
|
||||
.fg(Color::Yellow)
|
||||
.add_modifier(Modifier::BOLD),
|
||||
),
|
||||
);
|
||||
f.render_widget(search_input, chunks[0]);
|
||||
|
||||
// Search results
|
||||
let content_width = chunks[1].width.saturating_sub(2) as usize;
|
||||
let mut lines: Vec<Line> = Vec::new();
|
||||
|
||||
if results.is_empty() {
|
||||
if !query.is_empty() {
|
||||
lines.push(Line::from(Span::styled(
|
||||
"Ничего не найдено",
|
||||
Style::default().fg(Color::Gray),
|
||||
)));
|
||||
}
|
||||
} else {
|
||||
for (idx, msg) in results.iter().enumerate() {
|
||||
if idx > 0 {
|
||||
lines.push(Line::from(""));
|
||||
}
|
||||
lines.extend(render_message_item(msg, idx == selected_index, content_width, 2));
|
||||
}
|
||||
}
|
||||
|
||||
// Скролл к выбранному результату
|
||||
let scroll_offset = calculate_scroll_offset(selected_index, 4, chunks[1].height);
|
||||
|
||||
let results_widget = Paragraph::new(lines)
|
||||
.block(
|
||||
Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_style(Style::default().fg(Color::Yellow)),
|
||||
)
|
||||
.scroll((scroll_offset, 0));
|
||||
f.render_widget(results_widget, chunks[1]);
|
||||
|
||||
// Help bar
|
||||
let help = render_help_bar(
|
||||
&[
|
||||
("↑↓", "навигация", Color::Yellow),
|
||||
("n/N", "след./пред.", Color::Yellow),
|
||||
("Enter", "перейти", Color::Green),
|
||||
("Esc", "выход", Color::Red),
|
||||
],
|
||||
Color::Yellow,
|
||||
);
|
||||
f.render_widget(help, chunks[2]);
|
||||
}
|
||||
Reference in New Issue
Block a user