Commit 7df2107eb9

7df2107eb9196513307efa354b33397c2104450e

parent: 2a2a2fa4a5

Unsigned

Siriusmart <71584876+Siriusmart@users.noreply.github.com> · 2022-05-28 15:37 UTC

Search filter (And published to crates.io)

Layout: unified · split

README.md +7 −6
@@ -1,14 +1,15 @@
1## Warning: This program is made for Linux machines (And maybe MacOS?)
1## Warning:
2* This app is incomplete and is missing many features
3* This app is only for *\*nix* systems
24
35## Changes made in this commit
4* Watch history page
5* Config files in `~/.config/youtube-tui`
6* Added search filters
67
78## Installation
89Requirements: Git, Cargo and the Rust Compiler
910
1011```bash
11git clone https://github.com/Siriusmart/youtube-tui && cd youtube-tui && cargo build
12cargo install youtube-tui
1213```
1314
1415## Features
@@ -94,8 +95,8 @@ The config files are located in `~/.config/youtube-tui`, run the program once to
9495>
9596
9697## To Do
97* Make the search bar functional
98* View channels
98* Search
99* Adaptive config files (auto update when config files when there are new options in the config)
99100
100101## Bugs
101102* If there is a bug please open a GitHub issue thx :)
\ No newline at end of file
src/app/app.rs +58 −17
@@ -5,7 +5,7 @@ use std::{
55
66use crate::{
77 app::pages::main_menu::*,
8 structs::{AppHistory, Item, Page, Row, WatchHistory},
8 structs::{AppHistory, Item, Page, Row, SearchSettings, WatchHistory},
99 traits::{KeyInput, SelectItem},
1010};
1111use crossterm::event::KeyCode;
@@ -18,7 +18,7 @@ use tui::{
1818 Frame,
1919};
2020
21use super::config::Config;
21use super::{config::Config, pages::item_info::ItemInfo};
2222
2323#[derive(Debug)]
2424pub struct App {
@@ -32,8 +32,10 @@ pub struct App {
3232 pub message: Arc<Mutex<Option<String>>>,
3333 pub load: bool,
3434 pub render: bool,
35 pub popup_focus: bool,
3536 pub history: Vec<AppHistory>,
3637 pub watch_history: WatchHistory,
38 pub search_settings: SearchSettings,
3739}
3840
3941impl Default for App {
@@ -50,9 +52,11 @@ impl Default for App {
5052 message: Arc::new(Mutex::new(None)),
5153 load: true,
5254 render: true,
55 popup_focus: false,
5356 history: Vec::new(),
5457 config: Config::load().unwrap(),
5558 watch_history: WatchHistory::load(),
59 search_settings: SearchSettings::default(),
5660 }
5761 }
5862}
@@ -157,6 +161,7 @@ impl App {
157161 KeyCode::Esc => {
158162 if self.selected.is_some() {
159163 self.selected = None;
164 self.popup_focus = false;
160165 return self;
161166 }
162167 }
@@ -226,11 +231,17 @@ impl App {
226231
227232 pub fn render<B: Backend>(&mut self, frame: &mut Frame<B>) {
228233 let size = frame.size();
234 let mut popups = Vec::new();
229235
230 if size.width < 45 || size.height < 16 {
236 let min = match self.page {
237 Page::MainMenu(_) => MainMenu::min(),
238 Page::ItemDisplay(_) => ItemInfo::min(),
239 };
240
241 if size.width < min.0 || size.height < min.1 {
231242 let paragraph = Paragraph::new(format!(
232 "Window too small. Minimum size 45 x 16. Current size is {} x {}",
233 size.width, size.height
243 "Window too small. Minimum size for this page is {} x {}. Current size is {} x {}",
244 min.0, min.1, size.width, size.height
234245 ))
235246 .block(Block::default())
236247 .style(Style::default().fg(Color::Red))
@@ -304,25 +315,53 @@ impl App {
304315
305316 let hover = hover_selected == Some((x, y));
306317
307 match item {
308 Item::Global(i) => {
309 i.render_item(
310 frame,
311 chunk,
312 selected,
313 hover,
314 &*self.message.lock().unwrap(),
315 );
316 }
318 if match item {
319 Item::Global(i) => i.render_item(
320 frame,
321 chunk,
322 selected,
323 hover,
324 false,
325 &*self.message.lock().unwrap(),
326 &mut self.search_settings,
327 ),
317328 Item::MainMenu(i) => {
318 i.render_item(frame, chunk, selected, hover, &self.page);
329 i.render_item(frame, chunk, selected, hover, self.popup_focus, &self.page);
330 false
319331 }
332
320333 Item::ItemInfo(i) => {
321 i.render_item(frame, chunk, selected, hover);
334 i.render_item(frame, chunk, selected, hover, self.popup_focus);
335 false
322336 }
337 } {
338 popups.push((item, selected, hover, chunk));
323339 }
324340 }
325341 }
342
343 for (item, selected, hover, chunk) in popups {
344 match item {
345 Item::Global(i) => {
346 i.render_item(
347 frame,
348 chunk,
349 selected,
350 hover,
351 true,
352 &*self.message.lock().unwrap(),
353 &mut self.search_settings,
354 );
355 }
356 _ => {} // Item::MainMenu(i) => {
357 // i.render_item(frame, chunk, selected, hover, &self.page);
358 // }
359
360 // Item::ItemInfo(i) => {
361 // i.render_item(frame, chunk, selected, hover);
362 // }
363 }
364 }
326365 }
327366
328367 pub fn pop(mut self) -> (App, bool) {
@@ -346,6 +385,8 @@ impl App {
346385 history: self.history.clone(),
347386 config: self.config,
348387 watch_history: self.watch_history,
388 search_settings: self.search_settings,
389 popup_focus: app_history.popup_focus,
349390 };
350391
351392 (self, true)
src/app/pages/global.rs +95 −5
@@ -5,18 +5,22 @@ use tui::{
55 backend::Backend,
66 layout::{Alignment, Rect},
77 style::{Color, Style},
8 widgets::{Block, BorderType, Borders, Paragraph},
8 widgets::{Block, BorderType, Borders, Clear, Paragraph},
99 Frame,
1010};
1111
1212use crate::{
1313 app::app::App,
14 functions::center_rect,
15 structs::SearchSettings,
1416 traits::{KeyInput, SelectItem},
17 widgets::{force_clear::ForceClear, horizontal_split::HorizontalSplit},
1518};
1619
1720#[derive(Debug, Clone)]
1821pub enum GlobalItem {
1922 SearchBar(String),
23 SearchSettings,
2024 MessageBar,
2125}
2226
@@ -45,9 +49,13 @@ impl Mode {
4549}
4650
4751impl SelectItem for GlobalItem {
48 fn select(&mut self, app: App) -> (App, bool) {
52 fn select(&mut self, mut app: App) -> (App, bool) {
4953 let selected = match self {
5054 GlobalItem::SearchBar(_) => true,
55 GlobalItem::SearchSettings => {
56 app.popup_focus = true;
57 true
58 }
5159 _ => false,
5260 };
5361
@@ -56,14 +64,14 @@ impl SelectItem for GlobalItem {
5664
5765 fn selectable(&self) -> bool {
5866 match self {
59 GlobalItem::SearchBar(_) => true,
67 GlobalItem::SearchBar(_) | GlobalItem::SearchSettings => true,
6068 _ => false,
6169 }
6270 }
6371}
6472
6573impl KeyInput for GlobalItem {
66 fn key_input(&mut self, key: KeyCode, app: App) -> (bool, App) {
74 fn key_input(&mut self, key: KeyCode, mut app: App) -> (bool, App) {
6775 match self {
6876 GlobalItem::SearchBar(search_bar) => match key {
6977 KeyCode::Char(c) => {
@@ -75,6 +83,9 @@ impl KeyInput for GlobalItem {
7583 KeyCode::Enter => {}
7684 _ => {}
7785 },
86 GlobalItem::SearchSettings => {
87 app.search_settings.key_input(key);
88 }
7889 _ => {}
7990 }
8091
@@ -89,8 +100,11 @@ impl GlobalItem {
89100 rect: Rect,
90101 selected: bool,
91102 hover: bool,
103 popup_render: bool,
92104 message: &Option<String>,
93 ) {
105 search_settings: &mut SearchSettings,
106 ) -> bool {
107 let area = frame.size();
94108 match self {
95109 GlobalItem::SearchBar(search) => {
96110 let block = Block::default()
@@ -123,6 +137,82 @@ impl GlobalItem {
123137 .block(block);
124138 frame.render_widget(paragraph, rect);
125139 }
140 GlobalItem::SearchSettings => {
141 let block = Block::default()
142 .border_type(BorderType::Rounded)
143 .borders(Borders::ALL)
144 .border_style(Style::default().fg(if selected {
145 Color::LightYellow
146 } else if hover {
147 Color::LightRed
148 } else {
149 Color::Reset
150 }));
151 let paragraph = Paragraph::new(String::from("...")).block(block);
152 frame.render_widget(paragraph, rect);
153
154 if selected {
155 if popup_render {
156 match center_rect((area.width * 70 / 100, area.height * 70 / 100), area) {
157 Ok(rect) => {
158 let split = HorizontalSplit::default()
159 .percentages(vec![40, 60])
160 .border_style(Style::default().fg(if selected {
161 Color::LightBlue
162 } else if hover {
163 Color::LightRed
164 } else {
165 Color::Reset
166 }));
167 let chunks = split.inner(rect);
168
169 frame.render_widget(split, rect);
170
171 search_settings.text_list.area(chunks[0]);
172
173 if search_settings.row {
174 search_settings
175 .text_list
176 .selected_style(Style::default().fg(Color::LightRed));
177
178 search_settings
179 .select_text_list
180 .selected_style(Style::default().fg(Color::LightYellow));
181 } else {
182 search_settings
183 .text_list
184 .selected_style(Style::default().fg(Color::LightYellow));
185
186 search_settings
187 .select_text_list
188 .selected_style(Style::default().fg(Color::LightRed));
189 }
190
191 frame.render_widget(search_settings.text_list.clone(), chunks[0]);
192
193 search_settings.select_text_list.area(chunks[1]);
194
195 frame.render_widget(
196 search_settings.select_text_list.clone(),
197 chunks[1],
198 );
199
200 frame.render_widget(ForceClear, chunks[0]);
201
202 frame.render_widget(ForceClear, chunks[1]);
203 }
204 Err(rect) => {
205 frame.render_widget(Clear, rect);
206 }
207 }
208 //panic!("{:?}", rect);
209 } else {
210 return true;
211 }
212 }
213 }
126214 }
215
216 false
127217 }
128218}
src/app/pages/item_info.rs +11 −4
@@ -306,6 +306,7 @@ impl ItemInfoItem {
306306 rect: Rect,
307307 selected: bool,
308308 hover: bool,
309 popup_focus: bool,
309310 ) {
310311 match self {
311312 ItemInfoItem::Video(videoinfo) => {
@@ -335,11 +336,13 @@ impl ItemInfoItem {
335336
336337 frame.render_widget(split, rect);
337338
338 let item_display = ItemDisplay {
339 item: ListItem::FullVideo(videoinfo.video.clone()),
340 };
339 if !popup_focus {
340 let item_display = ItemDisplay {
341 item: ListItem::FullVideo(videoinfo.video.clone()),
342 };
341343
342 frame.render_widget(item_display, chunks[0]);
344 frame.render_widget(item_display, chunks[0]);
345 }
343346
344347 frame.render_widget(list, chunks[1]);
345348 }
@@ -372,6 +375,10 @@ impl ItemInfo {
372375 String::from("Loading item info...")
373376 }
374377
378 pub fn min() -> (u16, u16) {
379 (21, 12)
380 }
381
375382 pub fn default() -> Vec<Row> {
376383 vec![
377384 Row {
src/app/pages/main_menu.rs +18 −5
@@ -201,6 +201,7 @@ impl MainMenuItem {
201201 rect: Rect,
202202 selected: bool,
203203 hover: bool,
204 popup_focus: bool,
204205 page: &Page,
205206 ) {
206207 let mut style = Style::default().fg(if selected {
@@ -258,7 +259,9 @@ impl MainMenuItem {
258259 }
259260
260261 if let Some(item) = videos.iter().nth(list.selected) {
261 frame.render_widget(ItemDisplay { item: item.clone() }, chunks[1]);
262 if !popup_focus {
263 frame.render_widget(ItemDisplay { item: item.clone() }, chunks[1]);
264 }
262265 }
263266
264267 frame.render_widget(list, chunks[0]);
@@ -305,13 +308,23 @@ impl MainMenu {
305308 String::from("Loading home page...")
306309 }
307310
311 pub fn min() -> (u16, u16) {
312 (45, 15)
313 }
314
308315 pub fn default() -> Vec<Row> {
309316 vec![
310317 Row {
311 items: vec![RowItem {
312 item: Item::Global(GlobalItem::SearchBar(String::new())),
313 constraint: Constraint::Percentage(100),
314 }],
318 items: vec![
319 RowItem {
320 item: Item::Global(GlobalItem::SearchBar(String::new())),
321 constraint: Constraint::Min(16),
322 },
323 RowItem {
324 item: Item::Global(GlobalItem::SearchSettings),
325 constraint: Constraint::Length(5),
326 },
327 ],
315328 centered: false,
316329 height: Constraint::Length(3),
317330 },
src/functions/center_rect.rs added +36
@@ -0,0 +1,36 @@
1use tui::layout::Rect;
2
3pub fn center_rect(rect: (u16, u16), frame_rect: Rect) -> Result<Rect, Rect> {
4 let width_too_big = rect.0 > frame_rect.width;
5 let height_too_big = rect.1 > frame_rect.height;
6
7 if width_too_big || height_too_big {
8 return Err(Rect {
9 width: if width_too_big {
10 frame_rect.width
11 } else {
12 rect.0
13 },
14 height: if height_too_big {
15 frame_rect.height
16 } else {
17 rect.1
18 },
19 x: if width_too_big {
20 frame_rect.x
21 } else {
22 (frame_rect.x + frame_rect.width - rect.0) / 2
23 },
24 y: if height_too_big {
25 frame_rect.y
26 } else {
27 (frame_rect.y + frame_rect.height - rect.1) / 2
28 },
29 });
30 }
31
32 let x = (frame_rect.x + frame_rect.width - rect.0) / 2;
33 let y = (frame_rect.y + frame_rect.height - rect.1) / 2;
34
35 Ok(Rect::new(x, y, rect.0, rect.1))
36}
src/functions/mod.rs +4 −1
@@ -2,4 +2,7 @@ mod download_all_thumbnails;
22pub use download_all_thumbnails::*;
33
44mod insert_vec;
5pub use insert_vec::*;
\ No newline at end of file
5pub use insert_vec::*;
6
7mod center_rect;
8pub use center_rect::*;
\ No newline at end of file
src/structs/apphistory.rs +2
@@ -18,6 +18,7 @@ pub struct AppHistory {
1818 pub message: Arc<Mutex<Option<String>>>,
1919 pub load: bool,
2020 pub render: bool,
21 pub popup_focus: bool,
2122}
2223
2324impl From<App> for AppHistory {
@@ -32,6 +33,7 @@ impl From<App> for AppHistory {
3233 message: original.message,
3334 load: original.load,
3435 render: original.render,
36 popup_focus: original.popup_focus,
3537 }
3638 }
3739}
src/structs/mod.rs +4 −1
@@ -17,4 +17,7 @@ mod fullvideo;
1717pub use fullvideo::*;
1818
1919mod watchhistory;
20pub use watchhistory::*;
\ No newline at end of file
20pub use watchhistory::*;
21
22mod search_settings;
23pub use search_settings::*;
\ No newline at end of file
src/structs/search_settings.rs added +361
@@ -0,0 +1,361 @@
1use crossterm::event::KeyCode;
2
3use crate::widgets::text_list::TextList;
4
5#[derive(Debug, Clone)]
6pub struct SearchSettings {
7 pub sort_by: SearchSettingsSortBy,
8 pub date: Option<SearchSettingsDate>,
9 pub duartion: Option<SearchSettingsDuration>,
10 pub r#type: Option<SearchSettingsType>,
11
12 pub row: bool, // left: true, right: false
13
14 pub text_list: TextList,
15 pub select_text_list: TextList,
16}
17
18impl Default for SearchSettings {
19 fn default() -> Self {
20 let mut text_list = TextList::default();
21 text_list.items = vec![
22 String::from("Sort by"),
23 String::from("Date"),
24 String::from("Duration"),
25 String::from("Type"),
26 String::from("Reset All"),
27 ];
28
29 let mut out = SearchSettings {
30 sort_by: SearchSettingsSortBy::Relevance,
31 date: None,
32 duartion: None,
33 r#type: None,
34
35 row: true,
36
37 text_list,
38 select_text_list: TextList::default(),
39 };
40
41 out.update_left();
42
43 out
44 }
45}
46
47impl SearchSettings {
48 pub fn to_vec(self) -> Vec<String> {
49 let mut vec = vec![self.sort_by.as_url_string()];
50
51 if let Some(date) = self.date {
52 vec.push(date.as_url_string());
53 }
54
55 if let Some(duration) = self.duartion {
56 vec.push(duration.as_url_string());
57 }
58
59 if let Some(r#type) = self.r#type {
60 vec.push(r#type.as_url_string());
61 }
62
63 vec
64 }
65
66 pub fn key_input(&mut self, keycode: KeyCode) {
67 match keycode {
68 KeyCode::Up => {
69 if self.row {
70 self.text_list.up();
71 self.update_left()
72 } else {
73 self.select_text_list.up();
74
75 match self.text_list.selected {
76 0 => self.sort_by = SearchSettingsSortBy::index_to_value(self.select_text_list.selected),
77 1 => self.date = SearchSettingsDate::index_to_value(self.select_text_list.selected),
78 2 => self.duartion = SearchSettingsDuration::index_to_value(self.select_text_list.selected),
79 3 => self.r#type = SearchSettingsType::index_to_value(self.select_text_list.selected),
80 _ => {}
81 }
82 }
83 }
84 KeyCode::Down => {
85 if self.row {
86 self.text_list.down();
87 self.update_left()
88 } else {
89 self.select_text_list.down();
90
91 match self.text_list.selected {
92 0 => self.sort_by = SearchSettingsSortBy::index_to_value(self.select_text_list.selected),
93 1 => self.date = SearchSettingsDate::index_to_value(self.select_text_list.selected),
94 2 => self.duartion = SearchSettingsDuration::index_to_value(self.select_text_list.selected),
95 3 => self.r#type = SearchSettingsType::index_to_value(self.select_text_list.selected),
96 _ => {}
97 }
98 }
99 }
100 KeyCode::Left => {
101 self.row = true;
102 }
103 KeyCode::Right => {
104 self.row = false;
105 }
106 KeyCode::Enter => {
107 if self.text_list.selected == 4 && !self.row {
108 *self = Self::default();
109 self.text_list.selected = 4;
110 self.update_left();
111 } else {
112 self.row = false;
113 }
114 }
115 _ => {}
116 }
117 }
118
119 pub fn update_left(&mut self) {
120 match self.text_list.selected {
121 0 => {
122 self.select_text_list.items = SearchSettingsSortBy::as_vec();
123 self.select_text_list.selected = SearchSettingsSortBy::value_to_index(self.sort_by);
124 }
125 1 => {
126 self.select_text_list.items = SearchSettingsDate::as_vec();
127 self.select_text_list.selected = SearchSettingsDate::value_to_index(self.date);
128 }
129 2 => {
130 self.select_text_list.items = SearchSettingsDuration::as_vec();
131 self.select_text_list.selected =
132 SearchSettingsDuration::value_to_index(self.duartion);
133 }
134 3 => {
135 self.select_text_list.items = SearchSettingsType::as_vec();
136 self.select_text_list.selected = SearchSettingsType::value_to_index(self.r#type);
137 }
138 4 => {
139 self.select_text_list.items = vec![String::from("Reset All")];
140 self.select_text_list.selected = 0;
141 }
142 _ => {}
143 }
144 }
145}
146
147pub trait AsUrlString {
148 fn as_url_string(&self) -> String;
149}
150
151#[derive(Debug, Clone, Copy)]
152pub enum SearchSettingsSortBy {
153 Relevance,
154 Rating,
155 Date,
156 ViewCount,
157}
158
159impl AsUrlString for SearchSettingsSortBy {
160 fn as_url_string(&self) -> String {
161 format!(
162 "sort_by={}",
163 match self {
164 SearchSettingsSortBy::Relevance => String::from("relevance"),
165 SearchSettingsSortBy::Rating => String::from("rating"),
166 SearchSettingsSortBy::Date => String::from("upload_date"),
167 SearchSettingsSortBy::ViewCount => String::from("view_count"),
168 }
169 )
170 }
171}
172
173impl SearchSettingsSortBy {
174 pub fn as_vec() -> Vec<String> {
175 vec![
176 String::from("Relevance"),
177 String::from("Rating"),
178 String::from("Date"),
179 String::from("View Count"),
180 ]
181 }
182
183 pub fn index_to_value(index: usize) -> SearchSettingsSortBy {
184 match index {
185 0 => SearchSettingsSortBy::Relevance,
186 1 => SearchSettingsSortBy::Rating,
187 2 => SearchSettingsSortBy::Date,
188 3 => SearchSettingsSortBy::ViewCount,
189 _ => unreachable!(),
190 }
191 }
192
193 pub fn value_to_index(value: SearchSettingsSortBy) -> usize {
194 match value {
195 SearchSettingsSortBy::Relevance => 0,
196 SearchSettingsSortBy::Rating => 1,
197 SearchSettingsSortBy::Date => 2,
198 SearchSettingsSortBy::ViewCount => 3,
199 }
200 }
201}
202
203#[derive(Debug, Clone, Copy)]
204pub enum SearchSettingsDate {
205 Hour,
206 Day,
207 Week,
208 Month,
209 Year,
210}
211
212impl AsUrlString for SearchSettingsDate {
213 fn as_url_string(&self) -> String {
214 format!(
215 "date={}",
216 match self {
217 SearchSettingsDate::Hour => String::from("hour"),
218 SearchSettingsDate::Day => String::from("today"),
219 SearchSettingsDate::Week => String::from("week"),
220 SearchSettingsDate::Month => String::from("month"),
221 SearchSettingsDate::Year => String::from("year"),
222 }
223 )
224 }
225}
226
227impl SearchSettingsDate {
228 pub fn as_vec() -> Vec<String> {
229 vec![
230 String::from("No Filter"),
231 String::from("Hour"),
232 String::from("Day"),
233 String::from("Week"),
234 String::from("Month"),
235 String::from("Year"),
236 ]
237 }
238
239 pub fn index_to_value(index: usize) -> Option<SearchSettingsDate> {
240 match index {
241 0 => None,
242 1 => Some(SearchSettingsDate::Hour),
243 2 => Some(SearchSettingsDate::Day),
244 3 => Some(SearchSettingsDate::Week),
245 4 => Some(SearchSettingsDate::Month),
246 5 => Some(SearchSettingsDate::Year),
247 _ => unreachable!(),
248 }
249 }
250
251 pub fn value_to_index(value: Option<SearchSettingsDate>) -> usize {
252 match value {
253 None => 0,
254 Some(SearchSettingsDate::Hour) => 1,
255 Some(SearchSettingsDate::Day) => 2,
256 Some(SearchSettingsDate::Week) => 3,
257 Some(SearchSettingsDate::Month) => 4,
258 Some(SearchSettingsDate::Year) => 5,
259 }
260 }
261}
262
263#[derive(Debug, Clone, Copy)]
264pub enum SearchSettingsDuration {
265 Short,
266 Long,
267}
268
269impl AsUrlString for SearchSettingsDuration {
270 fn as_url_string(&self) -> String {
271 format!(
272 "duration={}",
273 match self {
274 SearchSettingsDuration::Short => String::from("short"),
275 SearchSettingsDuration::Long => String::from("long"),
276 }
277 )
278 }
279}
280
281impl SearchSettingsDuration {
282 pub fn as_vec() -> Vec<String> {
283 vec![
284 String::from("No Filter"),
285 String::from("Short"),
286 String::from("Long"),
287 ]
288 }
289
290 pub fn index_to_value(index: usize) -> Option<SearchSettingsDuration> {
291 match index {
292 0 => None,
293 1 => Some(SearchSettingsDuration::Short),
294 2 => Some(SearchSettingsDuration::Long),
295 _ => unreachable!(),
296 }
297 }
298
299 pub fn value_to_index(value: Option<SearchSettingsDuration>) -> usize {
300 match value {
301 None => 0,
302 Some(SearchSettingsDuration::Short) => 1,
303 Some(SearchSettingsDuration::Long) => 2,
304 }
305 }
306}
307
308#[derive(Debug, Clone, Copy)]
309pub enum SearchSettingsType {
310 Video,
311 Channel,
312 Playlist,
313 All,
314}
315
316impl AsUrlString for SearchSettingsType {
317 fn as_url_string(&self) -> String {
318 format!(
319 "type={}",
320 match self {
321 SearchSettingsType::Video => String::from("video"),
322 SearchSettingsType::Channel => String::from("channel"),
323 SearchSettingsType::Playlist => String::from("playlist"),
324 SearchSettingsType::All => String::from("all"),
325 }
326 )
327 }
328}
329
330impl SearchSettingsType {
331 pub fn as_vec() -> Vec<String> {
332 vec![
333 String::from("No Filter"),
334 String::from("Video"),
335 String::from("Channel"),
336 String::from("Playlist"),
337 String::from("All"),
338 ]
339 }
340
341 pub fn index_to_value(index: usize) -> Option<SearchSettingsType> {
342 match index {
343 0 => None,
344 1 => Some(SearchSettingsType::Video),
345 2 => Some(SearchSettingsType::Channel),
346 3 => Some(SearchSettingsType::Playlist),
347 4 => Some(SearchSettingsType::All),
348 _ => unreachable!(),
349 }
350 }
351
352 pub fn value_to_index(value: Option<SearchSettingsType>) -> usize {
353 match value {
354 None => 0,
355 Some(SearchSettingsType::Video) => 1,
356 Some(SearchSettingsType::Channel) => 2,
357 Some(SearchSettingsType::Playlist) => 3,
358 Some(SearchSettingsType::All) => 4,
359 }
360 }
361}
src/widgets/force_clear.rs added +13
@@ -0,0 +1,13 @@
1use tui::{widgets::Widget, buffer::Buffer, layout::Rect, style::{Color, Style}};
2
3pub struct ForceClear;
4
5impl Widget for ForceClear {
6 fn render(self, rect: Rect, buffer: &mut Buffer) {
7 for y in rect.y..rect.y + rect.height {
8 for x in rect.x..rect.x + rect.width {
9 buffer.get_mut(x, y).set_style(Style::default().bg(Color::DarkGray));
10 }
11 }
12 }
13}
src/widgets/mod.rs +1
@@ -1,3 +1,4 @@
11pub mod horizontal_split;
22pub mod item_display;
33pub mod text_list;
4pub mod force_clear;
\ No newline at end of file