Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

style(tui): improve notification popup layout

Samir Hossains06e1b38b3cb8
diff --git a/src/cache.rs b/src/cache.rs
index 4825e70..8e04a82 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -58,7 +58,6 @@ fn stream_payload_has_results(data: &serde_json::Value) -> bool {
})
}
-
pub fn get_cache_dir(subdir: &str) -> PathBuf {
get_provider_cache_dir(ProviderKind::MovieBox, subdir)
}
@@ -395,7 +394,10 @@ pub fn get_captions_path(subject_id: &str, resource_id: &str) -> PathBuf {
}
pub fn get_captions_cache(subject_id: &str, resource_id: &str) -> Option<serde_json::Value> {
- read_json_cache(&get_captions_path(subject_id, resource_id), CACHE_EXPIRY_SECS)
+ read_json_cache(
+ &get_captions_path(subject_id, resource_id),
+ CACHE_EXPIRY_SECS,
+ )
}
pub fn set_captions_cache(subject_id: &str, resource_id: &str, data: &serde_json::Value) {
diff --git a/src/history.rs b/src/history.rs
index 1fed833..05becd2 100644
--- a/src/history.rs
+++ b/src/history.rs
@@ -44,13 +44,25 @@ impl HistoryManager {
format!("{provider}::{subject_id}::{season}::{episode}")
}
- pub fn mark_watched(&mut self, provider: &str, subject_id: &str, season: usize, episode: usize) {
+ pub fn mark_watched(
+ &mut self,
+ provider: &str,
+ subject_id: &str,
+ season: usize,
+ episode: usize,
+ ) {
let key = Self::key(provider, subject_id, season, episode);
self.watched.insert(key);
self.save();
}
- pub fn is_watched(&self, provider: &str, subject_id: &str, season: usize, episode: usize) -> bool {
+ pub fn is_watched(
+ &self,
+ provider: &str,
+ subject_id: &str,
+ season: usize,
+ episode: usize,
+ ) -> bool {
let key = Self::key(provider, subject_id, season, episode);
self.watched.contains(&key)
}
diff --git a/src/providers/fourkhdhub/hubcloud.rs b/src/providers/fourkhdhub/hubcloud.rs
index a22adbf..df445b5 100644
--- a/src/providers/fourkhdhub/hubcloud.rs
+++ b/src/providers/fourkhdhub/hubcloud.rs
@@ -92,21 +92,24 @@ fn extract_hubcloud_drive_url(html: &str) -> Option<String> {
let raw = node.value().attr("href")?;
let url = Url::parse(raw).ok()?;
let host = url.host_str()?;
- (host.contains("hubcloud.") && url.path().starts_with("/drive/"))
- .then(|| url.to_string())
+ (host.contains("hubcloud.") && url.path().starts_with("/drive/")).then(|| url.to_string())
})
}
fn extract_script_pixeldrain_urls(html: &str) -> Vec<String> {
let mut urls = Vec::new();
-
+
let mut search_prefix = |prefix: &str| {
let mut remainder = html;
while let Some(url_offset) = remainder.find(prefix) {
let candidate = &remainder[url_offset..];
let end = candidate
.find(|character: char| {
- character == '"' || character == '\'' || character.is_whitespace() || character == '<' || character == '\\'
+ character == '"'
+ || character == '\''
+ || character.is_whitespace()
+ || character == '<'
+ || character == '\\'
})
.unwrap_or(candidate.len());
if let Some(url) = pixeldrain_api_url(&candidate[..end])
@@ -133,10 +136,9 @@ fn pixeldrain_api_url(raw: &str) -> Option<String> {
}
let id = if let Some(stripped) = url.path().strip_prefix("/u/") {
stripped.trim_matches('/')
- } else if let Some(stripped) = url.path().strip_prefix("/api/file/") {
- stripped.trim_matches('/')
} else {
- return None;
+ let stripped = url.path().strip_prefix("/api/file/")?;
+ stripped.trim_matches('/')
};
if id.is_empty()
|| !id
@@ -151,9 +153,7 @@ fn pixeldrain_api_url(raw: &str) -> Option<String> {
fn validate_resolver_url(raw: &str) -> Result<(), FourKHdHubError> {
let url = Url::parse(raw).map_err(|_| FourKHdHubError::InvalidUrl(raw.into()))?;
let host = url.host_str().unwrap_or_default();
- if url.scheme() != "https"
- || !host.contains("hubcloud.")
- || !url.path().starts_with("/drive/")
+ if url.scheme() != "https" || !host.contains("hubcloud.") || !url.path().starts_with("/drive/")
{
return Err(FourKHdHubError::InvalidUrl(raw.into()));
}
@@ -163,10 +163,7 @@ fn validate_resolver_url(raw: &str) -> Result<(), FourKHdHubError> {
fn validate_hubdrive_url(raw: &str) -> Result<(), FourKHdHubError> {
let url = Url::parse(raw).map_err(|_| FourKHdHubError::InvalidUrl(raw.into()))?;
let host = url.host_str().unwrap_or_default();
- if url.scheme() != "https"
- || !host.contains("hubdrive.")
- || !url.path().starts_with("/file/")
- {
+ if url.scheme() != "https" || !host.contains("hubdrive.") || !url.path().starts_with("/file/") {
return Err(FourKHdHubError::InvalidUrl(raw.into()));
}
Ok(())
diff --git a/src/tui/app.rs b/src/tui/app.rs
index 1d9e303..6a42739 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -157,7 +157,9 @@ impl App {
let season = self.state.selected_season;
let episode = self.state.selected_episode;
let provider = self.state.active_provider.cache_key();
- self.state.history.mark_watched(provider, subject_id, season, episode);
+ self.state
+ .history
+ .mark_watched(provider, subject_id, season, episode);
self.state.dirty = true;
}
@@ -919,7 +921,10 @@ impl App {
self.state.update_available = None;
}
KeyCode::Char('o') | KeyCode::Char('O') => {
- let url = format!("https://github.com/mesamirh/MovieBox-Tui/releases/tag/v{}", version);
+ let url = format!(
+ "https://github.com/mesamirh/MovieBox-Tui/releases/tag/v{}",
+ version
+ );
let _ = open::that(&url);
self.state.update_available = None;
}
@@ -3259,7 +3264,11 @@ impl App {
tokio::spawn(async move {
if let Some(res) = crate::cache::get_captions_cache(&subject_id, &rid) {
sender
- .send(Action::ShowSubtitlePopup(link_clone.clone(), res, open_with))
+ .send(Action::ShowSubtitlePopup(
+ link_clone.clone(),
+ res,
+ open_with,
+ ))
.ok();
return;
}
@@ -4539,7 +4548,9 @@ impl App {
match result {
Ok(Some((version, notes))) => {
- update_sender.send(Action::UpdateAvailable(version, notes)).ok();
+ update_sender
+ .send(Action::UpdateAvailable(version, notes))
+ .ok();
}
Ok(None) => {
update_sender
@@ -4548,7 +4559,10 @@ impl App {
}
Err(error) => {
update_sender
- .send(Action::UpdateAvailable(format!("error:{}", error), "".into()))
+ .send(Action::UpdateAvailable(
+ format!("error:{}", error),
+ "".into(),
+ ))
.ok();
}
}
@@ -4709,9 +4723,9 @@ impl App {
}
if let Some((version, notes)) = &self.state.update_available {
- use ratatui::layout::{Constraint, Direction, Layout, Alignment};
- use ratatui::widgets::{Block, Borders, Paragraph, Clear};
+ use ratatui::layout::{Alignment, Constraint, Direction, Layout};
use ratatui::text::{Line, Span};
+ use ratatui::widgets::{Block, Borders, Clear, Paragraph};
let popup_width = 65;
let popup_height = 20;
@@ -4738,7 +4752,8 @@ impl App {
frame.render_widget(Clear, popup_area);
let mut text = vec![
- Line::from(Span::styled("Update Available!", self.theme.accent)).alignment(Alignment::Center),
+ Line::from(Span::styled("Update Available!", self.theme.accent))
+ .alignment(Alignment::Center),
Line::from(""),
Line::from("A new version of MovieBox-Tui is available."),
Line::from(""),
@@ -4748,7 +4763,11 @@ impl App {
Line::from(Span::styled("Release Notes:", self.theme.highlight)),
];
- let note_lines = notes.lines().filter(|l| !l.trim().is_empty()).take(3).collect::<Vec<_>>();
+ let note_lines = notes
+ .lines()
+ .filter(|l| !l.trim().is_empty())
+ .take(3)
+ .collect::<Vec<_>>();
for line in note_lines {
let mut truncated = line.to_string();
if truncated.len() > 55 {
@@ -4758,18 +4777,26 @@ impl App {
text.push(Line::from(truncated));
}
if notes.lines().count() > 3 {
- text.push(Line::from(Span::styled("... (read more on GitHub)", self.theme.text_dim)));
+ text.push(Line::from(Span::styled(
+ "... (read more on GitHub)",
+ self.theme.text_dim,
+ )));
}
text.push(Line::from(""));
- text.push(Line::from(Span::styled("[Enter] Close popup [o] Open in Browser", self.theme.accent)).alignment(Alignment::Center));
+ text.push(
+ Line::from(Span::styled(
+ "[Enter] Close popup [o] Open in Browser",
+ self.theme.accent,
+ ))
+ .alignment(Alignment::Center),
+ );
- let popup = Paragraph::new(text)
- .block(
- Block::default()
- .borders(Borders::ALL)
- .border_style(self.theme.border)
- );
+ let popup = Paragraph::new(text).block(
+ Block::default()
+ .borders(Borders::ALL)
+ .border_style(self.theme.border),
+ );
frame.render_widget(popup, popup_area);
}
diff --git a/src/tui/overlay.rs b/src/tui/overlay.rs
index c9fb12a..6529860 100644
--- a/src/tui/overlay.rs
+++ b/src/tui/overlay.rs
@@ -252,7 +252,7 @@ pub fn notifications(
theme: &Theme,
basic_terminal: bool,
) {
- let mut y = area.y.saturating_add(1);
+ let mut y = area.bottom().saturating_sub(6);
for notification in notifications.iter().rev().take(3) {
let message = middle_truncate(&notification.message, 48);
let title_width = crate::tui::text::width(&notification.title).saturating_add(6);
@@ -261,7 +261,7 @@ pub fn notifications(
.max(message_width.saturating_add(4))
.clamp(24, 52)
.min(area.width.saturating_sub(4) as usize) as u16;
- if width < 4 || y.saturating_add(3) > area.bottom() {
+ if width < 4 || y < area.y {
break;
}
let toast_area = Rect::new(
@@ -296,7 +296,7 @@ pub fn notifications(
.block(block),
toast_area,
);
- y = y.saturating_add(3);
+ y = y.saturating_sub(4);
}
}
diff --git a/src/tui/screens/details.rs b/src/tui/screens/details.rs
index e2e7463..6f1bdbe 100644
--- a/src/tui/screens/details.rs
+++ b/src/tui/screens/details.rs
@@ -663,7 +663,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)
.unwrap_or(1) as usize;
let subject_id = state.active_subject_id.as_deref().unwrap_or("");
let provider = state.active_provider.cache_key();
-
+
ep_numbers
.iter()
.map(|&ep| {
@@ -1379,7 +1379,12 @@ fn render_workflow(
));
let is_watched = if let Some(subject_id) = state.active_subject_id.as_deref() {
let provider = state.active_provider.cache_key();
- state.history.is_watched(provider, subject_id, state.selected_season, state.selected_episode)
+ state.history.is_watched(
+ provider,
+ subject_id,
+ state.selected_season,
+ state.selected_episode,
+ )
} else {
false
};
@@ -1396,10 +1401,7 @@ fn render_workflow(
ep_label
};
- steps.push((
- crate::tui::state::DetailsPane::Episodes,
- ep_label,
- ));
+ steps.push((crate::tui::state::DetailsPane::Episodes, ep_label));
}
steps.push((
crate::tui::state::DetailsPane::Streams,