cleanups + make search results scrollable
This commit is contained in:
@@ -17,4 +17,6 @@ toml = "0.4"
|
|||||||
tokio-core = "0.1"
|
tokio-core = "0.1"
|
||||||
|
|
||||||
[dependencies.librespot]
|
[dependencies.librespot]
|
||||||
git = "https://github.com/librespot-org/librespot.git"
|
git = "https://github.com/librespot-org/librespot.git"
|
||||||
|
default-features = false
|
||||||
|
features = ["pulseaudio-backend"]
|
||||||
23
src/main.rs
23
src/main.rs
@@ -20,30 +20,24 @@ use std::fs::OpenOptions;
|
|||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process;
|
use std::process;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use cursive::views::*;
|
use cursive::views::*;
|
||||||
use cursive::Cursive;
|
use cursive::Cursive;
|
||||||
|
|
||||||
use librespot::core::spotify_id::SpotifyId;
|
|
||||||
|
|
||||||
mod config;
|
mod config;
|
||||||
mod spotify;
|
mod spotify;
|
||||||
mod theme;
|
mod theme;
|
||||||
mod ui;
|
mod ui;
|
||||||
|
|
||||||
fn main() {
|
fn init_logger(content: TextContent) {
|
||||||
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");
|
|
||||||
|
|
||||||
let mut builder = env_logger::Builder::from_default_env();
|
let mut builder = env_logger::Builder::from_default_env();
|
||||||
{
|
{
|
||||||
builder
|
builder
|
||||||
.format(move |_, record| {
|
.format(move |_, record| {
|
||||||
|
let mut buffer = content.clone();
|
||||||
let line = format!("[{}] {}\n", record.level(), record.args());
|
let line = format!("[{}] {}\n", record.level(), record.args());
|
||||||
logbuf.clone().append(line.clone());
|
buffer.append(line.clone());
|
||||||
|
|
||||||
let mut file = OpenOptions::new()
|
let mut file = OpenOptions::new()
|
||||||
.create(true)
|
.create(true)
|
||||||
@@ -58,6 +52,15 @@ fn main() {
|
|||||||
})
|
})
|
||||||
.init();
|
.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();
|
let mut cursive = Cursive::default();
|
||||||
cursive.add_global_callback('q', |s| s.quit());
|
cursive.add_global_callback('q', |s| s.quit());
|
||||||
|
|||||||
@@ -152,10 +152,6 @@ impl Spotify {
|
|||||||
debug!("worker thread finished.");
|
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> {
|
pub fn search(&self, query: &str, limit: u32, offset: u32) -> Result<SearchTracks, Error> {
|
||||||
self.api.search_track(query, limit, offset, None)
|
self.api.search_track(query, limit, offset, None)
|
||||||
}
|
}
|
||||||
@@ -172,12 +168,12 @@ impl Spotify {
|
|||||||
self.channel.unbounded_send(WorkerCommand::Play).unwrap();
|
self.channel.unbounded_send(WorkerCommand::Play).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pause(&mut self) {
|
pub fn pause(&self) {
|
||||||
info!("pause()");
|
info!("pause()");
|
||||||
self.channel.unbounded_send(WorkerCommand::Pause).unwrap();
|
self.channel.unbounded_send(WorkerCommand::Pause).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop(&mut self) {
|
pub fn stop(&self) {
|
||||||
info!("stop()");
|
info!("stop()");
|
||||||
self.channel.unbounded_send(WorkerCommand::Stop).unwrap();
|
self.channel.unbounded_send(WorkerCommand::Stop).unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ pub struct SearchView {
|
|||||||
impl SearchView {
|
impl SearchView {
|
||||||
pub fn search_handler(s: &mut Cursive, input: &str, spotify: Arc<Spotify>) {
|
pub fn search_handler(s: &mut Cursive, input: &str, spotify: Arc<Spotify>) {
|
||||||
let mut results: ViewRef<ListView> = s.find_id("search_results").unwrap();
|
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();
|
results.clear();
|
||||||
|
|
||||||
@@ -42,13 +42,11 @@ impl SearchView {
|
|||||||
.with_id("search_edit")
|
.with_id("search_edit")
|
||||||
.full_width()
|
.full_width()
|
||||||
.fixed_height(1);
|
.fixed_height(1);
|
||||||
let results = ListView::new()
|
let results = ListView::new().with_id("search_results");
|
||||||
.with_id("search_results")
|
let scrollable = ScrollView::new(results).full_width().full_height();
|
||||||
.full_width()
|
|
||||||
.full_height();
|
|
||||||
let layout = LinearLayout::new(Orientation::Vertical)
|
let layout = LinearLayout::new(Orientation::Vertical)
|
||||||
.child(searchfield)
|
.child(searchfield)
|
||||||
.child(results);
|
.child(scrollable);
|
||||||
let rootpanel = Panel::new(layout).title("Search");
|
let rootpanel = Panel::new(layout).title("Search");
|
||||||
return SearchView { view: rootpanel };
|
return SearchView { view: rootpanel };
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user