├── .gitignore ├── CONFIGURATION.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── flake.lock ├── flake.nix ├── images ├── artist_search.png ├── inori-logo-white.svg ├── inori-logo.svg ├── library.png ├── queue.png └── search.png ├── pkgs ├── default.nix ├── inori-logo │ ├── default.nix │ └── src │ │ └── inori-logo.tex └── inori │ └── default.nix ├── rustfmt.toml └── src ├── config.rs ├── config └── keybind.rs ├── event_handler.rs ├── main.rs ├── model.rs ├── model ├── impl_album_song.rs ├── impl_artiststate.rs ├── impl_library.rs ├── impl_queue.rs ├── impl_searchstate.rs ├── proto.rs └── search_utils.rs ├── update.rs ├── update ├── build_library.rs ├── handlers.rs ├── handlers │ ├── library_handler.rs │ └── queue_handler.rs └── updaters.rs ├── util.rs ├── view.rs └── view ├── artist_select_renderer.rs ├── layout.rs ├── layout ├── library_layout.rs └── queue_layout.rs ├── library_renderer.rs ├── queue_renderer.rs ├── search_renderer.rs ├── status_renderer.rs └── track_select_renderer.rs /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | .direnv/ 3 | .envrc 4 | .dir-locals.el 5 | result 6 | -------------------------------------------------------------------------------- /CONFIGURATION.md: -------------------------------------------------------------------------------- 1 | # Configuration 2 | 3 | The config file is read from `/inori/config.toml`. 4 | On GNU/Linux and macOS, this is `$XDG_CONFIG_HOME/inori/config.toml` or `$HOME/.config/inori/config.toml`. 5 | For other operating systems, check the 6 | [platform-dirs documentation](https://docs.rs/platform-dirs/latest/platform_dirs/). 7 | 8 | ## General 9 | 10 | - `mpd_address` 11 | - Type: String 12 | - Default: `localhost:6600` 13 | - The host and port to check for mpd. Alternatively you can set the 14 | `MPD_HOST` and `MPD_PORT` environment variables. Note that the 15 | configuration option currently has precedence. 16 | - `seek_seconds` 17 | - Type: 64-bit integer 18 | - Default: 5 19 | - The time in seconds to seek by when using the `seek` and `seek_backwards` command 20 | - `screens` 21 | - Type: Array of strings 22 | - Default: `["library", "queue"]` 23 | - Defines the screens mapped by keybindings. The first screen in the 24 | array is the initial startup screen. The last screen is the initial 25 | screen that `toggle_screen` (default: ``) toggles to. 26 | - The only two currently available screens are `"library"` and `"queue"`. 27 | - `nucleo_prefer_prefix` 28 | - See [relevant nucleo docs](https://docs.rs/nucleo/latest/nucleo/struct.Config.html#structfield.prefer_prefix). 29 | 30 | ## Keybindings 31 | 32 | ### Keybinding sets 33 | 34 | inori comes with sensible default keybindings for some commands. It 35 | also includes two extra sets for convenience to hopefully suit most 36 | users. 37 | 38 | To enable the dvorak set, use 39 | 40 | ```toml 41 | dvorak_keybindings = true 42 | ``` 43 | 44 | and likewise, to enable the qwerty set, use 45 | 46 | ```toml 47 | qwerty_keybindings = true 48 | ``` 49 | 50 | Note that if both are set to true, the option set last will shadow the 51 | option set first. 52 | 53 | In general, the dvorak set will be more familiar to emacs users (this 54 | is what I personally use), and the qwerty set will be familiar to vim 55 | users. 56 | 57 | ### Keybinding syntax 58 | 59 | Keybindings set in the config file _override_ the defaults if they are 60 | set, but do not delete them. 61 | 62 | Keybindings should be defined in a toml table called `keybindings` like 63 | so: 64 | 65 | ```toml 66 | [keybindings] 67 | command1 = "KEYSTR1" 68 | command2 = "KEYSTR2" 69 | ``` 70 | 71 | where a `"KEYSTR"` describes a keybinding with the following format that 72 | will be reminiscent to emacs users: 73 | 74 | ``` 75 | KEYSTR := | 76 | KEYBIND := 77 | MODIFIER := C- | M- | S- | C-M- | "" 78 | CHARACTER := char | 79 | SPECIAL_KEY := 80 | | 81 | | 82 | | 83 | | 84 | | 85 | | 86 | | 87 | | 88 | | 89 | | 90 | | 91 | | 92 | | 93 | ``` 94 | 95 | Each of the modifiers corresponds to a modifier key, `CTRL, META, 96 | SUPER, CTRL+META`. So, your keybindings will look like `g g` or `C-c 97 | C-n` or `C-` 98 | 99 | You can create multiple keybinds for the same command using an array 100 | of `KEYSTR`: 101 | 102 | ```toml 103 | [keybindings] 104 | command1 = ["KEYSTR1", "KEYSTR2"] 105 | ``` 106 | 107 | ### List of commands and defaults 108 | 109 | | Command name | Explanation | default | dvorak set | qwerty set | 110 | | ------------------ | -------------------------------------------------------------------- | ------------- | ---------- | ---------- | 111 | | `up` | move up | ``, C-p | t | k | 112 | | `down` | move down | ``, C-n | h | j | 113 | | `left` | move left | `` | d | h | 114 | | `right` | move right | `` | n | l | 115 | | `top` | jump to top | `` | < | g g | 116 | | `bottom` | jump to bottom | `` | > | G | 117 | | `screenful_up` | scroll down one page, cursor to first line | `` | M-v | C-b | 118 | | `screenful_down` | scroll up one page, cursor to last line | `` | C-v | C-f | 119 | | `toggle_playpause` | toggles between play and pause | p | | | 120 | | `next song` | jumps to the next song in the queue | | | | 121 | | `previous song` | jumps to the previous song in the queue | | | | 122 | | `seek` | seeks forward by 5 seconds | | | | 123 | | `seek_backwards` | seeks backwards by 5 seconds | | | | 124 | | `select` | act on the selected entry | `` | | | 125 | | `quit` | close the program | q | | | 126 | | `screen_1` | switch to screen 1 (default: library) | 1 | | | 127 | | `screen_2` | switch to screen 2 (default: queue) | 2 | | | 128 | | `toggle_screen` | toggle between your last two used screens (default: library & queue) | `` | | | 129 | | `toggle_panel` | [library] switch between artist and track selector | | | | 130 | | `fold` | [library/track] toggle fold album | `` | | | 131 | | `clear_queue` | clear queue | - | | | 132 | | `local_search` | search local selector | / | | | 133 | | `global_search` | [library] global jumping search | C-s | g | C-g | 134 | | `escape` | escape | `` | C-g | | 135 | | `delete` | [queue] deletes the selected item off queue | `` | | | 136 | | `toggle_repeat` | toggle repeat | r | | | 137 | | `toggle_single` | toggle single | s | | | 138 | | `toggle_consume` | toggle consume | c | | | 139 | | `toggle_random` | toggle random | z | | | 140 | | `update_db` | update mpd db | u | | | 141 | 142 | Note that the dvorak/qwerty sets _do not_ delete the default 143 | keybindings. 144 | 145 | ## Theme 146 | 147 | Colors should be specified in a table called "theme", like this: 148 | 149 | ```toml 150 | [theme.item_to_color] 151 | fg = "" 152 | bg = "" 153 | add_modifier = [""] 154 | sub_modifier = [""] 155 | ``` 156 | 157 | All fields are optional. `` should be one of 158 | 159 | - rgb hex: `#FF0000` 160 | - [ansi escape index](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit): `9` 161 | - ansi color code: `White`, `Red`, `LightCyan`, etc 162 | 163 | `` should be one of: 164 | 165 | - BOLD 166 | - DIM 167 | - ITALIC 168 | - UNDERLINED 169 | - SLOW_BLINK 170 | - RAPID_BLINK 171 | - REVERSED 172 | - HIDDEN 173 | - CROSSED_OUT 174 | 175 | For example, you might write `add_modifier = ["BOLD", "ITALIC"]`. 176 | 177 | Here is the full list of styles available for customization: 178 | 179 | | Name | Explanation | 180 | | ------------------------- | ---------------------------------------------- | 181 | | `block_active` | active block border style | 182 | | `field_album` | generic album (track selection, queue) | 183 | | `field_artistsort` | albumartistsort field in fuzzy search displays | 184 | | `item_highlight_active` | selected item in an active list | 185 | | `item_highlight_inactive` | selected item in an inactive list | 186 | | `search_query_active` | search query text when the search is active | 187 | | `search_query_inactive` | search query text when the search is inactive | 188 | | `slash_span` | the slashes in global search | 189 | | `status_album` | album text in status | 190 | | `status_artist` | artist text in status | 191 | | `status_paused` | the "paused" text in status | 192 | | `status_playing` | the "playing" text in status | 193 | | `status_stopped` | the "stopped" text in status | 194 | | `status_title` | title text in status | 195 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "ahash" 7 | version = "0.8.11" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" 10 | dependencies = [ 11 | "cfg-if", 12 | "once_cell", 13 | "version_check", 14 | "zerocopy", 15 | ] 16 | 17 | [[package]] 18 | name = "allocator-api2" 19 | version = "0.2.18" 20 | source = "registry+https://github.com/rust-lang/crates.io-index" 21 | checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" 22 | 23 | [[package]] 24 | name = "autocfg" 25 | version = "1.3.0" 26 | source = "registry+https://github.com/rust-lang/crates.io-index" 27 | checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" 28 | 29 | [[package]] 30 | name = "bitflags" 31 | version = "2.6.0" 32 | source = "registry+https://github.com/rust-lang/crates.io-index" 33 | checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" 34 | dependencies = [ 35 | "serde", 36 | ] 37 | 38 | [[package]] 39 | name = "bufstream" 40 | version = "0.1.4" 41 | source = "registry+https://github.com/rust-lang/crates.io-index" 42 | checksum = "40e38929add23cdf8a366df9b0e088953150724bcbe5fc330b0d8eb3b328eec8" 43 | 44 | [[package]] 45 | name = "cassowary" 46 | version = "0.3.0" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53" 49 | 50 | [[package]] 51 | name = "castaway" 52 | version = "0.2.3" 53 | source = "registry+https://github.com/rust-lang/crates.io-index" 54 | checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" 55 | dependencies = [ 56 | "rustversion", 57 | ] 58 | 59 | [[package]] 60 | name = "cfg-if" 61 | version = "1.0.0" 62 | source = "registry+https://github.com/rust-lang/crates.io-index" 63 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 64 | 65 | [[package]] 66 | name = "compact_str" 67 | version = "0.8.1" 68 | source = "registry+https://github.com/rust-lang/crates.io-index" 69 | checksum = "3b79c4069c6cad78e2e0cdfcbd26275770669fb39fd308a752dc110e83b9af32" 70 | dependencies = [ 71 | "castaway", 72 | "cfg-if", 73 | "itoa", 74 | "rustversion", 75 | "ryu", 76 | "serde", 77 | "static_assertions", 78 | ] 79 | 80 | [[package]] 81 | name = "crossterm" 82 | version = "0.28.1" 83 | source = "registry+https://github.com/rust-lang/crates.io-index" 84 | checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" 85 | dependencies = [ 86 | "bitflags", 87 | "crossterm_winapi", 88 | "mio", 89 | "parking_lot", 90 | "rustix", 91 | "signal-hook", 92 | "signal-hook-mio", 93 | "winapi", 94 | ] 95 | 96 | [[package]] 97 | name = "crossterm_winapi" 98 | version = "0.9.1" 99 | source = "registry+https://github.com/rust-lang/crates.io-index" 100 | checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" 101 | dependencies = [ 102 | "winapi", 103 | ] 104 | 105 | [[package]] 106 | name = "darling" 107 | version = "0.20.11" 108 | source = "registry+https://github.com/rust-lang/crates.io-index" 109 | checksum = "fc7f46116c46ff9ab3eb1597a45688b6715c6e628b5c133e288e709a29bcb4ee" 110 | dependencies = [ 111 | "darling_core", 112 | "darling_macro", 113 | ] 114 | 115 | [[package]] 116 | name = "darling_core" 117 | version = "0.20.11" 118 | source = "registry+https://github.com/rust-lang/crates.io-index" 119 | checksum = "0d00b9596d185e565c2207a0b01f8bd1a135483d02d9b7b0a54b11da8d53412e" 120 | dependencies = [ 121 | "fnv", 122 | "ident_case", 123 | "proc-macro2", 124 | "quote", 125 | "strsim", 126 | "syn", 127 | ] 128 | 129 | [[package]] 130 | name = "darling_macro" 131 | version = "0.20.11" 132 | source = "registry+https://github.com/rust-lang/crates.io-index" 133 | checksum = "fc34b93ccb385b40dc71c6fceac4b2ad23662c7eeb248cf10d529b7e055b6ead" 134 | dependencies = [ 135 | "darling_core", 136 | "quote", 137 | "syn", 138 | ] 139 | 140 | [[package]] 141 | name = "dirs" 142 | version = "5.0.1" 143 | source = "registry+https://github.com/rust-lang/crates.io-index" 144 | checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225" 145 | dependencies = [ 146 | "dirs-sys", 147 | ] 148 | 149 | [[package]] 150 | name = "dirs-next" 151 | version = "1.0.2" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | checksum = "cf36e65a80337bea855cd4ef9b8401ffce06a7baedf2e85ec467b1ac3f6e82b6" 154 | dependencies = [ 155 | "cfg-if", 156 | "dirs-sys-next", 157 | ] 158 | 159 | [[package]] 160 | name = "dirs-sys" 161 | version = "0.4.1" 162 | source = "registry+https://github.com/rust-lang/crates.io-index" 163 | checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c" 164 | dependencies = [ 165 | "libc", 166 | "option-ext", 167 | "redox_users", 168 | "windows-sys 0.48.0", 169 | ] 170 | 171 | [[package]] 172 | name = "dirs-sys-next" 173 | version = "0.1.2" 174 | source = "registry+https://github.com/rust-lang/crates.io-index" 175 | checksum = "4ebda144c4fe02d1f7ea1a7d9641b6fc6b580adcfa024ae48797ecdeb6825b4d" 176 | dependencies = [ 177 | "libc", 178 | "redox_users", 179 | "winapi", 180 | ] 181 | 182 | [[package]] 183 | name = "either" 184 | version = "1.13.0" 185 | source = "registry+https://github.com/rust-lang/crates.io-index" 186 | checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" 187 | 188 | [[package]] 189 | name = "equivalent" 190 | version = "1.0.1" 191 | source = "registry+https://github.com/rust-lang/crates.io-index" 192 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" 193 | 194 | [[package]] 195 | name = "errno" 196 | version = "0.3.11" 197 | source = "registry+https://github.com/rust-lang/crates.io-index" 198 | checksum = "976dd42dc7e85965fe702eb8164f21f450704bdde31faefd6471dba214cb594e" 199 | dependencies = [ 200 | "libc", 201 | "windows-sys 0.59.0", 202 | ] 203 | 204 | [[package]] 205 | name = "fnv" 206 | version = "1.0.7" 207 | source = "registry+https://github.com/rust-lang/crates.io-index" 208 | checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 209 | 210 | [[package]] 211 | name = "getrandom" 212 | version = "0.2.15" 213 | source = "registry+https://github.com/rust-lang/crates.io-index" 214 | checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" 215 | dependencies = [ 216 | "cfg-if", 217 | "libc", 218 | "wasi", 219 | ] 220 | 221 | [[package]] 222 | name = "hashbrown" 223 | version = "0.14.5" 224 | source = "registry+https://github.com/rust-lang/crates.io-index" 225 | checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" 226 | dependencies = [ 227 | "ahash", 228 | "allocator-api2", 229 | ] 230 | 231 | [[package]] 232 | name = "heck" 233 | version = "0.5.0" 234 | source = "registry+https://github.com/rust-lang/crates.io-index" 235 | checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 236 | 237 | [[package]] 238 | name = "ident_case" 239 | version = "1.0.1" 240 | source = "registry+https://github.com/rust-lang/crates.io-index" 241 | checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" 242 | 243 | [[package]] 244 | name = "indexmap" 245 | version = "2.4.0" 246 | source = "registry+https://github.com/rust-lang/crates.io-index" 247 | checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" 248 | dependencies = [ 249 | "equivalent", 250 | "hashbrown", 251 | ] 252 | 253 | [[package]] 254 | name = "indoc" 255 | version = "2.0.6" 256 | source = "registry+https://github.com/rust-lang/crates.io-index" 257 | checksum = "f4c7245a08504955605670dbf141fceab975f15ca21570696aebe9d2e71576bd" 258 | 259 | [[package]] 260 | name = "inori" 261 | version = "0.2.5" 262 | dependencies = [ 263 | "bitflags", 264 | "inori-mpd", 265 | "itertools 0.14.0", 266 | "nucleo-matcher", 267 | "platform-dirs", 268 | "ratatui", 269 | "toml", 270 | ] 271 | 272 | [[package]] 273 | name = "inori-mpd" 274 | version = "0.2.2" 275 | source = "registry+https://github.com/rust-lang/crates.io-index" 276 | checksum = "a12ad4d5a500546b58fa9f4654a5852a37a40a48909988e5fbd22bfc9f6b8bbd" 277 | dependencies = [ 278 | "bufstream", 279 | "dirs", 280 | "itertools 0.13.0", 281 | ] 282 | 283 | [[package]] 284 | name = "instability" 285 | version = "0.3.7" 286 | source = "registry+https://github.com/rust-lang/crates.io-index" 287 | checksum = "0bf9fed6d91cfb734e7476a06bde8300a1b94e217e1b523b6f0cd1a01998c71d" 288 | dependencies = [ 289 | "darling", 290 | "indoc", 291 | "proc-macro2", 292 | "quote", 293 | "syn", 294 | ] 295 | 296 | [[package]] 297 | name = "itertools" 298 | version = "0.13.0" 299 | source = "registry+https://github.com/rust-lang/crates.io-index" 300 | checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" 301 | dependencies = [ 302 | "either", 303 | ] 304 | 305 | [[package]] 306 | name = "itertools" 307 | version = "0.14.0" 308 | source = "registry+https://github.com/rust-lang/crates.io-index" 309 | checksum = "2b192c782037fadd9cfa75548310488aabdbf3d2da73885b31bd0abd03351285" 310 | dependencies = [ 311 | "either", 312 | ] 313 | 314 | [[package]] 315 | name = "itoa" 316 | version = "1.0.11" 317 | source = "registry+https://github.com/rust-lang/crates.io-index" 318 | checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" 319 | 320 | [[package]] 321 | name = "libc" 322 | version = "0.2.172" 323 | source = "registry+https://github.com/rust-lang/crates.io-index" 324 | checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa" 325 | 326 | [[package]] 327 | name = "libredox" 328 | version = "0.1.3" 329 | source = "registry+https://github.com/rust-lang/crates.io-index" 330 | checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d" 331 | dependencies = [ 332 | "bitflags", 333 | "libc", 334 | ] 335 | 336 | [[package]] 337 | name = "linux-raw-sys" 338 | version = "0.4.15" 339 | source = "registry+https://github.com/rust-lang/crates.io-index" 340 | checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" 341 | 342 | [[package]] 343 | name = "lock_api" 344 | version = "0.4.12" 345 | source = "registry+https://github.com/rust-lang/crates.io-index" 346 | checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" 347 | dependencies = [ 348 | "autocfg", 349 | "scopeguard", 350 | ] 351 | 352 | [[package]] 353 | name = "log" 354 | version = "0.4.22" 355 | source = "registry+https://github.com/rust-lang/crates.io-index" 356 | checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" 357 | 358 | [[package]] 359 | name = "lru" 360 | version = "0.12.4" 361 | source = "registry+https://github.com/rust-lang/crates.io-index" 362 | checksum = "37ee39891760e7d94734f6f63fedc29a2e4a152f836120753a72503f09fcf904" 363 | dependencies = [ 364 | "hashbrown", 365 | ] 366 | 367 | [[package]] 368 | name = "memchr" 369 | version = "2.7.4" 370 | source = "registry+https://github.com/rust-lang/crates.io-index" 371 | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" 372 | 373 | [[package]] 374 | name = "mio" 375 | version = "1.0.3" 376 | source = "registry+https://github.com/rust-lang/crates.io-index" 377 | checksum = "2886843bf800fba2e3377cff24abf6379b4c4d5c6681eaf9ea5b0d15090450bd" 378 | dependencies = [ 379 | "libc", 380 | "log", 381 | "wasi", 382 | "windows-sys 0.52.0", 383 | ] 384 | 385 | [[package]] 386 | name = "nucleo-matcher" 387 | version = "0.3.1" 388 | source = "registry+https://github.com/rust-lang/crates.io-index" 389 | checksum = "bf33f538733d1a5a3494b836ba913207f14d9d4a1d3cd67030c5061bdd2cac85" 390 | dependencies = [ 391 | "memchr", 392 | "unicode-segmentation", 393 | ] 394 | 395 | [[package]] 396 | name = "once_cell" 397 | version = "1.19.0" 398 | source = "registry+https://github.com/rust-lang/crates.io-index" 399 | checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" 400 | 401 | [[package]] 402 | name = "option-ext" 403 | version = "0.2.0" 404 | source = "registry+https://github.com/rust-lang/crates.io-index" 405 | checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" 406 | 407 | [[package]] 408 | name = "parking_lot" 409 | version = "0.12.3" 410 | source = "registry+https://github.com/rust-lang/crates.io-index" 411 | checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" 412 | dependencies = [ 413 | "lock_api", 414 | "parking_lot_core", 415 | ] 416 | 417 | [[package]] 418 | name = "parking_lot_core" 419 | version = "0.9.10" 420 | source = "registry+https://github.com/rust-lang/crates.io-index" 421 | checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" 422 | dependencies = [ 423 | "cfg-if", 424 | "libc", 425 | "redox_syscall", 426 | "smallvec", 427 | "windows-targets 0.52.6", 428 | ] 429 | 430 | [[package]] 431 | name = "paste" 432 | version = "1.0.15" 433 | source = "registry+https://github.com/rust-lang/crates.io-index" 434 | checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" 435 | 436 | [[package]] 437 | name = "platform-dirs" 438 | version = "0.3.0" 439 | source = "registry+https://github.com/rust-lang/crates.io-index" 440 | checksum = "e188d043c1a692985f78b5464853a263f1a27e5bd6322bad3a4078ee3c998a38" 441 | dependencies = [ 442 | "dirs-next", 443 | ] 444 | 445 | [[package]] 446 | name = "proc-macro2" 447 | version = "1.0.95" 448 | source = "registry+https://github.com/rust-lang/crates.io-index" 449 | checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" 450 | dependencies = [ 451 | "unicode-ident", 452 | ] 453 | 454 | [[package]] 455 | name = "quote" 456 | version = "1.0.40" 457 | source = "registry+https://github.com/rust-lang/crates.io-index" 458 | checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" 459 | dependencies = [ 460 | "proc-macro2", 461 | ] 462 | 463 | [[package]] 464 | name = "ratatui" 465 | version = "0.29.0" 466 | source = "registry+https://github.com/rust-lang/crates.io-index" 467 | checksum = "eabd94c2f37801c20583fc49dd5cd6b0ba68c716787c2dd6ed18571e1e63117b" 468 | dependencies = [ 469 | "bitflags", 470 | "cassowary", 471 | "compact_str", 472 | "crossterm", 473 | "indoc", 474 | "instability", 475 | "itertools 0.13.0", 476 | "lru", 477 | "paste", 478 | "serde", 479 | "strum", 480 | "unicode-segmentation", 481 | "unicode-truncate", 482 | "unicode-width 0.2.0", 483 | ] 484 | 485 | [[package]] 486 | name = "redox_syscall" 487 | version = "0.5.3" 488 | source = "registry+https://github.com/rust-lang/crates.io-index" 489 | checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" 490 | dependencies = [ 491 | "bitflags", 492 | ] 493 | 494 | [[package]] 495 | name = "redox_users" 496 | version = "0.4.6" 497 | source = "registry+https://github.com/rust-lang/crates.io-index" 498 | checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43" 499 | dependencies = [ 500 | "getrandom", 501 | "libredox", 502 | "thiserror", 503 | ] 504 | 505 | [[package]] 506 | name = "rustix" 507 | version = "0.38.44" 508 | source = "registry+https://github.com/rust-lang/crates.io-index" 509 | checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" 510 | dependencies = [ 511 | "bitflags", 512 | "errno", 513 | "libc", 514 | "linux-raw-sys", 515 | "windows-sys 0.59.0", 516 | ] 517 | 518 | [[package]] 519 | name = "rustversion" 520 | version = "1.0.17" 521 | source = "registry+https://github.com/rust-lang/crates.io-index" 522 | checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" 523 | 524 | [[package]] 525 | name = "ryu" 526 | version = "1.0.18" 527 | source = "registry+https://github.com/rust-lang/crates.io-index" 528 | checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" 529 | 530 | [[package]] 531 | name = "scopeguard" 532 | version = "1.2.0" 533 | source = "registry+https://github.com/rust-lang/crates.io-index" 534 | checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" 535 | 536 | [[package]] 537 | name = "serde" 538 | version = "1.0.209" 539 | source = "registry+https://github.com/rust-lang/crates.io-index" 540 | checksum = "99fce0ffe7310761ca6bf9faf5115afbc19688edd00171d81b1bb1b116c63e09" 541 | dependencies = [ 542 | "serde_derive", 543 | ] 544 | 545 | [[package]] 546 | name = "serde_derive" 547 | version = "1.0.209" 548 | source = "registry+https://github.com/rust-lang/crates.io-index" 549 | checksum = "a5831b979fd7b5439637af1752d535ff49f4860c0f341d1baeb6faf0f4242170" 550 | dependencies = [ 551 | "proc-macro2", 552 | "quote", 553 | "syn", 554 | ] 555 | 556 | [[package]] 557 | name = "serde_spanned" 558 | version = "0.6.7" 559 | source = "registry+https://github.com/rust-lang/crates.io-index" 560 | checksum = "eb5b1b31579f3811bf615c144393417496f152e12ac8b7663bf664f4a815306d" 561 | dependencies = [ 562 | "serde", 563 | ] 564 | 565 | [[package]] 566 | name = "signal-hook" 567 | version = "0.3.17" 568 | source = "registry+https://github.com/rust-lang/crates.io-index" 569 | checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" 570 | dependencies = [ 571 | "libc", 572 | "signal-hook-registry", 573 | ] 574 | 575 | [[package]] 576 | name = "signal-hook-mio" 577 | version = "0.2.4" 578 | source = "registry+https://github.com/rust-lang/crates.io-index" 579 | checksum = "34db1a06d485c9142248b7a054f034b349b212551f3dfd19c94d45a754a217cd" 580 | dependencies = [ 581 | "libc", 582 | "mio", 583 | "signal-hook", 584 | ] 585 | 586 | [[package]] 587 | name = "signal-hook-registry" 588 | version = "1.4.2" 589 | source = "registry+https://github.com/rust-lang/crates.io-index" 590 | checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" 591 | dependencies = [ 592 | "libc", 593 | ] 594 | 595 | [[package]] 596 | name = "smallvec" 597 | version = "1.13.2" 598 | source = "registry+https://github.com/rust-lang/crates.io-index" 599 | checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" 600 | 601 | [[package]] 602 | name = "static_assertions" 603 | version = "1.1.0" 604 | source = "registry+https://github.com/rust-lang/crates.io-index" 605 | checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" 606 | 607 | [[package]] 608 | name = "strsim" 609 | version = "0.11.1" 610 | source = "registry+https://github.com/rust-lang/crates.io-index" 611 | checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 612 | 613 | [[package]] 614 | name = "strum" 615 | version = "0.26.3" 616 | source = "registry+https://github.com/rust-lang/crates.io-index" 617 | checksum = "8fec0f0aef304996cf250b31b5a10dee7980c85da9d759361292b8bca5a18f06" 618 | dependencies = [ 619 | "strum_macros", 620 | ] 621 | 622 | [[package]] 623 | name = "strum_macros" 624 | version = "0.26.4" 625 | source = "registry+https://github.com/rust-lang/crates.io-index" 626 | checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" 627 | dependencies = [ 628 | "heck", 629 | "proc-macro2", 630 | "quote", 631 | "rustversion", 632 | "syn", 633 | ] 634 | 635 | [[package]] 636 | name = "syn" 637 | version = "2.0.100" 638 | source = "registry+https://github.com/rust-lang/crates.io-index" 639 | checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" 640 | dependencies = [ 641 | "proc-macro2", 642 | "quote", 643 | "unicode-ident", 644 | ] 645 | 646 | [[package]] 647 | name = "thiserror" 648 | version = "1.0.63" 649 | source = "registry+https://github.com/rust-lang/crates.io-index" 650 | checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" 651 | dependencies = [ 652 | "thiserror-impl", 653 | ] 654 | 655 | [[package]] 656 | name = "thiserror-impl" 657 | version = "1.0.63" 658 | source = "registry+https://github.com/rust-lang/crates.io-index" 659 | checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" 660 | dependencies = [ 661 | "proc-macro2", 662 | "quote", 663 | "syn", 664 | ] 665 | 666 | [[package]] 667 | name = "toml" 668 | version = "0.8.19" 669 | source = "registry+https://github.com/rust-lang/crates.io-index" 670 | checksum = "a1ed1f98e3fdc28d6d910e6737ae6ab1a93bf1985935a1193e68f93eeb68d24e" 671 | dependencies = [ 672 | "serde", 673 | "serde_spanned", 674 | "toml_datetime", 675 | "toml_edit", 676 | ] 677 | 678 | [[package]] 679 | name = "toml_datetime" 680 | version = "0.6.8" 681 | source = "registry+https://github.com/rust-lang/crates.io-index" 682 | checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" 683 | dependencies = [ 684 | "serde", 685 | ] 686 | 687 | [[package]] 688 | name = "toml_edit" 689 | version = "0.22.20" 690 | source = "registry+https://github.com/rust-lang/crates.io-index" 691 | checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" 692 | dependencies = [ 693 | "indexmap", 694 | "serde", 695 | "serde_spanned", 696 | "toml_datetime", 697 | "winnow", 698 | ] 699 | 700 | [[package]] 701 | name = "unicode-ident" 702 | version = "1.0.12" 703 | source = "registry+https://github.com/rust-lang/crates.io-index" 704 | checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" 705 | 706 | [[package]] 707 | name = "unicode-segmentation" 708 | version = "1.11.0" 709 | source = "registry+https://github.com/rust-lang/crates.io-index" 710 | checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" 711 | 712 | [[package]] 713 | name = "unicode-truncate" 714 | version = "1.1.0" 715 | source = "registry+https://github.com/rust-lang/crates.io-index" 716 | checksum = "b3644627a5af5fa321c95b9b235a72fd24cd29c648c2c379431e6628655627bf" 717 | dependencies = [ 718 | "itertools 0.13.0", 719 | "unicode-segmentation", 720 | "unicode-width 0.1.13", 721 | ] 722 | 723 | [[package]] 724 | name = "unicode-width" 725 | version = "0.1.13" 726 | source = "registry+https://github.com/rust-lang/crates.io-index" 727 | checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" 728 | 729 | [[package]] 730 | name = "unicode-width" 731 | version = "0.2.0" 732 | source = "registry+https://github.com/rust-lang/crates.io-index" 733 | checksum = "1fc81956842c57dac11422a97c3b8195a1ff727f06e85c84ed2e8aa277c9a0fd" 734 | 735 | [[package]] 736 | name = "version_check" 737 | version = "0.9.5" 738 | source = "registry+https://github.com/rust-lang/crates.io-index" 739 | checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" 740 | 741 | [[package]] 742 | name = "wasi" 743 | version = "0.11.0+wasi-snapshot-preview1" 744 | source = "registry+https://github.com/rust-lang/crates.io-index" 745 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 746 | 747 | [[package]] 748 | name = "winapi" 749 | version = "0.3.9" 750 | source = "registry+https://github.com/rust-lang/crates.io-index" 751 | checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" 752 | dependencies = [ 753 | "winapi-i686-pc-windows-gnu", 754 | "winapi-x86_64-pc-windows-gnu", 755 | ] 756 | 757 | [[package]] 758 | name = "winapi-i686-pc-windows-gnu" 759 | version = "0.4.0" 760 | source = "registry+https://github.com/rust-lang/crates.io-index" 761 | checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 762 | 763 | [[package]] 764 | name = "winapi-x86_64-pc-windows-gnu" 765 | version = "0.4.0" 766 | source = "registry+https://github.com/rust-lang/crates.io-index" 767 | checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" 768 | 769 | [[package]] 770 | name = "windows-sys" 771 | version = "0.48.0" 772 | source = "registry+https://github.com/rust-lang/crates.io-index" 773 | checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" 774 | dependencies = [ 775 | "windows-targets 0.48.5", 776 | ] 777 | 778 | [[package]] 779 | name = "windows-sys" 780 | version = "0.52.0" 781 | source = "registry+https://github.com/rust-lang/crates.io-index" 782 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 783 | dependencies = [ 784 | "windows-targets 0.52.6", 785 | ] 786 | 787 | [[package]] 788 | name = "windows-sys" 789 | version = "0.59.0" 790 | source = "registry+https://github.com/rust-lang/crates.io-index" 791 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 792 | dependencies = [ 793 | "windows-targets 0.52.6", 794 | ] 795 | 796 | [[package]] 797 | name = "windows-targets" 798 | version = "0.48.5" 799 | source = "registry+https://github.com/rust-lang/crates.io-index" 800 | checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" 801 | dependencies = [ 802 | "windows_aarch64_gnullvm 0.48.5", 803 | "windows_aarch64_msvc 0.48.5", 804 | "windows_i686_gnu 0.48.5", 805 | "windows_i686_msvc 0.48.5", 806 | "windows_x86_64_gnu 0.48.5", 807 | "windows_x86_64_gnullvm 0.48.5", 808 | "windows_x86_64_msvc 0.48.5", 809 | ] 810 | 811 | [[package]] 812 | name = "windows-targets" 813 | version = "0.52.6" 814 | source = "registry+https://github.com/rust-lang/crates.io-index" 815 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 816 | dependencies = [ 817 | "windows_aarch64_gnullvm 0.52.6", 818 | "windows_aarch64_msvc 0.52.6", 819 | "windows_i686_gnu 0.52.6", 820 | "windows_i686_gnullvm", 821 | "windows_i686_msvc 0.52.6", 822 | "windows_x86_64_gnu 0.52.6", 823 | "windows_x86_64_gnullvm 0.52.6", 824 | "windows_x86_64_msvc 0.52.6", 825 | ] 826 | 827 | [[package]] 828 | name = "windows_aarch64_gnullvm" 829 | version = "0.48.5" 830 | source = "registry+https://github.com/rust-lang/crates.io-index" 831 | checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" 832 | 833 | [[package]] 834 | name = "windows_aarch64_gnullvm" 835 | version = "0.52.6" 836 | source = "registry+https://github.com/rust-lang/crates.io-index" 837 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 838 | 839 | [[package]] 840 | name = "windows_aarch64_msvc" 841 | version = "0.48.5" 842 | source = "registry+https://github.com/rust-lang/crates.io-index" 843 | checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" 844 | 845 | [[package]] 846 | name = "windows_aarch64_msvc" 847 | version = "0.52.6" 848 | source = "registry+https://github.com/rust-lang/crates.io-index" 849 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 850 | 851 | [[package]] 852 | name = "windows_i686_gnu" 853 | version = "0.48.5" 854 | source = "registry+https://github.com/rust-lang/crates.io-index" 855 | checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" 856 | 857 | [[package]] 858 | name = "windows_i686_gnu" 859 | version = "0.52.6" 860 | source = "registry+https://github.com/rust-lang/crates.io-index" 861 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 862 | 863 | [[package]] 864 | name = "windows_i686_gnullvm" 865 | version = "0.52.6" 866 | source = "registry+https://github.com/rust-lang/crates.io-index" 867 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 868 | 869 | [[package]] 870 | name = "windows_i686_msvc" 871 | version = "0.48.5" 872 | source = "registry+https://github.com/rust-lang/crates.io-index" 873 | checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" 874 | 875 | [[package]] 876 | name = "windows_i686_msvc" 877 | version = "0.52.6" 878 | source = "registry+https://github.com/rust-lang/crates.io-index" 879 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 880 | 881 | [[package]] 882 | name = "windows_x86_64_gnu" 883 | version = "0.48.5" 884 | source = "registry+https://github.com/rust-lang/crates.io-index" 885 | checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" 886 | 887 | [[package]] 888 | name = "windows_x86_64_gnu" 889 | version = "0.52.6" 890 | source = "registry+https://github.com/rust-lang/crates.io-index" 891 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 892 | 893 | [[package]] 894 | name = "windows_x86_64_gnullvm" 895 | version = "0.48.5" 896 | source = "registry+https://github.com/rust-lang/crates.io-index" 897 | checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" 898 | 899 | [[package]] 900 | name = "windows_x86_64_gnullvm" 901 | version = "0.52.6" 902 | source = "registry+https://github.com/rust-lang/crates.io-index" 903 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 904 | 905 | [[package]] 906 | name = "windows_x86_64_msvc" 907 | version = "0.48.5" 908 | source = "registry+https://github.com/rust-lang/crates.io-index" 909 | checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" 910 | 911 | [[package]] 912 | name = "windows_x86_64_msvc" 913 | version = "0.52.6" 914 | source = "registry+https://github.com/rust-lang/crates.io-index" 915 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 916 | 917 | [[package]] 918 | name = "winnow" 919 | version = "0.6.18" 920 | source = "registry+https://github.com/rust-lang/crates.io-index" 921 | checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" 922 | dependencies = [ 923 | "memchr", 924 | ] 925 | 926 | [[package]] 927 | name = "zerocopy" 928 | version = "0.7.35" 929 | source = "registry+https://github.com/rust-lang/crates.io-index" 930 | checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" 931 | dependencies = [ 932 | "zerocopy-derive", 933 | ] 934 | 935 | [[package]] 936 | name = "zerocopy-derive" 937 | version = "0.7.35" 938 | source = "registry+https://github.com/rust-lang/crates.io-index" 939 | checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" 940 | dependencies = [ 941 | "proc-macro2", 942 | "quote", 943 | "syn", 944 | ] 945 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "inori" 3 | version = "0.2.5" 4 | edition = "2021" 5 | rust-version = "1.82" 6 | authors = ["esrh "] 7 | description = "mpd client" 8 | homepage = "https://github.com/eshrh/inori" 9 | repository = "https://github.com/eshrh/inori" 10 | license = "GPL-3.0-only" 11 | readme = "README.md" 12 | keywords = ["mpd", "music"] 13 | categories = ["command-line-utilities", "multimedia", "multimedia::audio"] 14 | 15 | [lints.rust] 16 | unsafe_code = "forbid" 17 | 18 | [dependencies] 19 | ratatui = { version = "0.29.0", features = ["serde"] } 20 | nucleo-matcher = "0.3.1" 21 | itertools = "0.14.0" 22 | bitflags = "2.6.0" 23 | toml = "0.8.19" 24 | platform-dirs = "0.3.0" 25 | 26 | [dependencies.mpd] 27 | version = "0.2.2" 28 | package = "inori-mpd" 29 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # inori 2 | 3 |

4 | 8 | 9 | 13 | 17 | inori logo 18 | 19 | 20 |

21 | 22 | Client for the Music Player Daemon ([MPD](https://www.musicpd.org/)). 23 | 24 | ## Features 25 | 26 | - Fuzzy search everywhere with 27 | [nucleo](https://github.com/helix-editor/nucleo) 28 | - Fully unicode aware, with special attention to the "albumartistsort" 29 | field 30 | - Global search across all tracks, albums, and artists 31 | - Folding library interface inspired by [cmus](https://cmus.github.io/) 32 | - Queue viewer and manipulation interface 33 | - Configurable, chainable keybindings 34 | 35 | ## Installation & Usage 36 | 37 | Inori is on [crates.io](https://crates.io/crates/inori): `cargo install inori`. 38 | 39 | Inori is also available on: 40 | 41 | - AUR as [inori](https://aur.archlinux.org/packages/inori) 42 | [maintainer: [@eshrh](https://aur.archlinux.org/account/esrh)] 43 | - Nixpkgs as [inori](https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/by-name/in/inori/package.nix) 44 | [maintainers: [@stephen-huan](https://github.com/stephen-huan), [@eshrh](https://github.com/eshrh)] 45 | - home-manager module [`programs.inori`](https://github.com/nix-community/home-manager/blob/master/modules/programs/inori.nix) 46 | [maintainers: [@miku4k](https://github.com/miku4k), [@stephen-huan](https://github.com/stephen-huan)] 47 | 48 | See [configuration.md](./CONFIGURATION.md) for config options, as well 49 | as a full list of all default keybindings. 50 | 51 | ## Screenshots 52 | 53 | ![Screenshot showing the library view](./images/library.png) 54 | ![Screenshot showing the search feature](./images/search.png) 55 | ![Screenshot showing the queue view](./images/queue.png) 56 | 57 | ## Todo 58 | 59 | - [ ] Playlist interface 60 | - [ ] Compile feature flag for Japanese album/track title romanization for search using a tokenizer & dictionary 61 | - [ ] More thorough customization options, especially for behavior & layout tweaks 62 | - [ ] Spectrum visualizer like ncmpcpp 63 | 64 | ## Acknowledgements 65 | 66 | - authors of [ratatui](https://ratatui.rs/) and 67 | [rust-mpd](https://docs.rs/mpd/latest/mpd/) 68 | - [mmtc](https://github.com/figsoda/mmtc) and 69 | [rmptui](https://github.com/krolyxon/rmptui), two other rust mpd 70 | clients, helped me learn rust 71 | - [@stephen-huan](https://github.com/stephen-huan): here from day one 72 | -------------------------------------------------------------------------------- /flake.lock: -------------------------------------------------------------------------------- 1 | { 2 | "nodes": { 3 | "nixpkgs": { 4 | "locked": { 5 | "lastModified": 1734649271, 6 | "narHash": "sha256-4EVBRhOjMDuGtMaofAIqzJbg4Ql7Ai0PSeuVZTHjyKQ=", 7 | "owner": "nixos", 8 | "repo": "nixpkgs", 9 | "rev": "d70bd19e0a38ad4790d3913bf08fcbfc9eeca507", 10 | "type": "github" 11 | }, 12 | "original": { 13 | "owner": "nixos", 14 | "ref": "nixos-unstable", 15 | "repo": "nixpkgs", 16 | "type": "github" 17 | } 18 | }, 19 | "root": { 20 | "inputs": { 21 | "nixpkgs": "nixpkgs" 22 | } 23 | } 24 | }, 25 | "root": "root", 26 | "version": 7 27 | } 28 | -------------------------------------------------------------------------------- /flake.nix: -------------------------------------------------------------------------------- 1 | { 2 | description = "inori mpd client"; 3 | 4 | inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; 5 | 6 | outputs = { self, nixpkgs }: 7 | let 8 | inherit (nixpkgs) lib; 9 | systems = lib.systems.flakeExposed; 10 | eachDefaultSystem = f: builtins.foldl' lib.attrsets.recursiveUpdate { } 11 | (map f systems); 12 | in 13 | eachDefaultSystem (system: 14 | let 15 | pkgs = nixpkgs.legacyPackages.${system}; 16 | formatters = [ 17 | pkgs.cargo 18 | pkgs.rustfmt 19 | pkgs.nixpkgs-fmt 20 | pkgs.nodePackages.prettier 21 | ]; 22 | linters = [ pkgs.clippy pkgs.statix ]; 23 | in 24 | { 25 | legacyPackages.${system} = self.packages.${system}; 26 | 27 | packages.${system} = (import ./pkgs { inherit pkgs; }) // { 28 | default = self.packages.${system}.inori; 29 | }; 30 | 31 | formatter.${system} = pkgs.writeShellApplication { 32 | name = "formatter"; 33 | runtimeInputs = formatters; 34 | text = '' 35 | cargo fmt 36 | prettier --write "$@" 37 | nixpkgs-fmt "$@" 38 | ''; 39 | }; 40 | 41 | checks.${system}.lint = pkgs.rustPlatform.buildRustPackage { 42 | name = "lint"; 43 | src = ./.; 44 | cargoLock.lockFile = ./Cargo.lock; 45 | doCheck = true; 46 | nativeCheckInputs = linters ++ formatters; 47 | checkPhase = '' 48 | cargo fmt --check 49 | cargo check 50 | cargo clippy 51 | cargo test 52 | prettier --check . 53 | nixpkgs-fmt --check . 54 | statix check 55 | ''; 56 | installPhase = "touch $out"; 57 | }; 58 | 59 | apps.${system} = { 60 | update-logo = { 61 | type = "app"; 62 | program = lib.getExe (pkgs.writeShellApplication { 63 | name = "update-logo"; 64 | runtimeInputs = [ ]; 65 | text = '' 66 | cp ${self.packages.${system}.inori-logo}/inori-logo.svg \ 67 | -T images/inori-logo.svg 68 | cp ${self.packages.${system}.inori-logo}/inori-logo-white.svg \ 69 | -T images/inori-logo-white.svg 70 | chmod +w images/inori-logo.svg 71 | chmod +w images/inori-logo-white.svg 72 | ''; 73 | }); 74 | }; 75 | }; 76 | 77 | devShells.${system}.default = pkgs.mkShell { 78 | packages = [ 79 | pkgs.rust-analyzer 80 | pkgs.rustc 81 | ] 82 | ++ linters 83 | ++ formatters; 84 | }; 85 | } 86 | ); 87 | } 88 | -------------------------------------------------------------------------------- /images/artist_search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eshrh/inori/76da3dff2c20685704d18ad83000b48f8741d248/images/artist_search.png -------------------------------------------------------------------------------- /images/inori-logo-white.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /images/inori-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /images/library.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eshrh/inori/76da3dff2c20685704d18ad83000b48f8741d248/images/library.png -------------------------------------------------------------------------------- /images/queue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eshrh/inori/76da3dff2c20685704d18ad83000b48f8741d248/images/queue.png -------------------------------------------------------------------------------- /images/search.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/eshrh/inori/76da3dff2c20685704d18ad83000b48f8741d248/images/search.png -------------------------------------------------------------------------------- /pkgs/default.nix: -------------------------------------------------------------------------------- 1 | { pkgs }: 2 | 3 | { 4 | inori = pkgs.callPackage ./inori { }; 5 | inori-logo = pkgs.callPackage ./inori-logo { }; 6 | } 7 | -------------------------------------------------------------------------------- /pkgs/inori-logo/default.nix: -------------------------------------------------------------------------------- 1 | { lib, stdenvNoCC, fetchFromGitHub, tectonic, poppler_utils }: 2 | 3 | stdenvNoCC.mkDerivation rec { 4 | name = "inori-logo"; 5 | src = ./src; 6 | 7 | strictDeps = true; 8 | nativeBuildInputs = [ tectonic poppler_utils ]; 9 | preferLocalBuild = true; 10 | 11 | cache = fetchFromGitHub { 12 | owner = "stephen-huan"; 13 | repo = "tectonic-cache"; 14 | rev = "acfff2b6f6fcfeaae2098b1069230c57cd56c92a"; 15 | hash = "sha256-99Q2l48G0R8gUaE31BgZqeAKiBzOVfzh/PIAauZT5mo="; 16 | }; 17 | 18 | buildPhase = '' 19 | runHook preBuild 20 | 21 | mkdir -p .cache 22 | export XDG_CACHE_HOME=$(realpath .cache) 23 | export TECTONIC_CACHE_DIR=${cache} 24 | export SOURCE_DATE_EPOCH=0 25 | substitute ${name}.tex ${name}-black.tex --subst-var-by fg 000000 26 | tectonic --only-cached -Z deterministic-mode ${name}-black.tex 27 | pdftocairo -svg ${name}-black.pdf 28 | substitute ${name}.tex ${name}-white.tex --subst-var-by fg ffffff 29 | tectonic --only-cached -Z deterministic-mode ${name}-white.tex 30 | pdftocairo -svg ${name}-white.pdf 31 | 32 | runHook postBuild 33 | ''; 34 | 35 | installPhase = '' 36 | runHook preInstall 37 | 38 | install -Dm644 ${name}-black.svg -T $out/${name}.svg 39 | install -Dm644 ${name}-white.svg -T $out/${name}-white.svg 40 | 41 | runHook postInstall 42 | ''; 43 | 44 | meta = with lib; { 45 | description = "Logo for inori"; 46 | license = licenses.unlicense; 47 | platforms = platforms.all; 48 | maintainers = with maintainers; [ stephen-huan ]; 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /pkgs/inori-logo/src/inori-logo.tex: -------------------------------------------------------------------------------- 1 | \documentclass[tikz]{standalone} 2 | \usepackage{amsmath} 3 | 4 | % https://flyx.org/nix-flakes-latex/ 5 | \special{pdf:trailerid [ 6 | <00112233445566778899aabbccddeeff> 7 | <00112233445566778899aabbccddeeff> 8 | ]} 9 | 10 | \definecolor{fg}{HTML}{@fg@} 11 | 12 | \begin{document} 13 | \begin{tikzpicture} 14 | % https://tikz.dev/tikz-shapes#sec-17.2.3 15 | \node[inner xsep=0mm, inner ysep=0.07em] {% 16 | \( \textcolor{fg}{\lvert \mathcal{X} \rvert_0} \) 17 | }; 18 | \end{tikzpicture} 19 | \end{document} 20 | -------------------------------------------------------------------------------- /pkgs/inori/default.nix: -------------------------------------------------------------------------------- 1 | { lib, rustPlatform }: 2 | 3 | rustPlatform.buildRustPackage { 4 | pname = "inori"; 5 | version = "0.2.2"; 6 | src = ../..; 7 | 8 | cargoLock.lockFile = ../../Cargo.lock; 9 | 10 | meta = with lib; { 11 | description = "Client for the Music Player Daemon (MPD)"; 12 | homepage = "https://github.com/eshrh/inori"; 13 | license = licenses.gpl3Only; 14 | platforms = platforms.unix ++ platforms.windows; 15 | mainProgram = "inori"; 16 | maintainers = with maintainers; [ stephen-huan ]; 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /rustfmt.toml: -------------------------------------------------------------------------------- 1 | newline_style = "Unix" 2 | use_field_init_shorthand = true 3 | use_try_shorthand = true 4 | max_width = 80 5 | -------------------------------------------------------------------------------- /src/config.rs: -------------------------------------------------------------------------------- 1 | use crate::model::*; 2 | use crate::view::Theme; 3 | use platform_dirs::AppDirs; 4 | use ratatui::style::Modifier; 5 | use ratatui::style::Style; 6 | use std::fs; 7 | use toml::Table; 8 | use toml::Value; 9 | pub mod keybind; 10 | use keybind::{get_message, KeybindMap}; 11 | 12 | pub struct Config { 13 | pub keybindings: KeybindMap, 14 | pub theme: Theme, 15 | pub seek_seconds: i64, 16 | pub mpd_address: Option, 17 | pub screens: Vec, 18 | pub nucleo_prefer_prefix: bool, 19 | } 20 | 21 | impl Config { 22 | pub fn default() -> Self { 23 | Config { 24 | keybindings: KeybindMap::default(), 25 | theme: Theme::new(), 26 | seek_seconds: 5, 27 | mpd_address: None, 28 | screens: vec![Screen::Library, Screen::Queue], 29 | nucleo_prefer_prefix: false, 30 | } 31 | } 32 | pub fn try_read_config(mut self) -> Self { 33 | let app_dirs = AppDirs::new(Some("inori"), true); 34 | let config_file_path = 35 | app_dirs.map(|d| d.config_dir.join("config.toml")); 36 | 37 | if let Some(Ok(contents)) = config_file_path.map(fs::read_to_string) { 38 | let toml = contents.parse::().expect("failed to parse toml"); 39 | for (key, value) in toml { 40 | match (key.as_str(), value) { 41 | ("keybindings", Value::Table(t)) => self.read_keybinds(t), 42 | ("seek_seconds", Value::Integer(k)) if k > 0 => { 43 | self.seek_seconds = k 44 | } 45 | ("theme", Value::Table(t)) => self.read_theme(t), 46 | ("dvorak_keybindings", Value::Boolean(true)) => { 47 | self.keybindings = self.keybindings.with_dvorak_style(); 48 | } 49 | ("qwerty_keybindings", Value::Boolean(true)) => { 50 | self.keybindings = self.keybindings.with_qwerty_style(); 51 | } 52 | ("mpd_address", Value::String(addr)) => { 53 | self.mpd_address = Some(addr); 54 | } 55 | ("screens", Value::Array(screens)) => { 56 | self.screens = screens 57 | .iter() 58 | .map(|v| match v { 59 | Value::String(s) => s.into(), 60 | _ => panic!("Non-string value found in screens array: {}", v), 61 | }) 62 | .collect() 63 | } 64 | ("nucleo_prefer_prefix", Value::Boolean(t)) => self.nucleo_prefer_prefix = t, 65 | (_k, _v) => panic!("unknown key {} or value {}", _k, _v), 66 | } 67 | } 68 | } 69 | self 70 | } 71 | pub fn read_keybinds(&mut self, t: Table) { 72 | for (key, value) in t { 73 | match (get_message(&key), value) { 74 | (Some(m), Value::String(s)) => { 75 | let keybinds = keybind::parse_keybind(s).unwrap(); 76 | self.keybindings.insert(m.clone(), &keybinds); 77 | } 78 | (Some(m), Value::Array(a)) => { 79 | for s in a { 80 | if let Value::String(s) = s { 81 | let keybinds = keybind::parse_keybind(s).unwrap(); 82 | self.keybindings.insert(m.clone(), &keybinds); 83 | } else { 84 | panic!( 85 | "keybind {} for command {} must be a string", 86 | s, key 87 | ) 88 | } 89 | } 90 | } 91 | (Some(_), other) => panic!( 92 | "keybind {} for command {} must be a string or an array", 93 | other, key 94 | ), 95 | (None, _) => panic!("message {} does not exist", key), 96 | } 97 | } 98 | } 99 | pub fn read_theme(&mut self, t: Table) { 100 | for (key, value) in t { 101 | match (key.as_str(), value) { 102 | ("item_highlight_active", Value::Table(t)) => { 103 | self.theme.item_highlight_active = deserialize_style(t); 104 | } 105 | ("item_highlight_inactive", Value::Table(t)) => { 106 | self.theme.item_highlight_inactive = deserialize_style(t); 107 | } 108 | ("block_active", Value::Table(t)) => { 109 | self.theme.block_active = deserialize_style(t); 110 | } 111 | ("status_artist", Value::Table(t)) => { 112 | self.theme.status_artist = deserialize_style(t); 113 | } 114 | ("status_album", Value::Table(t)) => { 115 | self.theme.status_album = deserialize_style(t); 116 | } 117 | ("status_title", Value::Table(t)) => { 118 | self.theme.status_title = deserialize_style(t); 119 | } 120 | ("artist_sort", Value::Table(t)) => { 121 | self.theme.field_artistsort = deserialize_style(t); 122 | } 123 | ("field_artistsort", Value::Table(t)) => { 124 | self.theme.field_artistsort = deserialize_style(t); 125 | } 126 | ("album", Value::Table(t)) => { 127 | self.theme.field_album = deserialize_style(t); 128 | } 129 | ("field_album", Value::Table(t)) => { 130 | self.theme.field_album = deserialize_style(t); 131 | } 132 | ("playing", Value::Table(t)) => { 133 | self.theme.status_playing = deserialize_style(t); 134 | } 135 | ("paused", Value::Table(t)) => { 136 | self.theme.status_paused = deserialize_style(t); 137 | } 138 | ("stopped", Value::Table(t)) => { 139 | self.theme.status_stopped = deserialize_style(t); 140 | } 141 | ("status_playing", Value::Table(t)) => { 142 | self.theme.status_playing = deserialize_style(t); 143 | } 144 | ("status_paused", Value::Table(t)) => { 145 | self.theme.status_paused = deserialize_style(t); 146 | } 147 | ("status_stopped", Value::Table(t)) => { 148 | self.theme.status_stopped = deserialize_style(t); 149 | } 150 | ("slash_span", Value::Table(t)) => { 151 | self.theme.slash_span = deserialize_style(t); 152 | } 153 | ("search_query_active", Value::Table(t)) => { 154 | self.theme.search_query_active = deserialize_style(t); 155 | } 156 | ("search_query_inactive", Value::Table(t)) => { 157 | self.theme.search_query_inactive = deserialize_style(t); 158 | } 159 | ("progress_bar_filled", Value::Table(t)) => { 160 | self.theme.progress_bar_filled = deserialize_style(t) 161 | } 162 | ("progress_bar_unfilled", Value::Table(t)) => { 163 | self.theme.progress_bar_unfilled = deserialize_style(t) 164 | } 165 | (other, _) => panic!("theme option {} not found", other), 166 | } 167 | } 168 | } 169 | } 170 | 171 | fn modifiers_arr(modifiers: &Vec) -> String { 172 | let mut m = String::new(); 173 | for i in modifiers { 174 | if let Value::String(s) = i { 175 | if Modifier::from_name(s).is_some() { 176 | if !m.is_empty() { 177 | m.push('|'); 178 | } 179 | m.push_str(s); 180 | } else { 181 | panic!( 182 | "Error while parsing theme modifier array: unknown modifier \"{}\"" 183 | ,s 184 | ) 185 | } 186 | } 187 | } 188 | m 189 | } 190 | 191 | pub fn deserialize_style(mut t: Table) -> Style { 192 | if !t.contains_key("add_modifier") { 193 | t.insert("add_modifier".into(), Value::String("".into())); 194 | } 195 | if !t.contains_key("sub_modifier") { 196 | t.insert("sub_modifier".into(), Value::String("".into())); 197 | } 198 | if let Value::Array(a) = t.get("add_modifier").unwrap() { 199 | t.insert("add_modifier".into(), Value::String(modifiers_arr(a))); 200 | } 201 | if let Value::Array(a) = t.get("sub_modifier").unwrap() { 202 | t.insert("sub_modifier".into(), Value::String(modifiers_arr(a))); 203 | } 204 | t.try_into().expect("Style parse failure") 205 | } 206 | -------------------------------------------------------------------------------- /src/config/keybind.rs: -------------------------------------------------------------------------------- 1 | use crate::event_handler::Result; 2 | use crate::model::State; 3 | use crate::update::Message::{self, *}; 4 | use crate::update::*; 5 | use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; 6 | use std::collections::HashMap; 7 | use std::fmt; 8 | 9 | pub enum KeybindTarget { 10 | Map(KeybindMap), 11 | Msg(Message), 12 | } 13 | use KeybindTarget::*; 14 | 15 | pub struct KeybindMap(pub HashMap); 16 | const EMPTY: KeyModifiers = KeyModifiers::empty(); 17 | 18 | pub fn get_message(s: &str) -> Option { 19 | match s { 20 | "up" => Some(Message::Direction(Dirs::Vert(Vertical::Up))), 21 | "down" => Some(Message::Direction(Dirs::Vert(Vertical::Down))), 22 | "screenful_up" => Some(Message::ScrollScreenful(Vertical::Up)), 23 | "screenful_down" => Some(Message::ScrollScreenful(Vertical::Down)), 24 | "top" => Some(Message::Direction(Dirs::Vert(Vertical::Top))), 25 | "bottom" => Some(Message::Direction(Dirs::Vert(Vertical::Bottom))), 26 | "left" => Some(Message::Direction(Dirs::Horiz(Horizontal::Left))), 27 | "right" => Some(Message::Direction(Dirs::Horiz(Horizontal::Right))), 28 | "toggle_playpause" => Some(Message::PlayPause), 29 | "update_db" => Some(Message::UpdateDB), 30 | "select" => Some(Message::Select), 31 | "quit" => Some(Message::SwitchState(State::Done)), 32 | "screen_1" => Some(Message::SwitchScreen(1)), 33 | "screen_2" => Some(Message::SwitchScreen(2)), 34 | "toggle_screen" | "toggle_screen_lq" => Some(Message::ToggleScreen), 35 | "toggle_panel" => Some(Message::TogglePanel), 36 | "fold" => Some(Message::Fold), 37 | "clear_queue" => Some(Message::Clear), 38 | "local_search" => Some(Message::LocalSearch(SearchMsg::Start)), 39 | "global_search" => Some(Message::GlobalSearch(SearchMsg::Start)), 40 | "escape" => Some(Message::Escape), 41 | "delete" => Some(Message::Delete), 42 | "toggle_repeat" => Some(Message::Set(Toggle::Repeat)), 43 | "toggle_single" => Some(Message::Set(Toggle::Single)), 44 | "toggle_consume" => Some(Message::Set(Toggle::Consume)), 45 | "toggle_random" => Some(Message::Set(Toggle::Random)), 46 | "next_song" => Some(Message::NextSong), 47 | "previous_song" => Some(Message::PreviousSong), 48 | "seek" => Some(Message::Seek(SeekDirection::Forward)), 49 | "seek_backwards" => Some(Message::Seek(SeekDirection::Backward)), 50 | _ => None, 51 | } 52 | } 53 | 54 | impl KeybindMap { 55 | pub fn default() -> Self { 56 | let mut keybindings = HashMap::new(); 57 | keybindings.insert( 58 | KeyEvent::new(KeyCode::Up, EMPTY), 59 | Msg(Direction(Dirs::Vert(Vertical::Up))), 60 | ); 61 | keybindings.insert( 62 | KeyEvent::new(KeyCode::Char('p'), KeyModifiers::CONTROL), 63 | Msg(Direction(Dirs::Vert(Vertical::Up))), 64 | ); 65 | keybindings.insert( 66 | KeyEvent::new(KeyCode::Down, EMPTY), 67 | Msg(Direction(Dirs::Vert(Vertical::Down))), 68 | ); 69 | keybindings.insert( 70 | KeyEvent::new(KeyCode::Char('n'), KeyModifiers::CONTROL), 71 | Msg(Direction(Dirs::Vert(Vertical::Down))), 72 | ); 73 | keybindings.insert( 74 | KeyEvent::new(KeyCode::Left, EMPTY), 75 | Msg(Direction(Dirs::Horiz(Horizontal::Left))), 76 | ); 77 | keybindings.insert( 78 | KeyEvent::new(KeyCode::Right, EMPTY), 79 | Msg(Direction(Dirs::Horiz(Horizontal::Right))), 80 | ); 81 | keybindings.insert( 82 | KeyEvent::new(KeyCode::Home, EMPTY), 83 | Msg(Direction(Dirs::Vert(Vertical::Top))), 84 | ); 85 | keybindings.insert( 86 | KeyEvent::new(KeyCode::End, EMPTY), 87 | Msg(Direction(Dirs::Vert(Vertical::Bottom))), 88 | ); 89 | keybindings.insert( 90 | KeyEvent::new(KeyCode::Char('s'), KeyModifiers::CONTROL), 91 | Msg(GlobalSearch(SearchMsg::Start)), 92 | ); 93 | 94 | keybindings 95 | .insert(KeyEvent::new(KeyCode::Char('p'), EMPTY), Msg(PlayPause)); 96 | keybindings.insert(KeyEvent::new(KeyCode::Enter, EMPTY), Msg(Select)); 97 | keybindings.insert( 98 | KeyEvent::new(KeyCode::Char('1'), EMPTY), 99 | Msg(SwitchScreen(1)), 100 | ); 101 | keybindings.insert( 102 | KeyEvent::new(KeyCode::Char('2'), EMPTY), 103 | Msg(SwitchScreen(2)), 104 | ); 105 | keybindings.insert( 106 | KeyEvent::new(KeyCode::Char('q'), EMPTY), 107 | Msg(SwitchState(super::State::Done)), 108 | ); 109 | keybindings 110 | .insert(KeyEvent::new(KeyCode::Backspace, EMPTY), Msg(Delete)); 111 | keybindings 112 | .insert(KeyEvent::new(KeyCode::Tab, EMPTY), Msg(ToggleScreen)); 113 | keybindings.insert(KeyEvent::new(KeyCode::Char(' '), EMPTY), Msg(Fold)); 114 | keybindings 115 | .insert(KeyEvent::new(KeyCode::Char('-'), EMPTY), Msg(Clear)); 116 | keybindings.insert( 117 | KeyEvent::new(KeyCode::Char('/'), EMPTY), 118 | Msg(LocalSearch(SearchMsg::Start)), 119 | ); 120 | keybindings.insert(KeyEvent::new(KeyCode::Esc, EMPTY), Msg(Escape)); 121 | keybindings.insert( 122 | KeyEvent::new(KeyCode::Char('r'), EMPTY), 123 | Msg(Set(Toggle::Repeat)), 124 | ); 125 | keybindings.insert( 126 | KeyEvent::new(KeyCode::Char('z'), EMPTY), 127 | Msg(Set(Toggle::Random)), 128 | ); 129 | keybindings.insert( 130 | KeyEvent::new(KeyCode::Char('s'), EMPTY), 131 | Msg(Set(Toggle::Single)), 132 | ); 133 | keybindings.insert( 134 | KeyEvent::new(KeyCode::Char('c'), EMPTY), 135 | Msg(Set(Toggle::Consume)), 136 | ); 137 | keybindings 138 | .insert(KeyEvent::new(KeyCode::Char('u'), EMPTY), Msg(UpdateDB)); 139 | 140 | keybindings.insert( 141 | KeyEvent::new(KeyCode::PageDown, EMPTY), 142 | Msg(ScrollScreenful(Vertical::Down)), 143 | ); 144 | keybindings.insert( 145 | KeyEvent::new(KeyCode::PageUp, EMPTY), 146 | Msg(ScrollScreenful(Vertical::Up)), 147 | ); 148 | 149 | Self(keybindings) 150 | } 151 | pub fn with_dvorak_style(mut self) -> Self { 152 | self.0.insert( 153 | KeyEvent::new(KeyCode::Char('t'), EMPTY), 154 | Msg(Direction(Dirs::Vert(Vertical::Up))), 155 | ); 156 | self.0.insert( 157 | KeyEvent::new(KeyCode::Char('h'), EMPTY), 158 | Msg(Direction(Dirs::Vert(Vertical::Down))), 159 | ); 160 | self.0.insert( 161 | KeyEvent::new(KeyCode::Char('d'), EMPTY), 162 | Msg(Direction(Dirs::Horiz(Horizontal::Left))), 163 | ); 164 | self.0.insert( 165 | KeyEvent::new(KeyCode::Char('n'), EMPTY), 166 | Msg(Direction(Dirs::Horiz(Horizontal::Right))), 167 | ); 168 | self.0.insert( 169 | KeyEvent::new(KeyCode::Char('<'), EMPTY), 170 | Msg(Direction(Dirs::Vert(Vertical::Top))), 171 | ); 172 | self.0.insert( 173 | KeyEvent::new(KeyCode::Char('>'), EMPTY), 174 | Msg(Direction(Dirs::Vert(Vertical::Bottom))), 175 | ); 176 | self.0.insert( 177 | KeyEvent::new(KeyCode::Char('g'), EMPTY), 178 | Msg(GlobalSearch(SearchMsg::Start)), 179 | ); 180 | self.0.insert( 181 | KeyEvent::new(KeyCode::Char('g'), KeyModifiers::CONTROL), 182 | Msg(Escape), 183 | ); 184 | self.0.insert( 185 | KeyEvent::new(KeyCode::Char('v'), KeyModifiers::CONTROL), 186 | Msg(ScrollScreenful(Vertical::Down)), 187 | ); 188 | self.0.insert( 189 | KeyEvent::new(KeyCode::Char('v'), KeyModifiers::ALT), 190 | Msg(ScrollScreenful(Vertical::Up)), 191 | ); 192 | self 193 | } 194 | pub fn with_qwerty_style(mut self) -> Self { 195 | self.0.insert( 196 | KeyEvent::new(KeyCode::Char('k'), EMPTY), 197 | Msg(Direction(Dirs::Vert(Vertical::Up))), 198 | ); 199 | self.0.insert( 200 | KeyEvent::new(KeyCode::Char('j'), EMPTY), 201 | Msg(Direction(Dirs::Vert(Vertical::Down))), 202 | ); 203 | self.0.insert( 204 | KeyEvent::new(KeyCode::Char('h'), EMPTY), 205 | Msg(Direction(Dirs::Horiz(Horizontal::Left))), 206 | ); 207 | self.0.insert( 208 | KeyEvent::new(KeyCode::Char('l'), EMPTY), 209 | Msg(Direction(Dirs::Horiz(Horizontal::Right))), 210 | ); 211 | self.0.insert( 212 | KeyEvent::new(KeyCode::Char('g'), KeyModifiers::CONTROL), 213 | Msg(GlobalSearch(SearchMsg::Start)), 214 | ); 215 | self.0.insert( 216 | KeyEvent::new(KeyCode::Char('G'), KeyModifiers::empty()), 217 | Msg(Direction(Dirs::Vert(Vertical::Bottom))), 218 | ); 219 | self.0.insert( 220 | KeyEvent::new(KeyCode::Char('f'), KeyModifiers::CONTROL), 221 | Msg(ScrollScreenful(Vertical::Down)), 222 | ); 223 | self.0.insert( 224 | KeyEvent::new(KeyCode::Char('b'), KeyModifiers::CONTROL), 225 | Msg(ScrollScreenful(Vertical::Up)), 226 | ); 227 | self.insert( 228 | Direction(Dirs::Vert(Vertical::Top)), 229 | &[ 230 | KeyEvent::new(KeyCode::Char('g'), EMPTY), 231 | KeyEvent::new(KeyCode::Char('g'), EMPTY), 232 | ], 233 | ); 234 | self 235 | } 236 | pub fn insert(&mut self, msg: Message, bind: &[KeyEvent]) { 237 | if bind.len() == 1 { 238 | self.0.insert(bind[0], KeybindTarget::Msg(msg)); 239 | return; 240 | } 241 | if self.0.contains_key(&bind[0]) { 242 | match self.0.get_mut(&bind[0]).unwrap() { 243 | KeybindTarget::Map(m) => m.insert(msg, &bind[1..]), 244 | KeybindTarget::Msg(_m) => { 245 | self.0.insert( 246 | bind[0], 247 | KeybindTarget::Map(KeybindMap(HashMap::new())), 248 | ); 249 | self.insert(msg, bind) 250 | } 251 | } 252 | } else { 253 | self.0.insert( 254 | bind[0], 255 | KeybindTarget::Map(KeybindMap(HashMap::new())), 256 | ); 257 | self.insert(msg, bind) 258 | } 259 | } 260 | pub fn lookup(&self, bind: &[KeyEvent]) -> Option<&KeybindTarget> { 261 | if bind.is_empty() { 262 | return None; 263 | } 264 | if bind.len() == 1 { 265 | return self.0.get(&bind[0]); 266 | } 267 | match self.0.get(&bind[0]) { 268 | Some(KeybindTarget::Map(m)) => m.lookup(&bind[1..]), 269 | None => None, 270 | o => o, 271 | } 272 | } 273 | } 274 | 275 | pub fn parse_keybind_single(s: &str) -> Option { 276 | if s.len() == 1 { 277 | s.chars().next().map(KeyCode::Char) 278 | } else { 279 | match s { 280 | "" => Some(KeyCode::Char(' ')), 281 | "" => Some(KeyCode::Esc), // deprecated 282 | "" => Some(KeyCode::Esc), 283 | "" => Some(KeyCode::Tab), 284 | "" => Some(KeyCode::Backspace), 285 | "" => Some(KeyCode::Delete), 286 | "" => Some(KeyCode::Up), 287 | "" => Some(KeyCode::Down), 288 | "" => Some(KeyCode::Left), 289 | "" => Some(KeyCode::Right), 290 | "" => Some(KeyCode::Enter), 291 | "" => Some(KeyCode::Home), 292 | "" => Some(KeyCode::End), 293 | "" => Some(KeyCode::PageUp), 294 | "" => Some(KeyCode::PageDown), 295 | _ => None, 296 | } 297 | } 298 | } 299 | 300 | #[derive(Debug)] 301 | pub enum KeybindParseError { 302 | EmptyKeybindParseError, 303 | ParseError(String), 304 | } 305 | 306 | impl std::error::Error for KeybindParseError {} 307 | 308 | impl fmt::Display for KeybindParseError { 309 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { 310 | match self { 311 | Self::EmptyKeybindParseError => { 312 | write!(f, "empty keybind not allowed") 313 | } 314 | Self::ParseError(input) => { 315 | write!(f, "failed to parse keybind {}", input) 316 | } 317 | } 318 | } 319 | } 320 | 321 | pub fn parse_keybind(s: String) -> Result> { 322 | let mut out: Vec = Vec::new(); 323 | for word in s.split(' ') { 324 | if let Some(keycode) = 325 | word.strip_prefix("C-").and_then(parse_keybind_single) 326 | { 327 | out.push(KeyEvent::new(keycode, KeyModifiers::CONTROL)) 328 | } else if let Some(keycode) = 329 | word.strip_prefix("M-").and_then(parse_keybind_single) 330 | { 331 | out.push(KeyEvent::new(keycode, KeyModifiers::ALT)) 332 | } else if let Some(keycode) = 333 | word.strip_prefix("S-").and_then(parse_keybind_single) 334 | { 335 | out.push(KeyEvent::new(keycode, KeyModifiers::SUPER)) 336 | } else if let Some(keycode) = 337 | word.strip_prefix("C-M-").and_then(parse_keybind_single) 338 | { 339 | out.push(KeyEvent::new( 340 | keycode, 341 | KeyModifiers::CONTROL | KeyModifiers::META, 342 | )) 343 | } else if let Some(keycode) = parse_keybind_single(word) { 344 | out.push(KeyEvent::new(keycode, EMPTY)) 345 | } else if word.is_empty() { 346 | return Err(Box::new(KeybindParseError::EmptyKeybindParseError)); 347 | } else { 348 | return Err(Box::new(KeybindParseError::ParseError(word.into()))); 349 | } 350 | } 351 | Ok(out) 352 | } 353 | -------------------------------------------------------------------------------- /src/event_handler.rs: -------------------------------------------------------------------------------- 1 | use ratatui::crossterm; 2 | use std::time::{Duration, Instant}; 3 | 4 | pub type Result = std::result::Result>; 5 | 6 | pub enum Event { 7 | Tick, 8 | Key(crossterm::event::KeyEvent), 9 | } 10 | 11 | pub struct EventHandler { 12 | rx: std::sync::mpsc::Receiver, 13 | } 14 | 15 | impl EventHandler { 16 | pub fn new() -> Self { 17 | let poll_time = Duration::from_millis(16); 18 | let tick_interval = Duration::from_millis(500); 19 | 20 | let (tx, rx) = std::sync::mpsc::channel(); 21 | let mut now = Instant::now(); 22 | let mut last_event = Instant::now(); 23 | std::thread::spawn(move || loop { 24 | if crossterm::event::poll(poll_time).expect("event poll failed") { 25 | match crossterm::event::read().expect("event read failed") { 26 | crossterm::event::Event::Key(e) => { 27 | last_event = Instant::now(); 28 | tx.send(Event::Key(e)) 29 | } 30 | crossterm::event::Event::Resize(_, _) => Ok(()), 31 | _ => unimplemented!(), 32 | } 33 | .expect("event send failed") 34 | } 35 | // only tick when idle. 36 | if now.elapsed() >= tick_interval 37 | && (Instant::now() - last_event >= Duration::from_millis(500)) 38 | { 39 | tx.send(Event::Tick).expect("tick send failed"); 40 | now = Instant::now(); 41 | } 42 | }); 43 | EventHandler { rx } 44 | } 45 | 46 | pub fn next(&self) -> Result { 47 | Ok(self.rx.recv()?) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | extern crate mpd; 2 | use model::State; 3 | use ratatui::{ 4 | backend::CrosstermBackend, 5 | crossterm::{ 6 | terminal::{ 7 | disable_raw_mode, enable_raw_mode, EnterAlternateScreen, 8 | LeaveAlternateScreen, 9 | }, 10 | ExecutableCommand, 11 | }, 12 | Terminal, 13 | }; 14 | use std::io::stdout; 15 | use std::panic; 16 | use update::Update; 17 | mod config; 18 | mod event_handler; 19 | mod model; 20 | mod update; 21 | mod util; 22 | mod view; 23 | use event_handler::{Event, Result}; 24 | 25 | fn main() -> Result<()> { 26 | stdout().execute(EnterAlternateScreen)?; 27 | enable_raw_mode()?; 28 | let mut terminal = Terminal::new(CrosstermBackend::new(stdout()))?; 29 | terminal.clear()?; 30 | 31 | let hook = panic::take_hook(); 32 | panic::set_hook(Box::new(move |panic| { 33 | reset_terminal().expect("Failed to reset the terminal."); 34 | hook(panic); 35 | })); 36 | 37 | let mut model = model::Model::new(terminal.get_frame().area()) 38 | .expect("Failed to init."); 39 | update::update_tick(&mut model)?; 40 | update::update_screens(&mut model, Update::empty())?; 41 | terminal.draw(|f| view::view(&mut model, f))?; 42 | 43 | let event_handler = event_handler::EventHandler::new(); 44 | loop { 45 | match event_handler.next()? { 46 | Event::Tick => update::update_tick(&mut model)?, 47 | Event::Key(k) => { 48 | let update = update::handle_key(&mut model, k)?; 49 | update::update_screens(&mut model, update)?; 50 | } 51 | } 52 | model.frame_size = terminal.get_frame().area(); 53 | terminal.draw(|f| view::view(&mut model, f))?; 54 | if let State::Done = model.state { 55 | break; 56 | } 57 | } 58 | reset_terminal().expect("Failed to reset terminal."); 59 | Ok(()) 60 | } 61 | 62 | fn reset_terminal() -> Result<()> { 63 | stdout().execute(LeaveAlternateScreen)?; 64 | disable_raw_mode()?; 65 | Ok(()) 66 | } 67 | -------------------------------------------------------------------------------- /src/model.rs: -------------------------------------------------------------------------------- 1 | extern crate mpd; 2 | use mpd::client::StreamTypes; 3 | use mpd::error::Result; 4 | use mpd::idle::IdleClient; 5 | use mpd::{Client, Song, Status, Subsystem}; 6 | use nucleo_matcher::{Matcher, Utf32String}; 7 | use ratatui::crossterm::event::KeyEvent; 8 | use ratatui::layout::Rect; 9 | use ratatui::widgets::*; 10 | mod impl_album_song; 11 | mod impl_artiststate; 12 | mod impl_library; 13 | mod impl_queue; 14 | mod impl_searchstate; 15 | pub mod proto; 16 | mod search_utils; 17 | use crate::config::Config; 18 | use crate::model::proto::*; 19 | use crate::update::build_library; 20 | 21 | #[derive(Clone, Debug)] 22 | pub enum Screen { 23 | Library, 24 | Queue, 25 | } 26 | 27 | impl From<&String> for Screen { 28 | fn from(s: &String) -> Self { 29 | match s.as_str() { 30 | "library" | "Library" => Screen::Library, 31 | "queue" | "Queue" => Screen::Queue, 32 | _ => panic!("unknown screen: {}", s), 33 | } 34 | } 35 | } 36 | 37 | #[derive(Clone, Debug)] 38 | pub enum State { 39 | Searching, 40 | Running, 41 | Done, 42 | } 43 | 44 | #[derive(Debug)] 45 | pub struct AlbumData { 46 | pub expanded: bool, 47 | pub name: String, 48 | pub tracks: Vec, 49 | } 50 | 51 | #[derive(Debug)] 52 | pub enum ItemRef<'a> { 53 | Album(&'a AlbumData), 54 | Song(&'a Song), 55 | } 56 | 57 | #[derive(Debug)] 58 | pub struct TrackSelItem<'a> { 59 | pub item: ItemRef<'a>, 60 | pub rank: Option, 61 | } 62 | 63 | pub struct ArtistData { 64 | pub name: String, 65 | pub fetched: bool, 66 | pub sort_names: Vec, 67 | pub albums: Vec, 68 | pub track_sel_state: TableState, 69 | pub search: Filter, 70 | } 71 | 72 | pub enum LibActiveSelector { 73 | ArtistSelector, 74 | TrackSelector, 75 | } 76 | 77 | pub struct FilterCache { 78 | pub query: String, 79 | pub order: Vec>, 80 | pub indices: Vec>, 81 | pub utfstrings_cache: Option>, 82 | } 83 | 84 | pub struct Filter { 85 | pub active: bool, 86 | pub query: String, 87 | pub cache: FilterCache, 88 | } 89 | 90 | #[derive(Clone)] 91 | pub struct InfoEntry { 92 | pub artist: String, 93 | pub artist_sort: Option, 94 | pub album: Option, 95 | pub title: Option, 96 | } 97 | pub struct GlobalSearchState { 98 | pub search: Filter, 99 | pub contents: Option>, 100 | pub results_state: ListState, 101 | } 102 | 103 | pub struct LibraryState { 104 | pub artist_search: Filter, 105 | pub global_search: GlobalSearchState, 106 | pub active: LibActiveSelector, 107 | pub contents: Vec, 108 | pub artist_state: ListState, 109 | } 110 | 111 | pub struct QueueSelector { 112 | pub search: Filter, 113 | pub contents: Vec, 114 | pub state: TableState, 115 | } 116 | 117 | pub struct Model { 118 | pub state: State, 119 | pub status: Status, 120 | pub conn: Client, 121 | pub idle_conn: IdleClient, 122 | pub screen: Screen, 123 | pub toggle_screen: Screen, 124 | pub library: LibraryState, 125 | pub queue: QueueSelector, 126 | pub currentsong: Option, 127 | pub matcher: nucleo_matcher::Matcher, 128 | pub config: Config, 129 | pub parse_state: Vec, 130 | pub frame_size: Rect, 131 | } 132 | 133 | impl Model { 134 | pub fn new(frame_size: Rect) -> Result { 135 | let config = Config::default().try_read_config(); 136 | let mut conn = Self::make_connection(&config); 137 | let idle_conn = IdleClient::new( 138 | Self::make_connection(&config), 139 | &[Subsystem::Database, Subsystem::Player, Subsystem::Options], 140 | )?; 141 | Ok(Model { 142 | state: State::Running, 143 | status: conn.status()?, 144 | conn, 145 | idle_conn, 146 | screen: config.screens.first().cloned().unwrap_or(Screen::Library), 147 | toggle_screen: config 148 | .screens 149 | .last() 150 | .cloned() 151 | .unwrap_or(Screen::Queue), 152 | library: LibraryState::new(), 153 | queue: QueueSelector::new(), 154 | currentsong: None, 155 | matcher: { 156 | let mut default_config = nucleo_matcher::Config::DEFAULT; 157 | default_config.prefer_prefix = config.nucleo_prefer_prefix; 158 | Matcher::new(default_config) 159 | }, 160 | config, 161 | parse_state: Vec::new(), 162 | frame_size, 163 | }) 164 | } 165 | 166 | pub fn make_connection(conf: &Config) -> Client { 167 | if let Some(mpd_url) = &conf.mpd_address { 168 | Client::::connect(mpd_url).unwrap() 169 | } else { 170 | Client::::default() 171 | } 172 | } 173 | 174 | pub fn update_status(&mut self) -> Result<()> { 175 | self.status = self.conn.status()?; 176 | Ok(()) 177 | } 178 | pub fn update_currentsong(&mut self) -> Result<()> { 179 | self.currentsong = self.conn.currentsong()?; 180 | Ok(()) 181 | } 182 | 183 | pub fn update_global_search_contents(&mut self) -> Result<()> { 184 | let mut res = self.conn.list_groups(vec![ 185 | "title", 186 | "album", 187 | "albumartistsort", 188 | "albumartist", 189 | ])?; 190 | self.library.global_search.contents = Some( 191 | res.iter_mut() 192 | .filter_map(|vec| { 193 | let ie = InfoEntry::from(vec); 194 | if !ie.is_redundant() { 195 | Some(ie) 196 | } else { 197 | None 198 | } 199 | }) 200 | .collect::>(), 201 | ); 202 | Ok(()) 203 | } 204 | 205 | pub fn jump_to(&mut self, target: InfoEntry) { 206 | // order: albumartist albumartistsort album title 207 | let artist_idx = self 208 | .library 209 | .contents() 210 | .position(|i| i.name == target.artist); 211 | self.library.artist_state.set_selected(artist_idx); 212 | 213 | if target.album.is_some() || target.title.is_some() { 214 | self.library.active = LibActiveSelector::TrackSelector; 215 | } else { 216 | self.library.active = LibActiveSelector::ArtistSelector; 217 | } 218 | 219 | if target.album.is_none() { 220 | return; 221 | } 222 | if self.library.selected_item().is_some_and(|i| !i.fetched) { 223 | build_library::add_tracks(self) 224 | .expect("couldn't add tracks on the fly while searching"); 225 | } 226 | if let Some(artist) = self.library.selected_item_mut() { 227 | let mut idx: Option = None; 228 | artist.expand_all(); 229 | if let Some(track_name) = target.title { 230 | idx = artist.contents().iter().position(|i| match i.item { 231 | ItemRef::Song(s) => { 232 | *s.title.as_ref().unwrap() == track_name 233 | } 234 | _ => false, 235 | }); 236 | } else if let Some(album_name) = target.album { 237 | idx = artist.contents().iter().position(|i| match i.item { 238 | ItemRef::Album(a) => a.name == *album_name, 239 | _ => false, 240 | }); 241 | } 242 | artist.set_selected(idx); 243 | } 244 | } 245 | } 246 | -------------------------------------------------------------------------------- /src/model/impl_album_song.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use std::time::Duration; 3 | 4 | impl AlbumData { 5 | pub fn total_time(&self) -> Duration { 6 | self.tracks 7 | .iter() 8 | .map(|i| i.duration.unwrap_or(Duration::from_secs(0))) 9 | .sum() 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/model/impl_artiststate.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::model::search_utils::compute_orders; 3 | use proto::*; 4 | use search_utils::compute_indices; 5 | 6 | impl Selector for ArtistData { 7 | fn selector(&self) -> &impl SelectorState { 8 | &self.track_sel_state 9 | } 10 | fn selector_mut(&mut self) -> &mut impl SelectorState { 11 | &mut self.track_sel_state 12 | } 13 | fn len(&self) -> usize { 14 | self.albums.len() 15 | + self 16 | .albums 17 | .iter() 18 | .map(|i| if i.expanded { i.tracks.len() } else { 0 }) 19 | .sum::() 20 | } 21 | } 22 | 23 | impl<'a> ArtistData { 24 | fn find_rank(&self, idx: usize) -> Option { 25 | self.search 26 | .cache 27 | .order 28 | .iter() 29 | .take_while(|i| i.is_some()) 30 | .position(|i| *i == Some(idx)) 31 | } 32 | pub fn expand_all(&mut self) { 33 | for album in &mut self.albums { 34 | if !album.expanded { 35 | album.expanded = true; 36 | } 37 | } 38 | } 39 | pub fn contents(&'a self) -> Vec> { 40 | let mut new: Vec = Vec::new(); 41 | let mut i = 0; // full index 42 | for album in &self.albums { 43 | if self.search.active { 44 | new.push(TrackSelItem::from(album).rank(self.find_rank(i))) 45 | } else { 46 | new.push(album.into()); 47 | } 48 | i += 1; 49 | if album.expanded { 50 | for track in &album.tracks { 51 | if self.search.active { 52 | new.push( 53 | TrackSelItem::from(track).rank(self.find_rank(i)), 54 | ) 55 | } else { 56 | new.push(track.into()); 57 | } 58 | i += 1; 59 | } 60 | } else { 61 | i += album.tracks.len(); 62 | } 63 | } 64 | // if self.search.active && self.search.query.len() > 0 { 65 | // println!("{:?}", new.iter().map(|i| i.rank).collect::>>()); 66 | // // println!("{:?}", self.search.cache.order); 67 | // panic!(); 68 | // } 69 | new 70 | } 71 | pub fn selected_item(&self) -> Option { 72 | let sel_idx = self.selector().selected()?; 73 | let mut i = 0; // keeps track of index with folding 74 | let mut full_index = 0; // keeps track of index without considering folding 75 | for album in &self.albums { 76 | if sel_idx == i { 77 | if self.search.active { 78 | return Some( 79 | TrackSelItem::from(album) 80 | .rank(self.find_rank(full_index)), 81 | ); 82 | } else { 83 | return Some(album.into()); 84 | } 85 | } 86 | i += 1; 87 | full_index += 1; 88 | let al_len = album.tracks.len(); 89 | if album.expanded { 90 | if (sel_idx - i) < al_len { 91 | if self.search.active { 92 | return album.tracks.get(sel_idx - i).map(|song| { 93 | TrackSelItem::from(song).rank( 94 | self.find_rank(full_index + (sel_idx - i)), 95 | ) 96 | }); 97 | } else { 98 | return album 99 | .tracks 100 | .get(sel_idx - i) 101 | .map(|song| song.into()); 102 | } 103 | } 104 | i += al_len; 105 | } 106 | full_index += al_len; 107 | } 108 | None 109 | } 110 | pub fn selected_album_mut(&mut self) -> Option<&mut AlbumData> { 111 | // assumption: order in self.albums is the same as in the viewer. 112 | // NOTE: can't use TrackSelItem enum since references are immutable. 113 | // Tried this and it's busted. 114 | let sel_idx = self.selector().selected()?; 115 | let mut i = 0; 116 | for (album_i, album) in self.albums.iter().enumerate() { 117 | if sel_idx == i { 118 | return self.albums.get_mut(album_i); 119 | } 120 | i += 1; 121 | if album.expanded { 122 | i += album.tracks.len() 123 | } 124 | } 125 | None 126 | } 127 | 128 | pub fn update_search(&mut self, matcher: &mut Matcher) { 129 | if self.search.cache.query == self.search.query { 130 | return; 131 | } 132 | if self.search.cache.utfstrings_cache.is_none() { 133 | let mut tmp: Vec = Vec::new(); 134 | for album in &self.albums { 135 | tmp.push(Utf32String::from(album.name.clone())); 136 | for track in &album.tracks { 137 | tmp.push(Utf32String::from( 138 | track.title.clone().unwrap_or("".into()), 139 | )); 140 | } 141 | } 142 | self.search.cache.utfstrings_cache = Some(tmp); 143 | } 144 | self.search.cache.order = compute_orders( 145 | &self.search.query, 146 | self.search.cache.utfstrings_cache.as_ref().unwrap(), 147 | matcher, 148 | 0, 149 | ); 150 | let strings_for_indices: Vec<&Utf32String> = self 151 | .search 152 | .cache 153 | .order 154 | .iter() 155 | .take_while(|i| i.is_some()) 156 | .map(|i| { 157 | &self.search.cache.utfstrings_cache.as_ref().unwrap() 158 | [i.unwrap()] 159 | }) 160 | .collect(); 161 | 162 | self.search.cache.indices = 163 | compute_indices(&self.search.query, strings_for_indices, matcher); 164 | self.search.cache.query = self.search.query.clone(); 165 | 166 | if self.search.cache.order.iter().any(|i| i.is_some()) { 167 | let mut i = 0; 168 | for album in self.albums.iter_mut() { 169 | album.expanded = false; 170 | if self.search.cache.order.contains(&Some(i)) { 171 | album.expanded = true; 172 | } 173 | i += 1; 174 | for _ in &album.tracks { 175 | if self.search.cache.order.contains(&Some(i)) { 176 | album.expanded = true; 177 | } 178 | i += 1 179 | } 180 | } 181 | } 182 | let mut top_idx: Option = None; 183 | for (i, item) in self.contents().iter().enumerate() { 184 | if let Some(0) = item.rank { 185 | top_idx = Some(i); 186 | } 187 | } 188 | self.set_selected(top_idx); 189 | } 190 | } 191 | 192 | impl ArtistData { 193 | pub fn from_names(name: String, sort_names: Vec) -> Self { 194 | Self { 195 | name, 196 | fetched: false, 197 | albums: Vec::new(), 198 | sort_names, 199 | track_sel_state: TableState::default(), 200 | search: Filter::new(), 201 | } 202 | } 203 | pub fn to_fuzzy_find_str(&self) -> String { 204 | if self.sort_names.first().is_some_and(|n| *n == self.name) { 205 | self.name.clone() 206 | } else { 207 | format!("{} [{}]", self.name, self.sort_names.join(", ")) 208 | } 209 | } 210 | } 211 | 212 | impl<'a> From<&'a AlbumData> for TrackSelItem<'a> { 213 | fn from(value: &'a AlbumData) -> Self { 214 | Self { 215 | item: ItemRef::Album(value), 216 | rank: None, 217 | } 218 | } 219 | } 220 | 221 | impl<'a> From<&'a Song> for TrackSelItem<'a> { 222 | fn from(value: &'a Song) -> Self { 223 | Self { 224 | item: ItemRef::Song(value), 225 | rank: None, 226 | } 227 | } 228 | } 229 | 230 | impl TrackSelItem<'_> { 231 | pub fn rank(mut self, val: Option) -> Self { 232 | self.rank = val; 233 | self 234 | } 235 | } 236 | -------------------------------------------------------------------------------- /src/model/impl_library.rs: -------------------------------------------------------------------------------- 1 | use super::proto::*; 2 | use super::*; 3 | use nucleo_matcher::Matcher; 4 | use search_utils::{compute_indices, compute_orders}; 5 | 6 | impl LibraryState { 7 | pub fn new() -> Self { 8 | Self { 9 | artist_search: super::Filter::new(), 10 | global_search: GlobalSearchState { 11 | contents: None, 12 | results_state: ListState::default(), 13 | search: Filter::new(), 14 | }, 15 | active: super::LibActiveSelector::ArtistSelector, 16 | contents: Vec::new(), 17 | artist_state: ListState::default(), 18 | } 19 | } 20 | } 21 | 22 | impl Selector for LibraryState { 23 | fn selector(&self) -> &impl SelectorState { 24 | &self.artist_state 25 | } 26 | fn selector_mut(&mut self) -> &mut impl SelectorState { 27 | &mut self.artist_state 28 | } 29 | fn len(&self) -> usize { 30 | self.contents_vec().len() 31 | } 32 | } 33 | 34 | impl Searchable for LibraryState { 35 | fn filter(&self) -> &Filter { 36 | &self.artist_search 37 | } 38 | fn filter_mut(&mut self) -> &mut Filter { 39 | &mut self.artist_search 40 | } 41 | fn contents(&self) -> Box + '_> { 42 | if self.should_filter() { 43 | Box::new( 44 | self.filter() 45 | .cache 46 | .order 47 | .iter() 48 | .filter_map(|idx| idx.map(|i| &self.contents[i])), 49 | ) 50 | } else { 51 | Box::new(self.contents.iter()) 52 | } 53 | } 54 | fn selected_item_mut(&mut self) -> Option<&mut ArtistData> { 55 | if self.should_filter() { 56 | self.selector().selected().and_then(|i| { 57 | self.artist_search.cache.order[i] 58 | .and_then(|j| self.contents.get_mut(j)) 59 | }) 60 | } else { 61 | self.selector() 62 | .selected() 63 | .and_then(|i| self.contents.get_mut(i)) 64 | } 65 | } 66 | fn update_filter_cache( 67 | &mut self, 68 | matcher: &mut Matcher, 69 | top_k: Option, 70 | ) { 71 | if self.filter().cache.query == self.artist_search.query { 72 | return; 73 | } 74 | if self.filter().cache.utfstrings_cache.is_none() { 75 | self.filter_mut().cache.utfstrings_cache = Some( 76 | self.contents 77 | .iter() 78 | .map(|i| Utf32String::from(i.to_fuzzy_find_str())) 79 | .collect(), 80 | ); 81 | } 82 | self.filter_mut().cache.order = compute_orders( 83 | &self.filter().query, 84 | self.filter().cache.utfstrings_cache.as_ref().unwrap(), 85 | matcher, 86 | 0, 87 | ); 88 | 89 | let strings_iterator = self 90 | .filter() 91 | .cache 92 | .order 93 | .iter() 94 | .take_while(|i| i.is_some()) 95 | .map(|i| { 96 | &self.filter().cache.utfstrings_cache.as_ref().unwrap() 97 | [i.unwrap()] 98 | }); 99 | let strings: Vec<&Utf32String>; 100 | if let Some(k) = top_k { 101 | strings = strings_iterator.take(k).collect(); 102 | } else { 103 | strings = strings_iterator.collect(); 104 | } 105 | self.filter_mut().cache.indices = 106 | compute_indices(&self.filter().query, strings, matcher); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/model/impl_queue.rs: -------------------------------------------------------------------------------- 1 | use super::proto::*; 2 | use super::*; 3 | use crate::util::song_to_str; 4 | use nucleo_matcher::Matcher; 5 | 6 | impl Selector for QueueSelector { 7 | fn selector(&self) -> &impl SelectorState { 8 | &self.state 9 | } 10 | fn selector_mut(&mut self) -> &mut impl SelectorState { 11 | &mut self.state 12 | } 13 | fn len(&self) -> usize { 14 | self.contents_vec().len() 15 | } 16 | } 17 | 18 | impl Searchable for QueueSelector { 19 | fn filter(&self) -> &Filter { 20 | &self.search 21 | } 22 | fn filter_mut(&mut self) -> &mut Filter { 23 | &mut self.search 24 | } 25 | fn contents(&self) -> Box + '_> { 26 | if self.should_filter() { 27 | Box::new( 28 | self.filter() 29 | .cache 30 | .order 31 | .iter() 32 | .filter_map(|idx| idx.map(|i| &self.contents[i])), 33 | ) 34 | } else { 35 | Box::new(self.contents.iter()) 36 | } 37 | } 38 | fn selected_item_mut(&mut self) -> Option<&mut Song> { 39 | if self.should_filter() { 40 | self.selector() 41 | .selected() 42 | .and_then(|i| self.filter().cache.order.get(i).cloned()) 43 | .and_then(|i| self.contents.get_mut(i?)) 44 | } else { 45 | self.selector() 46 | .selected() 47 | .and_then(|i| self.contents.get_mut(i)) 48 | } 49 | } 50 | 51 | #[allow(unused_variables)] 52 | fn update_filter_cache( 53 | &mut self, 54 | matcher: &mut Matcher, 55 | top_k: Option, 56 | ) { 57 | if self.filter().cache.query == self.filter().query { 58 | return; 59 | } 60 | if self.filter().cache.utfstrings_cache.is_none() { 61 | self.filter_mut().cache.utfstrings_cache = Some( 62 | self.contents 63 | .iter() 64 | .map(|i| Utf32String::from(song_to_str(i))) 65 | .collect(), 66 | ); 67 | } 68 | self.filter_mut().cache.order = search_utils::compute_orders( 69 | &self.filter().query, 70 | self.filter().cache.utfstrings_cache.as_ref().unwrap(), 71 | matcher, 72 | 0, 73 | ); 74 | } 75 | } 76 | 77 | impl QueueSelector { 78 | pub fn new() -> Self { 79 | Self { 80 | search: Filter::new(), 81 | contents: Vec::new(), 82 | state: TableState::default(), 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/model/impl_searchstate.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use nucleo_matcher::Matcher; 3 | use proto::*; 4 | use search_utils::*; 5 | 6 | impl FilterCache { 7 | pub fn new() -> Self { 8 | Self { 9 | query: String::new(), 10 | order: Vec::new(), 11 | indices: Vec::new(), 12 | utfstrings_cache: None, 13 | } 14 | } 15 | pub fn clear_matches(&mut self) { 16 | self.query.clear(); 17 | self.order.clear(); 18 | self.indices.clear(); 19 | } 20 | } 21 | 22 | impl Filter { 23 | pub fn new() -> Self { 24 | Self { 25 | active: false, 26 | query: String::new(), 27 | cache: FilterCache::new(), 28 | } 29 | } 30 | pub fn set_on(&mut self) { 31 | self.active = true; 32 | } 33 | pub fn set_off(&mut self) { 34 | self.active = false; 35 | self.query.clear(); 36 | self.cache.clear_matches(); 37 | } 38 | } 39 | 40 | impl From<&mut Vec> for InfoEntry { 41 | fn from(v: &mut Vec) -> Self { 42 | if v.len() > 4 { 43 | panic!("too much info given to infoentry"); 44 | } else { 45 | let mut drained = v.drain(..); 46 | InfoEntry { 47 | artist: drained.nth(0).unwrap(), 48 | artist_sort: drained.nth(0), 49 | album: drained.nth(0), 50 | title: drained.nth(0), 51 | } 52 | } 53 | } 54 | } 55 | 56 | impl InfoEntry { 57 | pub fn is_redundant(&self) -> bool { 58 | self.album.is_none() 59 | && self.title.is_none() 60 | && self.artist_sort.as_ref().is_some_and(|i| *i == self.artist) 61 | } 62 | pub fn to_search_string(&self) -> String { 63 | let mut out: String = self.artist.clone(); 64 | if let Some(artist_sort) = &self.artist_sort { 65 | if *artist_sort != out { 66 | out.push_str(&format!(" {}{}{}", "[", artist_sort, "]")); 67 | } 68 | } 69 | if let Some(album) = &self.album { 70 | out.push('/'); 71 | out.push_str(album); 72 | } 73 | if let Some(title) = &self.title { 74 | out.push('/'); 75 | out.push_str(title); 76 | } 77 | out 78 | } 79 | } 80 | 81 | impl Selector for GlobalSearchState { 82 | fn selector(&self) -> &impl SelectorState { 83 | &self.results_state 84 | } 85 | fn selector_mut(&mut self) -> &mut impl SelectorState { 86 | &mut self.results_state 87 | } 88 | fn len(&self) -> usize { 89 | if self.filter().active { 90 | self.filter() 91 | .cache 92 | .order 93 | .iter() 94 | .take_while(|i| i.is_some()) 95 | .count() 96 | } else { 97 | match &self.contents { 98 | Some(v) => v.len(), 99 | None => 0, 100 | } 101 | } 102 | } 103 | } 104 | 105 | impl Searchable for GlobalSearchState { 106 | fn filter(&self) -> &Filter { 107 | &self.search 108 | } 109 | fn filter_mut(&mut self) -> &mut Filter { 110 | &mut self.search 111 | } 112 | fn contents(&self) -> Box + '_> { 113 | match &self.contents { 114 | Some(c) => { 115 | if self.should_filter() { 116 | Box::new( 117 | self.filter() 118 | .cache 119 | .order 120 | .iter() 121 | .filter_map(|idx| idx.map(|i| &c[i])), 122 | ) 123 | } else { 124 | Box::new(c.iter()) 125 | } 126 | } 127 | None => Box::new(std::iter::empty()), 128 | } 129 | } 130 | 131 | fn selected_item_mut(&mut self) -> Option<&mut InfoEntry> { 132 | unimplemented!(); 133 | } 134 | 135 | fn update_filter_cache( 136 | &mut self, 137 | matcher: &mut Matcher, 138 | top_k: Option, 139 | ) { 140 | if self.search.query == self.search.cache.query { 141 | return; 142 | } 143 | if self.contents.is_none() { 144 | self.search.cache.order = Vec::new(); 145 | self.search.cache.indices = Vec::new(); 146 | return; 147 | } 148 | if self.filter().cache.utfstrings_cache.is_none() { 149 | self.filter_mut().cache.utfstrings_cache = Some( 150 | self.contents 151 | .iter() 152 | .flatten() 153 | .map(|i| Utf32String::from(i.to_search_string())) 154 | .collect(), 155 | ); 156 | } 157 | 158 | self.filter_mut().cache.query = self.filter().query.clone(); 159 | self.filter_mut().cache.order = compute_orders( 160 | &self.filter().query, 161 | self.filter().cache.utfstrings_cache.as_ref().unwrap(), 162 | matcher, 163 | 0, 164 | ); 165 | 166 | let strings_iterator = self 167 | .filter() 168 | .cache 169 | .order 170 | .iter() 171 | .take_while(|i| i.is_some()) 172 | .map(|i| { 173 | &self.filter().cache.utfstrings_cache.as_ref().unwrap() 174 | [i.unwrap()] 175 | }); 176 | let strings: Vec<&Utf32String>; 177 | if let Some(k) = top_k { 178 | strings = strings_iterator.take(k).collect(); 179 | } else { 180 | strings = strings_iterator.collect(); 181 | } 182 | self.filter_mut().cache.indices = 183 | compute_indices(&self.filter().query, strings, matcher); 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /src/model/proto.rs: -------------------------------------------------------------------------------- 1 | extern crate mpd; 2 | use super::*; 3 | 4 | pub trait SelectorState { 5 | fn selected(&self) -> Option; 6 | fn set_selected(&mut self, s: Option); 7 | fn offset(&self) -> usize; 8 | fn set_offset(&mut self, s: usize); 9 | } 10 | 11 | impl SelectorState for ListState { 12 | fn selected(&self) -> Option { 13 | self.selected() 14 | } 15 | fn offset(&self) -> usize { 16 | self.offset() 17 | } 18 | fn set_selected(&mut self, s: Option) { 19 | *self.selected_mut() = s; 20 | } 21 | fn set_offset(&mut self, s: usize) { 22 | *self.offset_mut() = s; 23 | } 24 | } 25 | 26 | impl SelectorState for TableState { 27 | fn selected(&self) -> Option { 28 | self.selected() 29 | } 30 | fn offset(&self) -> usize { 31 | self.offset() 32 | } 33 | fn set_selected(&mut self, s: Option) { 34 | *self.selected_mut() = s; 35 | } 36 | fn set_offset(&mut self, s: usize) { 37 | *self.offset_mut() = s; 38 | } 39 | } 40 | 41 | pub trait Selector { 42 | fn selector(&self) -> &impl SelectorState; 43 | fn selector_mut(&mut self) -> &mut impl SelectorState; 44 | fn len(&self) -> usize; 45 | 46 | fn selected(&self) -> Option { 47 | self.selector().selected() 48 | } 49 | fn offset(&self) -> usize { 50 | self.selector().offset() 51 | } 52 | fn set_selected(&mut self, val: Option) { 53 | self.selector_mut().set_selected(val); 54 | } 55 | fn set_offset(&mut self, val: usize) { 56 | self.selector_mut().set_offset(val); 57 | } 58 | fn init(&mut self) { 59 | // idempotent 60 | if self.len() != 0 && self.selected().is_none() { 61 | self.set_selected(Some(0)); 62 | } 63 | } 64 | fn watch_oob(&mut self) { 65 | if self.len() == 0 || self.selected().is_some_and(|f| f >= self.len()) { 66 | self.set_selected(None) 67 | } 68 | } 69 | } 70 | 71 | pub trait Searchable: Selector { 72 | fn filter(&self) -> &Filter; 73 | fn filter_mut(&mut self) -> &mut Filter; 74 | fn contents(&self) -> Box + '_>; 75 | fn selected_item_mut(&mut self) -> Option<&mut T>; 76 | fn update_filter_cache( 77 | &mut self, 78 | matcher: &mut Matcher, 79 | top_k: Option, 80 | ); 81 | fn selected_item(&self) -> Option<&T> { 82 | self.selector() 83 | .selected() 84 | .and_then(|i| self.contents().nth(i)) 85 | } 86 | fn contents_vec(&self) -> Vec<&T> { 87 | self.contents().collect() 88 | } 89 | fn should_filter(&self) -> bool { 90 | self.filter().active 91 | && self.filter().cache.order.iter().any(|i| i.is_some()) 92 | && !self.filter().query.is_empty() 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/model/search_utils.rs: -------------------------------------------------------------------------------- 1 | use nucleo_matcher::pattern::{AtomKind, CaseMatching, Normalization, Pattern}; 2 | use nucleo_matcher::Matcher; 3 | use nucleo_matcher::Utf32String; 4 | 5 | pub fn compute_orders( 6 | query: &str, 7 | strings: &[Utf32String], 8 | matcher: &mut Matcher, 9 | score_threshold: u32, 10 | ) -> Vec> { 11 | let pattern = Pattern::new( 12 | query, 13 | CaseMatching::Ignore, 14 | Normalization::Smart, 15 | AtomKind::Fuzzy, 16 | ); 17 | let scores = strings 18 | .iter() 19 | .map(|i| pattern.score(i.slice(..), matcher)) 20 | .collect::>>(); 21 | let mut order = scores 22 | .into_iter() 23 | .enumerate() 24 | .collect::)>>(); 25 | order.sort_by(|a, b| b.1.unwrap_or(0).cmp(&a.1.unwrap_or(0))); 26 | let order = order 27 | .iter() 28 | .map(|i| { 29 | if i.1.is_some_and(|score| score > score_threshold) { 30 | Some(i.0) 31 | } else { 32 | None 33 | } 34 | }) 35 | .collect::>>(); 36 | order 37 | } 38 | 39 | pub fn compute_indices( 40 | query: &str, 41 | strings: Vec<&Utf32String>, 42 | matcher: &mut Matcher, 43 | ) -> Vec> { 44 | let pattern = Pattern::new( 45 | query, 46 | CaseMatching::Ignore, 47 | Normalization::Smart, 48 | AtomKind::Fuzzy, 49 | ); 50 | let mut indices: Vec> = Vec::new(); 51 | for s in strings { 52 | let mut tmp: Vec = Vec::new(); 53 | pattern.indices(s.slice(..), matcher, &mut tmp); 54 | indices.push(tmp); 55 | } 56 | indices 57 | } 58 | -------------------------------------------------------------------------------- /src/update.rs: -------------------------------------------------------------------------------- 1 | use crate::config::keybind::{KeybindMap, KeybindTarget}; 2 | use crate::event_handler::Result; 3 | use crate::model::proto::Searchable; 4 | use crate::model::{Model, Screen, State}; 5 | use bitflags::bitflags; 6 | use mpd::status::State as PlayState; 7 | use mpd::Subsystem; 8 | use ratatui::crossterm::event::{self, KeyCode, KeyEvent}; 9 | use std::option::Option; 10 | use std::time::Duration; 11 | 12 | pub mod build_library; 13 | mod handlers; 14 | mod updaters; 15 | 16 | bitflags! { 17 | pub struct Update: u8 { 18 | const QUEUE = 0b00000001; 19 | const CURRENT_ARTIST = 0b00000010; 20 | const STATUS = 0b00000100; 21 | const CURRENT_SONG = 0b00001000; 22 | const START_PLAYING = 0b00010000; 23 | const IDLE_UPDATES = 0b00100000; 24 | } 25 | } 26 | 27 | #[derive(PartialEq, Eq, Debug, Clone)] 28 | pub enum Vertical { 29 | Up, 30 | Down, 31 | Top, 32 | Bottom, 33 | } 34 | 35 | #[derive(PartialEq, Eq, Clone, Debug)] 36 | pub enum Horizontal { 37 | Left, 38 | Right, 39 | } 40 | 41 | #[derive(PartialEq, Eq, Clone, Debug)] 42 | pub enum Dirs { 43 | Vert(Vertical), 44 | Horiz(Horizontal), 45 | } 46 | 47 | #[derive(PartialEq, Eq, Clone, Debug)] 48 | pub enum SearchMsg { 49 | Start, 50 | End, 51 | } 52 | 53 | #[derive(Clone, Debug)] 54 | pub enum Toggle { 55 | Repeat, 56 | Random, 57 | Single, 58 | Consume, 59 | } 60 | 61 | #[derive(PartialEq, Clone, Debug)] 62 | pub enum SeekDirection { 63 | Forward, 64 | Backward, 65 | } 66 | 67 | #[derive(Clone, Debug)] 68 | pub enum Message { 69 | Direction(Dirs), 70 | ScrollScreenful(Vertical), 71 | PlayPause, 72 | NextSong, 73 | PreviousSong, 74 | Seek(SeekDirection), 75 | UpdateDB, 76 | Select, 77 | SwitchState(State), 78 | SwitchScreen(usize), 79 | ToggleScreen, 80 | Delete, 81 | TogglePanel, 82 | Fold, 83 | Clear, 84 | LocalSearch(SearchMsg), 85 | GlobalSearch(SearchMsg), 86 | Escape, 87 | Set(Toggle), 88 | } 89 | 90 | pub fn update_tick(model: &mut Model) -> Result<()> { 91 | update_screens(model, Update::all())?; 92 | Ok(()) 93 | } 94 | 95 | pub fn update_screens(model: &mut Model, mut update: Update) -> Result<()> { 96 | if update.contains(Update::IDLE_UPDATES) { 97 | let changes = model.idle_conn.get()?; 98 | if changes.contains(&Subsystem::Database) { 99 | build_library::build_library(model)?; 100 | } 101 | if changes.contains(&Subsystem::Update) 102 | || changes.contains(&Subsystem::Options) 103 | { 104 | update |= Update::STATUS; 105 | } 106 | } 107 | if update.contains(Update::QUEUE) { 108 | model.queue.contents = model.conn.queue().unwrap_or_default(); 109 | } 110 | if update.contains(Update::CURRENT_ARTIST) 111 | && model.library.selected_item_mut().is_some() 112 | { 113 | build_library::add_tracks(model)?; 114 | } 115 | if update.contains(Update::START_PLAYING) { 116 | if !update.contains(Update::QUEUE) { 117 | model.queue.contents = model.conn.queue().unwrap_or_default(); 118 | } 119 | model.update_status()?; 120 | if model.status.queue_len > 0 && model.status.state == mpd::State::Stop 121 | { 122 | model.conn.switch(0)?; 123 | } 124 | } 125 | if update.contains(Update::CURRENT_SONG) { 126 | model.update_currentsong()?; 127 | } 128 | if update.contains(Update::STATUS) { 129 | model.update_status()?; 130 | } 131 | match model.screen { 132 | Screen::Library => updaters::update_library(model)?, 133 | Screen::Queue => updaters::update_queue(model)?, 134 | } 135 | Ok(()) 136 | } 137 | 138 | fn parse_msg( 139 | key: event::KeyEvent, 140 | state: &mut Vec, 141 | keybinds: &KeybindMap, 142 | ) -> Option { 143 | state.push(key); 144 | match keybinds.lookup(state) { 145 | Some(KeybindTarget::Msg(m)) => { 146 | state.clear(); 147 | Some(m.clone()) 148 | } 149 | Some(KeybindTarget::Map(_)) => None, 150 | None => { 151 | state.clear(); 152 | None 153 | } 154 | } 155 | } 156 | 157 | pub fn handle_key(model: &mut Model, k: KeyEvent) -> Result { 158 | match model.state { 159 | State::Searching => match model.screen { 160 | Screen::Library => { 161 | Ok(handlers::library_handler::handle_search(model, k)?) 162 | } 163 | Screen::Queue => { 164 | Ok(handlers::queue_handler::handle_search(model, k)?) 165 | } 166 | }, 167 | State::Running => { 168 | if let Some(m) = 169 | parse_msg(k, &mut model.parse_state, &model.config.keybindings) 170 | { 171 | Ok(handle_msg(model, m)?) 172 | } else { 173 | Ok(Update::empty()) 174 | } 175 | } 176 | State::Done => Ok(Update::empty()), 177 | } 178 | } 179 | 180 | pub fn handle_msg(model: &mut Model, m: Message) -> Result { 181 | match m { 182 | Message::SwitchState(state) => { 183 | model.state = state; 184 | Ok(Update::empty()) 185 | } 186 | Message::SwitchScreen(to) => { 187 | if let Some(screen) = model.config.screens.get(to - 1) { 188 | model.toggle_screen = model.screen.clone(); 189 | model.screen = screen.clone(); 190 | } 191 | Ok(Update::empty()) 192 | } 193 | Message::UpdateDB => { 194 | let id = model.conn.update()?; 195 | loop { 196 | // hang until finished updating (this update job) 197 | if model 198 | .conn 199 | .status() 200 | .ok() 201 | .and_then(|i| i.updating_db) 202 | .is_none_or(|i| i != id) 203 | { 204 | break; 205 | } 206 | } 207 | build_library::build_library(model)?; 208 | Ok(Update::empty()) 209 | } 210 | Message::PlayPause => { 211 | model.conn.toggle_pause()?; 212 | Ok(Update::STATUS) 213 | } 214 | Message::NextSong => match model.status.state { 215 | PlayState::Stop => Ok(Update::empty()), 216 | _ => { 217 | model.conn.next()?; 218 | Ok(Update::CURRENT_SONG | Update::STATUS) 219 | } 220 | }, 221 | Message::PreviousSong => match model.status.state { 222 | PlayState::Stop => Ok(Update::empty()), 223 | _ => { 224 | model.conn.prev()?; 225 | Ok(Update::CURRENT_SONG | Update::STATUS) 226 | } 227 | }, 228 | Message::Seek(direction) => { 229 | if let (Some((current_pos, total)), Some(queue_pos)) = 230 | (model.status.time, model.status.song) 231 | { 232 | let delta = Duration::from_secs( 233 | model.config.seek_seconds.unsigned_abs(), 234 | ); 235 | 236 | let new_pos = if direction == SeekDirection::Backward { 237 | (current_pos.checked_sub(delta)) 238 | .unwrap_or(Duration::default()) 239 | } else { 240 | (current_pos.checked_add(delta)).unwrap_or(total).min(total) 241 | }; 242 | 243 | if new_pos >= total { 244 | model.conn.next()?; 245 | Ok(Update::CURRENT_SONG | Update::STATUS) 246 | } else { 247 | model.conn.seek(queue_pos.pos, new_pos)?; 248 | Ok(Update::STATUS) 249 | } 250 | } else { 251 | Ok(Update::empty()) 252 | } 253 | } 254 | Message::Set(t) => { 255 | match t { 256 | Toggle::Repeat => model.conn.repeat(!model.status.repeat), 257 | Toggle::Single => model.conn.single(!model.status.single), 258 | Toggle::Random => model.conn.random(!model.status.random), 259 | Toggle::Consume => model.conn.consume(!model.status.consume), 260 | }?; 261 | Ok(Update::STATUS) 262 | } 263 | Message::Clear => { 264 | model.conn.clear()?; 265 | Ok(Update::STATUS | Update::QUEUE | Update::CURRENT_SONG) 266 | } 267 | other => match model.screen { 268 | Screen::Library => { 269 | handlers::library_handler::handle_library(model, other) 270 | } 271 | Screen::Queue => { 272 | handlers::queue_handler::handle_queue(model, other) 273 | } 274 | }, 275 | } 276 | } 277 | -------------------------------------------------------------------------------- /src/update/build_library.rs: -------------------------------------------------------------------------------- 1 | extern crate mpd; 2 | use crate::event_handler::Result; 3 | use crate::model::proto::*; 4 | use crate::model::{AlbumData, ArtistData, Model}; 5 | use itertools::Itertools; 6 | use mpd::{Query, Term}; 7 | use std::borrow::Cow::Borrowed; 8 | 9 | pub fn build_library(model: &mut Model) -> Result<()> { 10 | let artists = model 11 | .conn 12 | .list_group_2(("albumartistsort".into(), "albumartist".into()))?; 13 | 14 | model.library.contents.clear(); 15 | for chunk in artists.chunk_by(|_a, b| b.0 == "AlbumArtistSort") { 16 | if let Some(albumartist) = chunk.first().map(|i| i.1.clone()) { 17 | model.library.contents.push(ArtistData::from_names( 18 | albumartist, 19 | chunk.iter().skip(1).map(|i| i.1.clone()).collect(), 20 | )); 21 | } 22 | } 23 | // sort by sort name 24 | model.library.contents.sort_by(|a, b| { 25 | let a_name = a.sort_names.first().unwrap_or(&a.name); 26 | let b_name = b.sort_names.first().unwrap_or(&a.name); 27 | a_name.to_lowercase().cmp(&b_name.to_lowercase()) 28 | }); 29 | model.library.contents.shrink_to_fit(); 30 | Ok(()) 31 | } 32 | 33 | pub fn add_tracks(model: &mut Model) -> Result<()> { 34 | let song_data = model.conn.find( 35 | Query::new().and( 36 | Term::Tag(Borrowed("AlbumArtist")), 37 | match model.library.selected_item_mut() { 38 | Some(a) => a.name.clone(), 39 | None => return Ok(()), 40 | }, 41 | ), 42 | None, 43 | )?; 44 | let mut albums: Vec = Vec::new(); 45 | 46 | // chunks have album field invariant! 47 | for album in song_data.chunk_by(|a, b| { 48 | a.tags.iter().find(|t| t.0 == "Album") 49 | == b.tags.iter().find(|t| t.0 == "Album") 50 | }) { 51 | if let Some(track) = album.first() { 52 | albums.push(AlbumData { 53 | name: track 54 | .tags 55 | .iter() 56 | .find(|t| t.0 == "Album") 57 | .cloned() 58 | .map(|i| i.1) 59 | .unwrap_or("".into()), 60 | tracks: album.to_vec(), 61 | expanded: true, 62 | }); 63 | } 64 | } 65 | if let Some(states) = model 66 | .library 67 | .selected_item() 68 | .map(|item| item.albums.iter().map(|i| i.expanded).collect_vec()) 69 | { 70 | if states.len() == albums.len() { 71 | for (i, prev) in albums.iter_mut().zip(states) { 72 | i.expanded = prev; 73 | } 74 | } 75 | } 76 | if let Some(item) = model.library.selected_item_mut() { 77 | item.albums = albums; 78 | item.fetched = true; 79 | } 80 | Ok(()) 81 | } 82 | -------------------------------------------------------------------------------- /src/update/handlers.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::model::*; 3 | use crate::util::safe_add; 4 | use crate::util::safe_subtract; 5 | use event::KeyModifiers; 6 | use nucleo_matcher::Matcher; 7 | use proto::*; 8 | 9 | pub mod library_handler; 10 | pub mod queue_handler; 11 | 12 | pub fn handle_vertical(msg: Vertical, selector: &mut impl Selector) { 13 | match selector.selected() { 14 | None => { 15 | if selector.len() != 0 { 16 | selector.set_selected(Some(0)); 17 | } 18 | } 19 | Some(sel) => selector.set_selected(match msg { 20 | Vertical::Up => Some(safe_subtract(sel, 1, selector.len())), 21 | Vertical::Down => Some(safe_add(sel, 1, selector.len())), 22 | Vertical::Top => Some(0), 23 | Vertical::Bottom => { 24 | Some(safe_subtract(selector.len(), 1, selector.len())) 25 | } 26 | }), 27 | } 28 | } 29 | 30 | pub fn scroll_screenful( 31 | dir: Vertical, 32 | height: usize, 33 | selector: &mut impl Selector, 34 | ) { 35 | let len = selector.len(); 36 | match dir { 37 | Vertical::Up => { 38 | selector.set_selected(Some(selector.offset())); 39 | selector.set_offset(safe_subtract(selector.offset(), height, len)); 40 | } 41 | Vertical::Down => { 42 | let mut next = safe_add(selector.offset(), height, len); 43 | if next > 0 && next < safe_subtract(len, 1, len) { 44 | next = safe_subtract(next, 3, len); 45 | selector.set_offset(next); 46 | } 47 | selector.set_selected(Some(next)); 48 | } 49 | _ => {} 50 | } 51 | } 52 | 53 | // TODO: Figure out a way to eliminate code duplication here 54 | pub fn handle_search_k_tracksel( 55 | artist: &mut ArtistData, 56 | k: KeyEvent, 57 | matcher: &mut Matcher, 58 | ) -> Option { 59 | if k.modifiers.contains(KeyModifiers::CONTROL) { 60 | match k.code { 61 | // TODO: keep track of cursor and implement AEFB 62 | KeyCode::Char('u') => artist.search.query.clear(), 63 | KeyCode::Char('n') => { 64 | if let Some(Some(r)) = artist.selected_item().map(|i| i.rank) { 65 | let idx = artist 66 | .contents() 67 | .iter() 68 | .position(|i| i.rank == Some(r + 1)); 69 | if idx.is_some() { 70 | artist.set_selected(idx) 71 | } 72 | } 73 | } 74 | KeyCode::Char('p') => { 75 | if let Some(Some(r)) = artist.selected_item().map(|i| i.rank) { 76 | if r > 0 { 77 | artist.set_selected( 78 | artist 79 | .contents() 80 | .iter() 81 | .position(|i| i.rank == Some(r - 1)), 82 | ); 83 | } 84 | } 85 | } 86 | _ => {} 87 | } 88 | } else { 89 | match k.code { 90 | KeyCode::Char(c) => artist.search.query.push(c), 91 | KeyCode::Backspace => { 92 | let _ = artist.search.query.pop(); 93 | } 94 | KeyCode::Esc => { 95 | return Some(Message::LocalSearch(SearchMsg::End)); 96 | } 97 | KeyCode::Enter => return Some(Message::Select), 98 | _ => {} 99 | } 100 | } 101 | artist.update_search(matcher); 102 | None 103 | } 104 | 105 | pub fn handle_search_k( 106 | s: &mut impl Searchable, 107 | k: KeyEvent, 108 | matcher: &mut Matcher, 109 | top_k: usize, 110 | ) -> Option { 111 | if k.modifiers.contains(KeyModifiers::CONTROL) { 112 | match k.code { 113 | // TODO: keep track of cursor and implement AEFB 114 | KeyCode::Char('u') => s.filter_mut().query.clear(), 115 | KeyCode::Char('n') => handle_vertical(Vertical::Down, s), 116 | KeyCode::Char('p') => handle_vertical(Vertical::Up, s), 117 | _ => {} 118 | } 119 | } else { 120 | match k.code { 121 | KeyCode::Char(c) => { 122 | s.filter_mut().query.push(c); 123 | } 124 | KeyCode::Backspace => { 125 | let _ = s.filter_mut().query.pop(); 126 | } 127 | KeyCode::Esc => { 128 | return Some(Message::LocalSearch(SearchMsg::End)); 129 | } 130 | KeyCode::Enter => return Some(Message::Select), 131 | _ => {} 132 | } 133 | } 134 | s.update_filter_cache(matcher, Some(top_k)); 135 | s.watch_oob(); 136 | None 137 | } 138 | -------------------------------------------------------------------------------- /src/update/handlers/library_handler.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::event_handler::Result; 3 | use crate::model::ItemRef::*; 4 | use crate::model::LibActiveSelector::*; 5 | use crate::view::layout::library_layout::LibraryLayout; 6 | use crate::view::layout::InoriLayout; 7 | use mpd::Query; 8 | use mpd::Term; 9 | use std::borrow::Cow::Borrowed; 10 | 11 | pub fn handle_library(model: &mut Model, msg: Message) -> Result { 12 | match msg { 13 | Message::LocalSearch(SearchMsg::Start) => { 14 | match model.library.active { 15 | ArtistSelector => { 16 | model.library.artist_search.set_on(); 17 | if model.library.len() != 0 { 18 | model.library.set_selected(Some(0)) 19 | } 20 | } 21 | TrackSelector => { 22 | if let Some(a) = model.library.selected_item_mut() { 23 | a.search.set_on(); 24 | } 25 | } 26 | }; 27 | model.state = State::Searching; 28 | Ok(Update::empty()) 29 | } 30 | Message::LocalSearch(SearchMsg::End) => { 31 | model.state = State::Running; 32 | if model.library.global_search.search.active { 33 | model.library.global_search.search.set_off(); 34 | } 35 | Ok(Update::empty()) 36 | } 37 | Message::GlobalSearch(SearchMsg::Start) => { 38 | model.state = State::Searching; 39 | model.library.artist_search.set_off(); 40 | model.library.global_search.search.set_on(); 41 | if model.library.global_search.contents.is_none() { 42 | model.update_global_search_contents()?; 43 | } 44 | Ok(Update::empty()) 45 | } 46 | Message::Escape => { 47 | match model.library.active { 48 | ArtistSelector => model.library.artist_search.set_off(), 49 | TrackSelector => { 50 | if let Some(a) = model.library.selected_item_mut() { 51 | a.search.set_off(); 52 | a.expand_all(); 53 | } 54 | } 55 | }; 56 | Ok(Update::empty()) 57 | } 58 | Message::ToggleScreen => { 59 | model.screen = Screen::Queue; 60 | Ok(Update::empty()) 61 | } 62 | Message::TogglePanel => { 63 | model.library.active = match model.library.active { 64 | TrackSelector => ArtistSelector, 65 | ArtistSelector => TrackSelector, 66 | }; 67 | Ok(Update::empty()) 68 | } 69 | other => match model.library.active { 70 | ArtistSelector => handle_library_artist(model, other), 71 | TrackSelector => handle_library_track(model, other), 72 | }, 73 | } 74 | } 75 | 76 | pub fn handle_search(model: &mut Model, k: KeyEvent) -> Result { 77 | match ( 78 | &model.library.active, 79 | model.library.global_search.search.active, 80 | ) { 81 | (_, true) => { 82 | if let Some(m) = handle_search_k( 83 | &mut model.library.global_search, 84 | k, 85 | &mut model.matcher, 86 | model.frame_size.height.into(), 87 | ) { 88 | handle_msg(model, m) 89 | } else { 90 | if let Some(item) = model.library.global_search.selected_item() 91 | { 92 | model.jump_to(item.clone()); 93 | } 94 | Ok(Update::empty()) 95 | } 96 | } 97 | (ArtistSelector, _) => { 98 | if let Some(m) = handle_search_k( 99 | &mut model.library, 100 | k, 101 | &mut model.matcher, 102 | model.frame_size.height.into(), 103 | ) { 104 | handle_msg(model, m) 105 | } else { 106 | Ok(Update::empty()) 107 | } 108 | } 109 | (TrackSelector, _) => { 110 | if let Some(artist) = model.library.selected_item_mut() { 111 | let msg = 112 | handle_search_k_tracksel(artist, k, &mut model.matcher); 113 | if let Some(m) = msg { 114 | handle_msg(model, m) 115 | } else { 116 | Ok(Update::empty()) 117 | } 118 | } else { 119 | Ok(Update::empty()) 120 | } 121 | } 122 | } 123 | } 124 | 125 | pub fn handle_library_artist( 126 | model: &mut Model, 127 | msg: Message, 128 | ) -> Result { 129 | match msg { 130 | Message::Direction(Dirs::Vert(d)) => { 131 | handle_vertical(d, &mut model.library); 132 | Ok(Update::CURRENT_ARTIST) 133 | } 134 | Message::ScrollScreenful(v) => { 135 | let k = LibraryLayout::new(model.frame_size, model) 136 | .artist_select 137 | .height; 138 | scroll_screenful(v, k.into(), &mut model.library); 139 | Ok(Update::CURRENT_ARTIST) 140 | } 141 | Message::Direction(Dirs::Horiz(Horizontal::Right)) => { 142 | model.library.active = TrackSelector; 143 | if let Some(f) = model.library.selected_item_mut() { 144 | f.init(); 145 | } 146 | Ok(Update::empty()) 147 | } 148 | Message::Select => { 149 | if let Some(artist) = model.library.selected_item() { 150 | model.conn.findadd(Query::new().and( 151 | Term::Tag(Borrowed("AlbumArtist")), 152 | artist.name.clone(), 153 | ))?; 154 | } 155 | Ok(Update::STATUS 156 | | Update::QUEUE 157 | | Update::START_PLAYING 158 | | Update::CURRENT_SONG) 159 | } 160 | _ => Ok(Update::empty()), 161 | } 162 | } 163 | 164 | pub fn add_item(model: &mut Model) -> Result { 165 | if let Some(artist) = model.library.selected_item_mut() { 166 | match artist.selected_item().map(|i| i.item) { 167 | Some(Album(album)) => model.conn.findadd( 168 | Query::new() 169 | .and( 170 | Term::Tag(Borrowed("AlbumArtist")), 171 | artist.name.clone(), 172 | ) 173 | .and(Term::Tag(Borrowed("Album")), album.name.clone()), 174 | )?, 175 | Some(Song(song)) => model 176 | .conn 177 | .findadd(Query::new().and(Term::File, song.file.clone()))?, 178 | None => {} 179 | } 180 | } 181 | Ok(Update::STATUS 182 | | Update::QUEUE 183 | | Update::START_PLAYING 184 | | Update::CURRENT_SONG) 185 | } 186 | 187 | pub fn handle_library_track(model: &mut Model, msg: Message) -> Result { 188 | match msg { 189 | Message::Direction(Dirs::Vert(d)) => { 190 | if let Some(art) = model.library.selected_item_mut() { 191 | handle_vertical(d, art); 192 | } 193 | Ok(Update::empty()) 194 | } 195 | Message::ScrollScreenful(v) => { 196 | let k = LibraryLayout::new(model.frame_size, model) 197 | .track_select 198 | .height; 199 | if let Some(art) = model.library.selected_item_mut() { 200 | scroll_screenful(v, k.into(), art); 201 | } 202 | Ok(Update::empty()) 203 | } 204 | Message::Direction(Dirs::Horiz(Horizontal::Left)) => { 205 | model.library.active = ArtistSelector; 206 | Ok(Update::empty()) 207 | } 208 | Message::Select => add_item(model), 209 | Message::Fold | Message::Direction(Dirs::Horiz(Horizontal::Right)) => { 210 | if let Some(art) = model.library.selected_item_mut() { 211 | if let Some(album) = art.selected_album_mut() { 212 | album.expanded = !album.expanded; 213 | } else if let Some(idx) = art.selected() { 214 | for i in (0..idx).rev() { 215 | if let Some(Album(_)) = 216 | art.contents().get(i).map(|i| &i.item) 217 | { 218 | art.set_selected(Some(i)); 219 | } 220 | if let Some(album) = art.selected_album_mut() { 221 | album.expanded = !album.expanded; 222 | break; 223 | } 224 | } 225 | } 226 | } 227 | Ok(Update::empty()) 228 | } 229 | _ => Ok(Update::empty()), 230 | } 231 | } 232 | -------------------------------------------------------------------------------- /src/update/handlers/queue_handler.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::view::layout::InoriLayout; 3 | use crate::{event_handler::Result, view::layout::queue_layout::QueueLayout}; 4 | 5 | pub fn handle_queue(model: &mut Model, msg: Message) -> Result { 6 | match msg { 7 | Message::ToggleScreen => { 8 | model.screen = Screen::Library; 9 | Ok(Update::empty()) 10 | } 11 | Message::Direction(Dirs::Vert(d)) => { 12 | handle_vertical(d, &mut model.queue); 13 | Ok(Update::empty()) 14 | } 15 | Message::ScrollScreenful(v) => { 16 | let k = QueueLayout::new(model.frame_size, model).queue.height; 17 | scroll_screenful(v, k.into(), &mut model.queue); 18 | Ok(Update::empty()) 19 | } 20 | Message::Select => { 21 | if let Some(s) = model.queue.selected_item() { 22 | model 23 | .conn 24 | .switch(s.place.expect("Selected song has no place").pos)?; 25 | } 26 | Ok(Update::STATUS | Update::CURRENT_SONG) 27 | } 28 | Message::Direction(Dirs::Horiz(d)) => { 29 | if model.queue.len() >= 2 { 30 | if let Some(p) = model.queue.selected() { 31 | let to = match d { 32 | Horizontal::Left => { 33 | safe_subtract(p, 1, model.queue.len()) 34 | } 35 | Horizontal::Right => safe_add(p, 1, model.queue.len()), 36 | }; 37 | model.conn.swap(p as u32, to as u32)?; 38 | model.queue.set_selected(Some(to)); 39 | model.queue.watch_oob(); 40 | } 41 | } 42 | Ok(Update::STATUS | Update::QUEUE) 43 | } 44 | Message::Delete => { 45 | if let Some(p) = model.queue.selected() { 46 | model.conn.delete(p as u32)?; 47 | model.queue.set_selected(Some(safe_subtract( 48 | p, 49 | 1, 50 | model.queue.len() - 1, 51 | ))); 52 | model.queue.watch_oob(); 53 | } 54 | Ok(Update::STATUS | Update::QUEUE) 55 | } 56 | Message::LocalSearch(SearchMsg::Start) => { 57 | model.queue.search.active = true; 58 | model.state = State::Searching; 59 | if model.queue.len() != 0 { 60 | model.queue.set_selected(Some(0)); 61 | } 62 | Ok(Update::empty()) 63 | } 64 | Message::LocalSearch(SearchMsg::End) => { 65 | model.state = State::Running; 66 | Ok(Update::empty()) 67 | } 68 | Message::Escape => { 69 | model.queue.search.active = false; 70 | model.queue.search.query = String::new(); 71 | Ok(Update::empty()) 72 | } 73 | _ => Ok(Update::empty()), 74 | } 75 | } 76 | 77 | pub fn handle_search(model: &mut Model, k: KeyEvent) -> Result { 78 | if let Some(m) = handle_search_k( 79 | &mut model.queue, 80 | k, 81 | &mut model.matcher, 82 | model.frame_size.height.into(), 83 | ) { 84 | handle_msg(model, m) 85 | } else { 86 | Ok(Update::empty()) 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/update/updaters.rs: -------------------------------------------------------------------------------- 1 | use super::build_library; 2 | use crate::event_handler::Result; 3 | use crate::model::*; 4 | use proto::*; 5 | 6 | pub fn update_library(model: &mut Model) -> Result<()> { 7 | model.library.watch_oob(); 8 | if model.library.contents.is_empty() { 9 | build_library::build_library(model)?; 10 | } 11 | if model.library.len() != 0 && model.library.selected().is_none() { 12 | model.library.set_selected(Some(0)) 13 | } 14 | if !model.library.selected_item().is_some_and(|i| i.fetched) { 15 | build_library::add_tracks(model)?; 16 | } 17 | Ok(()) 18 | } 19 | 20 | pub fn update_queue(model: &mut Model) -> Result<()> { 21 | if model.queue.selected().is_none() 22 | && !model.queue.contents_vec().is_empty() 23 | { 24 | model.queue.set_selected(Some(0)); 25 | } 26 | if model.queue.contents.is_empty() { 27 | model.queue.set_selected(None); 28 | } 29 | Ok(()) 30 | } 31 | -------------------------------------------------------------------------------- /src/util.rs: -------------------------------------------------------------------------------- 1 | use mpd::Song; 2 | use mpd::Status; 3 | use std::time::Duration; 4 | 5 | pub fn safe_add(idx: usize, k: usize, length: usize) -> usize { 6 | if length == 0 { 7 | return idx; 8 | } 9 | if idx + k >= length { 10 | return length - 1; 11 | } 12 | idx + k 13 | } 14 | 15 | pub fn safe_subtract(idx: usize, k: usize, length: usize) -> usize { 16 | if length == 0 || idx == 0 { 17 | return idx; 18 | } 19 | if k >= idx { 20 | return 0; 21 | } 22 | idx - k 23 | } 24 | 25 | pub fn song_album(s: &Song) -> Option<&String> { 26 | Some(&s.tags.iter().find(|t| t.0 == "Album")?.1) 27 | } 28 | 29 | pub fn format_time(d: Duration) -> String { 30 | let total = d.as_secs(); 31 | let m = total / 60; 32 | let s = total % 60; 33 | if m > 59 { 34 | format!("{}:{:02}:{:02}", m / 60, m % 60, s) 35 | } else { 36 | format!("{}:{:02}", m, s) 37 | } 38 | } 39 | 40 | pub fn format_progress(s: &Status) -> String { 41 | if let (Some(e), Some(d)) = (s.elapsed, s.duration) { 42 | format!("{}/{}", format_time(e), &format_time(d)) 43 | } else { 44 | String::new() 45 | } 46 | } 47 | pub fn song_to_str(song: &Song) -> String { 48 | let mut out = String::new(); 49 | if let Some(title) = &song.title { 50 | out.push_str(title); 51 | } 52 | if let Some(artist) = &song.artist { 53 | out.push(' '); 54 | out.push_str(artist); 55 | } 56 | if let Some(album) = song_album(song) { 57 | out.push(' '); 58 | out.push_str(album); 59 | } 60 | out 61 | } 62 | -------------------------------------------------------------------------------- /src/view.rs: -------------------------------------------------------------------------------- 1 | use crate::model::*; 2 | use ratatui::prelude::*; 3 | use ratatui::style::Color::*; 4 | use ratatui::style::Style; 5 | mod artist_select_renderer; 6 | pub mod layout; 7 | pub mod library_renderer; 8 | pub mod queue_renderer; 9 | mod search_renderer; 10 | mod status_renderer; 11 | mod track_select_renderer; 12 | 13 | #[derive(Clone)] 14 | pub struct Theme { 15 | pub block_active: Style, 16 | pub field_album: Style, 17 | pub field_artistsort: Style, 18 | pub item_highlight_active: Style, 19 | pub item_highlight_inactive: Style, 20 | pub progress_bar_filled: Style, 21 | pub progress_bar_unfilled: Style, 22 | pub search_query_active: Style, 23 | pub search_query_inactive: Style, 24 | pub slash_span: Style, 25 | pub status_album: Style, 26 | pub status_artist: Style, 27 | pub status_paused: Style, 28 | pub status_playing: Style, 29 | pub status_stopped: Style, 30 | pub status_title: Style, 31 | } 32 | impl Theme { 33 | pub fn new() -> Self { 34 | Self { 35 | block_active: Style::default().fg(Red), 36 | field_album: Style::default().bold().italic().fg(Red), 37 | field_artistsort: Style::default().fg(DarkGray), 38 | item_highlight_active: Style::default().fg(Black).bg(White), 39 | item_highlight_inactive: Style::default().fg(Black).bg(DarkGray), 40 | progress_bar_filled: Style::default() 41 | .fg(LightYellow) 42 | .bg(Black) 43 | .add_modifier(Modifier::BOLD), 44 | progress_bar_unfilled: Style::default().fg(Black), 45 | search_query_active: Style::default().bg(White).fg(Black), 46 | search_query_inactive: Style::default().bg(DarkGray).fg(Black), 47 | slash_span: Style::default().fg(LightMagenta), 48 | status_album: Style::default().bold().italic().fg(Red), 49 | status_artist: Style::default().fg(Cyan), 50 | status_paused: Style::default().fg(LightRed), 51 | status_playing: Style::default().fg(LightGreen), 52 | status_stopped: Style::default().fg(Red), 53 | status_title: Style::default().bold(), 54 | } 55 | } 56 | } 57 | 58 | pub fn view(model: &mut Model, frame: &mut Frame) { 59 | // only &mut for ListState/TableState updating. 60 | // view function should be pure! 61 | 62 | let theme = model.config.theme.clone(); 63 | match model.screen { 64 | Screen::Library => library_renderer::render(model, frame, &theme), 65 | Screen::Queue => queue_renderer::render(model, frame, &theme), 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/view/artist_select_renderer.rs: -------------------------------------------------------------------------------- 1 | use super::Theme; 2 | use crate::model::proto::*; 3 | use crate::model::LibActiveSelector::*; 4 | use crate::model::*; 5 | use ratatui::prelude::*; 6 | use ratatui::widgets::*; 7 | 8 | pub fn render_str_with_idxs<'a>( 9 | str: String, 10 | idxs: &[u32], 11 | len: usize, 12 | theme: &Theme, 13 | ) -> Vec> { 14 | let spans: Vec = str 15 | .chars() 16 | .enumerate() 17 | .map(|(i, c)| { 18 | if idxs.contains(&u32::try_from(i).unwrap()) { 19 | Span::from(c.to_string()) 20 | .style(Style::default().add_modifier(Modifier::UNDERLINED)) 21 | } else { 22 | Span::from(c.to_string()) 23 | } 24 | .patch_style(if i >= len { 25 | theme.field_artistsort 26 | } else { 27 | Style::default() 28 | }) 29 | }) 30 | .collect(); 31 | spans 32 | } 33 | 34 | pub fn get_artist_list<'a>(model: &Model, theme: &Theme) -> List<'a> { 35 | if model.library.should_filter() { 36 | let indices = &model.library.artist_search.cache.indices; 37 | List::new(model.library.contents().zip(indices).map( 38 | |(artist, idxs_o)| { 39 | let len = artist.name.chars().count(); 40 | let l = Line::from(render_str_with_idxs( 41 | artist.to_fuzzy_find_str(), 42 | idxs_o, 43 | len, 44 | theme, 45 | )); 46 | l 47 | }, 48 | )) 49 | } else { 50 | List::new( 51 | model 52 | .library 53 | .contents() 54 | .map(|artist| artist.name.clone()) 55 | .collect::>(), 56 | ) 57 | } 58 | } 59 | 60 | pub fn render_artist_list( 61 | model: &mut Model, 62 | frame: &mut Frame, 63 | area: Rect, 64 | theme: &Theme, 65 | ) { 66 | let artist_list = get_artist_list(model, theme) 67 | .block( 68 | match model.library.active { 69 | ArtistSelector => { 70 | Block::bordered().border_style(theme.block_active) 71 | } 72 | TrackSelector => Block::bordered(), 73 | } 74 | .title("Artists"), 75 | ) 76 | .highlight_style(match model.library.active { 77 | ArtistSelector => theme.item_highlight_active, 78 | TrackSelector => theme.item_highlight_inactive, 79 | }); 80 | 81 | frame.render_stateful_widget( 82 | artist_list, 83 | area, 84 | &mut model.library.artist_state, 85 | ); 86 | } 87 | -------------------------------------------------------------------------------- /src/view/layout.rs: -------------------------------------------------------------------------------- 1 | pub mod library_layout; 2 | pub mod queue_layout; 3 | use crate::model::*; 4 | use crate::view::Rect; 5 | 6 | pub trait InoriLayout { 7 | fn new(frame_rect: Rect, model: &Model) -> Self; 8 | } 9 | -------------------------------------------------------------------------------- /src/view/layout/library_layout.rs: -------------------------------------------------------------------------------- 1 | use crate::model::proto::Searchable; 2 | use crate::model::*; 3 | use crate::view::layout::InoriLayout; 4 | use ratatui::prelude::Constraint::*; 5 | use ratatui::prelude::*; 6 | 7 | #[derive(Default)] 8 | pub struct LibraryLayout { 9 | pub artist_select: Rect, 10 | pub artist_search: Option, 11 | pub track_select: Rect, 12 | pub track_search: Option, 13 | pub header: Rect, 14 | pub center_popup: Option, 15 | } 16 | 17 | impl InoriLayout for LibraryLayout { 18 | fn new(frame_rect: Rect, model: &Model) -> Self { 19 | let mut new = LibraryLayout::default(); 20 | let layout = Layout::vertical(vec![Max(4), Min(1)]).split(frame_rect); 21 | let menu_layout = 22 | Layout::horizontal(vec![Ratio(1, 3), Ratio(2, 3)]).split(layout[1]); 23 | 24 | new.header = Layout::horizontal(vec![Ratio(1, 1)]).split(layout[0])[0]; 25 | 26 | let left_panel = 27 | Layout::vertical(vec![Max(3), Min(1)]).split(menu_layout[0]); 28 | 29 | let right_panel = 30 | Layout::vertical(vec![Max(3), Min(1)]).split(menu_layout[1]); 31 | 32 | if model.library.artist_search.active { 33 | new.artist_select = left_panel[1]; 34 | new.artist_search = Some(left_panel[0]); 35 | } else { 36 | new.artist_select = menu_layout[0]; 37 | } 38 | 39 | if model 40 | .library 41 | .selected_item() 42 | .is_some_and(|a| a.search.active) 43 | { 44 | new.track_select = right_panel[1]; 45 | new.track_search = Some(right_panel[0]); 46 | } else { 47 | new.track_select = menu_layout[1]; 48 | } 49 | 50 | let center_popup_h = Layout::horizontal(vec![ 51 | Percentage(20), 52 | Percentage(60), 53 | Percentage(20), 54 | ]) 55 | .split(frame_rect); 56 | 57 | let center_popup_v = Layout::vertical(vec![ 58 | Percentage(20), 59 | Percentage(60), 60 | Percentage(20), 61 | ]) 62 | .split(center_popup_h[1]); 63 | 64 | if model.library.global_search.search.active { 65 | new.center_popup = Some(center_popup_v[1]); 66 | } 67 | 68 | new 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/view/layout/queue_layout.rs: -------------------------------------------------------------------------------- 1 | use crate::model::*; 2 | use ratatui::prelude::Constraint::*; 3 | use ratatui::prelude::*; 4 | 5 | use super::InoriLayout; 6 | 7 | #[derive(Default)] 8 | pub struct QueueLayout { 9 | pub header: Rect, 10 | pub search: Option, 11 | pub queue: Rect, 12 | pub progress: Rect, 13 | } 14 | 15 | impl InoriLayout for QueueLayout { 16 | fn new(frame_rect: Rect, model: &Model) -> Self { 17 | let mut new = QueueLayout::default(); 18 | let layout = Layout::default() 19 | .direction(Direction::Vertical) 20 | .constraints(vec![Max(4), Min(1), Max(3)]) 21 | .split(frame_rect); 22 | let content = Layout::vertical(vec![Max(3), Min(1)]).split(layout[1]); 23 | new.header = layout[0]; 24 | 25 | if model.queue.search.active { 26 | new.search = Some(content[0]); 27 | new.queue = content[1]; 28 | } else { 29 | new.queue = layout[1]; 30 | } 31 | new.progress = layout[2]; 32 | new 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/view/library_renderer.rs: -------------------------------------------------------------------------------- 1 | use super::artist_select_renderer::render_artist_list; 2 | use super::layout; 3 | use super::layout::InoriLayout; 4 | use super::search_renderer::make_search_box; 5 | use super::status_renderer::render_status; 6 | use super::track_select_renderer::render_track_list; 7 | use super::Theme; 8 | use crate::model::proto::*; 9 | use crate::model::*; 10 | use ratatui::prelude::Constraint::*; 11 | use ratatui::prelude::*; 12 | use ratatui::widgets::*; 13 | 14 | pub fn render_search_item<'a>( 15 | ie: &InfoEntry, 16 | idx: &[u32], 17 | theme: &Theme, 18 | ) -> Line<'a> { 19 | let mut out: Vec = ie 20 | .to_search_string() 21 | .chars() 22 | .map(|c| Span::from(c.to_string())) 23 | .collect(); 24 | 25 | let mut cur = ie.artist.chars().count(); 26 | if let Some(artist_sort) = &ie.artist_sort { 27 | if *artist_sort != ie.artist { 28 | let len = artist_sort.chars().count(); 29 | cur += 1; // for spc 30 | for item in out.iter_mut().take(cur + len + 2).skip(cur) { 31 | item.style = theme.field_artistsort; 32 | } 33 | cur += len + 2; 34 | } 35 | } 36 | if let Some(album) = &ie.album { 37 | let len = album.chars().count(); 38 | out[cur].style = theme.slash_span; 39 | cur += 1; 40 | for item in out.iter_mut().skip(cur).take(len) { 41 | item.style = theme.field_album; 42 | } 43 | cur += len; 44 | } 45 | if let Some(_title) = &ie.title { 46 | out[cur].style = theme.slash_span; 47 | } 48 | for (i, item) in out.iter_mut().enumerate() { 49 | if idx.contains(&u32::try_from(i).unwrap()) { 50 | item.style = item.style.add_modifier(Modifier::UNDERLINED); 51 | } 52 | } 53 | Line::from(out) 54 | } 55 | 56 | pub fn render_global_search( 57 | model: &mut Model, 58 | frame: &mut Frame, 59 | area: Rect, 60 | theme: &Theme, 61 | ) { 62 | let layout = Layout::vertical(vec![Max(3), Min(1)]) 63 | .horizontal_margin(2) 64 | .vertical_margin(1) 65 | .split(area); 66 | 67 | frame.render_widget(Clear, area); 68 | frame.render_widget( 69 | Block::bordered().border_type(BorderType::Rounded), 70 | area, 71 | ); 72 | frame.render_widget( 73 | make_search_box(&model.library.global_search.search.query, true, theme), 74 | layout[0], 75 | ); 76 | let list = List::new( 77 | model 78 | .library 79 | .global_search 80 | .contents() 81 | .zip(&model.library.global_search.search.cache.indices) 82 | .map(|(ie, idxs)| render_search_item(ie, idxs, theme)), 83 | ); 84 | frame.render_stateful_widget( 85 | list.block(Block::bordered()) 86 | .highlight_style(theme.item_highlight_active), 87 | layout[1], 88 | &mut model.library.global_search.results_state, 89 | ); 90 | } 91 | 92 | pub fn render(model: &mut Model, frame: &mut Frame, theme: &Theme) { 93 | let layout = 94 | layout::library_layout::LibraryLayout::new(frame.area(), model); 95 | 96 | render_status(model, frame, layout.header, theme); 97 | render_track_list(model, frame, layout.track_select, theme); 98 | 99 | if let Some(a) = layout.track_search { 100 | frame.render_widget( 101 | make_search_box( 102 | &model.library.selected_item().unwrap().search.query, 103 | matches!(model.state, State::Searching), 104 | theme, 105 | ), 106 | a, 107 | ); 108 | } 109 | 110 | render_artist_list(model, frame, layout.artist_select, theme); 111 | if let Some(a) = layout.artist_search { 112 | frame.render_widget( 113 | make_search_box( 114 | &model.library.artist_search.query, 115 | matches!(model.state, State::Searching), 116 | theme, 117 | ), 118 | a, 119 | ); 120 | } 121 | if let Some(a) = layout.center_popup { 122 | render_global_search(model, frame, a, theme); 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /src/view/queue_renderer.rs: -------------------------------------------------------------------------------- 1 | use super::layout::queue_layout::QueueLayout; 2 | use super::layout::InoriLayout; 3 | use super::search_renderer::make_search_box; 4 | use super::Theme; 5 | use crate::model::proto::Searchable; 6 | use crate::model::*; 7 | use crate::util::{format_time, song_album}; 8 | use ratatui::prelude::Constraint::*; 9 | use ratatui::prelude::*; 10 | use ratatui::widgets::*; 11 | use std::time::Duration; 12 | 13 | use super::status_renderer::render_status; 14 | 15 | pub fn make_queue<'a>(model: &mut Model, theme: &Theme) -> Table<'a> { 16 | let rows: Vec = model 17 | .queue 18 | .contents() 19 | .map(|song| { 20 | Row::new(vec![ 21 | Cell::from(song.title.clone().unwrap_or("".to_string())), 22 | Cell::from( 23 | Text::from( 24 | song.artist.clone().unwrap_or("Unknown Artist".into()), 25 | ) 26 | .style(theme.status_artist) 27 | .left_aligned(), 28 | ), 29 | Cell::from( 30 | Text::from( 31 | song_album(song) 32 | .cloned() 33 | .unwrap_or("Unknown Album".into()), 34 | ) 35 | .style(theme.field_album) 36 | .left_aligned(), 37 | ), 38 | Cell::from( 39 | Text::from(format_time( 40 | song.duration.unwrap_or(Duration::new(0, 0)), 41 | )) 42 | .left_aligned(), 43 | ), 44 | ]) 45 | .add_modifier( 46 | if song 47 | .place 48 | .is_some_and(|s| model.status.song.is_some_and(|o| s == o)) 49 | { 50 | Modifier::ITALIC | Modifier::BOLD 51 | } else { 52 | Modifier::empty() 53 | }, 54 | ) 55 | }) 56 | .collect(); 57 | let table = Table::new( 58 | rows, 59 | vec![Percentage(50), Percentage(30), Percentage(20), Min(5)], 60 | ) 61 | .row_highlight_style(theme.item_highlight_active) 62 | .block(Block::bordered().title("Queue")); 63 | 64 | table 65 | } 66 | 67 | pub fn render(model: &mut Model, frame: &mut Frame, theme: &Theme) { 68 | let layout = QueueLayout::new(frame.area(), model); 69 | render_status(model, frame, layout.header, theme); 70 | let table = make_queue(model, theme); 71 | 72 | if let Some(a) = layout.search { 73 | frame.render_widget( 74 | make_search_box( 75 | &model.queue.search.query, 76 | matches!(model.state, State::Searching), 77 | theme, 78 | ), 79 | a, 80 | ); 81 | } 82 | 83 | frame.render_stateful_widget(table, layout.queue, &mut model.queue.state); 84 | 85 | let ratio: f64 = match (model.status.elapsed, model.status.duration) { 86 | (Some(e), Some(t)) => e.as_secs_f64() / t.as_secs_f64(), 87 | _ => 0 as f64, 88 | }; 89 | 90 | frame.render_widget( 91 | LineGauge::default() 92 | .block(Block::bordered().title("Progress")) 93 | .filled_style(theme.progress_bar_filled) 94 | .unfilled_style(theme.progress_bar_unfilled) 95 | .line_set(symbols::line::THICK) 96 | .ratio(ratio), 97 | layout.progress, 98 | ); 99 | } 100 | -------------------------------------------------------------------------------- /src/view/search_renderer.rs: -------------------------------------------------------------------------------- 1 | use super::Theme; 2 | use ratatui::prelude::*; 3 | use ratatui::widgets::*; 4 | 5 | pub fn make_search_box<'a>( 6 | query: &'a String, 7 | active: bool, 8 | theme: &Theme, 9 | ) -> Paragraph<'a> { 10 | Paragraph::new(vec![Line::from(vec![ 11 | Span::from("> "), 12 | Span::from(query).style(if active { 13 | theme.search_query_active 14 | } else { 15 | theme.search_query_inactive 16 | }), 17 | ])]) 18 | .block(Block::bordered().border_type(BorderType::Thick)) 19 | } 20 | -------------------------------------------------------------------------------- /src/view/status_renderer.rs: -------------------------------------------------------------------------------- 1 | use super::Theme; 2 | use crate::model::Model; 3 | use crate::util::*; 4 | use mpd::State::*; 5 | use ratatui::prelude::Constraint::*; 6 | use ratatui::prelude::*; 7 | use ratatui::style::Styled; 8 | use ratatui::widgets::*; 9 | 10 | pub fn format_status(state: bool) -> String { 11 | if state { 12 | "#".to_string() 13 | } else { 14 | "-".to_string() 15 | } 16 | } 17 | 18 | pub fn render_status( 19 | model: &mut Model, 20 | frame: &mut Frame, 21 | area: Rect, 22 | theme: &Theme, 23 | ) { 24 | let w = Table::new::, Vec>( 25 | vec![ 26 | Row::new(vec![ 27 | Cell::from(match model.status.state { 28 | Play | Pause => format_progress(&model.status), 29 | Stop => String::new(), 30 | }), 31 | Cell::from( 32 | match &model.currentsong { 33 | Some(song) => Line::from( 34 | song.title 35 | .clone() 36 | .unwrap_or("".into()), 37 | ), 38 | None => Line::from("祈"), 39 | } 40 | .centered() 41 | .set_style(theme.status_title), 42 | ), 43 | Cell::from(Line::from("⎡r z s c⎤").right_aligned()), 44 | ]), 45 | Row::new(vec![ 46 | Cell::from(match model.status.state { 47 | Play => Text::from("[playing]").style(theme.status_playing), 48 | Pause => Text::from("[paused]").style(theme.status_paused), 49 | Stop => Text::from("[stopped]").style(theme.status_stopped), 50 | }), 51 | Cell::from( 52 | match &model.currentsong { 53 | Some(song) => Line::from(vec![ 54 | Span::from( 55 | song.artist 56 | .clone() 57 | .unwrap_or("<ARTIST NOT FOUND>".into()), 58 | ) 59 | .style(theme.status_artist), 60 | Span::from(format!( 61 | " ({})", 62 | song_album(song) 63 | .cloned() 64 | .unwrap_or("<ALBUM NOT FOUND>".into()) 65 | )) 66 | .style(theme.status_album), 67 | ]), 68 | None => "いのり".into(), 69 | } 70 | .centered(), 71 | ), 72 | Cell::from( 73 | Line::from(format!( 74 | "⎣{} {} {} {}⎦", 75 | format_status(model.status.repeat), 76 | format_status(model.status.random), 77 | format_status(model.status.single), 78 | format_status(model.status.consume) 79 | )) 80 | .right_aligned(), 81 | ), 82 | ]), 83 | ], 84 | vec![Max(20), Min(10), Max(20)], 85 | ) 86 | .block(Block::bordered().border_type(BorderType::Rounded)); 87 | frame.render_widget(w, area); 88 | } 89 | -------------------------------------------------------------------------------- /src/view/track_select_renderer.rs: -------------------------------------------------------------------------------- 1 | use super::artist_select_renderer::render_str_with_idxs; 2 | use super::Theme; 3 | use crate::model::proto::*; 4 | use crate::model::LibActiveSelector::*; 5 | use crate::model::*; 6 | use crate::util::format_time; 7 | use ratatui::prelude::Constraint::*; 8 | use ratatui::prelude::*; 9 | use ratatui::widgets::*; 10 | use std::time::Duration; 11 | 12 | fn itemref_to_row<'a>( 13 | artist: &ArtistData, 14 | item: &TrackSelItem, 15 | width: u16, 16 | theme: &Theme, 17 | ) -> Row<'a> { 18 | let idxs = item.rank.and_then(|r| artist.search.cache.indices.get(r)); 19 | let row = match item.item { 20 | ItemRef::Album(a) => { 21 | let mut album_line = vec![Span::from(" ")]; 22 | if let Some(idxs) = idxs { 23 | album_line.extend(render_str_with_idxs( 24 | a.name.clone(), 25 | idxs, 26 | a.name.chars().count(), 27 | theme, 28 | )) 29 | } else { 30 | album_line.push(Span::from(a.name.clone())) 31 | } 32 | album_line.push(Span::from(str::repeat("─", width.into()))); 33 | Row::new(vec![ 34 | Line::from(album_line), 35 | Line::from(format_time(a.total_time())).right_aligned(), 36 | ]) 37 | .style(theme.field_album) 38 | } 39 | ItemRef::Song(s) => { 40 | let mut track_line = vec![Span::from(str::repeat(" ", 3))]; 41 | if let Some(title) = s.title.clone() { 42 | if let Some(idxs) = idxs { 43 | track_line.extend(render_str_with_idxs( 44 | title.clone(), 45 | idxs, 46 | title.chars().count(), 47 | theme, 48 | )) 49 | } else { 50 | track_line.push(Span::from(title)) 51 | } 52 | } else { 53 | track_line.push(Span::from("Unknown Song")) 54 | } 55 | 56 | Row::new(vec![ 57 | Line::from(track_line), 58 | Line::from(vec![Span::from(format_time( 59 | s.duration.unwrap_or(Duration::from_secs(0)), 60 | ))]) 61 | .right_aligned(), 62 | ]) 63 | } 64 | }; 65 | if idxs.is_some() { 66 | row.style(Style::new().bg(Color::DarkGray)) 67 | } else { 68 | row 69 | } 70 | } 71 | 72 | fn get_track_data<'a>( 73 | artist: Option<&ArtistData>, 74 | theme: &Theme, 75 | width: u16, 76 | ) -> Table<'a> { 77 | if let Some(artist) = artist { 78 | let items = artist 79 | .contents() 80 | .iter() 81 | .map(|i| itemref_to_row(artist, i, width, theme)) 82 | .collect::<Vec<Row>>(); 83 | Table::new::<Vec<Row>, Vec<Constraint>>(items, vec![Min(10), Max(9)]) 84 | } else { 85 | Table::new::<Vec<Row>, Vec<u16>>(vec![], vec![]) 86 | } 87 | } 88 | 89 | pub fn render_track_list( 90 | model: &mut Model, 91 | frame: &mut Frame, 92 | area: Rect, 93 | theme: &Theme, 94 | ) { 95 | let list = get_track_data(model.library.selected_item(), theme, area.width) 96 | .block( 97 | match model.library.active { 98 | ArtistSelector => Block::bordered(), 99 | TrackSelector => { 100 | Block::bordered().border_style(theme.block_active) 101 | } 102 | } 103 | .title("Tracks"), 104 | ) 105 | .row_highlight_style(match model.library.active { 106 | ArtistSelector => theme.item_highlight_inactive, 107 | TrackSelector => theme.item_highlight_active, 108 | }) 109 | .highlight_spacing(HighlightSpacing::Always); 110 | 111 | match model.library.selected_item_mut() { 112 | Some(artist) => frame.render_stateful_widget( 113 | list, 114 | area, 115 | &mut artist.track_sel_state, 116 | ), 117 | None => frame.render_widget(list, area), 118 | } 119 | } 120 | --------------------------------------------------------------------------------