cleanups + make search results scrollable

This commit is contained in:
Henrik Friedrichsen
2018-12-23 20:23:10 +01:00
parent 278bb7844f
commit f1ec67db0c
4 changed files with 22 additions and 23 deletions

View File

@@ -17,4 +17,6 @@ toml = "0.4"
tokio-core = "0.1"
[dependencies.librespot]
git = "https://github.com/librespot-org/librespot.git"
git = "https://github.com/librespot-org/librespot.git"
default-features = false
features = ["pulseaudio-backend"]

View File

@@ -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());

View File

@@ -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<SearchTracks, Error> {
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();
}

View File

@@ -16,7 +16,7 @@ pub struct SearchView {
impl SearchView {
pub fn search_handler(s: &mut Cursive, input: &str, spotify: Arc<Spotify>) {
let mut results: ViewRef<ListView> = 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 };
}