Skip to content

Commit

Permalink
Make the some kind of work
Browse files Browse the repository at this point in the history
  • Loading branch information
LaineZ committed Nov 1, 2020
1 parent c62c878 commit 74b1af1
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 99 deletions.
53 changes: 6 additions & 47 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,13 @@ ureq = "1.5.1"
regex = "1.4.1"
anyhow = "1.0"
minimp3 = "0.5.0"
crossterm = "0.18.1"
webbrowser = "0.5.5"
log = "0.4.11"
flexi_logger = "0.16.1"
clipboard = "0.5.0"
rand = "0.7.3"
unicode-truncate = "0.1.1"
console_engine = "1.2.0"
console_engine = {git = "https://github.com/VincentFoulon80/console_engine"}

[dependencies.cpal]
git = "https://github.com/RustAudio/cpal.git"
Expand Down
25 changes: 19 additions & 6 deletions src/bop_interfaces/listbox.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
use console_engine::{Color, pixel::Pixel, screen::Screen, pixel};
const BASE_HEADER: &str = "▶ BandcampOnlinePlayer RS | ";
use console_engine::{screen::Screen, Color};

#[derive(Clone)]
pub struct ListBox {
pub display: Vec<String>,
pub page: usize,
pub position: usize,
pub screen: Screen,
pub focused: bool,
}

impl ListBox {
pub fn new(w: u16, h: u16,) -> Self {
pub fn new(w: u16, h: u16, focused: bool) -> Self {
Self {
display: Vec::new(),
page: 0,
position: 0,
screen: Screen::new_empty(w as u32, h as u32),
focused,
}
}

pub fn get_page_count(&mut self) -> usize {
self.display.chunks((self.screen.get_height() - 2) as usize).len()
self.display
.chunks((self.screen.get_height() - 2) as usize)
.len()
}

pub fn scroll_down(&mut self) {
Expand Down Expand Up @@ -66,10 +69,20 @@ impl ListBox {
self.display.retain(|x| x == &value);
}

pub fn get_selected_str(&mut self) -> String {
self.display[self.position].clone()
}

pub fn sel_idx_glob(&mut self, pos: usize) -> usize {
pos + (self.page * self.screen.get_height() as usize)
}

pub fn resize(&mut self, w: u16, h: u16) {
self.position = 0;
self.screen.clear();
self.screen.resize(w as u32, h as u32);
}

pub fn draw(&mut self) -> &Screen {
// drawing
let splited_pags = self.display.chunks((self.screen.get_height() - 2) as usize);
Expand All @@ -78,14 +91,14 @@ impl ListBox {
if i == self.page {
for (index, page) in v.into_iter().enumerate() {
if index == self.position {
self.screen.print_fbg(0, index as i32, page, Color::Black, Color::White)
self.screen
.print_fbg(0, index as i32, page, Color::Black, Color::White)
} else {
self.screen.print(0, index as i32, page);
}
}
}
}

&self.screen
}
}
3 changes: 2 additions & 1 deletion src/bop_interfaces/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod tui;
pub mod listbox;
pub mod tui_structs;
pub mod tui_structs;
pub mod statebar;
51 changes: 51 additions & 0 deletions src/bop_interfaces/statebar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use std::fmt::Display;

use console_engine::{Color, crossterm::terminal::size, pixel, pixel::Pixel, screen::Screen};

const BASE_HEADER: &str = "▶ BandcampOnlinePlayer RS | ";

#[derive(Clone)]
pub struct StateBar {
header_text: String,
bottom_text: String,
error: bool,
screen: Screen,
pub y: u32,
}

impl StateBar {
pub fn new() -> Self {
let (cols, rows) = size().expect("Unable to get terminal size continue work is not available!");

Self {
header_text: BASE_HEADER.to_string(),
bottom_text: String::from("Loading..."),
error: false,
screen: Screen::new(cols.into(), 2),
y: (rows as u32) - 2,
}
}

pub fn error<T: Display>(&mut self, item: &T) {
self.error = true;
self.header_text = item.to_string();
}

pub fn information<T: Display>(&mut self, item: &T) {
self.error = false;
self.header_text = item.to_string();
}

pub fn draw(&mut self) -> &Screen {
self.screen.fill(pixel::pxl_bg(' ', Color::Blue));
self.screen.print_fbg(0, 0, self.header_text.as_str(), Color::White, Color::Blue);
self.screen.print_fbg(0, 1, self.bottom_text.as_str(), Color::White, Color::Blue);
&self.screen
}

pub fn resize(&mut self, w: u16, h: u16) {
self.screen.clear();
self.screen.resize(w as u32, 2);
self.y = (h as u32) - 2;
}
}
Loading

0 comments on commit 74b1af1

Please sign in to comment.