Commit f321f7c1e9
Unsigned
Layout: unified · split
Cargo.lock +2
| @@ -1178,6 +1178,8 @@ checksum = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" | ||
| 1178 | 1178 | [[package]] |
| 1179 | 1179 | name = "tui-additions" |
| 1180 | 1180 | version = "0.2.1" |
| 1181 | source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 1182 | checksum = "1de5841ec45de71c46252a832bb1e3e69abf2ee2492eb309ea077c8d78e798e7" | |
| 1181 | 1183 | dependencies = [ |
| 1182 | 1184 | "crossterm 0.26.1", |
| 1183 | 1185 | "dyn-clone", |
Cargo.toml +2 −2
| @@ -29,7 +29,7 @@ viuer = {version = "0.6", default-features = false, optional = true} | ||
| 29 | 29 | home = "0.5" |
| 30 | 30 | chrono = {version = "0.4", default-features = false, features = ["clock"]} |
| 31 | 31 | typemap = {version = "0.3", default-features = false} |
| 32 | # tui-additions = {version = "0.2.1", default-features = false, features = ["framework", "widgets"]} | |
| 32 | tui-additions = {version = "0.2.1", default-features = false, features = ["framework", "widgets"]} | |
| 33 | 33 | invidious = {version = "0.5"} |
| 34 | 34 | serde_yaml = {version = "0.9", default-features = false} |
| 35 | 35 | dyn-clone = {version = "1.0", default-features = false} |
| @@ -40,7 +40,7 @@ ratatui = {version = "0.21", default-features = false, features = ["serde"]} | ||
| 40 | 40 | libmpv = { git = "https://github.com/sudipghimire533/libmpv-rs", optional = true } |
| 41 | 41 | unicode-segmentation = "1" |
| 42 | 42 | |
| 43 | tui-additions = {path = "../../Rust/Packages/tui-additions", default-features = false, features = ["framework", "widgets"]} | |
| 43 | # tui-additions = {path = "../../Rust/Packages/tui-additions", default-features = false, features = ["framework", "widgets"]} | |
| 44 | 44 | # invidious = {path = "../../Rust/Packages/invidious"} |
| 45 | 45 | |
| 46 | 46 | [package.metadata.docs.rs] |
README.md +6 −11
| @@ -7,21 +7,16 @@ | ||
| 7 | 7 | |
| 8 | 8 | ***Read more in the [user manual](https://siriusmart.github.io/youtube-tui) (including installation guide and documentation).*** |
| 9 | 9 | |
| 10 | > "May Invidious live and prosper, with, or without us." | |
| 11 | > | |
| 12 | > ~ The Invidious team on [YouTube trying to take them down](https://github.com/iv-org/invidious/issues/3872). | |
| 13 | ||
| 14 | Go show them some support by [donating](https://invidious.io/donate/) and starring their | |
| 15 | [GitHub repos](https://github.com/iv-org)! | |
| 16 | ||
| 17 | 10 | # Overview |
| 18 | 11 | |
| 19 | Written in Rust, the **YouTube TUI** is a lightweight and user friendly TUI for browsing YouTube content from the terminal. | |
| 12 | Written in Rust, the **YouTube TUI** is a lightweight and user friendly TUI for browsing YouTube content from the terminal. Works out of the box and easily to configurable. | |
| 20 | 13 | |
| 21 | 14 |  |
| 22 | 15 | |
| 23 | 16 | It is like an _app launcher_, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos). |
| 24 | 17 | |
| 18 | <sub>It also have an embedded mpv music player, but that can be disabled in compile time.</sub> | |
| 19 | ||
| 25 | 20 | > Consider regenerating config files on updates to allow new features. |
| 26 | 21 | |
| 27 | 22 | ## Customisable |
| @@ -61,10 +56,10 @@ However, the programs to launch can be changed, and therefore the YouTube TUI <u | ||
| 61 | 56 | |
| 62 | 57 | The YouTube TUI allows you to browse YouTube with (almost) all of it's features, functions including: |
| 63 | 58 | |
| 64 | - View popular/trending videos | |
| 65 | 59 | - View information about channels, playlists and videos |
| 66 | 60 | - Use search filters to sort and filter search results |
| 67 | 61 | - Save browsing history |
| 62 | - Embedded audio/music player | |
| 68 | 63 | |
| 69 | 64 | It also includes features like: |
| 70 | 65 | |
| @@ -77,9 +72,9 @@ It also includes features like: | ||
| 77 | 72 | ### What it doesn't have |
| 78 | 73 | |
| 79 | 74 | - [URGENT] Replace the no-longer-going-to-compile `typemap` dependency with either a self implementation of it or a useable crate. |
| 80 | - Strip down some libraries to reduce compile speed, specifically removing. | |
| 75 | - Strip down some libraries to reduce compile speed. | |
| 81 | 76 | - Add command section for channel main page (first priority) |
| 82 | - Add NewPipe as a source alongside Invidious | |
| 77 | - Git like command line to improve on `yt-dlp` - make changes to existing downloaded playlists instead of redownloading the entire thing. | |
| 83 | 78 | |
| 84 | 79 | ## How to contribute |
| 85 | 80 | |
docs/src/README.md +5 −3
| @@ -1,11 +1,13 @@ | ||
| 1 | 1 | # Overview |
| 2 | 2 | |
| 3 | Written in Rust, the **YouTube TUI** is a lightweight and user friendly TUI for browsing YouTube content from the terminal. | |
| 3 | Written in Rust, the **YouTube TUI** is a lightweight and user friendly TUI for browsing YouTube content from the terminal. Works out of the box and easily to configurable. | |
| 4 | 4 | |
| 5 | 5 |  |
| 6 | 6 | |
| 7 | 7 | It is like an _app launcher_, it launches other programs to do the heavy lifting (for example, `mpv` for playing videos). |
| 8 | 8 | |
| 9 | <sub>It also have an embedded mpv music player, but that can be disabled in compile time.</sub> | |
| 10 | ||
| 9 | 11 | > Consider regenerating config files on updates to allow new features. |
| 10 | 12 | |
| 11 | 13 | ## Customisable |
| @@ -45,10 +47,10 @@ However, the programs to launch can be changed, and therefore the YouTube TUI <u | ||
| 45 | 47 | |
| 46 | 48 | The YouTube TUI allows you to browse YouTube with (almost) all of it's features, functions including: |
| 47 | 49 | |
| 48 | - View popular/trending videos | |
| 49 | 50 | - View information about channels, playlists and videos |
| 50 | 51 | - Use search filters to sort and filter search results |
| 51 | 52 | - Save browsing history |
| 53 | - Embedded audio/music player | |
| 52 | 54 | |
| 53 | 55 | It also includes features like: |
| 54 | 56 | |
| @@ -63,7 +65,7 @@ It also includes features like: | ||
| 63 | 65 | - [URGENT] Replace the no-longer-going-to-compile `typemap` dependency with either a self implementation of it or a useable crate. |
| 64 | 66 | - Strip down some libraries to reduce compile speed. |
| 65 | 67 | - Add command section for channel main page (first priority) |
| 66 | - Up arrow command history + Ctrl arrow keys move between words | |
| 68 | - Git like command line to improve on `yt-dlp` - make changes to existing downloaded playlists instead of redownloading the entire thing. | |
| 67 | 69 | |
| 68 | 70 | ## How to contribute |
| 69 | 71 | |
docs/src/SUMMARY.md +4 −1
| @@ -3,7 +3,8 @@ | ||
| 3 | 3 | - [Overview](README.md) |
| 4 | 4 | - [Installation](installation.md) |
| 5 | 5 | - [Basic usage](basic_usage.md) |
| 6 | - [Invidious](invidious.md) | |
| 6 | <!-- - [Invidious](invidious.md) --> | |
| 7 | <!-- Will add it back in when it's relevant again --> | |
| 7 | 8 | - [Commands](commands.md) |
| 8 | 9 | |
| 9 | 10 | # Customisation guide |
| @@ -16,6 +17,8 @@ | ||
| 16 | 17 | - [pages](config/pages.md) |
| 17 | 18 | - [appearance](config/appearance.md) |
| 18 | 19 | - [search](config/search.md) |
| 20 | - [cmdefine](config/cmdefine.md) | |
| 21 | - [remap](config/remap.md) | |
| 19 | 22 | |
| 20 | 23 | # Contributing |
| 21 | 24 | |
docs/src/basic_usage.md +20 −2
| @@ -24,6 +24,10 @@ The item with the cursor hovering will have a <u>red outline</u>. | ||
| 24 | 24 | |First page history|Home| |
| 25 | 25 | |Clear page history|End| |
| 26 | 26 | |Paste from clipboard|`Ctrl` + `V`| |
| 27 | |Next/previous entry on search and command|`Ctrl` + up/down arrow| | |
| 28 | |Next song|`Ctrl` + `Shift` + Right arrow| | |
| 29 | |Seek audio|`Ctrl` + left/right arrow| | |
| 30 | |Pause/resume audio|Space| | |
| 27 | 31 | |Enter command mode|`:`| |
| 28 | 32 | |Quit|`q`| |
| 29 | 33 | |
| @@ -41,13 +45,27 @@ To apply search filters, select the button with 3 dots (`...`) to the right of t | ||
| 41 | 45 | |
| 42 | 46 |  |
| 43 | 47 | |
| 44 | ## Playing videos and playlists | |
| 48 | > You may use `Ctrl + Up/Down arrow` to cycle through previously searched queries (when focused on the search bar). | |
| 49 | ||
| 50 | ## Playing media with embedded player | |
| 51 | ||
| 52 | By default, running any "play video" options in video or playlist view will open a new mpv player window. | |
| 53 | ||
| 54 | While any "play audio" options will start playing the audio in the embedded audio player, | |
| 55 | ||
| 56 | - seek and rewind using `Ctrl + Left/Right arrow` | |
| 57 | - skip with `Ctrl + Shift + Right arrow` | |
| 58 | - pause and resume with space | |
| 59 | ||
| 60 | ## Playing videos and playlists externally | |
| 61 | ||
| 62 | You can also play audio and videos externally. | |
| 45 | 63 | |
| 46 | 64 | > This part assumes that you use `mpv` as your video player, `konsole` as your terminal emulator, `yt-dlp` as your YouTube video downloader, and `firefox` as your browser. |
| 47 | 65 | > |
| 48 | 66 | > If that is not the case, you can learn how to change that in the *custom commands* section. |
| 49 | 67 | |
| 50 | Press `Enter` to select a video or playlist from any lists, then move the cursor to the *bottom item* where you can play, download and open the webpage in browser. | |
| 68 | You can press keybindings like `Shift` + `A` to run a command which opens a new terminal screen, and in that terminal screen it runs an mpv command to play the media. | |
| 51 | 69 | |
| 52 | 70 | ## Feeds |
| 53 | 71 | |
docs/src/changelogs.md +17 −9
| @@ -1,20 +1,28 @@ | ||
| 1 | 1 | # Changelogs |
| 2 | 2 | |
| 3 | ### v0.8.0 (latest unstable on Github) | |
| 3 | ## v0.8.0 (latest) | |
| 4 | 4 | |
| 5 | #### Added | |
| 5 | ### Added | |
| 6 | 6 | |
| 7 | - Build in MPV player, controlled by command `mpv [libmpv command] [args...]` | |
| 7 | - Built in MPV player, controlled by command `mpv [libmpv command] [args...]` | |
| 8 | - Command/search histories. | |
| 9 | - Keys remapping, custom commands. | |
| 8 | 10 | |
| 9 | ## v0.7.4 (latest stable on crates.io) | |
| 11 | ### Fixed | |
| 10 | 12 | |
| 11 | ### Added | |
| 13 | - Some keys captured in search bar and are not working [#37](https://github.com/Siriusmart/youtube-tui/issues/37). | |
| 14 | ||
| 15 | --- | |
| 16 | ||
| 17 | ### v0.7.4 | |
| 18 | ||
| 19 | #### Added | |
| 12 | 20 | |
| 13 | 21 | - `Ctrl + w` and `Ctrl + u` in search bar and command mode. |
| 14 | 22 | - Keybindings works even when an item is selected (`legacy_input_handling: false` in `main.yml`). |
| 15 | 23 | - Creating fake key input using `:key` |
| 16 | 24 | |
| 17 | ### Fixed | |
| 25 | #### Fixed | |
| 18 | 26 | |
| 19 | 27 | - Search filters popup closing when you click on it. |
| 20 | 28 | - Configured keybindings in all items. |
| @@ -66,7 +74,7 @@ | ||
| 66 | 74 | |
| 67 | 75 | - Empty ItemList crash (<a href="https://github.com/Siriusmart/youtube-tui/issues/26" target=_blank>issue 26</a>) |
| 68 | 76 | |
| 69 | <hr> | |
| 77 | --- | |
| 70 | 78 | |
| 71 | 79 | ## v0.6.2 |
| 72 | 80 | |
| @@ -98,7 +106,7 @@ | ||
| 98 | 106 | - Vim-like commands |
| 99 | 107 | - Pasting with `Ctrl + V` in search bar and command mode |
| 100 | 108 | |
| 101 | <hr> | |
| 109 | --- | |
| 102 | 110 | |
| 103 | 111 | ## v0.5.3 |
| 104 | 112 | |
| @@ -132,7 +140,7 @@ | ||
| 132 | 140 | - Sixels image support |
| 133 | 141 | - Improved config files |
| 134 | 142 | |
| 135 | <hr> | |
| 143 | --- | |
| 136 | 144 | |
| 137 | 145 | ## v0.4.4 |
| 138 | 146 | |
docs/src/commands.md +26 −12
| @@ -1,6 +1,12 @@ | ||
| 1 | 1 | # Commands |
| 2 | 2 | |
| 3 | Commands can be entered to the TUI by pressing the `:` key, the same as in Vim. Some commands have shorter *alternatives* that can be used instead. | |
| 3 | Commands can be entered to the TUI by pressing the `:` key, the same as in Vim. | |
| 4 | ||
| 5 | Run the help command to view more detailed help. | |
| 6 | ||
| 7 | ```sh | |
| 8 | youtube-tui help | |
| 9 | ``` | |
| 4 | 10 | |
| 5 | 11 | > Env variables can be used by passing in as `${key}`, such as `:channel ${channel-id}` when in a video or playlist page. |
| 6 | 12 | |
| @@ -15,13 +21,7 @@ Below are the avaliable commands: | ||
| 15 | 21 | `loadpage` can be used to load a specific page. |
| 16 | 22 | |
| 17 | 23 | ```vim |
| 18 | loadpage popular (alt: `popular`) | |
| 19 | loadpage trending (alt: `trending`) | |
| 20 | loadpage watchhistory (alt: `watchhistory`) | |
| 21 | loadpage search [search query] (alt: `search [search query]`) | |
| 22 | loadpage video [id or url] (alt: `video [id or url]`) | |
| 23 | loadpage playlist [id or url] (alt: `playlist [id or url] `) | |
| 24 | loadpage channel [id or url] (alt: `channel [id or url] `) | |
| 24 | loadpage [page] | |
| 25 | 25 | ``` |
| 26 | 26 | |
| 27 | 27 | ## History |
| @@ -29,20 +29,21 @@ loadpage channel [id or url] (alt: `channel [id or url] `) | ||
| 29 | 29 | `history` is used to manage page history (`Backspace` equivalent). |
| 30 | 30 | |
| 31 | 31 | ```vim |
| 32 | history back (alt: `back`) | |
| 32 | history back | |
| 33 | 33 | history clear |
| 34 | 34 | ``` |
| 35 | 35 | |
| 36 | 36 | ## Utility |
| 37 | 37 | |
| 38 | 38 | ```vim |
| 39 | reload (alt `r`) | |
| 40 | reload configs (alt `reload/r config/configs`) | |
| 39 | reload // reloads the page | |
| 40 | reload configs // reload config files in ~/.config/youtube-tui/ | |
| 41 | 41 | flush |
| 42 | quit (alt `q`, `exit`, `x`) | |
| 42 | quit | |
| 43 | 43 | run [command] |
| 44 | 44 | parrun [command] |
| 45 | 45 | key [keycode] [keymodifier] |
| 46 | echo [mode] (message) # run youtube-tui help to learn more about modes | |
| 46 | 47 | ``` |
| 47 | 48 | |
| 48 | 49 | > The `flush` command is used to run all tasks in queue immediately, this is usually done automatically. |
| @@ -66,6 +67,19 @@ unsub [id or url] Remove channel from subscription | ||
| 66 | 67 | syncall Sync all subscriptions |
| 67 | 68 | ``` |
| 68 | 69 | |
| 70 | ## MPV commands | |
| 71 | ||
| 72 | <sub>Only with the [`mpv`](installation.md#mpv-default) feature.</sub> | |
| 73 | ||
| 74 | ```vim | |
| 75 | mpv prop [label] Gets mpv property | |
| 76 | mpv sprop [label] [value] Set mpv property | |
| 77 | mpv tprop [label] [value] Toggle a yes/no property | |
| 78 | mpv [command] Runs a libmpv command | |
| 79 | ``` | |
| 80 | ||
| 81 | > Note that properties and commands are **libmpv** commands, *not* mpv commands. Please refer to [mpv reference](https://mpv.io/manual/master/). | |
| 82 | ||
| 69 | 83 | ## Text commands |
| 70 | 84 | |
| 71 | 85 | Text commands generates a *text only response* without launching the TUI. |
docs/src/config/README.md +2
| @@ -12,3 +12,5 @@ In the following sections we will go through all config files including: | ||
| 12 | 12 | - [`pages.yml`](./pages.md) |
| 13 | 13 | - [`appearance.yml`](./appearance.md) |
| 14 | 14 | - [`search.yml`](./search.md) |
| 15 | - [`cmdefine.yml`](./cmdefine.md) | |
| 16 | - [`remap.yml`](./remap.md) | |
docs/src/config/cmdefine.md added +28
| @@ -0,0 +1,28 @@ | ||
| 1 | # Custom commands | |
| 2 | ||
| 3 | Define custom commands. It can be found in `~/.config/youtube-tui/cmdefine.yml`. | |
| 4 | ||
| 5 | > This is still a work in progress, perhaps in the future scripting will be allowed to control and interact with elements within the TUI. | |
| 6 | ||
| 7 | ```yml | |
| 8 | print: echo | |
| 9 | pause: mpv sprop pause yes ;; echo mpv Player paused | |
| 10 | next: mpv playlist-next ;; echo mpv Skipped | |
| 11 | resume: mpv sprop pause no ;; echo mpv Player resumed | |
| 12 | search: loadpage search | |
| 13 | rc: reload configs | |
| 14 | ``` | |
| 15 | ||
| 16 | --- | |
| 17 | ||
| 18 | General format: | |
| 19 | ||
| 20 | ```yml | |
| 21 | new command: original command | |
| 22 | ``` | |
| 23 | ||
| 24 | This allows for alternative shorthand commands. | |
| 25 | ||
| 26 | <sub>More about commands run `youtube-tui help` or check out [commands](commands.md).</sub> | |
| 27 | ||
| 28 | > Try not to use self referencing commands, it'll make a mess. | |
docs/src/config/commands.md +62 −58
| @@ -5,73 +5,74 @@ The commands config file decides what options (that will run a certain command o | ||
| 5 | 5 | ## Example commands config |
| 6 | 6 | |
| 7 | 7 | ```yaml |
| 8 | launch_command: loadpage popular ;; flush ;; history clear # suggested to set page to watchhistory if you don't want to wait for popular to load | |
| 8 | launch_command: loadpage library ;; flush ;; history clear ;; key Esc 0 ;; key Up 0 ;; key Up 0 ;; key Left 0 ;; key Enter 0 # the key commands select the searchbar on launch | |
| 9 | 9 | video: |
| 10 | - Play video: ${video-player} ${embed-url} | |
| 11 | - Play audio: ${terminal-emulator} ${video-player} ${embed-url} --no-video | |
| 12 | - Play audio (loop): ${terminal-emulator} ${video-player} ${embed-url} --no-video --loop-file=inf | |
| 13 | - View channel: :channel ${channel-id} | |
| 14 | - Open in browser: ${browser} ${url} | |
| 15 | - Download video (webm): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url} | |
| 16 | - Download audio (opus): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${embed-url} -x | |
| 17 | - 'Mode: ${provider}': '%switch-provider%' | |
| 18 | playlist: | |
| 19 | - Switch view: '%switch-view%' | |
| 20 | - Play all videos: ${video-player} ${all-videos} | |
| 21 | - Play all audio: ${terminal-emulator} ${video-player} ${all-videos} --no-video | |
| 22 | - Shuffle play all audio: ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle | |
| 23 | - Shuffle play all audio (loop): ${terminal-emulator} ${video-player} ${all-videos} --no-video --shuffle --loop-playlist=inf | |
| 24 | - View channel: :channel ${channel-id} | |
| 25 | - Open in browser: ${browser} ${url} | |
| 26 | - Download all video (webm): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos} | |
| 27 | - Download all audio (opus): ${terminal-emulator} ${youtube-downloader} -o ${download-path} ${all-videos} -x | |
| 28 | - 'Mode: ${provider}': '%switch-provider%' | |
| 10 | - Reload updated video: run rm '~/.cache/youtube-tui/info/${id}.json' ;; video ${id} # remove the cached info first, then reload the page | |
| 11 | - Play video: parrun ${video-player} '${embed-url}' | |
| 12 | - Play audio: mpv stop ;; resume ;; mpv sprop loop-file no ;; mpv loadfile '${embed-url}' ;; echo mpv Player started | |
| 13 | - Play audio (loop): mpv stop ;; resume ;; mpv sprop loop-file inf ;; mpv loadfile '${embed-url}' ;; echo mpv Player started | |
| 14 | - View channel: channel ${channel-id} | |
| 15 | - Subscribe to channel: sync ${channel-id} | |
| 16 | - Open in browser: parrun ${browser} '${url}' | |
| 17 | - Toggle bookmark: togglemark ${id} | |
| 18 | - Save video to library: bookmark ${id} ;; run rm -rf '${save-path}${id}.*' ;; parrun ${terminal-emulator} ${youtube-downloader} '${embed-url}' -o '${save-path}%(title)s[%(id)s].%(ext)s' | |
| 19 | - Save audio to library: bookmark ${id} ;; parrun rm -rf '${save-path}${id}.*' ;; parrun ${terminal-emulator} ${youtube-downloader} '${embed-url}' -x -o '${save-path}%(title)s[%(id)s].%(ext)s' | |
| 20 | - 'Mode: ${provider}': switchprovider | |
| 21 | ||
| 22 | # ... | |
| 29 | 23 | ``` |
| 30 | 24 | |
| 31 | ## Env variables | |
| 32 | ||
| 33 | Notice that a lot of the commands contains the `${label}` pattern, this actually replaces the text with the env variables set in `main.yml`, or is added by the current page (video or playlist) on-the-go. | |
| 34 | ||
| 35 | Replacing all these with known values it might look something like this: | |
| 36 | ||
| 37 | ```yaml | |
| 38 | launch_command: loadpage popular ;; flush ;; history clear | |
| 39 | video: | |
| 40 | - Play video: mpv 'https://youtube.com/embed/dQw4w9WgXcQ' | |
| 41 | - Play audio: konsole -e mpv 'https://youtube.com/embed/dQw4w9WgXcQ' --no-video | |
| 42 | - Open in browser: firefox 'https://youtu.be/dQw4w9WgXcQ' | |
| 43 | - Download video (webm): konsole -e yt-dlp -o '~/Downloads/%(title)s-%(id)s.%(ext)s' 'https://youtube.com/embed/dQw4w9WgXcQ' | |
| 44 | - 'Mode: ${provider}': '%switch-provider%' | |
| 45 | ||
| 46 | playlist: | |
| 47 | - Switch view: '%switch-view%' | |
| 48 | - Play all videos: mpv 'https://youtube.com/embed/Z8oiddSsB6I' 'https://youtube.com/embed/yiS0DPekSDQ' 'https://youtube.com/embed/YhM8GYuDFps' # and much more... | |
| 49 | - Play all audio: konsole -e mpv 'https://youtube.com/embed/Z8oiddSsB6I' 'https://youtube.com/embed/yiS0DPekSDQ' 'https://youtube.com/embed/YhM8GYuDFps' --no-video | |
| 50 | - Shuffle play all audio: konsole -e mpv 'https://youtube.com/embed/Z8oiddSsB6I' 'https://youtube.com/embed/yiS0DPekSDQ' 'https://youtube.com/embed/YhM8GYuDFps' --no-video --shuffle | |
| 51 | - Open in browser: firefox 'https://www.youtube.com/playlist?list=PLdgHTasZAjYZlCXN9rTcX9LFOQ-RIrzCs' | |
| 52 | - Download all video (webm): konsole -e yt-dlp -o '~/Downloads/%(title)s-%(id)s.%(ext)s' 'https://youtube.com/embed/Z8oiddSsB6I' 'https://youtube.com/embed/yiS0DPekSDQ' 'https://youtube.com/embed/YhM8GYuDFps' | |
| 53 | - 'Mode: ${provider}': '%switch-provider%' | |
| 54 | ``` | |
| 55 | ||
| 56 | > Global commands can also be used here. (Ones that start with an `:`). | |
| 57 | ||
| 58 | 25 | <hr> |
| 59 | 26 | |
| 60 | Below are the description of each of the fields: | |
| 61 | ||
| 62 | ### video | |
| 27 | The few required fields are: | |
| 63 | 28 | |
| 64 | Commands to be displayed in a video page. | |
| 29 | - `video` | |
| 30 | - `saved_video` | |
| 31 | - `playlist` | |
| 32 | - `saved_playlist` | |
| 65 | 33 | |
| 66 | *Accept: `string_label: string_command` pairs* | |
| 67 | ||
| 68 | ### playlist | |
| 69 | ||
| 70 | Commands to be displayed in a playlist page (commands view). | |
| 34 | ## Env variables | |
| 71 | 35 | |
| 72 | *Accept: `string_label: string_command` pairs* | |
| 36 | Notice that a lot of the commands contains the `${label}` pattern, this actually replaces the text with the env variables set in `main.yml`, or is added by the current page (video or playlist) on-the-go. | |
| 73 | 37 | |
| 74 | ## Env reference | |
| 38 | <!-- Replacing all these with known values it might look something like this: --> | |
| 39 | <!-- --> | |
| 40 | <!-- ```yaml --> | |
| 41 | <!-- launch_command: loadpage popular ;; flush ;; history clear --> | |
| 42 | <!-- video: --> | |
| 43 | <!-- - Play video: mpv 'https://youtube.com/embed/dQw4w9WgXcQ' --> | |
| 44 | <!-- - Play audio: konsole -e mpv 'https://youtube.com/embed/dQw4w9WgXcQ' --no-video --> | |
| 45 | <!-- - Open in browser: firefox 'https://youtu.be/dQw4w9WgXcQ' --> | |
| 46 | <!-- - Download video (webm): konsole -e yt-dlp -o '~/Downloads/%(title)s-%(id)s.%(ext)s' 'https://youtube.com/embed/dQw4w9WgXcQ' --> | |
| 47 | <!-- - 'Mode: ${provider}': '%switch-provider%' --> | |
| 48 | <!-- --> | |
| 49 | <!-- playlist: --> | |
| 50 | <!-- - Switch view: '%switch-view%' --> | |
| 51 | <!-- - Play all videos: mpv 'https://youtube.com/embed/Z8oiddSsB6I' 'https://youtube.com/embed/yiS0DPekSDQ' 'https://youtube.com/embed/YhM8GYuDFps' # and much more... --> | |
| 52 | <!-- - Play all audio: konsole -e mpv 'https://youtube.com/embed/Z8oiddSsB6I' 'https://youtube.com/embed/yiS0DPekSDQ' 'https://youtube.com/embed/YhM8GYuDFps' --no-video --> | |
| 53 | <!-- - Shuffle play all audio: konsole -e mpv 'https://youtube.com/embed/Z8oiddSsB6I' 'https://youtube.com/embed/yiS0DPekSDQ' 'https://youtube.com/embed/YhM8GYuDFps' --no-video --shuffle --> | |
| 54 | <!-- - Open in browser: firefox 'https://www.youtube.com/playlist?list=PLdgHTasZAjYZlCXN9rTcX9LFOQ-RIrzCs' --> | |
| 55 | <!-- - Download all video (webm): konsole -e yt-dlp -o '~/Downloads/%(title)s-%(id)s.%(ext)s' 'https://youtube.com/embed/Z8oiddSsB6I' 'https://youtube.com/embed/yiS0DPekSDQ' 'https://youtube.com/embed/YhM8GYuDFps' --> | |
| 56 | <!-- - 'Mode: ${provider}': '%switch-provider%' --> | |
| 57 | <!-- ``` --> | |
| 58 | ||
| 59 | <!-- > Global commands can also be used here. (Ones that start with an `:`). --> | |
| 60 | ||
| 61 | <!-- Below are the description of each of the fields: --> | |
| 62 | <!-- --> | |
| 63 | <!-- ### video --> | |
| 64 | <!-- --> | |
| 65 | <!-- Commands to be displayed in a video page. --> | |
| 66 | <!-- --> | |
| 67 | <!-- *Accept: `string_label: string_command` pairs* --> | |
| 68 | <!-- --> | |
| 69 | <!-- ### playlist --> | |
| 70 | <!-- --> | |
| 71 | <!-- Commands to be displayed in a playlist page (commands view). --> | |
| 72 | <!-- --> | |
| 73 | <!-- *Accept: `string_label: string_command` pairs* --> | |
| 74 | ||
| 75 | ### Env reference | |
| 75 | 76 | |
| 76 | 77 | Does not include custom env set in `main.yml`. |
| 77 | 78 | |
| @@ -88,3 +89,6 @@ Does not include custom env set in `main.yml`. | ||
| 88 | 89 | |`hover-video-url`|feed|Url of the currenly hovering video.| |
| 89 | 90 | |`hover-video-id`|feed|ID of the currenly hovering video.| |
| 90 | 91 | |`all-ids`|playlist|IDs of all videos in a playlist, separated with space.| |
| 92 | |`offline-path`|Saved video and playlist only|Direct path to saved file.| | |
| 93 | |`mpv-queuelist`|Online playlists only|Valid mpv command to queue all videos in the list.| | |
| 94 | |`offline-queuelist`|Saved playlists only|Valid mpv command to queue all saved videos in the list.| | |
docs/src/config/main.md +23 −10
| @@ -6,20 +6,32 @@ The main config file is located in `~/.config/youtube-tui/main.yml`. | ||
| 6 | 6 | |
| 7 | 7 | ```yaml |
| 8 | 8 | mouse_support: true |
| 9 | invidious_instance: https://y.com.sb | |
| 9 | invidious_instance: https://invidious.fdn.fr | |
| 10 | 10 | write_config: Try |
| 11 | max_watch_history: 50 | |
| 12 | allow_unicode: false | |
| 11 | allow_unicode: true | |
| 13 | 12 | message_bar_default: All good :) |
| 14 | 13 | images: Sixels |
| 15 | 14 | refresh_after_modifying_search_filters: true |
| 15 | syncing: | |
| 16 | download_images: true | |
| 17 | sync_channel_info: true | |
| 18 | sync_channel_cooldown_secs: 86400 | |
| 19 | sync_videos_cooldown_secs: 600 | |
| 20 | limits: | |
| 21 | watch_history: 50 | |
| 22 | search_history: 75 | |
| 23 | commands_history: 75 | |
| 16 | 24 | image_index: 4 |
| 17 | 25 | provider: YouTube |
| 26 | shell: sh | |
| 27 | legacy_input_handling: false | |
| 18 | 28 | env: |
| 19 | browser: firefox | |
| 29 | video-player: mpv | |
| 30 | download-path: ~/Downloads/%(title)s-%(id)s.%(ext)s | |
| 20 | 31 | terminal-emulator: konsole -e |
| 21 | 32 | youtube-downloader: yt-dlp |
| 22 | video-player: mpv | |
| 33 | save-path: ~/.local/share/youtube-tui/saved/ | |
| 34 | browser: firefox | |
| 23 | 35 | ``` |
| 24 | 36 | |
| 25 | 37 | <hr> |
| @@ -52,11 +64,6 @@ Whether to write to config after every read, this allows for auto-formatting the | ||
| 52 | 64 | |
| 53 | 65 | *Accept: `Must`/`Try`/`Dont`* |
| 54 | 66 | |
| 55 | ### max_watch_history | |
| 56 | ||
| 57 | The maximum length that the watch history can hold, a value higher will record more items, but will also result in a larger file size in storage. | |
| 58 | ||
| 59 | *Accept: positive integer below 2<sup>*your CPU architecture*</sup> - 1* | |
| 60 | 67 | |
| 61 | 68 | ### allow_unicode |
| 62 | 69 | |
| @@ -106,6 +113,12 @@ Sync all do not sync videos from channel if it has been synced in the past *n* s | ||
| 106 | 113 | |
| 107 | 114 | *Accept: integer value seconds* |
| 108 | 115 | |
| 116 | ### limits | |
| 117 | ||
| 118 | The maximum length that the watch/search/command history can hold, a value higher will record more items, but will also result in a larger file size in storage. | |
| 119 | ||
| 120 | *Accept: positive integer below 2<sup>*your CPU architecture*</sup> - 1* | |
| 121 | ||
| 109 | 122 | ### image_index |
| 110 | 123 | |
| 111 | 124 | The index in the array of thumbnail qualities you want to download |
docs/src/config/pages.md +2
| @@ -64,3 +64,5 @@ Command to run when the page loads, you can use the `key` command to select an i | ||
| 64 | 64 | |ChannelMain|Channel display|Loads the main channel page| |
| 65 | 65 | |ChannelVideos|Channel display|Loads the channel videos page| |
| 66 | 66 | |ChannelPlaylists|Channel display|Loads the channel playlists page| |
| 67 | |ChannelList|Feed|Displays subscribed channels| | |
| 68 | |VideoList|Feed|Displays videos of subscribed channels| | |
docs/src/config/remap.md added +5
| @@ -0,0 +1,5 @@ | ||
| 1 | # Key remaps | |
| 2 | ||
| 3 | Very old concept of hard remapping one key to another. The config file can be found in `~/.config/youtube-tui/remaps.yml`. | |
| 4 | ||
| 5 | Not recommended using unless you got some issues that prevents certain keys from being pressed. | |
docs/src/config/search.md +21 −1
| @@ -23,8 +23,28 @@ The default query when you launch the TUI. | ||
| 23 | 23 | |
| 24 | 24 | *Accept: any string* |
| 25 | 25 | |
| 26 | ### Sort | |
| 26 | ### sort | |
| 27 | 27 | |
| 28 | 28 | How the search results are sorted. |
| 29 | 29 | |
| 30 | 30 | *Accept: `Relevance`/`Rating`/`Date`/`Views`* |
| 31 | ||
| 32 | ### date | |
| 33 | ||
| 34 | Restrict videos publish date. | |
| 35 | ||
| 36 | *Accept: `None`, `Hour`, `Day`, `Week`, `Month`, `Year`* | |
| 37 | ||
| 38 | ### duration | |
| 39 | ||
| 40 | Restrict videos duration. | |
| 41 | ||
| 42 | *Accept: `None`, `Short`, `Medium`, `Long`* | |
| 43 | ||
| 44 | ### type | |
| 45 | ||
| 46 | Restrict video types | |
| 47 | ||
| 48 | *Accept: `All`, `Video`, `Channel`, `Playlist`* | |
| 49 | ||
| 50 | > All these options can also be changed in runtime using [search filters](basic_usage.md#searching) | |
docs/src/images/search-showcase.png
Binary file not shown.
docs/src/installation.md +6
| @@ -85,3 +85,9 @@ Requires <a href="https://github.com/saitoha/libsixel" target=_blank>`libsixel`< | ||
| 85 | 85 | Allows clipboard pasting in commands and search bar. |
| 86 | 86 | |
| 87 | 87 | Requires <a href="https://xcb.freedesktop.org/" target=_blank>`libxcb`</a>. |
| 88 | ||
| 89 | ### `mpv` (default) | |
| 90 | ||
| 91 | Embedded audio player | |
| 92 | ||
| 93 | Requires <a href="https://mpv.io/" target=_blank>`mpv`</a> (libmpv) to be installed in your system. | |
src/config/commandbindings.rs +1 −1
| @@ -184,7 +184,7 @@ fn global_default() -> HashMap<KeyCodeSerde, HashMap<u8, String>> { | ||
| 184 | 184 | HashMap::from([ |
| 185 | 185 | ( |
| 186 | 186 | 2, |
| 187 | String::from("mpv seek -5 ;; echo mpv Reversed 5 seconds"), | |
| 187 | String::from("mpv seek -5 ;; echo mpv Rewinded 5 seconds"), | |
| 188 | 188 | ), |
| 189 | 189 | (3, String::from("back ;; echo mpv Unskipped")), |
| 190 | 190 | ]), |
src/global/functions/key_input.rs +1 −3
| @@ -2,9 +2,7 @@ use std::{any::TypeId, io::Stdout}; | ||
| 2 | 2 | |
| 3 | 3 | use crossterm::event::KeyEvent; |
| 4 | 4 | use ratatui::{backend::CrosstermBackend, Terminal}; |
| 5 | use tui_additions::{ | |
| 6 | framework::{Framework, FrameworkDirection}, | |
| 7 | }; | |
| 5 | use tui_additions::framework::{Framework, FrameworkDirection}; | |
| 8 | 6 | |
| 9 | 7 | use crate::{config::*, global::structs::*, items::SearchBar}; |
| 10 | 8 | |
src/global/functions/run_command.rs +12
| @@ -303,6 +303,12 @@ pub fn run_single_command( | ||
| 303 | 303 | *framework.data.global.get_mut::<Message>().unwrap() = |
| 304 | 304 | Message::Success(String::from("Copied to clipboad")); |
| 305 | 305 | } |
| 306 | #[cfg(not(feature = "clipboard"))] | |
| 307 | ["copy", ..] => { | |
| 308 | *framework.data.global.get_mut::<Message>().unwrap() = Message::Error(String::from( | |
| 309 | "Feature `clipboard` is disabled and not compiled", | |
| 310 | )); | |
| 311 | } | |
| 306 | 312 | ["sync", identifier] => { |
| 307 | 313 | let id = if identifier.len() == 24 { |
| 308 | 314 | identifier.to_string() |
| @@ -520,6 +526,11 @@ pub fn run_single_command( | ||
| 520 | 526 | _ => unreachable!(), |
| 521 | 527 | }; |
| 522 | 528 | } |
| 529 | #[cfg(not(feature = "mpv"))] | |
| 530 | ["mpv", ..] => { | |
| 531 | *framework.data.global.get_mut::<Message>().unwrap() = | |
| 532 | Message::Error(String::from("Feature `mpv` is disabled and not compiled")); | |
| 533 | } | |
| 523 | 534 | ["echo", r#type, ..] => { |
| 524 | 535 | *framework.data.global.get_mut::<Message>().unwrap() = match *r#type { |
| 525 | 536 | "message" => Message::Message(command[2..].join(" ")), |
| @@ -618,6 +629,7 @@ fn help_msg(cmdefines: &CommandsRemapConfig) -> String { | ||
| 618 | 629 | \x1b[33mparrun [command]\x1b[0m Runs a system command non blocking (e.g. `run firefox example.com`) |
| 619 | 630 | \x1b[33mcopy [text]\x1b[0m Copies text to clipboard |
| 620 | 631 | \x1b[33mkey [keycode] [keymodifier]\x1b[0m Create a key input event |
| 632 | \x1b[33mecho [mode] [message]\x1b[0m Dispalys a message in message bar, mode: none, success, warn, error, mpv (can be overwritten by mpv player) | |
| 621 | 633 | |
| 622 | 634 | \x1b[91mLIBRARY:\x1b[0m |
| 623 | 635 | \x1b[33mbookmark [id]\x1b[0m Bookmark item with ID (item must be already loaded) |
src/global/structs/tasks.rs +31 −31
| @@ -7,7 +7,7 @@ use ratatui::{ | ||
| 7 | 7 | backend::CrosstermBackend, layout::Alignment, style::Style, widgets::Paragraph, Frame, Terminal, |
| 8 | 8 | }; |
| 9 | 9 | use std::{error::Error, io::Stdout, mem}; |
| 10 | use tui_additions::framework::{CursorState, Framework, FrameworkItem}; | |
| 10 | use tui_additions::framework::{CursorState, Framework}; | |
| 11 | 11 | use typemap::Key; |
| 12 | 12 | |
| 13 | 13 | /// tasks to be put on taskqueues |
| @@ -258,36 +258,36 @@ impl TaskQueue { | ||
| 258 | 258 | framework.render(frame); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | pub fn render_filter( | |
| 262 | framework: &mut Framework, | |
| 263 | terminal: &mut Terminal<CrosstermBackend<Stdout>>, | |
| 264 | filter: impl Fn(&Box<dyn FrameworkItem>) -> bool, | |
| 265 | ) -> Result<(), Box<dyn Error>> { | |
| 266 | Self::render_filter_with_frame(framework, &mut terminal.get_frame(), filter); | |
| 267 | terminal.flush()?; | |
| 268 | Ok(()) | |
| 269 | } | |
| 270 | ||
| 271 | pub fn render_filter_with_frame( | |
| 272 | framework: &mut Framework, | |
| 273 | frame: &mut Frame<CrosstermBackend<Stdout>>, | |
| 274 | filter: impl Fn(&Box<dyn FrameworkItem>) -> bool, | |
| 275 | ) { | |
| 276 | let area = frame.size(); | |
| 277 | ||
| 278 | framework | |
| 279 | .data | |
| 280 | .global | |
| 281 | .get_mut::<Status>() | |
| 282 | .unwrap() | |
| 283 | .prev_frame = Some(area); | |
| 284 | ||
| 285 | if Self::protective_screen(framework, frame) { | |
| 286 | return; | |
| 287 | } | |
| 288 | ||
| 289 | framework.render_filter(frame, filter); | |
| 290 | } | |
| 261 | // pub fn render_filter( | |
| 262 | // framework: &mut Framework, | |
| 263 | // terminal: &mut Terminal<CrosstermBackend<Stdout>>, | |
| 264 | // filter: impl Fn(&Box<dyn FrameworkItem>) -> bool, | |
| 265 | // ) -> Result<(), Box<dyn Error>> { | |
| 266 | // Self::render_filter_with_frame(framework, &mut terminal.get_frame(), filter); | |
| 267 | // terminal.flush()?; | |
| 268 | // Ok(()) | |
| 269 | // } | |
| 270 | // | |
| 271 | // pub fn render_filter_with_frame( | |
| 272 | // framework: &mut Framework, | |
| 273 | // frame: &mut Frame<CrosstermBackend<Stdout>>, | |
| 274 | // filter: impl Fn(&Box<dyn FrameworkItem>) -> bool, | |
| 275 | // ) { | |
| 276 | // let area = frame.size(); | |
| 277 | // | |
| 278 | // framework | |
| 279 | // .data | |
| 280 | // .global | |
| 281 | // .get_mut::<Status>() | |
| 282 | // .unwrap() | |
| 283 | // .prev_frame = Some(area); | |
| 284 | // | |
| 285 | // if Self::protective_screen(framework, frame) { | |
| 286 | // return; | |
| 287 | // } | |
| 288 | // | |
| 289 | // framework.render_filter(frame, filter); | |
| 290 | // } | |
| 291 | 291 | |
| 292 | 292 | /// this function renders onto the given frame |
| 293 | 293 | pub fn protective_screen( |
src/items/messagebar.rs +71 −68
| @@ -1,13 +1,12 @@ | ||
| 1 | use crate::{ | |
| 2 | config::*, | |
| 3 | global::{functions::secs_display_string, structs::*}, | |
| 4 | }; | |
| 1 | #[cfg(feature = "mpv")] | |
| 2 | use crate::global::functions::secs_display_string; | |
| 3 | use crate::{config::*, global::structs::*}; | |
| 5 | 4 | use ratatui::{ |
| 6 | 5 | layout::Rect, |
| 7 | 6 | style::Style, |
| 8 | 7 | widgets::{Block, Borders, Paragraph}, |
| 9 | 8 | }; |
| 10 | use tui_additions::framework::{FrameworkClean, FrameworkItem}; | |
| 9 | use tui_additions::framework::*; | |
| 11 | 10 | |
| 12 | 11 | /// a message bar item, contains no fields because the message is taken from `data.global.Message` |
| 13 | 12 | #[derive(Clone, Copy, Default)] |
| @@ -26,72 +25,75 @@ impl FrameworkItem for MessageBar { | ||
| 26 | 25 | return; |
| 27 | 26 | } |
| 28 | 27 | |
| 29 | let mpv = framework.data.global.get::<MpvWrapper>().unwrap(); | |
| 30 | if Self::is_mpv_render(framework) { | |
| 31 | let mut label = mpv.property("media-title".to_string()).unwrap(); | |
| 32 | if let Some((name, ext)) = label.rsplit_once('.') { | |
| 33 | if ext.len() < 5 | |
| 34 | && !name.len() > 13 | |
| 35 | && &name[name.len() - 1..name.len()] == "]" | |
| 36 | && name[name.len() - 12..name.len() - 1] | |
| 37 | .chars() | |
| 38 | .all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_')) | |
| 39 | && &name[name.len() - 13..name.len() - 12] == "[" | |
| 40 | { | |
| 41 | label = name[0..name.len() - 13].to_string(); | |
| 28 | #[cfg(feature = "mpv")] | |
| 29 | { | |
| 30 | let mpv = framework.data.global.get::<MpvWrapper>().unwrap(); | |
| 31 | if Self::is_mpv_render(framework) { | |
| 32 | let mut label = mpv.property("media-title".to_string()).unwrap(); | |
| 33 | if let Some((name, ext)) = label.rsplit_once('.') { | |
| 34 | if ext.len() < 5 | |
| 35 | && !name.len() > 13 | |
| 36 | && &name[name.len() - 1..name.len()] == "]" | |
| 37 | && name[name.len() - 12..name.len() - 1] | |
| 38 | .chars() | |
| 39 | .all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '_')) | |
| 40 | && &name[name.len() - 13..name.len() - 12] == "[" | |
| 41 | { | |
| 42 | label = name[0..name.len() - 13].to_string(); | |
| 43 | } | |
| 42 | 44 | } |
| 43 | } | |
| 44 | let duration = mpv | |
| 45 | .property("duration".to_string()) | |
| 46 | .unwrap_or_default() | |
| 47 | .parse::<f64>() | |
| 48 | .unwrap() as u64; | |
| 49 | let duration_s = secs_display_string(duration as u32); | |
| 50 | let playerhead = mpv | |
| 51 | .property("time-pos".to_string()) | |
| 52 | .unwrap_or_default() | |
| 53 | .parse::<f64>() | |
| 54 | .unwrap() as u64; | |
| 55 | let mut playerhead_s = secs_display_string(playerhead as u32); | |
| 56 | if playerhead_s.len() != duration_s.len() { | |
| 57 | playerhead_s = format!( | |
| 58 | "{}{playerhead_s}", | |
| 59 | " ".repeat(duration_s.len() - playerhead_s.len()) | |
| 60 | ); | |
| 61 | } | |
| 62 | let percentage = (playerhead * 100 / duration).to_string(); | |
| 45 | let duration = mpv | |
| 46 | .property("duration".to_string()) | |
| 47 | .unwrap_or_default() | |
| 48 | .parse::<f64>() | |
| 49 | .unwrap() as u64; | |
| 50 | let duration_s = secs_display_string(duration as u32); | |
| 51 | let playerhead = mpv | |
| 52 | .property("time-pos".to_string()) | |
| 53 | .unwrap_or_default() | |
| 54 | .parse::<f64>() | |
| 55 | .unwrap() as u64; | |
| 56 | let mut playerhead_s = secs_display_string(playerhead as u32); | |
| 57 | if playerhead_s.len() != duration_s.len() { | |
| 58 | playerhead_s = format!( | |
| 59 | "{}{playerhead_s}", | |
| 60 | " ".repeat(duration_s.len() - playerhead_s.len()) | |
| 61 | ); | |
| 62 | } | |
| 63 | let percentage = (playerhead * 100 / duration).to_string(); | |
| 63 | 64 | |
| 64 | let right_chunk = format!( | |
| 65 | "{playerhead_s}/{duration_s} {}[{percentage}%]", | |
| 66 | " ".repeat(3 - percentage.len()) | |
| 67 | ); | |
| 68 | let left_chunk = format!("[Now Playing]: {label}"); | |
| 69 | let length = area.width as usize - 2; | |
| 70 | let total_len = right_chunk.len() + left_chunk.len(); | |
| 65 | let right_chunk = format!( | |
| 66 | "{playerhead_s}/{duration_s} {}[{percentage}%]", | |
| 67 | " ".repeat(3 - percentage.len()) | |
| 68 | ); | |
| 69 | let left_chunk = format!("[Now Playing]: {label}"); | |
| 70 | let length = area.width as usize - 2; | |
| 71 | let total_len = right_chunk.len() + left_chunk.len(); | |
| 71 | 72 | |
| 72 | *framework.data.global.get_mut::<Message>().unwrap() = | |
| 73 | Message::Mpv(if length > total_len + 6 { | |
| 74 | let mut seeker_len = length - total_len - 4; | |
| 75 | let seeker_pad = if seeker_len > 10 { seeker_len / 10 } else { 0 }; | |
| 76 | seeker_len -= seeker_pad * 2; | |
| 77 | let seeker_pos = (seeker_len - 1) * playerhead as usize / duration as usize; | |
| 78 | format!( | |
| 79 | "{left_chunk} {}├{}-{}┤{} {right_chunk}", | |
| 80 | " ".repeat(seeker_pad), | |
| 81 | "─".repeat(seeker_pos), | |
| 82 | "─".repeat(seeker_len - seeker_pos - 1), | |
| 83 | " ".repeat(seeker_pad) | |
| 84 | ) | |
| 85 | } else if length > total_len + 3 { | |
| 86 | format!( | |
| 87 | "{left_chunk}{}{right_chunk}", | |
| 88 | " ".repeat(length - total_len) | |
| 89 | ) | |
| 90 | } else if length > 19 { | |
| 91 | left_chunk | |
| 92 | } else { | |
| 93 | String::from("Not enough width") | |
| 94 | }); | |
| 73 | *framework.data.global.get_mut::<Message>().unwrap() = | |
| 74 | Message::Mpv(if length > total_len + 6 { | |
| 75 | let mut seeker_len = length - total_len - 4; | |
| 76 | let seeker_pad = if seeker_len > 10 { seeker_len / 10 } else { 0 }; | |
| 77 | seeker_len -= seeker_pad * 2; | |
| 78 | let seeker_pos = (seeker_len - 1) * playerhead as usize / duration as usize; | |
| 79 | format!( | |
| 80 | "{left_chunk} {}├{}-{}┤{} {right_chunk}", | |
| 81 | " ".repeat(seeker_pad), | |
| 82 | "─".repeat(seeker_pos), | |
| 83 | "─".repeat(seeker_len - seeker_pos - 1), | |
| 84 | " ".repeat(seeker_pad) | |
| 85 | ) | |
| 86 | } else if length > total_len + 3 { | |
| 87 | format!( | |
| 88 | "{left_chunk}{}{right_chunk}", | |
| 89 | " ".repeat(length - total_len) | |
| 90 | ) | |
| 91 | } else if length > 19 { | |
| 92 | left_chunk | |
| 93 | } else { | |
| 94 | String::from("Not enough width") | |
| 95 | }); | |
| 96 | } | |
| 95 | 97 | } |
| 96 | 98 | |
| 97 | 99 | let message = framework.data.global.get::<Message>().unwrap(); |
| @@ -156,6 +158,7 @@ impl FrameworkItem for MessageBar { | ||
| 156 | 158 | } |
| 157 | 159 | } |
| 158 | 160 | |
| 161 | #[cfg(feature = "mpv")] | |
| 159 | 162 | impl MessageBar { |
| 160 | 163 | pub fn is_mpv_render(framework: &FrameworkClean) -> bool { |
| 161 | 164 | framework.data.global.get::<MpvWrapper>().unwrap().playing() |
src/run.rs +7 −7
| @@ -1,17 +1,14 @@ | ||
| 1 | 1 | use crossterm::event::{self, Event, MouseButton, MouseEventKind}; |
| 2 | 2 | use ratatui::{backend::CrosstermBackend, Terminal}; |
| 3 | use std::{ | |
| 4 | any::TypeId, | |
| 5 | error::Error, | |
| 6 | io::Stdout, | |
| 7 | time::{Duration, Instant}, | |
| 8 | }; | |
| 3 | #[cfg(feature = "mpv")] | |
| 4 | use std::time::{Duration, Instant}; | |
| 5 | use std::{any::TypeId, error::Error, io::Stdout}; | |
| 9 | 6 | use tui_additions::framework::Framework; |
| 10 | 7 | |
| 11 | 8 | use crate::{ |
| 12 | 9 | config::*, |
| 13 | 10 | global::{functions::*, structs::*}, |
| 14 | items::{MessageBar, SearchFilter}, | |
| 11 | items::*, | |
| 15 | 12 | }; |
| 16 | 13 | |
| 17 | 14 | /// the main event loop of the program |
| @@ -19,7 +16,9 @@ pub fn run( | ||
| 19 | 16 | terminal: &mut Terminal<CrosstermBackend<Stdout>>, |
| 20 | 17 | framework: &mut Framework, |
| 21 | 18 | ) -> Result<(), Box<dyn Error>> { |
| 19 | #[cfg(feature = "mpv")] | |
| 22 | 20 | let tick_rate = Duration::from_secs(1); |
| 21 | #[cfg(feature = "mpv")] | |
| 23 | 22 | let mut last_tick = Instant::now(); |
| 24 | 23 | loop { |
| 25 | 24 | // repeat forever until all tasks are ran (and Tasks is cleared) |
| @@ -41,6 +40,7 @@ pub fn run( | ||
| 41 | 40 | break; |
| 42 | 41 | } |
| 43 | 42 | |
| 43 | #[cfg(feature = "mpv")] | |
| 44 | 44 | if !event::poll( |
| 45 | 45 | tick_rate |
| 46 | 46 | .checked_sub(last_tick.elapsed()) |