aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--yt/src/ansi_escape_codes.rs26
-rw-r--r--yt/src/download/progress_hook.rs16
-rw-r--r--yt/src/main.rs1
-rw-r--r--yt/src/update/updater.rs24
-rw-r--r--yt/src/watch/playlist.rs16
5 files changed, 37 insertions, 46 deletions
diff --git a/yt/src/ansi_escape_codes.rs b/yt/src/ansi_escape_codes.rs
new file mode 100644
index 0000000..ae1805d
--- /dev/null
+++ b/yt/src/ansi_escape_codes.rs
@@ -0,0 +1,26 @@
+// see: https://en.wikipedia.org/wiki/ANSI_escape_code#Control_Sequence_Introducer_commands
+const CSI: &str = "\x1b[";
+pub fn erase_in_display_from_cursor() {
+ print!("{CSI}0J");
+}
+pub fn cursor_up(number: usize) {
+ // HACK(@bpeetz): The default is `1` and running this command with a
+ // number of `0` results in it using the default (i.e., `1`) <2025-03-25>
+ if number != 0 {
+ print!("{CSI}{number}A");
+ }
+}
+
+pub fn clear_whole_line() {
+ eprint!("{CSI}2K");
+}
+pub fn move_to_col(x: usize) {
+ eprint!("{CSI}{x}G");
+}
+
+pub fn hide_cursor() {
+ eprint!("{CSI}?25l");
+}
+pub fn show_cursor() {
+ eprint!("{CSI}?25h");
+}
diff --git a/yt/src/download/progress_hook.rs b/yt/src/download/progress_hook.rs
index 65156e7..db58225 100644
--- a/yt/src/download/progress_hook.rs
+++ b/yt/src/download/progress_hook.rs
@@ -7,7 +7,10 @@ use bytes::Bytes;
use log::{Level, log_enabled};
use yt_dlp::mk_python_function;
-use crate::select::selection_file::duration::MaybeDuration;
+use crate::{
+ ansi_escape_codes::{clear_whole_line, move_to_col},
+ select::selection_file::duration::MaybeDuration,
+};
// #[allow(clippy::too_many_lines)]
// #[allow(clippy::missing_panics_doc)]
@@ -26,17 +29,6 @@ pub fn progress_hook(
return Ok(());
}
- // ANSI ESCAPE CODES Wrappers {{{
- // see: https://en.wikipedia.org/wiki/ANSI_escape_code#Control_Sequence_Introducer_commands
- const CSI: &str = "\x1b[";
- fn clear_whole_line() {
- eprint!("{CSI}2K");
- }
- fn move_to_col(x: usize) {
- eprint!("{CSI}{x}G");
- }
- // }}}
-
macro_rules! get {
(@interrogate $item:ident, $type_fun:ident, $get_fun:ident, $name:expr) => {{
let a = $item.get($name).expect(concat!(
diff --git a/yt/src/main.rs b/yt/src/main.rs
index 093d0e1..39f52f4 100644
--- a/yt/src/main.rs
+++ b/yt/src/main.rs
@@ -33,6 +33,7 @@ use tokio::{
use crate::{cli::Command, storage::subscriptions};
+pub mod ansi_escape_codes;
pub mod app;
pub mod cli;
pub mod unreachable;
diff --git a/yt/src/update/updater.rs b/yt/src/update/updater.rs
index 900fba7..8da654b 100644
--- a/yt/src/update/updater.rs
+++ b/yt/src/update/updater.rs
@@ -20,7 +20,11 @@ use log::{Level, debug, error, log_enabled};
use serde_json::json;
use yt_dlp::{InfoJson, YoutubeDLOptions, json_cast, json_get};
-use crate::{app::App, storage::subscriptions::Subscription};
+use crate::{
+ ansi_escape_codes::{clear_whole_line, move_to_col},
+ app::App,
+ storage::subscriptions::Subscription,
+};
use super::process_subscription;
@@ -71,24 +75,6 @@ impl<'a> Updater<'a> {
&self,
sub: &'a Subscription,
) -> Result<Vec<(&'a Subscription, InfoJson)>> {
- // TODO(@bpeetz): Deduplicate with the progress_hook. <2025-06-13> )
- // ANSI ESCAPE CODES Wrappers {{{
- // see: https://en.wikipedia.org/wiki/ANSI_escape_code#Control_Sequence_Introducer_commands
- const CSI: &str = "\x1b[";
- fn clear_whole_line() {
- eprint!("{CSI}2K");
- }
- fn move_to_col(x: usize) {
- eprint!("{CSI}{x}G");
- }
- // fn hide_cursor() {
- // eprint!("{CSI}?25l");
- // }
- // fn show_cursor() {
- // eprint!("{CSI}?25h");
- // }
- // }}}
-
let yt_dlp = YoutubeDLOptions::new()
.set("playliststart", 1)
.set("playlistend", self.max_backlog)
diff --git a/yt/src/watch/playlist.rs b/yt/src/watch/playlist.rs
index 5be46ce..ff383d0 100644
--- a/yt/src/watch/playlist.rs
+++ b/yt/src/watch/playlist.rs
@@ -11,6 +11,7 @@
use std::path::Path;
use crate::{
+ ansi_escape_codes::{cursor_up, erase_in_display_from_cursor},
app::App,
storage::video_database::{Video, VideoStatus, get, notify::wait_for_db_write},
};
@@ -31,21 +32,6 @@ fn cache_values(video: &Video) -> (&Path, bool) {
}
}
-// ANSI ESCAPE CODES Wrappers {{{
-// see: https://en.wikipedia.org/wiki/ANSI_escape_code#Control_Sequence_Introducer_commands
-const CSI: &str = "\x1b[";
-fn erase_in_display_from_cursor() {
- print!("{CSI}0J");
-}
-fn cursor_up(number: usize) {
- // HACK(@bpeetz): The default is `1` and running this command with a
- // number of `0` results in it using the default (i.e., `1`) <2025-03-25>
- if number != 0 {
- print!("{CSI}{number}A");
- }
-}
-// }}}
-
/// # Panics
/// Only if internal assertions fail.
pub async fn playlist(app: &App, watch: bool) -> Result<()> {