From 7d4cfe73767f6ae22055c61c5fecfd7c0a736b3c Mon Sep 17 00:00:00 2001 From: sudipghimire533 Date: Sat, 12 Aug 2023 21:53:50 +0100 Subject: [PATCH] Add local libmpv-rs --- .github/workflows/release-action.yml | 1 + Cargo.lock | 133 +++++++++++++++++++++------ README.md | 3 +- front-end/Cargo.toml | 7 +- front-end/src/ui/event.rs | 2 +- front-end/src/ui/utils.rs | 48 ++++++---- mpv-build | 1 + 7 files changed, 144 insertions(+), 51 deletions(-) create mode 160000 mpv-build diff --git a/.github/workflows/release-action.yml b/.github/workflows/release-action.yml index f11639b..5c9a12e 100644 --- a/.github/workflows/release-action.yml +++ b/.github/workflows/release-action.yml @@ -25,6 +25,7 @@ jobs: - name: Install dependencies run: | + git submodule init sudo apt update && sudo apt install libmpv-dev diff --git a/Cargo.lock b/Cargo.lock index d330217..ebcbf08 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -50,6 +50,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + [[package]] name = "bumpalo" version = "3.10.0" @@ -123,8 +129,8 @@ version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0ebde6a9dd5e331cd6c6f48253254d117642c31653baa475e394657c59c1f7d" dependencies = [ - "bitflags", - "crossterm_winapi", + "bitflags 1.3.2", + "crossterm_winapi 0.8.0", "futures-core", "libc", "mio 0.7.14", @@ -134,6 +140,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "crossterm" +version = "0.26.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13" +dependencies = [ + "bitflags 1.3.2", + "crossterm_winapi 0.9.1", + "libc", + "mio 0.8.4", + "parking_lot 0.12.1", + "signal-hook", + "signal-hook-mio", + "winapi", +] + [[package]] name = "crossterm_winapi" version = "0.8.0" @@ -143,6 +165,21 @@ dependencies = [ "winapi", ] +[[package]] +name = "crossterm_winapi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +dependencies = [ + "winapi", +] + +[[package]] +name = "deranged" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7684a49fb1af197853ef7b2ee694bc1f5b4179556f1e5710e1760c5db6f5e929" + [[package]] name = "dirs" version = "4.0.0" @@ -433,6 +470,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "indoc" +version = "2.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c785eefb63ebd0e33416dfcb8d6da0bf27ce752843a45632a67bf10d4d4b5c4" + [[package]] name = "instant" version = "0.1.12" @@ -478,8 +521,7 @@ checksum = "505e71a4706fa491e9b1b55f51b95d4037d0821ee40131190475f692b35b009b" [[package]] name = "libmpv" version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a58e2d19b34775e81e0fdca194b3b8ee8de973b092e7582b416343979e22e7" +source = "git+https://github.com/sudipghimire533/libmpv-rs?rev=18aa79a#18aa79a6b73e309360d3dcaeb434e862f9483350" dependencies = [ "libmpv-sys", ] @@ -487,8 +529,7 @@ dependencies = [ [[package]] name = "libmpv-sys" version = "3.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0df938d3145cd8f134572721a27afa3a51f9bc1c26ae30a1d5077162f96d074b" +source = "git+https://github.com/sudipghimire533/libmpv-rs?rev=18aa79a#18aa79a6b73e309360d3dcaeb434e862f9483350" [[package]] name = "libsqlite3-sys" @@ -618,6 +659,15 @@ dependencies = [ "libc", ] +[[package]] +name = "num_threads" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +dependencies = [ + "libc", +] + [[package]] name = "once_cell" version = "1.13.0" @@ -630,7 +680,7 @@ version = "0.10.41" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" dependencies = [ - "bitflags", + "bitflags 1.3.2", "cfg-if", "foreign-types", "libc", @@ -717,6 +767,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "paste" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" + [[package]] name = "percent-encoding" version = "2.1.0" @@ -795,13 +851,29 @@ dependencies = [ "getrandom", ] +[[package]] +name = "ratatui" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8285baa38bdc9f879d92c0e37cb562ef38aa3aeefca22b3200186bc39242d3d5" +dependencies = [ + "bitflags 2.4.0", + "cassowary", + "crossterm 0.26.1", + "indoc", + "paste", + "time", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "redox_syscall" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -869,7 +941,7 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01e213bc3ecb39ac32e81e51ebe31fd888a940515173e3a18a35f8c6e896422a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "fallible-iterator", "fallible-streaming-iterator", "hashlink", @@ -905,7 +977,7 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" dependencies = [ - "bitflags", + "bitflags 1.3.2", "core-foundation", "core-foundation-sys", "libc", @@ -983,6 +1055,7 @@ checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" dependencies = [ "libc", "mio 0.7.14", + "mio 0.8.4", "signal-hook", ] @@ -1065,6 +1138,25 @@ dependencies = [ "syn", ] +[[package]] +name = "time" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0fdd63d58b18d663fbdf70e049f00a22c8e42be082203be7f26589213cd75ea" +dependencies = [ + "deranged", + "libc", + "num_threads", + "serde", + "time-core", +] + +[[package]] +name = "time-core" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7300fbefb4dadc1af235a9cef3737cea692a9d97e1b9cbcd4ebdae6f8868e6fb" + [[package]] name = "tinyvec" version = "1.6.0" @@ -1168,19 +1260,6 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" -[[package]] -name = "tui" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39c8ce4e27049eed97cfa363a5048b09d995e209994634a0efc26a14ab6c0c23" -dependencies = [ - "bitflags", - "cassowary", - "crossterm", - "unicode-segmentation", - "unicode-width", -] - [[package]] name = "unicode-bidi" version = "0.3.8" @@ -1204,9 +1283,9 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.9.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" @@ -1409,13 +1488,13 @@ name = "ytui_music" version = "2.0.0-beta" dependencies = [ "config", - "crossterm", + "crossterm 0.20.0", "fetcher", "lazy_static", "libmpv", + "ratatui", "reqwest", "serde", "serde_json", "tokio", - "tui", ] diff --git a/README.md b/README.md index 992a53a..f0d81b9 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,8 @@ git clone git@github.com:sudipghimire533/ytui-music 3) `cd` into source root and do: ``` -cargo build --all --release +git submodule init +MPV_BUILD=mpv-build/ cargo build --all --release --features libmpv_build ``` 4) The compiled binary is located in `target/release/` directory. Copy the `ytui_music` binary and place it somewhere where it is easy to run. Preferrably under `$PATH`. diff --git a/front-end/Cargo.toml b/front-end/Cargo.toml index 085d336..0aee835 100644 --- a/front-end/Cargo.toml +++ b/front-end/Cargo.toml @@ -7,11 +7,14 @@ authors = ["Sudip Ghimire "] [dependencies] tokio = { version = "1", features = ["full"] } crossterm = { version = "0.20", features = ["event-stream"] } -tui = { version = "0.16", features = ["crossterm"], default-features = false } +tui = { package = "ratatui", version = "0.22.0", features = ["crossterm", "all-widgets"], default-features = false } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -libmpv = { version = "2.0.1" } +libmpv = { git = "https://github.com/sudipghimire533/libmpv-rs", rev = "master" } fetcher = { path = "../fetcher" } lazy_static = "1.4.0" config = { path = "../config" } reqwest = { version = "0.11", features = ["json", "gzip"] } + +[features] +build_libmpv = ["libmpv/build_libmpv"] diff --git a/front-end/src/ui/event.rs b/front-end/src/ui/event.rs index ec2327c..e399ee2 100644 --- a/front-end/src/ui/event.rs +++ b/front-end/src/ui/event.rs @@ -555,7 +555,7 @@ pub async fn event_sender( let increase_by = match direction { HeadTo::Next => CONFIG.constants.volume_step, HeadTo::Prev => CONFIG.constants.volume_step * -1, - HeadTo::Initial => 0 + HeadTo::Initial => 0, }; let res = state.player.change_volume(increase_by); diff --git a/front-end/src/ui/utils.rs b/front-end/src/ui/utils.rs index b62b248..aecb5a4 100644 --- a/front-end/src/ui/utils.rs +++ b/front-end/src/ui/utils.rs @@ -1,7 +1,7 @@ use crate::ui; use fetcher::ExtendDuration; use std::borrow::Cow; -use tui; +use tui::{self, text::Line}; use ui::shared_import::*; pub const SIDEBAR_LIST_COUNT: usize = 6; @@ -63,8 +63,8 @@ impl<'parent> ui::TopLayout { .add_modifier(Modifier::BOLD | Modifier::ITALIC) .fg(rgb!(CONFIG.theme.color_secondary)), )) - .block(Block::new("status".to_owned())) - .block(Block::new("status".to_owned())) + .block(Block::with_title("status".to_owned())) + .block(Block::with_title("status".to_owned())) } pub fn get_searchbox(state: &'parent ui::State) -> Paragraph<'parent> { @@ -77,7 +77,7 @@ impl<'parent> ui::TopLayout { } _ => { cursor_style = cursor_style.add_modifier(Modifier::HIDDEN); - Block::new("Search ".to_owned()) + Block::with_title("Search ".to_owned()) } }; let text = text::Spans::from(vec![ @@ -125,7 +125,7 @@ impl<'parent> ui::MiddleLayout { ui::Window::Musicbar => Block::active("Music ".to_owned()), _ => { state.musicbar.1.select(None); - Block::new("Music ".to_owned()) + Block::with_title("Music ".to_owned()) } }; @@ -176,7 +176,7 @@ impl<'parent> ui::MiddleBottom { ui::Window::Playlistbar => Block::active("Playlist ".to_owned()), _ => { state.playlistbar.1.select(None); - Block::new("Playlist ".to_owned()) + Block::with_title("Playlist ".to_owned()) } }; let data_list = &state.playlistbar.0; @@ -213,7 +213,7 @@ impl<'parent> ui::MiddleBottom { if state.active == ui::Window::Artistbar { block = Block::active("Artist ".to_string()); } else { - block = Block::new("Artist ".to_string()); + block = Block::with_title("Artist ".to_string()); state.artistbar.1.select(None); } let data_list = &state.artistbar; @@ -262,7 +262,7 @@ impl<'parent> ui::SideBar { pub fn get_shortcuts(state: &ui::State) -> List<'parent> { let block = match state.active { ui::Window::Sidebar => Block::active("Shortcut ".to_owned()), - _ => Block::new("Shortcut ".to_owned()), + _ => Block::with_title("Shortcut ".to_owned()), }; List::new( SIDEBAR_LIST_ITEMS @@ -308,7 +308,7 @@ impl<'parent> ui::BottomLayout { if state.active == ui::Window::BottomControl { block = Block::active(heading); } else { - block = Block::new(heading); + block = Block::with_title(heading); } block = block.title_alignment(Alignment::Center); @@ -361,16 +361,22 @@ impl<'parent> ui::BottomLayout { format!("Vol: {}", state.playback_behaviour.volume), Style::list_highlight(), ); + let content = Text::from(vec![ + Line::from(volume), + Line::from(repeat), + Line::from(suffle), + Line::from(paused_status), + ]); - let content = Text { - lines: [ - Spans([volume].to_vec()), - Spans([repeat].to_vec()), - Spans([suffle].to_vec()), - Spans([paused_status].to_vec()), - ] - .to_vec(), - }; + // let content = Text { + // lines: [ + // Spands([volume].to_vec()), + // Spans([repeat].to_vec()), + // Spans([suffle].to_vec()), + // Spans([paused_status].to_vec()), + // ] + // .to_vec(), + // }; Paragraph::new(content) .alignment(Alignment::Left) @@ -379,7 +385,7 @@ impl<'parent> ui::BottomLayout { } pub trait ExtendBlock<'a> { - fn new(title: String) -> Self; + fn with_title(title: String) -> Self; fn active(title: String) -> Self; } pub trait ExtendStyle { @@ -407,6 +413,7 @@ impl ExtendStyle for Style { bg: None, add_modifier: Modifier::BOLD | Modifier::ITALIC, sub_modifier: Modifier::empty(), + underline_color: None, } } @@ -417,12 +424,13 @@ impl ExtendStyle for Style { bg: None, add_modifier: Modifier::BOLD, sub_modifier: Modifier::empty(), + underline_color: None, } } } impl<'a> ExtendBlock<'a> for Block<'_> { - fn new(title: String) -> Self { + fn with_title(title: String) -> Self { Block::default() .title(Span::styled(title, Style::block_title())) .border_type(BorderType::Rounded) diff --git a/mpv-build b/mpv-build new file mode 160000 index 0000000..993fe7d --- /dev/null +++ b/mpv-build @@ -0,0 +1 @@ +Subproject commit 993fe7d4a07d0575662ed2563585734b7e58dccd