From f1ec67db0c34a41486c24524634ac397d0e2ae91 Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Sun, 23 Dec 2018 20:23:10 +0100 Subject: [PATCH] cleanups + make search results scrollable --- Cargo.toml | 4 +++- src/main.rs | 23 +++++++++++++---------- src/spotify.rs | 8 ++------ src/ui/search.rs | 10 ++++------ 4 files changed, 22 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 136e807..e158ea3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,4 +17,6 @@ toml = "0.4" tokio-core = "0.1" [dependencies.librespot] -git = "https://github.com/librespot-org/librespot.git" \ No newline at end of file +git = "https://github.com/librespot-org/librespot.git" +default-features = false +features = ["pulseaudio-backend"] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 62bf601..a4703ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,30 +20,24 @@ use std::fs::OpenOptions; use std::io::prelude::*; use std::path::PathBuf; use std::process; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use cursive::views::*; use cursive::Cursive; -use librespot::core::spotify_id::SpotifyId; - mod config; mod spotify; mod theme; mod ui; -fn main() { - let logbuf = TextContent::new("Welcome to ncspot\n"); - let logview = TextView::new_with_content(logbuf.clone()); - std::env::set_var("RUST_LOG", "ncspot=trace"); - std::env::set_var("RUST_BACKTRACE", "full"); - +fn init_logger(content: TextContent) { let mut builder = env_logger::Builder::from_default_env(); { builder .format(move |_, record| { + let mut buffer = content.clone(); let line = format!("[{}] {}\n", record.level(), record.args()); - logbuf.clone().append(line.clone()); + buffer.append(line.clone()); let mut file = OpenOptions::new() .create(true) @@ -58,6 +52,15 @@ fn main() { }) .init(); } +} + +fn main() { + let logbuf = TextContent::new("Welcome to ncspot\n"); + let logview = TextView::new_with_content(logbuf.clone()); + std::env::set_var("RUST_LOG", "ncspot=trace"); + std::env::set_var("RUST_BACKTRACE", "full"); + + init_logger(logbuf); let mut cursive = Cursive::default(); cursive.add_global_callback('q', |s| s.quit()); diff --git a/src/spotify.rs b/src/spotify.rs index b77e5b6..3f8f146 100644 --- a/src/spotify.rs +++ b/src/spotify.rs @@ -152,10 +152,6 @@ impl Spotify { debug!("worker thread finished."); } - pub fn run(&mut self) { - println!("Spotify::run() finished"); - } - pub fn search(&self, query: &str, limit: u32, offset: u32) -> Result { self.api.search_track(query, limit, offset, None) } @@ -172,12 +168,12 @@ impl Spotify { self.channel.unbounded_send(WorkerCommand::Play).unwrap(); } - pub fn pause(&mut self) { + pub fn pause(&self) { info!("pause()"); self.channel.unbounded_send(WorkerCommand::Pause).unwrap(); } - pub fn stop(&mut self) { + pub fn stop(&self) { info!("stop()"); self.channel.unbounded_send(WorkerCommand::Stop).unwrap(); } diff --git a/src/ui/search.rs b/src/ui/search.rs index ec5ec43..f61f9f8 100644 --- a/src/ui/search.rs +++ b/src/ui/search.rs @@ -16,7 +16,7 @@ pub struct SearchView { impl SearchView { pub fn search_handler(s: &mut Cursive, input: &str, spotify: Arc) { let mut results: ViewRef = s.find_id("search_results").unwrap(); - let tracks = spotify.search(input, 10, 0); + let tracks = spotify.search(input, 50, 0); results.clear(); @@ -42,13 +42,11 @@ impl SearchView { .with_id("search_edit") .full_width() .fixed_height(1); - let results = ListView::new() - .with_id("search_results") - .full_width() - .full_height(); + let results = ListView::new().with_id("search_results"); + let scrollable = ScrollView::new(results).full_width().full_height(); let layout = LinearLayout::new(Orientation::Vertical) .child(searchfield) - .child(results); + .child(scrollable); let rootpanel = Panel::new(layout).title("Search"); return SearchView { view: rootpanel }; }