cursive_table_view-0.15.0/.cargo_vcs_info.json0000644000000001360000000000100150000ustar { "git": { "sha1": "67ba97258691d9350b813ac5d286ec7346c046df" }, "path_in_vcs": "" }cursive_table_view-0.15.0/.gitignore000064400000000000000000000000221046102023000155520ustar 00000000000000Cargo.lock target cursive_table_view-0.15.0/Cargo.lock0000644000000547110000000000100127630ustar # This file is automatically @generated by Cargo. # It is not intended for manual editing. version = 3 [[package]] name = "ahash" version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" dependencies = [ "cfg-if", "getrandom", "once_cell", "version_check", "zerocopy 0.7.35", ] [[package]] name = "autocfg" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bitflags" version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" [[package]] name = "byteorder" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "castaway" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" dependencies = [ "rustversion", ] [[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "compact_str" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6050c3a16ddab2e412160b31f2c871015704239bca62f72f6e5f0be631d3f644" dependencies = [ "castaway", "cfg-if", "itoa", "rustversion", "ryu", "static_assertions", ] [[package]] name = "crossbeam-channel" version = "0.5.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" dependencies = [ "crossbeam-utils", ] [[package]] name = "crossbeam-utils" version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "crossterm" version = "0.28.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "829d955a0bb380ef178a640b91779e3987da38c9aea133b20614cfed8cdea9c6" dependencies = [ "bitflags", "crossterm_winapi", "mio", "parking_lot", "rustix", "signal-hook", "signal-hook-mio", "winapi", ] [[package]] name = "crossterm_winapi" version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" dependencies = [ "winapi", ] [[package]] name = "cursive" version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3dee384c1888a41189cadef7c9e9e9aa1141fc64491a8fb1c72a9184bae6d340" dependencies = [ "ahash", "cfg-if", "crossbeam-channel", "crossterm", "cursive_core", "lazy_static", "libc", "log", "signal-hook", "unicode-segmentation", "unicode-width", ] [[package]] name = "cursive-macros" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac7ac0eb0cede3dfdfebf4d5f22354e05a730b79c25fd03481fc69fcfba0a73e" dependencies = [ "proc-macro2", ] [[package]] name = "cursive_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3511201898b6e2ed37524b82a1e4f1124c1cbdd91cc23bf75c53c298d37acde5" dependencies = [ "ahash", "compact_str", "crossbeam-channel", "cursive-macros", "enum-map", "enumset", "lazy_static", "log", "num", "parking_lot", "serde_json", "serde_yaml", "time", "unicode-segmentation", "unicode-width", "xi-unicode", ] [[package]] name = "cursive_table_view" version = "0.15.0" dependencies = [ "cursive", "cursive_core", "rand", ] [[package]] name = "darling" version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f63b86c8a8826a49b8c21f08a2d07338eec8d900540f8630dc76284be802989" dependencies = [ "darling_core", "darling_macro", ] [[package]] name = "darling_core" version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95133861a8032aaea082871032f5815eb9e98cef03fa916ab4500513994df9e5" dependencies = [ "fnv", "ident_case", "proc-macro2", "quote", "syn", ] [[package]] name = "darling_macro" version = "0.20.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d336a2a514f6ccccaa3e09b02d41d35330c07ddf03a62165fcec10bb561c7806" dependencies = [ "darling_core", "quote", "syn", ] [[package]] name = "deranged" version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" dependencies = [ "powerfmt", ] [[package]] name = "enum-map" version = "2.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6866f3bfdf8207509a033af1a75a7b08abda06bbaaeae6669323fd5a097df2e9" dependencies = [ "enum-map-derive", ] [[package]] name = "enum-map-derive" version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "enumset" version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d07a4b049558765cef5f0c1a273c3fc57084d768b44d2f98127aef4cceb17293" dependencies = [ "enumset_derive", ] [[package]] name = "enumset_derive" version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59c3b24c345d8c314966bdc1832f6c2635bfcce8e7cf363bd115987bba2ee242" dependencies = [ "darling", "proc-macro2", "quote", "syn", ] [[package]] name = "equivalent" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys", ] [[package]] name = "fnv" version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "getrandom" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", "wasi", ] [[package]] name = "hashbrown" version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "hermit-abi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3fc2e30ba82dd1b3911c8de1ffc143c74a914a14e99514d7637e3099df5ea0" dependencies = [ "equivalent", "hashbrown", ] [[package]] name = "itoa" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "lazy_static" version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "linux-raw-sys" version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", ] [[package]] name = "log" version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" [[package]] name = "memchr" version = "2.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mio" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4569e456d394deccd22ce1c1913e6ea0e54519f577285001215d33557431afe4" dependencies = [ "hermit-abi", "libc", "log", "wasi", "windows-sys", ] [[package]] name = "num" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" dependencies = [ "num-complex", "num-integer", "num-iter", "num-rational", "num-traits", ] [[package]] name = "num-complex" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ "num-traits", ] [[package]] name = "num-conv" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-integer" version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ "num-traits", ] [[package]] name = "num-iter" version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" dependencies = [ "autocfg", "num-integer", "num-traits", ] [[package]] name = "num-rational" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ "num-integer", "num-traits", ] [[package]] name = "num-traits" version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] [[package]] name = "num_threads" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" dependencies = [ "libc", ] [[package]] name = "once_cell" version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "parking_lot" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", "parking_lot_core", ] [[package]] name = "parking_lot_core" version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", "windows-targets", ] [[package]] name = "powerfmt" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] name = "ppv-lite86" version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dee4364d9f3b902ef14fab8a1ddffb783a1cb6b4bba3bfc1fa3922732c7de97f" dependencies = [ "zerocopy 0.6.6", ] [[package]] name = "proc-macro2" version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" dependencies = [ "unicode-ident", ] [[package]] name = "quote" version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] [[package]] name = "rand" version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", "rand_core", ] [[package]] name = "rand_chacha" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", "rand_core", ] [[package]] name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] [[package]] name = "redox_syscall" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a908a6e00f1fdd0dfd9c0eb08ce85126f6d8bbda50017e74bc4a4b7d4a926a4" dependencies = [ "bitflags", ] [[package]] name = "rustix" version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys", ] [[package]] name = "rustversion" version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "ryu" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "scopeguard" version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] name = "serde" version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" version = "1.0.204" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "serde_json" version = "1.0.122" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "784b6203951c57ff748476b126ccb5e8e2959a5c19e5c617ab1956be3dbc68da" dependencies = [ "itoa", "memchr", "ryu", "serde", ] [[package]] name = "serde_yaml" version = "0.9.34+deprecated" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" dependencies = [ "indexmap", "itoa", "ryu", "serde", "unsafe-libyaml", ] [[package]] name = "signal-hook" version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" dependencies = [ "libc", "signal-hook-registry", ] [[package]] name = "signal-hook-mio" version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34db1a06d485c9142248b7a054f034b349b212551f3dfd19c94d45a754a217cd" dependencies = [ "libc", "mio", "signal-hook", ] [[package]] name = "signal-hook-registry" version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] [[package]] name = "smallvec" version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "syn" version = "2.0.72" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" dependencies = [ "proc-macro2", "quote", "unicode-ident", ] [[package]] name = "time" version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", "itoa", "libc", "num-conv", "num_threads", "powerfmt", "serde", "time-core", "time-macros", ] [[package]] name = "time-core" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ "num-conv", "time-core", ] [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-segmentation" version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" [[package]] name = "unicode-width" version = "0.1.13" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" [[package]] name = "unsafe-libyaml" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861" [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" dependencies = [ "winapi-i686-pc-windows-gnu", "winapi-x86_64-pc-windows-gnu", ] [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ "windows-targets", ] [[package]] name = "windows-targets" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", "windows_x86_64_msvc", ] [[package]] name = "windows_aarch64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "xi-unicode" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a67300977d3dc3f8034dae89778f502b6ba20b269527b3223ba59c0cf393bb8a" [[package]] name = "zerocopy" version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "854e949ac82d619ee9a14c66a1b674ac730422372ccb759ce0c39cabcf2bf8e6" dependencies = [ "byteorder", "zerocopy-derive 0.6.6", ] [[package]] name = "zerocopy" version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" dependencies = [ "zerocopy-derive 0.7.35", ] [[package]] name = "zerocopy-derive" version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "125139de3f6b9d625c39e2efdd73d41bdac468ccd556556440e322be0e1bbd91" dependencies = [ "proc-macro2", "quote", "syn", ] [[package]] name = "zerocopy-derive" version = "0.7.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", "syn", ] cursive_table_view-0.15.0/Cargo.toml0000644000000021140000000000100127740ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2021" name = "cursive_table_view" version = "0.15.0" authors = [ "Ivo Wetzel ", "Alexandre Bury ", ] description = "A basic table view implementation for cursive." readme = "README.md" keywords = [ "cursive", "ncurses", "TUI", "UI", "table", ] categories = [ "command-line-interface", "gui", ] license = "MIT/Apache-2.0" repository = "https://github.com/BonsaiDen/cursive_table_view.git" [dependencies.cursive_core] version = "0.4.0" [dev-dependencies.cursive] version = "0.21.0" [dev-dependencies.rand] version = "0.8" cursive_table_view-0.15.0/Cargo.toml.orig000064400000000000000000000010401046102023000164520ustar 00000000000000[package] name = "cursive_table_view" version = "0.15.0" edition = "2021" authors = ["Ivo Wetzel ", "Alexandre Bury "] description = "A basic table view implementation for cursive." repository = "https://github.com/BonsaiDen/cursive_table_view.git" readme = "README.md" keywords = ["cursive", "ncurses", "TUI", "UI", "table"] categories = ["command-line-interface", "gui"] license = "MIT/Apache-2.0" [dependencies] cursive_core = "0.4.0" [dev-dependencies] cursive = "0.21.0" rand = "0.8" cursive_table_view-0.15.0/LICENSE-APACHE000064400000000000000000000251401046102023000155160ustar 00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. cursive_table_view-0.15.0/LICENSE-MIT000064400000000000000000000020441046102023000152240ustar 00000000000000Copyright (c) 2015-2017 Ivo Wetzel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. cursive_table_view-0.15.0/README.md000064400000000000000000000022661046102023000150550ustar 00000000000000# cursive-table-view [![cursive-table-view on crates.io][cratesio-image]][cratesio] [![cursive-table-view on docs.rs][docsrs-image]][docsrs] [cratesio-image]: https://img.shields.io/crates/v/cursive_table_view.svg [cratesio]: https://crates.io/crates/cursive_table_view [docsrs-image]: https://docs.rs/cursive_table_view/badge.svg [docsrs]: https://docs.rs/cursive_table_view/ A basic table view implementation for [cursive](https://crates.io/crates/cursive). ![table](https://cloud.githubusercontent.com/assets/124674/25067632/a6784a56-2249-11e7-8885-50ba7058565f.png) ## Usage Add this to your `Cargo.toml`: ```toml [dependencies] cursive_table_view = "0.14" ``` and this to your crate root: ```rust extern crate cursive_table_view; ``` ## License Licensed under either of * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) at your option. ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you shall be dual licensed as above, without any additional terms or conditions. cursive_table_view-0.15.0/examples/basic.rs000064400000000000000000000074111046102023000170400ustar 00000000000000// Crate Dependencies --------------------------------------------------------- // ---------------------------------------------------------------------------- extern crate cursive; extern crate cursive_table_view; extern crate rand; // STD Dependencies ----------------------------------------------------------- // ---------------------------------------------------------------------------- use std::cmp::Ordering; // External Dependencies ------------------------------------------------------ // ---------------------------------------------------------------------------- use cursive::align::HAlign; use cursive::traits::*; use cursive::views::{Dialog, TextView}; use cursive::Cursive; use rand::Rng; // Modules -------------------------------------------------------------------- // ---------------------------------------------------------------------------- use cursive_table_view::{TableView, TableViewItem}; #[derive(Copy, Clone, PartialEq, Eq, Hash)] enum BasicColumn { Name, Count, Rate, } impl BasicColumn { fn as_str(&self) -> &str { match *self { BasicColumn::Name => "Name", BasicColumn::Count => "Count", BasicColumn::Rate => "Rate", } } } #[derive(Clone, Debug)] struct Foo { name: String, count: usize, rate: usize, } impl TableViewItem for Foo { fn to_column(&self, column: BasicColumn) -> String { match column { BasicColumn::Name => self.name.to_string(), BasicColumn::Count => format!("{}", self.count), BasicColumn::Rate => format!("{}", self.rate), } } fn cmp(&self, other: &Self, column: BasicColumn) -> Ordering where Self: Sized, { match column { BasicColumn::Name => self.name.cmp(&other.name), BasicColumn::Count => self.count.cmp(&other.count), BasicColumn::Rate => self.rate.cmp(&other.rate), } } } fn main() { let mut rng = rand::thread_rng(); let mut siv = cursive::default(); let mut table = TableView::::new() .column(BasicColumn::Name, "Name", |c| c.width_percent(20)) .column(BasicColumn::Count, "Count", |c| c.align(HAlign::Center)) .column(BasicColumn::Rate, "Rate", |c| { c.ordering(Ordering::Greater) .align(HAlign::Right) .width_percent(20) }); let mut items = Vec::new(); for i in 0..50 { items.push(Foo { name: format!("Name {}", i), count: rng.gen_range(0..=255), rate: rng.gen_range(0..=255), }); } table.set_items(items); table.set_on_sort(|siv: &mut Cursive, column: BasicColumn, order: Ordering| { siv.add_layer( Dialog::around(TextView::new(format!("{} / {:?}", column.as_str(), order))) .title("Sorted by") .button("Close", |s| { s.pop_layer(); }), ); }); table.set_on_submit(|siv: &mut Cursive, row: usize, index: usize| { let value = siv .call_on_name("table", move |table: &mut TableView| { format!("{:?}", table.borrow_item(index).unwrap()) }) .unwrap(); siv.add_layer( Dialog::around(TextView::new(value)) .title(format!("Removing row # {}", row)) .button("Close", move |s| { s.call_on_name("table", |table: &mut TableView| { table.remove_item(index); }); s.pop_layer(); }), ); }); siv.add_layer(Dialog::around(table.with_name("table").min_size((50, 20))).title("Table View")); siv.run(); } cursive_table_view-0.15.0/examples/double.rs000064400000000000000000000055051046102023000172330ustar 00000000000000// Crate Dependencies --------------------------------------------------------- // ---------------------------------------------------------------------------- extern crate cursive; extern crate cursive_table_view; extern crate rand; // STD Dependencies ----------------------------------------------------------- // ---------------------------------------------------------------------------- use std::cmp::Ordering; // External Dependencies ------------------------------------------------------ // ---------------------------------------------------------------------------- use cursive::align::HAlign; use cursive::direction::Orientation; use cursive::traits::*; use cursive::views::{Dialog, DummyView, LinearLayout, ResizedView}; use rand::Rng; // Modules -------------------------------------------------------------------- // ---------------------------------------------------------------------------- use cursive_table_view::{TableView, TableViewItem}; #[derive(Copy, Clone, PartialEq, Eq, Hash)] enum BasicColumn { Name, Count, Rate, } #[derive(Clone, Debug)] struct Foo { name: String, count: usize, rate: usize, } impl TableViewItem for Foo { fn to_column(&self, column: BasicColumn) -> String { match column { BasicColumn::Name => self.name.to_string(), BasicColumn::Count => format!("{}", self.count), BasicColumn::Rate => format!("{}", self.rate), } } fn cmp(&self, other: &Self, column: BasicColumn) -> Ordering where Self: Sized, { match column { BasicColumn::Name => self.name.cmp(&other.name), BasicColumn::Count => self.count.cmp(&other.count), BasicColumn::Rate => self.rate.cmp(&other.rate), } } } fn main() { let mut siv = cursive::default(); let mut layout = LinearLayout::new(Orientation::Horizontal); layout.add_child(create_table().min_size((32, 20))); layout.add_child(ResizedView::with_fixed_size((4, 0), DummyView)); layout.add_child(create_table().min_size((32, 20))); siv.add_layer(Dialog::around(layout).title("Table View Demo")); siv.run(); } fn create_table() -> TableView { let mut items = Vec::new(); let mut rng = rand::thread_rng(); for i in 0..50 { items.push(Foo { name: format!("Name {}", i), count: rng.gen_range(0..=255), rate: rng.gen_range(0..=255), }); } TableView::::new() .column(BasicColumn::Name, "Name", |c| c.width_percent(20)) .column(BasicColumn::Count, "Count", |c| c.align(HAlign::Center)) .column(BasicColumn::Rate, "Rate", |c| { c.ordering(Ordering::Greater) .align(HAlign::Right) .width_percent(20) }) .items(items) } cursive_table_view-0.15.0/src/lib.rs000064400000000000000000001140121046102023000154720ustar 00000000000000//! A basic table view implementation for [cursive](https://crates.io/crates/cursive). #![deny( missing_docs, missing_copy_implementations, trivial_casts, trivial_numeric_casts, unsafe_code, unused_import_braces, unused_qualifications )] // Crate Dependencies --------------------------------------------------------- extern crate cursive_core as cursive; // STD Dependencies ----------------------------------------------------------- use std::cmp::{self, Ordering}; use std::collections::HashMap; use std::hash::Hash; use std::sync::Arc; // External Dependencies ------------------------------------------------------ use cursive::{ align::HAlign, direction::Direction, event::{Callback, Event, EventResult, Key, MouseButton, MouseEvent}, theme, vec::Vec2, view::{scroll, CannotFocus, View}, Cursive, Printer, Rect, With, }; /// A trait for displaying and sorting items inside a /// [`TableView`](struct.TableView.html). pub trait TableViewItem: Clone + Sized where H: Eq + Hash + Copy + Clone + Send + Sync + 'static, { /// Method returning a string representation of the item for the /// specified column from type `H`. fn to_column(&self, column: H) -> String; /// Method comparing two items via their specified column from type `H`. fn cmp(&self, other: &Self, column: H) -> Ordering where Self: Sized; } /// Callback used when a column is sorted. /// /// It takes the column and the ordering as input. /// /// This is a private type to help readability. type OnSortCallback = Arc; /// Callback taking as argument the row and the index of an element. /// /// This is a private type to help readability. type IndexCallback = Arc; /// View to select an item among a list, supporting multiple columns for sorting. /// /// # Examples /// /// ```rust /// # extern crate cursive; /// # extern crate cursive_table_view; /// # use std::cmp::Ordering; /// # use cursive_table_view::{TableView, TableViewItem}; /// # use cursive::align::HAlign; /// # fn main() { /// // Provide a type for the table's columns /// #[derive(Copy, Clone, PartialEq, Eq, Hash)] /// enum BasicColumn { /// Name, /// Count, /// Rate /// } /// /// // Define the item type /// #[derive(Clone, Debug)] /// struct Foo { /// name: String, /// count: usize, /// rate: usize /// } /// /// impl TableViewItem for Foo { /// /// fn to_column(&self, column: BasicColumn) -> String { /// match column { /// BasicColumn::Name => self.name.to_string(), /// BasicColumn::Count => format!("{}", self.count), /// BasicColumn::Rate => format!("{}", self.rate) /// } /// } /// /// fn cmp(&self, other: &Self, column: BasicColumn) -> Ordering where Self: Sized { /// match column { /// BasicColumn::Name => self.name.cmp(&other.name), /// BasicColumn::Count => self.count.cmp(&other.count), /// BasicColumn::Rate => self.rate.cmp(&other.rate) /// } /// } /// /// } /// /// // Configure the actual table /// let table = TableView::::new() /// .column(BasicColumn::Name, "Name", |c| c.width(20)) /// .column(BasicColumn::Count, "Count", |c| c.align(HAlign::Center)) /// .column(BasicColumn::Rate, "Rate", |c| { /// c.ordering(Ordering::Greater).align(HAlign::Right).width(20) /// }) /// .default_column(BasicColumn::Name); /// # } /// ``` pub struct TableView { enabled: bool, scroll_core: scroll::Core, needs_relayout: bool, column_select: bool, columns: Vec>, column_indicies: HashMap, focus: usize, items: Vec, rows_to_items: Vec, on_sort: Option>, // TODO Pass drawing offsets into the handlers so a popup menu // can be created easily? on_submit: Option, on_select: Option, } cursive::impl_scroller!(TableView < T, H > ::scroll_core); impl Default for TableView where T: TableViewItem + PartialEq, H: Eq + Hash + Copy + Clone + Send + Sync + 'static, { /// Creates a new empty `TableView` without any columns. /// /// See [`TableView::new()`]. fn default() -> Self { Self::new() } } impl TableView where T: TableViewItem + PartialEq, H: Eq + Hash + Copy + Clone + Send + Sync + 'static, { /// Sets the contained items of the table. /// /// The currently active sort order is preserved and will be applied to all /// items. /// /// Compared to `set_items`, the current selection will be preserved. /// (But this is only available for `T: PartialEq`.) pub fn set_items_stable(&mut self, items: Vec) { // Preserve selection let new_location = self .item() .and_then(|old_item| { let old_item = &self.items[old_item]; items.iter().position(|new| new == old_item) }) .unwrap_or(0); self.set_items_and_focus(items, new_location); } } impl TableView where T: TableViewItem, H: Eq + Hash + Copy + Clone + Send + Sync + 'static, { /// Creates a new empty `TableView` without any columns. /// /// A TableView should be accompanied by a enum of type `H` representing /// the table columns. pub fn new() -> Self { Self { enabled: true, scroll_core: scroll::Core::new(), needs_relayout: true, column_select: false, columns: Vec::new(), column_indicies: HashMap::new(), focus: 0, items: Vec::new(), rows_to_items: Vec::new(), on_sort: None, on_submit: None, on_select: None, } } /// Adds a column for the specified table colum from type `H` along with /// a title for its visual display. /// /// The provided callback can be used to further configure the /// created [`TableColumn`](struct.TableColumn.html). pub fn column, C: FnOnce(TableColumn) -> TableColumn>( mut self, column: H, title: S, callback: C, ) -> Self { self.add_column(column, title, callback); self } /// Adds a column for the specified table colum from type `H` along with /// a title for its visual display. /// /// The provided callback can be used to further configure the /// created [`TableColumn`](struct.TableColumn.html). pub fn add_column, C: FnOnce(TableColumn) -> TableColumn>( &mut self, column: H, title: S, callback: C, ) { self.insert_column(self.columns.len(), column, title, callback); } /// Remove a column. pub fn remove_column(&mut self, i: usize) { // Update the existing indices for column in &self.columns[i + 1..] { *self.column_indicies.get_mut(&column.column).unwrap() -= 1; } let column = self.columns.remove(i); self.column_indicies.remove(&column.column); self.needs_relayout = true; } /// Adds a column for the specified table colum from type `H` along with /// a title for its visual display. /// /// The provided callback can be used to further configure the /// created [`TableColumn`](struct.TableColumn.html). pub fn insert_column, C: FnOnce(TableColumn) -> TableColumn>( &mut self, i: usize, column: H, title: S, callback: C, ) { // Update all existing indices for column in &self.columns[i..] { *self.column_indicies.get_mut(&column.column).unwrap() += 1; } self.column_indicies.insert(column, i); self.columns .insert(i, callback(TableColumn::new(column, title.into()))); // Make the first colum the default one if self.columns.len() == 1 { self.set_default_column(column); } self.needs_relayout = true; } /// Sets the initially active column of the table. pub fn default_column(mut self, column: H) -> Self { self.set_default_column(column); self } /// Sets the initially active column of the table. pub fn set_default_column(&mut self, column: H) { if self.column_indicies.contains_key(&column) { for c in &mut self.columns { c.selected = c.column == column; if c.selected { c.order = c.default_order; } else { c.order = Ordering::Equal; } } } } /// Sorts the table using the specified table `column` and the passed /// `order`. pub fn sort_by(&mut self, column: H, order: Ordering) { if self.column_indicies.contains_key(&column) { for c in &mut self.columns { // Move selection back to the sorted column. c.selected = c.column == column; if c.selected { c.order = order; } else { c.order = Ordering::Equal; } } } self.sort_items(column, order); } /// Sorts the table using the currently active column and its /// ordering. pub fn sort(&mut self) { if let Some((column, order)) = self.order() { self.sort_items(column, order); } } /// Returns the currently active column that is used for sorting /// along with its ordering. /// /// Might return `None` if there are currently no items in the table /// and it has not been sorted yet. pub fn order(&self) -> Option<(H, Ordering)> { for c in &self.columns { if c.order != Ordering::Equal { return Some((c.column, c.order)); } } None } /// Disables this view. /// /// A disabled view cannot be selected. pub fn disable(&mut self) { self.enabled = false; } /// Re-enables this view. pub fn enable(&mut self) { self.enabled = true; } /// Enable or disable this view. pub fn set_enabled(&mut self, enabled: bool) { self.enabled = enabled; } /// Returns `true` if this view is enabled. pub fn is_enabled(&self) -> bool { self.enabled } /// Sets a callback to be used when a selected column is sorted by /// pressing ``. /// /// # Example /// /// ```ignore /// table.set_on_sort(|siv: &mut Cursive, column: BasicColumn, order: Ordering| { /// /// }); /// ``` pub fn set_on_sort(&mut self, cb: F) where F: Fn(&mut Cursive, H, Ordering) + Send + Sync + 'static, { self.on_sort = Some(Arc::new(move |s, h, o| cb(s, h, o))); } /// Sets a callback to be used when a selected column is sorted by /// pressing ``. /// /// Chainable variant. /// /// # Example /// /// ```ignore /// table.on_sort(|siv: &mut Cursive, column: BasicColumn, order: Ordering| { /// /// }); /// ``` pub fn on_sort(self, cb: F) -> Self where F: Fn(&mut Cursive, H, Ordering) + Send + Sync + 'static, { self.with(|t| t.set_on_sort(cb)) } /// Sets a callback to be used when `` is pressed while an item /// is selected. /// /// Both the currently selected row and the index of the corresponding item /// within the underlying storage vector will be given to the callback. /// /// # Example /// /// ```ignore /// table.set_on_submit(|siv: &mut Cursive, row: usize, index: usize| { /// /// }); /// ``` pub fn set_on_submit(&mut self, cb: F) where F: Fn(&mut Cursive, usize, usize) + Send + Sync + 'static, { self.on_submit = Some(Arc::new(move |s, row, index| cb(s, row, index))); } /// Sets a callback to be used when `` is pressed while an item /// is selected. /// /// Both the currently selected row and the index of the corresponding item /// within the underlying storage vector will be given to the callback. /// /// Chainable variant. /// /// # Example /// /// ```ignore /// table.on_submit(|siv: &mut Cursive, row: usize, index: usize| { /// /// }); /// ``` pub fn on_submit(self, cb: F) -> Self where F: Fn(&mut Cursive, usize, usize) + Send + Sync + 'static, { self.with(|t| t.set_on_submit(cb)) } /// Sets a callback to be used when an item is selected. /// /// Both the currently selected row and the index of the corresponding item /// within the underlying storage vector will be given to the callback. /// /// # Example /// /// ```ignore /// table.set_on_select(|siv: &mut Cursive, row: usize, index: usize| { /// /// }); /// ``` pub fn set_on_select(&mut self, cb: F) where F: Fn(&mut Cursive, usize, usize) + Send + Sync + 'static, { self.on_select = Some(Arc::new(move |s, row, index| cb(s, row, index))); } /// Sets a callback to be used when an item is selected. /// /// Both the currently selected row and the index of the corresponding item /// within the underlying storage vector will be given to the callback. /// /// Chainable variant. /// /// # Example /// /// ```ignore /// table.on_select(|siv: &mut Cursive, row: usize, index: usize| { /// /// }); /// ``` pub fn on_select(self, cb: F) -> Self where F: Fn(&mut Cursive, usize, usize) + Send + Sync + 'static, { self.with(|t| t.set_on_select(cb)) } /// Removes all items from this view. pub fn clear(&mut self) { self.items.clear(); self.rows_to_items.clear(); self.focus = 0; self.needs_relayout = true; } /// Returns the number of items in this table. pub fn len(&self) -> usize { self.items.len() } /// Returns `true` if this table has no items. pub fn is_empty(&self) -> bool { self.items.is_empty() } /// Returns the index of the currently selected table row. pub fn row(&self) -> Option { if self.items.is_empty() { None } else { Some(self.focus) } } /// Selects the row at the specified index. pub fn set_selected_row(&mut self, row_index: usize) { self.focus = row_index; self.scroll_core.scroll_to_y(row_index); } /// Selects the row at the specified index. /// /// Chainable variant. pub fn selected_row(self, row_index: usize) -> Self { self.with(|t| t.set_selected_row(row_index)) } /// Sets the contained items of the table. /// /// The currently active sort order is preserved and will be applied to all /// items. pub fn set_items(&mut self, items: Vec) { self.set_items_and_focus(items, 0); } fn set_items_and_focus(&mut self, items: Vec, new_location: usize) { self.items = items; self.rows_to_items = Vec::with_capacity(self.items.len()); for i in 0..self.items.len() { self.rows_to_items.push(i); } if let Some((column, order)) = self.order() { // Preserve the selected column if possible. let selected_column = self.columns.iter().find(|c| c.selected).map(|c| c.column); self.sort_by(column, order); if let Some(column) = selected_column { for c in &mut self.columns { c.selected = c.column == column; } } } self.set_selected_item(new_location); self.needs_relayout = true; } /// Sets the contained items of the table. /// /// The order of the items will be preserved even when the table is sorted. /// /// Chainable variant. pub fn items(self, items: Vec) -> Self { self.with(|t| t.set_items(items)) } /// Returns a immmutable reference to the item at the specified index /// within the underlying storage vector. pub fn borrow_item(&self, index: usize) -> Option<&T> { self.items.get(index) } /// Returns a mutable reference to the item at the specified index within /// the underlying storage vector. pub fn borrow_item_mut(&mut self, index: usize) -> Option<&mut T> { self.items.get_mut(index) } /// Returns a immmutable reference to the items contained within the table. pub fn borrow_items(&mut self) -> &[T] { &self.items } /// Returns a mutable reference to the items contained within the table. /// /// Can be used to modify the items in place. pub fn borrow_items_mut(&mut self) -> &mut [T] { self.needs_relayout = true; &mut self.items } /// Returns the index of the currently selected item within the underlying /// storage vector. pub fn item(&self) -> Option { self.rows_to_items.get(self.focus).copied() } /// Selects the item at the specified index within the underlying storage /// vector. pub fn set_selected_item(&mut self, item_index: usize) { // TODO optimize the performance for very large item lists if item_index < self.items.len() { for (row, item) in self.rows_to_items.iter().enumerate() { if *item == item_index { self.focus = row; self.scroll_core.scroll_to_y(row); break; } } } } /// Selects the item at the specified index within the underlying storage /// vector. /// /// Chainable variant. pub fn selected_item(self, item_index: usize) -> Self { self.with(|t| t.set_selected_item(item_index)) } /// Inserts a new item into the table. /// /// The currently active sort order is preserved and will be applied to the /// newly inserted item. /// /// If no sort option is set, the item will be added to the end of the table. pub fn insert_item(&mut self, item: T) { self.insert_item_at(self.items.len(), item); } /// Inserts a new item into the table. /// /// The currently active sort order is preserved and will be applied to the /// newly inserted item. /// /// If no sort option is set, the item will be inserted at the given index. /// /// # Panics /// /// If `index > self.len()`. pub fn insert_item_at(&mut self, index: usize, item: T) { self.items.push(item); // Here we know self.items.len() > 0 self.rows_to_items.insert(index, self.items.len() - 1); if let Some((column, order)) = self.order() { self.sort_by(column, order); } self.needs_relayout = true; } /// Removes the item at the specified index within the underlying storage /// vector and returns it. pub fn remove_item(&mut self, item_index: usize) -> Option { if item_index < self.items.len() { // Move the selection if the currently selected item gets removed if let Some(selected_index) = self.item() { if selected_index == item_index { self.focus_up(1); } } // Remove the sorted reference to the item self.rows_to_items.retain(|i| *i != item_index); // Adjust remaining references for ref_index in &mut self.rows_to_items { if *ref_index > item_index { *ref_index -= 1; } } self.needs_relayout = true; // Remove actual item from the underlying storage Some(self.items.remove(item_index)) } else { None } } /// Removes all items from the underlying storage and returns them. pub fn take_items(&mut self) -> Vec { self.set_selected_row(0); self.rows_to_items.clear(); self.needs_relayout = true; self.items.drain(0..).collect() } } impl TableView where T: TableViewItem, H: Eq + Hash + Copy + Clone + Send + Sync + 'static, { fn draw_columns)>( &self, printer: &Printer, sep: &str, callback: C, ) { let mut column_offset = 0; let column_count = self.columns.len(); for (index, column) in self.columns.iter().enumerate() { let printer = &printer.offset((column_offset, 0)).focused(true); callback(printer, column); if 1 + index < column_count { printer.print((column.width + 1, 0), sep); } column_offset += column.width + 3; } } fn sort_items(&mut self, column: H, order: Ordering) { if !self.is_empty() { let old_item = self.item(); let mut rows_to_items = self.rows_to_items.clone(); rows_to_items.sort_by(|a, b| { if order == Ordering::Less { self.items[*a].cmp(&self.items[*b], column) } else { self.items[*b].cmp(&self.items[*a], column) } }); self.rows_to_items = rows_to_items; if let Some(old_item) = old_item { self.set_selected_item(old_item); } } } fn draw_item(&self, printer: &Printer, i: usize) { self.draw_columns(printer, "┆ ", |printer, column| { let value = self.items[self.rows_to_items[i]].to_column(column.column); column.draw_row(printer, value.as_str()); }); } fn on_focus_change(&self) -> EventResult { let row = self.row().unwrap(); let index = self.item().unwrap(); EventResult::Consumed( self.on_select .clone() .map(|cb| Callback::from_fn(move |s| cb(s, row, index))), ) } fn focus_up(&mut self, n: usize) { self.focus -= cmp::min(self.focus, n); } fn focus_down(&mut self, n: usize) { self.focus = cmp::min(self.focus + n, self.items.len().saturating_sub(1)); } fn active_column(&self) -> usize { self.columns.iter().position(|c| c.selected).unwrap_or(0) } fn column_cancel(&mut self) { self.column_select = false; for column in &mut self.columns { column.selected = column.order != Ordering::Equal; } } fn column_next(&mut self) -> bool { let column = self.active_column(); if 1 + column < self.columns.len() { self.columns[column].selected = false; self.columns[column + 1].selected = true; true } else { false } } fn column_prev(&mut self) -> bool { let column = self.active_column(); if column > 0 { self.columns[column].selected = false; self.columns[column - 1].selected = true; true } else { false } } fn column_select(&mut self) -> EventResult { let next = self.active_column(); let column = self.columns[next].column; let current = self .columns .iter() .position(|c| c.order != Ordering::Equal) .unwrap_or(0); let order = if current != next { self.columns[next].default_order } else if self.columns[current].order == Ordering::Less { Ordering::Greater } else { Ordering::Less }; self.sort_by(column, order); if self.on_sort.is_some() { let c = &self.columns[self.active_column()]; let column = c.column; let order = c.order; let cb = self.on_sort.clone().unwrap(); EventResult::with_cb(move |s| cb(s, column, order)) } else { EventResult::Consumed(None) } } fn column_for_x(&self, mut x: usize) -> Option { for (i, col) in self.columns.iter().enumerate() { x = match x.checked_sub(col.width) { None => return Some(i), Some(x) => x.checked_sub(3)?, }; } None } fn draw_content(&self, printer: &Printer) { for i in 0..self.rows_to_items.len() { let printer = printer.offset((0, i)); let color = if i == self.focus && self.enabled { if !self.column_select && self.enabled && printer.focused { theme::ColorStyle::highlight() } else { theme::ColorStyle::highlight_inactive() } } else { theme::ColorStyle::primary() }; if i < self.items.len() { printer.with_color(color, |printer| { self.draw_item(printer, i); }); } } } fn layout_content(&mut self, size: Vec2) { let column_count = self.columns.len(); // Split up all columns into sized / unsized groups let (mut sized, mut usized): (Vec<&mut TableColumn>, Vec<&mut TableColumn>) = self .columns .iter_mut() .partition(|c| c.requested_width.is_some()); // Subtract one for the seperators between our columns (that's column_count - 1) let available_width = size.x.saturating_sub(column_count.saturating_sub(1) * 3); // Calculate widths for all requested columns let mut remaining_width = available_width; for column in &mut sized { column.width = match *column.requested_width.as_ref().unwrap() { TableColumnWidth::Percent(width) => cmp::min( (size.x as f32 / 100.0 * width as f32).ceil() as usize, remaining_width, ), TableColumnWidth::Absolute(width) => width, }; remaining_width = remaining_width.saturating_sub(column.width); } // Spread the remaining with across the unsized columns let remaining_columns = usized.len(); for column in &mut usized { column.width = (remaining_width as f32 / remaining_columns as f32).floor() as usize; } self.needs_relayout = false; } fn content_required_size(&mut self, req: Vec2) -> Vec2 { Vec2::new(req.x, self.rows_to_items.len()) } fn on_inner_event(&mut self, event: Event) -> EventResult { let last_focus = self.focus; match event { Event::Key(Key::Right) => { if self.column_select { if !self.column_next() { return EventResult::Ignored; } } else { self.column_select = true; } } Event::Key(Key::Left) => { if self.column_select { if !self.column_prev() { return EventResult::Ignored; } } else { self.column_select = true; } } Event::Key(Key::Up) if self.focus > 0 || self.column_select => { if self.column_select { self.column_cancel(); } else { self.focus_up(1); } } Event::Key(Key::Down) if self.focus + 1 < self.items.len() || self.column_select => { if self.column_select { self.column_cancel(); } else { self.focus_down(1); } } Event::Key(Key::PageUp) => { self.column_cancel(); self.focus_up(10); } Event::Key(Key::PageDown) => { self.column_cancel(); self.focus_down(10); } Event::Key(Key::Home) => { self.column_cancel(); self.focus = 0; } Event::Key(Key::End) => { self.column_cancel(); self.focus = self.items.len().saturating_sub(1); } Event::Key(Key::Enter) => { if self.column_select { return self.column_select(); } else if !self.is_empty() && self.on_submit.is_some() { return self.on_submit_event(); } } Event::Mouse { position, offset, event: MouseEvent::Press(MouseButton::Left), } if !self.is_empty() && position .checked_sub(offset) .map_or(false, |p| p.y == self.focus) => { self.column_cancel(); return self.on_submit_event(); } Event::Mouse { position, offset, event: MouseEvent::Press(_), } if !self.is_empty() => match position.checked_sub(offset) { Some(position) if position.y < self.rows_to_items.len() => { self.column_cancel(); self.focus = position.y; } _ => return EventResult::Ignored, }, _ => return EventResult::Ignored, } let focus = self.focus; if self.column_select { EventResult::Consumed(None) } else if !self.is_empty() && last_focus != focus { self.on_focus_change() } else { EventResult::Ignored } } fn inner_important_area(&self, size: Vec2) -> Rect { Rect::from_size((0, self.focus), (size.x, 1)) } fn on_submit_event(&mut self) -> EventResult { if let Some(ref cb) = &self.on_submit { let cb = Arc::clone(cb); let row = self.row().unwrap(); let index = self.item().unwrap(); return EventResult::Consumed(Some(Callback::from_fn(move |s| cb(s, row, index)))); } EventResult::Ignored } } impl View for TableView where T: TableViewItem + Send + Sync + 'static, H: Eq + Hash + Copy + Clone + Send + Sync + 'static, { fn draw(&self, printer: &Printer) { self.draw_columns(printer, "╷ ", |printer, column| { let color = if self.enabled && (column.order != Ordering::Equal || column.selected) { if self.column_select && column.selected && self.enabled && printer.focused { theme::ColorStyle::highlight() } else { theme::ColorStyle::highlight_inactive() } } else { theme::ColorStyle::primary() }; printer.with_color(color, |printer| { column.draw_header(printer); }); }); self.draw_columns( &printer.offset((0, 1)).focused(true), "┴─", |printer, column| { printer.print_hline((0, 0), column.width + 1, "─"); }, ); // Extend the vertical bars to the end of the view for y in 2..printer.size.y { self.draw_columns(&printer.offset((0, y)), "┆ ", |_, _| ()); } let printer = &printer.offset((0, 2)).focused(true); scroll::draw(self, printer, Self::draw_content); } fn layout(&mut self, size: Vec2) { scroll::layout( self, size.saturating_sub((0, 2)), self.needs_relayout, Self::layout_content, Self::content_required_size, ); } fn take_focus(&mut self, _: Direction) -> Result { self.enabled.then(EventResult::consumed).ok_or(CannotFocus) } fn on_event(&mut self, event: Event) -> EventResult { if !self.enabled { return EventResult::Ignored; } match event { Event::Mouse { position, offset, event: MouseEvent::Press(MouseButton::Left), } if position.checked_sub(offset).map_or(false, |p| p.y == 0) => { if let Some(position) = position.checked_sub(offset) { if let Some(col) = self.column_for_x(position.x) { if self.column_select && self.columns[col].selected { return self.column_select(); } else { let active = self.active_column(); self.columns[active].selected = false; self.columns[col].selected = true; self.column_select = true; } } } EventResult::Ignored } event => scroll::on_event( self, event.relativized((0, 2)), Self::on_inner_event, Self::inner_important_area, ), } } fn important_area(&self, size: Vec2) -> Rect { self.inner_important_area(size.saturating_sub((0, 2))) + (0, 2) } } /// A type used for the construction of columns in a /// [`TableView`](struct.TableView.html). pub struct TableColumn { column: H, title: String, selected: bool, alignment: HAlign, order: Ordering, width: usize, default_order: Ordering, requested_width: Option, } enum TableColumnWidth { Percent(usize), Absolute(usize), } impl TableColumn { /// Sets the default ordering of the column. pub fn ordering(mut self, order: Ordering) -> Self { self.default_order = order; self } /// Sets the horizontal text alignment of the column. pub fn align(mut self, alignment: HAlign) -> Self { self.alignment = alignment; self } /// Sets how many characters of width this column will try to occupy. pub fn width(mut self, width: usize) -> Self { self.requested_width = Some(TableColumnWidth::Absolute(width)); self } /// Sets what percentage of the width of the entire table this column will /// try to occupy. pub fn width_percent(mut self, width: usize) -> Self { self.requested_width = Some(TableColumnWidth::Percent(width)); self } fn new(column: H, title: String) -> Self { Self { column, title, selected: false, alignment: HAlign::Left, order: Ordering::Equal, width: 0, default_order: Ordering::Less, requested_width: None, } } fn draw_header(&self, printer: &Printer) { let order = match self.order { Ordering::Less => "^", Ordering::Greater => "v", Ordering::Equal => " ", }; let header = match self.alignment { HAlign::Left => format!( "{: format!( "{:>width$} [{}]", self.title, order, width = self.width.saturating_sub(4) ), HAlign::Center => format!( "{:^width$} [{}]", self.title, order, width = self.width.saturating_sub(4) ), }; printer.print((0, 0), header.as_str()); } fn draw_row(&self, printer: &Printer, value: &str) { let value = match self.alignment { HAlign::Left => format!("{: format!("{:>width$} ", value, width = self.width), HAlign::Center => format!("{:^width$} ", value, width = self.width), }; printer.print((0, 0), value.as_str()); } } #[cfg(test)] mod tests { use super::*; #[derive(Copy, Clone, PartialEq, Eq, Hash)] enum SimpleColumn { Name, } #[allow(dead_code)] impl SimpleColumn { fn as_str(&self) -> &str { match *self { SimpleColumn::Name => "Name", } } } #[derive(Clone, Debug)] struct SimpleItem { name: String, } impl TableViewItem for SimpleItem { fn to_column(&self, column: SimpleColumn) -> String { match column { SimpleColumn::Name => self.name.to_string(), } } fn cmp(&self, other: &Self, column: SimpleColumn) -> Ordering where Self: Sized, { match column { SimpleColumn::Name => self.name.cmp(&other.name), } } } fn setup_test_table() -> TableView { TableView::::new() .column(SimpleColumn::Name, "Name", |c| c.width_percent(20)) } #[test] fn should_insert_into_existing_table() { let mut simple_table = setup_test_table(); let mut simple_items = Vec::new(); for i in 1..=10 { simple_items.push(SimpleItem { name: format!("{} - Name", i), }); } // Insert First Batch of Items simple_table.set_items(simple_items); // Test for Additional item insertion simple_table.insert_item(SimpleItem { name: format!("{} Name", 11), }); assert!(simple_table.len() == 11); } #[test] fn should_insert_into_empty_table() { let mut simple_table = setup_test_table(); // Test for First item insertion simple_table.insert_item(SimpleItem { name: format!("{} Name", 1), }); assert!(simple_table.len() == 1); } }