COMPLETED MPV INFO STREAMING
This commit is contained in:
73
src/main.rs
73
src/main.rs
@@ -2024,13 +2024,25 @@ fn render_mpv_panel(frame: &mut Frame, app: &App, area: Rect) {
|
|||||||
let bar_line = mpv_bar_line(safe_w, ratio, pct);
|
let bar_line = mpv_bar_line(safe_w, ratio, pct);
|
||||||
frame.render_widget(Paragraph::new(bar_line), c3);
|
frame.render_widget(Paragraph::new(bar_line), c3);
|
||||||
|
|
||||||
let pct = st.percent.unwrap_or(0.0);
|
let cur_secs = st.time_pos.unwrap_or(0.0);
|
||||||
|
let dur_secs = st.duration.unwrap_or(0.0);
|
||||||
|
|
||||||
let cur = st.time_pos.map(fmt_hms).unwrap_or("--:--".into());
|
let cur = st.time_pos.map(fmt_hms).unwrap_or("--:--".into());
|
||||||
let dur = st.duration.map(fmt_hms).unwrap_or("--:--".into());
|
let dur = st.duration.map(fmt_hms).unwrap_or("--:--".into());
|
||||||
frame.render_widget(Paragraph::new(format!("{cur} / {dur} ({pct:0.1}%)")), c4);
|
|
||||||
|
let remaining = if dur_secs > 0.0 && cur_secs <= dur_secs {
|
||||||
|
fmt_hms(dur_secs - cur_secs)
|
||||||
|
} else {
|
||||||
|
"--:--".into()
|
||||||
|
};
|
||||||
|
|
||||||
|
frame.render_widget(
|
||||||
|
Paragraph::new(format!("{cur} / {dur} ({remaining} remaining)")),
|
||||||
|
c4,
|
||||||
|
);
|
||||||
|
|
||||||
let controls =
|
let controls =
|
||||||
"p play P autoplay Space pause a audio s subs v sub vis f fullscreen x stop / search q quit";
|
"Space: pause x: stop f: fullscreen\na: audio s: subs v: sub vis";
|
||||||
frame.render_widget(Paragraph::new(controls).wrap(Wrap { trim: true }), c5);
|
frame.render_widget(Paragraph::new(controls).wrap(Wrap { trim: true }), c5);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2040,30 +2052,43 @@ fn mpv_bar_line(width: u16, ratio: f64, pct: f64) -> String {
|
|||||||
return String::new();
|
return String::new();
|
||||||
}
|
}
|
||||||
|
|
||||||
// If super narrow, just show percentage.
|
|
||||||
if w < 8 {
|
|
||||||
return format!("{:>4.0}%", pct.clamp(0.0, 100.0));
|
|
||||||
}
|
|
||||||
|
|
||||||
let prefix = "mpv ";
|
let prefix = "mpv ";
|
||||||
let mut suffix = format!(" {:>5.1}%", pct.clamp(0.0, 100.0));
|
let pct_text = format!("{:>5.1}%", pct.clamp(0.0, 100.0)); // " 43.3%"
|
||||||
let suffix_len = suffix.len();
|
let pct_area_min = pct_text.len().saturating_add(2); // a little breathing room
|
||||||
|
|
||||||
// If we can't fit the suffix, drop it.
|
// If we're super narrow, just show percent.
|
||||||
let bar_space = if prefix.len() + 2 + suffix_len <= w {
|
if w <= prefix.len() + pct_text.len() + 1 {
|
||||||
w - prefix.len() - suffix_len
|
return format!("{prefix}{pct_text}");
|
||||||
} else {
|
|
||||||
suffix.clear();
|
|
||||||
w - prefix.len()
|
|
||||||
};
|
|
||||||
|
|
||||||
// Need at least room for "[]"
|
|
||||||
if bar_space < 2 {
|
|
||||||
return format!("{prefix}{:>4.0}%", pct.clamp(0.0, 100.0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let bar = unicode_progress_bar(bar_space, ratio);
|
// Reserve a right-side "pct area" if possible; otherwise shrink it.
|
||||||
format!("{prefix}{bar}{suffix}")
|
let avail_after_prefix = w - prefix.len();
|
||||||
|
let pct_area = pct_area_min.min(avail_after_prefix.saturating_sub(3)); // keep some room for a bar
|
||||||
|
|
||||||
|
// Bar gets the rest.
|
||||||
|
let mut bar_w = avail_after_prefix.saturating_sub(pct_area);
|
||||||
|
|
||||||
|
// Ensure the bar is at least wide enough for "[]".
|
||||||
|
if bar_w < 2 {
|
||||||
|
bar_w = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
let bar = unicode_progress_bar(bar_w, ratio);
|
||||||
|
|
||||||
|
// Whatever remains after prefix+bar becomes the pct area (actual).
|
||||||
|
let pct_area_actual = w.saturating_sub(prefix.len() + bar.len());
|
||||||
|
let mut pct_buf = vec![' '; pct_area_actual];
|
||||||
|
|
||||||
|
// Center pct_text inside that pct area
|
||||||
|
if pct_area_actual >= pct_text.len() {
|
||||||
|
let start = (pct_area_actual - pct_text.len()) / 2;
|
||||||
|
for (i, ch) in pct_text.chars().enumerate() {
|
||||||
|
pct_buf[start + i] = ch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let pct_field: String = pct_buf.into_iter().collect();
|
||||||
|
format!("{prefix}{bar}{pct_field}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -2112,8 +2137,6 @@ fn unicode_progress_bar(width: usize, ratio: f64) -> String {
|
|||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct Panes {
|
struct Panes {
|
||||||
top: Rect,
|
top: Rect,
|
||||||
left_main: Rect,
|
left_main: Rect,
|
||||||
|
|||||||
Reference in New Issue
Block a user