use ratatui::text::Line;
use strum::IntoEnumIterator;
use strum_macros::{Display as DeriveDisplay, EnumIter as DeriveEnumIter};
#[derive(Debug, Clone, DeriveEnumIter, DeriveDisplay, PartialEq)]
pub enum Tab {
#[strum(to_string = "Web")]
Web,
#[strum(to_string = "Images")]
Images,
#[strum(to_string = "News")]
News,
#[strum(to_string = "Instant")]
Instant,
#[strum(to_string = "Settings")]
Settings,
}
impl Tab {
pub fn next(self) -> Self {
let mut iter = Tab::iter().cycle();
while let Some(tab) = iter.next() {
if tab == self {
return iter.next().unwrap_or(self);
}
}
self
}
pub fn previous(self) -> Self {
let tabs: Vec<_> = Tab::iter().collect();
let idx = tabs.iter().position(|t| *t == self).unwrap_or(0);
if idx == 0 {
tabs.last().cloned().unwrap_or(self)
} else {
tabs[idx - 1].clone()
}
}
pub fn icon(&self) -> &'static str {
match self {
Tab::Web => "Web",
Tab::Images => "Images",
Tab::News => "News",
Tab::Instant => "Instant",
Tab::Settings => "Settings",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum InputMode {
Normal,
Editing,
}
#[derive(Debug, Clone)]
pub struct WebResult {
pub title: String,
pub url: String,
pub snippet: String,
}
#[derive(Debug, Clone)]
pub struct ImageResult {
pub title: String,
pub page_url: String,
pub image_url: String,
pub source: String,
}
#[derive(Debug, Clone)]
pub struct NewsResult {
pub date: String,
pub title: String,
pub url: String,
pub source: String,
pub body: String,
}
#[derive(Debug, Clone, Default)]
pub struct InstantResult {
pub heading: String,
pub abstract_text: String,
pub abstract_source: String,
pub abstract_url: String,
pub answer: String,
pub definition: String,
pub entity: String,
pub result_type: String,
}
#[derive(Debug, Clone)]
pub struct PageLink {
pub text: String,
pub url: String,
}
#[derive(Debug, Clone)]
pub struct RenderedPage {
pub url: String,
pub domain: String,
pub lines: Vec<Line<'static>>,
pub links: Vec<PageLink>,
pub image_urls: Vec<String>,
}
#[derive(Debug, Clone)]
pub struct HistoryEntry {
pub url: String,
}