├── .devcontainer └── devcontainer.json ├── .github ├── example.cast ├── example.gif └── workflows │ └── rust.yml ├── .gitignore ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md └── src └── main.rs /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Rust", 3 | "image": "mcr.microsoft.com/devcontainers/rust:1-1-bullseye", 4 | "postCreateCommand": "rustc --version && cargo install cargo-deb" 5 | } 6 | -------------------------------------------------------------------------------- /.github/example.cast: -------------------------------------------------------------------------------- 1 | {"version": 2, "width": 131, "height": 22, "timestamp": 1691236885, "env": {"SHELL": "/bin/bash", "TERM": "xterm-256color"}} 2 | [0.019807, "o", "\u001b[?2004h\u001b[0;32m@urbanogilson \u001b[0m➜ \u001b[1;34m/workspaces/lineselect \u001b[0;36m(\u001b[1;31mmain\u001b[0;36m) \u001b[0m$ "] 3 | [1.140661, "o", "l"] 4 | [1.344658, "o", "i"] 5 | [1.533206, "o", "n"] 6 | [1.868221, "o", "e"] 7 | [2.051221, "o", "select "] 8 | [3.490145, "o", "-"] 9 | [3.652939, "o", "-"] 10 | [3.999968, "o", "h"] 11 | [4.117601, "o", "e"] 12 | [4.259762, "o", "l"] 13 | [4.46775, "o", "p"] 14 | [4.732263, "o", "\r\n\u001b[?2004l\r"] 15 | [4.750468, "o", "Select lines"] 16 | [4.7509, "o", "\r\n"] 17 | [4.751118, "o", "\r\n"] 18 | [4.751248, "o", "\u001b[1m\u001b[4mUsage:\u001b[0m | \u001b[1mlineselect\u001b[0m | "] 19 | [4.751393, "o", "\r\n"] 20 | [4.7515, "o", "\r\n"] 21 | [4.751667, "o", "\u001b[1m\u001b[4mOptions:\u001b[0m"] 22 | [4.751814, "o", "\r\n"] 23 | [4.75194, "o", " \u001b[1m-h\u001b[0m, \u001b[1m--help\u001b[0m Print help"] 24 | [4.75208, "o", "\r\n"] 25 | [4.752219, "o", " \u001b[1m-V\u001b[0m, \u001b[1m--version\u001b[0m Print version"] 26 | [4.752374, "o", "\r\n"] 27 | [4.806098, "o", "\u001b[?2004h"] 28 | [4.806434, "o", "\u001b[0;32m@urbanogilson \u001b[0m➜ \u001b[1;34m/workspaces/lineselect \u001b[0;36m(\u001b[1;31mmain\u001b[0;36m) \u001b[0m$ "] 29 | [6.330453, "o", "l"] 30 | [6.427617, "o", "s"] 31 | [6.632229, "o", "\r\n\u001b[?2004l\r"] 32 | [6.633986, "o", "Cargo.lock Cargo.toml \u001b[0m\u001b[01;32mdelete.sh\u001b[0m LICENSE lineselect.cast README.md \u001b[01;31mremove.gz\u001b[0m \u001b[34;42msrc\u001b[0m \u001b[34;42mtarget\u001b[0m\r\n"] 33 | [6.64445, "o", "\u001b[?2004h\u001b[0;32m@urbanogilson \u001b[0m➜ \u001b[1;34m/workspaces/lineselect \u001b[0;36m(\u001b[1;31mmain\u001b[0;36m) \u001b[0m$ "] 34 | [7.745454, "o", "l"] 35 | [7.942288, "o", "i"] 36 | [8.390345, "o", "\b\u001b[K"] 37 | [8.720667, "o", "s"] 38 | [9.370156, "o", " "] 39 | [9.659936, "o", "|"] 40 | [9.784441, "o", " "] 41 | [10.032167, "o", "l"] 42 | [10.279981, "o", "i"] 43 | [10.480658, "o", "n"] 44 | [10.54924, "o", "e"] 45 | [10.740549, "o", "select "] 46 | [11.900278, "o", "|"] 47 | [12.132554, "o", " "] 48 | [12.792222, "o", "x"] 49 | [13.070182, "o", "a"] 50 | [13.254345, "o", "r"] 51 | [13.493988, "o", "g"] 52 | [13.658779, "o", "s "] 53 | [14.437725, "o", "r"] 54 | [14.514382, "o", "m"] 55 | [14.910275, "o", "\r\n\u001b[?2004l\r"] 56 | [14.934757, "o", "\u001b[?25l? Pick some lines:\r\n> [ ] Cargo.lock\r\n [ ] Cargo.toml\r\n [ ] delete.sh\r\n [ ] LICENSE\r\n [ ] lineselect.cast\r\n [ ] README.md\r\n [ ] remove.gz\r\n [ ] src\r\n [ ] target\r\n"] 57 | [15.88109, "o", "\u001b[9A\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B"] 58 | [15.881804, "o", "\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\u001b[9A [ ] Cargo.lock\r\n> [ ] Cargo.toml\r\n [ ] delete.sh\r\n [ ] LICENSE\r\n [ ] lineselect.cast\r\n"] 59 | [15.882276, "o", " [ ] README.md\r\n [ ] remove.gz\r\n [ ] src\r\n [ ] target\r\n"] 60 | [16.013945, "o", "\u001b[9A\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\u001b[9A [ ] Cargo.lock\r\n [ ] Cargo.toml\r\n> [ ] delete.sh\r\n [ ] LICENSE\r\n [ ] lineselect.cast\r\n [ ] README.md\r\n [ ] remove.gz\r\n [ ] src\r\n [ ] target\r\n"] 61 | [16.199466, "o", "\u001b[9A\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K"] 62 | [16.199726, "o", "\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\u001b[9A [ ] Cargo.lock\r\n [ ] Cargo.toml\r\n [ ] delete.sh\r\n> [ ] LICENSE\r\n [ ] lineselect.cast\r\n [ ] README.md\r\n [ ] remove.gz\r\n [ ] src\r\n [ ] target\r\n"] 63 | [16.773409, "o", "\u001b[9A\r\u001b[2K\u001b[1B"] 64 | [16.773588, "o", "\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K"] 65 | [16.774236, "o", "\u001b[1B\r\u001b[2K\u001b[1B\u001b[9A"] 66 | [16.774277, "o", " [ ] Cargo.lock\r\n [ ] Cargo.toml\r\n> [ ] delete.sh\r\n [ ] LICENSE\r\n [ ] lineselect.cast\r\n"] 67 | [16.774291, "o", " [ ] README.md\r\n [ ] remove.gz"] 68 | [16.774306, "o", "\r\n [ ] src"] 69 | [16.77432, "o", "\r\n [ ] target\r\n"] 70 | [16.969374, "o", "\u001b[9A\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\u001b[9A [ ] Cargo.lock\r\n [ ] Cargo.toml\r\n> [x] delete.sh\r\n [ ] LICENSE\r\n"] 71 | [16.969453, "o", " [ ] lineselect.cast\r\n [ ] README.md\r\n [ ] remove.gz\r\n [ ] src\r\n [ ] target\r\n"] 72 | [17.330083, "o", "\u001b[9A\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\u001b[9A [ ] Cargo.lock\r\n [ ] Cargo.toml\r\n [x] delete.sh\r\n> [ ] LICENSE\r\n [ ] lineselect.cast"] 73 | [17.33061, "o", "\r\n [ ] README.md\r\n [ ] remove.gz\r\n [ ] src\r\n [ ] target\r\n"] 74 | [17.442048, "o", "\u001b[9A"] 75 | [17.442313, "o", "\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\u001b[9A [ ] Cargo.lock"] 76 | [17.442495, "o", "\r\n [ ] Cargo.toml\r\n [x] delete.sh\r\n [ ] LICENSE\r\n> [ ] lineselect.cast\r\n [ ] README.md\r\n [ ] remove.gz\r\n [ ] src"] 77 | [17.442603, "o", "\r\n [ ] target\r\n"] 78 | [17.674245, "o", "\u001b[9A\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B"] 79 | [17.674438, "o", "\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B"] 80 | [17.674519, "o", "\u001b[9A [ ] Cargo.lock\r\n [ ] Cargo.toml"] 81 | [17.674937, "o", "\r\n [x] delete.sh\r\n [ ] LICENSE\r\n [ ] lineselect.cast\r\n> [ ] README.md\r\n [ ] remove.gz\r\n [ ] src\r\n [ ] target\r\n"] 82 | [17.866753, "o", "\u001b[9A\r\u001b[2K\u001b[1B"] 83 | [17.866974, "o", "\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\u001b[9A [ ] Cargo.lock\r\n [ ] Cargo.toml\r\n [x] delete.sh\r\n [ ] LICENSE\r\n [ ] lineselect.cast\r\n [ ] README.md\r\n> [ ] remove.gz\r\n [ ] src\r\n [ ] target\r\n"] 84 | [18.760027, "o", "\u001b[9A\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K"] 85 | [18.761197, "o", "\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\u001b[9A [ ] Cargo.lock\r\n [ ] Cargo.toml\r\n [x] delete.sh\r\n [ ] LICENSE\r\n [ ] lineselect.cast\r\n [ ] README.md"] 86 | [18.761838, "o", "\r\n> [x] remove.gz\r\n [ ] src\r\n [ ] target\r\n"] 87 | [20.849827, "o", "\u001b[10A\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B"] 88 | [20.849906, "o", "\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\r\u001b[2K\u001b[1B\u001b[10A\u001b[?25h"] 89 | [20.863033, "o", "\u001b[?2004h\u001b[0;32m@urbanogilson \u001b[0m➜ \u001b[1;34m/workspaces/lineselect \u001b[0;36m(\u001b[1;31mmain\u001b[0;36m) \u001b[0m$ "] 90 | [21.690069, "o", "l"] 91 | [21.772299, "o", "s"] 92 | [21.909555, "o", "\r\n\u001b[?2004l\r"] 93 | [21.911345, "o", "Cargo.lock Cargo.toml LICENSE lineselect.cast README.md \u001b[0m\u001b[34;42msrc\u001b[0m \u001b[34;42mtarget\u001b[0m\r\n"] 94 | [21.92198, "o", "\u001b[?2004h\u001b[0;32m@urbanogilson \u001b[0m➜ \u001b[1;34m/workspaces/lineselect \u001b[0;36m(\u001b[1;31mmain\u001b[0;36m) \u001b[0m$ "] 95 | [22.949793, "o", "\u001b[?2004l\r\r\nexit"] 96 | [22.951216, "o", "\r\n"] 97 | -------------------------------------------------------------------------------- /.github/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/urbanogilson/lineselect/5c7fb66e71921520e4266ac334a718a1ca3da2b5/.github/example.gif -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | pull_request: 7 | branches: [ "main" ] 8 | 9 | env: 10 | CARGO_TERM_COLOR: always 11 | 12 | jobs: 13 | build: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: actions/checkout@v3 19 | - name: Build 20 | run: cargo build --verbose 21 | - name: Run tests 22 | run: cargo test --verbose 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 3 4 | 5 | [[package]] 6 | name = "anstream" 7 | version = "0.6.18" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "8acc5369981196006228e28809f761875c0327210a891e941f4c683b3a99529b" 10 | dependencies = [ 11 | "anstyle", 12 | "anstyle-parse", 13 | "anstyle-query", 14 | "anstyle-wincon", 15 | "colorchoice", 16 | "is_terminal_polyfill", 17 | "utf8parse", 18 | ] 19 | 20 | [[package]] 21 | name = "anstyle" 22 | version = "1.0.10" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "55cc3b69f167a1ef2e161439aa98aed94e6028e5f9a59be9a6ffb47aef1651f9" 25 | 26 | [[package]] 27 | name = "anstyle-parse" 28 | version = "0.2.1" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" 31 | dependencies = [ 32 | "utf8parse", 33 | ] 34 | 35 | [[package]] 36 | name = "anstyle-query" 37 | version = "1.0.0" 38 | source = "registry+https://github.com/rust-lang/crates.io-index" 39 | checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" 40 | dependencies = [ 41 | "windows-sys 0.48.0", 42 | ] 43 | 44 | [[package]] 45 | name = "anstyle-wincon" 46 | version = "3.0.7" 47 | source = "registry+https://github.com/rust-lang/crates.io-index" 48 | checksum = "ca3534e77181a9cc07539ad51f2141fe32f6c3ffd4df76db8ad92346b003ae4e" 49 | dependencies = [ 50 | "anstyle", 51 | "once_cell", 52 | "windows-sys 0.59.0", 53 | ] 54 | 55 | [[package]] 56 | name = "bitflags" 57 | version = "1.3.2" 58 | source = "registry+https://github.com/rust-lang/crates.io-index" 59 | checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 60 | 61 | [[package]] 62 | name = "bitflags" 63 | version = "2.3.3" 64 | source = "registry+https://github.com/rust-lang/crates.io-index" 65 | checksum = "630be753d4e58660abd17930c71b647fe46c27ea6b63cc59e1e3851406972e42" 66 | 67 | [[package]] 68 | name = "cc" 69 | version = "1.0.79" 70 | source = "registry+https://github.com/rust-lang/crates.io-index" 71 | checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" 72 | 73 | [[package]] 74 | name = "cfg-if" 75 | version = "1.0.0" 76 | source = "registry+https://github.com/rust-lang/crates.io-index" 77 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 78 | 79 | [[package]] 80 | name = "clap" 81 | version = "4.5.27" 82 | source = "registry+https://github.com/rust-lang/crates.io-index" 83 | checksum = "769b0145982b4b48713e01ec42d61614425f27b7058bda7180a3a41f30104796" 84 | dependencies = [ 85 | "clap_builder", 86 | ] 87 | 88 | [[package]] 89 | name = "clap_builder" 90 | version = "4.5.27" 91 | source = "registry+https://github.com/rust-lang/crates.io-index" 92 | checksum = "1b26884eb4b57140e4d2d93652abfa49498b938b3c9179f9fc487b0acc3edad7" 93 | dependencies = [ 94 | "anstream", 95 | "anstyle", 96 | "clap_lex", 97 | "strsim", 98 | ] 99 | 100 | [[package]] 101 | name = "clap_lex" 102 | version = "0.7.4" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" 105 | 106 | [[package]] 107 | name = "colorchoice" 108 | version = "1.0.0" 109 | source = "registry+https://github.com/rust-lang/crates.io-index" 110 | checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" 111 | 112 | [[package]] 113 | name = "colored" 114 | version = "3.0.0" 115 | source = "registry+https://github.com/rust-lang/crates.io-index" 116 | checksum = "fde0e0ec90c9dfb3b4b1a0891a7dcd0e2bffde2f7efed5fe7c9bb00e5bfb915e" 117 | dependencies = [ 118 | "windows-sys 0.59.0", 119 | ] 120 | 121 | [[package]] 122 | name = "console" 123 | version = "0.15.7" 124 | source = "registry+https://github.com/rust-lang/crates.io-index" 125 | checksum = "c926e00cc70edefdc64d3a5ff31cc65bb97a3460097762bd23afb4d8145fccf8" 126 | dependencies = [ 127 | "encode_unicode", 128 | "lazy_static", 129 | "libc", 130 | "unicode-width", 131 | "windows-sys 0.45.0", 132 | ] 133 | 134 | [[package]] 135 | name = "dialoguer" 136 | version = "0.11.0" 137 | source = "registry+https://github.com/rust-lang/crates.io-index" 138 | checksum = "658bce805d770f407bc62102fca7c2c64ceef2fbcb2b8bd19d2765ce093980de" 139 | dependencies = [ 140 | "console", 141 | "shell-words", 142 | "tempfile", 143 | "thiserror", 144 | "zeroize", 145 | ] 146 | 147 | [[package]] 148 | name = "encode_unicode" 149 | version = "0.3.6" 150 | source = "registry+https://github.com/rust-lang/crates.io-index" 151 | checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" 152 | 153 | [[package]] 154 | name = "errno" 155 | version = "0.3.1" 156 | source = "registry+https://github.com/rust-lang/crates.io-index" 157 | checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" 158 | dependencies = [ 159 | "errno-dragonfly", 160 | "libc", 161 | "windows-sys 0.48.0", 162 | ] 163 | 164 | [[package]] 165 | name = "errno-dragonfly" 166 | version = "0.1.2" 167 | source = "registry+https://github.com/rust-lang/crates.io-index" 168 | checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" 169 | dependencies = [ 170 | "cc", 171 | "libc", 172 | ] 173 | 174 | [[package]] 175 | name = "fastrand" 176 | version = "2.0.0" 177 | source = "registry+https://github.com/rust-lang/crates.io-index" 178 | checksum = "6999dc1837253364c2ebb0704ba97994bd874e8f195d665c50b7548f6ea92764" 179 | 180 | [[package]] 181 | name = "is_terminal_polyfill" 182 | version = "1.70.1" 183 | source = "registry+https://github.com/rust-lang/crates.io-index" 184 | checksum = "7943c866cc5cd64cbc25b2e01621d07fa8eb2a1a23160ee81ce38704e97b8ecf" 185 | 186 | [[package]] 187 | name = "lazy_static" 188 | version = "1.4.0" 189 | source = "registry+https://github.com/rust-lang/crates.io-index" 190 | checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 191 | 192 | [[package]] 193 | name = "libc" 194 | version = "0.2.147" 195 | source = "registry+https://github.com/rust-lang/crates.io-index" 196 | checksum = "b4668fb0ea861c1df094127ac5f1da3409a82116a4ba74fca2e58ef927159bb3" 197 | 198 | [[package]] 199 | name = "lineselect" 200 | version = "0.1.1" 201 | dependencies = [ 202 | "clap", 203 | "colored", 204 | "dialoguer", 205 | ] 206 | 207 | [[package]] 208 | name = "linux-raw-sys" 209 | version = "0.4.3" 210 | source = "registry+https://github.com/rust-lang/crates.io-index" 211 | checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" 212 | 213 | [[package]] 214 | name = "once_cell" 215 | version = "1.20.2" 216 | source = "registry+https://github.com/rust-lang/crates.io-index" 217 | checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775" 218 | 219 | [[package]] 220 | name = "proc-macro2" 221 | version = "1.0.93" 222 | source = "registry+https://github.com/rust-lang/crates.io-index" 223 | checksum = "60946a68e5f9d28b0dc1c21bb8a97ee7d018a8b322fa57838ba31cc878e22d99" 224 | dependencies = [ 225 | "unicode-ident", 226 | ] 227 | 228 | [[package]] 229 | name = "quote" 230 | version = "1.0.38" 231 | source = "registry+https://github.com/rust-lang/crates.io-index" 232 | checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" 233 | dependencies = [ 234 | "proc-macro2", 235 | ] 236 | 237 | [[package]] 238 | name = "redox_syscall" 239 | version = "0.3.5" 240 | source = "registry+https://github.com/rust-lang/crates.io-index" 241 | checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" 242 | dependencies = [ 243 | "bitflags 1.3.2", 244 | ] 245 | 246 | [[package]] 247 | name = "rustix" 248 | version = "0.38.4" 249 | source = "registry+https://github.com/rust-lang/crates.io-index" 250 | checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" 251 | dependencies = [ 252 | "bitflags 2.3.3", 253 | "errno", 254 | "libc", 255 | "linux-raw-sys", 256 | "windows-sys 0.48.0", 257 | ] 258 | 259 | [[package]] 260 | name = "shell-words" 261 | version = "1.1.0" 262 | source = "registry+https://github.com/rust-lang/crates.io-index" 263 | checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" 264 | 265 | [[package]] 266 | name = "strsim" 267 | version = "0.11.1" 268 | source = "registry+https://github.com/rust-lang/crates.io-index" 269 | checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" 270 | 271 | [[package]] 272 | name = "syn" 273 | version = "2.0.96" 274 | source = "registry+https://github.com/rust-lang/crates.io-index" 275 | checksum = "d5d0adab1ae378d7f53bdebc67a39f1f151407ef230f0ce2883572f5d8985c80" 276 | dependencies = [ 277 | "proc-macro2", 278 | "quote", 279 | "unicode-ident", 280 | ] 281 | 282 | [[package]] 283 | name = "tempfile" 284 | version = "3.7.0" 285 | source = "registry+https://github.com/rust-lang/crates.io-index" 286 | checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998" 287 | dependencies = [ 288 | "cfg-if", 289 | "fastrand", 290 | "redox_syscall", 291 | "rustix", 292 | "windows-sys 0.48.0", 293 | ] 294 | 295 | [[package]] 296 | name = "thiserror" 297 | version = "1.0.69" 298 | source = "registry+https://github.com/rust-lang/crates.io-index" 299 | checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" 300 | dependencies = [ 301 | "thiserror-impl", 302 | ] 303 | 304 | [[package]] 305 | name = "thiserror-impl" 306 | version = "1.0.69" 307 | source = "registry+https://github.com/rust-lang/crates.io-index" 308 | checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" 309 | dependencies = [ 310 | "proc-macro2", 311 | "quote", 312 | "syn", 313 | ] 314 | 315 | [[package]] 316 | name = "unicode-ident" 317 | version = "1.0.15" 318 | source = "registry+https://github.com/rust-lang/crates.io-index" 319 | checksum = "11cd88e12b17c6494200a9c1b683a04fcac9573ed74cd1b62aeb2727c5592243" 320 | 321 | [[package]] 322 | name = "unicode-width" 323 | version = "0.1.10" 324 | source = "registry+https://github.com/rust-lang/crates.io-index" 325 | checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" 326 | 327 | [[package]] 328 | name = "utf8parse" 329 | version = "0.2.1" 330 | source = "registry+https://github.com/rust-lang/crates.io-index" 331 | checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" 332 | 333 | [[package]] 334 | name = "windows-sys" 335 | version = "0.45.0" 336 | source = "registry+https://github.com/rust-lang/crates.io-index" 337 | checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" 338 | dependencies = [ 339 | "windows-targets 0.42.2", 340 | ] 341 | 342 | [[package]] 343 | name = "windows-sys" 344 | version = "0.48.0" 345 | source = "registry+https://github.com/rust-lang/crates.io-index" 346 | checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" 347 | dependencies = [ 348 | "windows-targets 0.48.1", 349 | ] 350 | 351 | [[package]] 352 | name = "windows-sys" 353 | version = "0.59.0" 354 | source = "registry+https://github.com/rust-lang/crates.io-index" 355 | checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" 356 | dependencies = [ 357 | "windows-targets 0.52.6", 358 | ] 359 | 360 | [[package]] 361 | name = "windows-targets" 362 | version = "0.42.2" 363 | source = "registry+https://github.com/rust-lang/crates.io-index" 364 | checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" 365 | dependencies = [ 366 | "windows_aarch64_gnullvm 0.42.2", 367 | "windows_aarch64_msvc 0.42.2", 368 | "windows_i686_gnu 0.42.2", 369 | "windows_i686_msvc 0.42.2", 370 | "windows_x86_64_gnu 0.42.2", 371 | "windows_x86_64_gnullvm 0.42.2", 372 | "windows_x86_64_msvc 0.42.2", 373 | ] 374 | 375 | [[package]] 376 | name = "windows-targets" 377 | version = "0.48.1" 378 | source = "registry+https://github.com/rust-lang/crates.io-index" 379 | checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" 380 | dependencies = [ 381 | "windows_aarch64_gnullvm 0.48.0", 382 | "windows_aarch64_msvc 0.48.0", 383 | "windows_i686_gnu 0.48.0", 384 | "windows_i686_msvc 0.48.0", 385 | "windows_x86_64_gnu 0.48.0", 386 | "windows_x86_64_gnullvm 0.48.0", 387 | "windows_x86_64_msvc 0.48.0", 388 | ] 389 | 390 | [[package]] 391 | name = "windows-targets" 392 | version = "0.52.6" 393 | source = "registry+https://github.com/rust-lang/crates.io-index" 394 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 395 | dependencies = [ 396 | "windows_aarch64_gnullvm 0.52.6", 397 | "windows_aarch64_msvc 0.52.6", 398 | "windows_i686_gnu 0.52.6", 399 | "windows_i686_gnullvm", 400 | "windows_i686_msvc 0.52.6", 401 | "windows_x86_64_gnu 0.52.6", 402 | "windows_x86_64_gnullvm 0.52.6", 403 | "windows_x86_64_msvc 0.52.6", 404 | ] 405 | 406 | [[package]] 407 | name = "windows_aarch64_gnullvm" 408 | version = "0.42.2" 409 | source = "registry+https://github.com/rust-lang/crates.io-index" 410 | checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" 411 | 412 | [[package]] 413 | name = "windows_aarch64_gnullvm" 414 | version = "0.48.0" 415 | source = "registry+https://github.com/rust-lang/crates.io-index" 416 | checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" 417 | 418 | [[package]] 419 | name = "windows_aarch64_gnullvm" 420 | version = "0.52.6" 421 | source = "registry+https://github.com/rust-lang/crates.io-index" 422 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 423 | 424 | [[package]] 425 | name = "windows_aarch64_msvc" 426 | version = "0.42.2" 427 | source = "registry+https://github.com/rust-lang/crates.io-index" 428 | checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" 429 | 430 | [[package]] 431 | name = "windows_aarch64_msvc" 432 | version = "0.48.0" 433 | source = "registry+https://github.com/rust-lang/crates.io-index" 434 | checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" 435 | 436 | [[package]] 437 | name = "windows_aarch64_msvc" 438 | version = "0.52.6" 439 | source = "registry+https://github.com/rust-lang/crates.io-index" 440 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 441 | 442 | [[package]] 443 | name = "windows_i686_gnu" 444 | version = "0.42.2" 445 | source = "registry+https://github.com/rust-lang/crates.io-index" 446 | checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" 447 | 448 | [[package]] 449 | name = "windows_i686_gnu" 450 | version = "0.48.0" 451 | source = "registry+https://github.com/rust-lang/crates.io-index" 452 | checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" 453 | 454 | [[package]] 455 | name = "windows_i686_gnu" 456 | version = "0.52.6" 457 | source = "registry+https://github.com/rust-lang/crates.io-index" 458 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 459 | 460 | [[package]] 461 | name = "windows_i686_gnullvm" 462 | version = "0.52.6" 463 | source = "registry+https://github.com/rust-lang/crates.io-index" 464 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 465 | 466 | [[package]] 467 | name = "windows_i686_msvc" 468 | version = "0.42.2" 469 | source = "registry+https://github.com/rust-lang/crates.io-index" 470 | checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" 471 | 472 | [[package]] 473 | name = "windows_i686_msvc" 474 | version = "0.48.0" 475 | source = "registry+https://github.com/rust-lang/crates.io-index" 476 | checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" 477 | 478 | [[package]] 479 | name = "windows_i686_msvc" 480 | version = "0.52.6" 481 | source = "registry+https://github.com/rust-lang/crates.io-index" 482 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 483 | 484 | [[package]] 485 | name = "windows_x86_64_gnu" 486 | version = "0.42.2" 487 | source = "registry+https://github.com/rust-lang/crates.io-index" 488 | checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" 489 | 490 | [[package]] 491 | name = "windows_x86_64_gnu" 492 | version = "0.48.0" 493 | source = "registry+https://github.com/rust-lang/crates.io-index" 494 | checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" 495 | 496 | [[package]] 497 | name = "windows_x86_64_gnu" 498 | version = "0.52.6" 499 | source = "registry+https://github.com/rust-lang/crates.io-index" 500 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 501 | 502 | [[package]] 503 | name = "windows_x86_64_gnullvm" 504 | version = "0.42.2" 505 | source = "registry+https://github.com/rust-lang/crates.io-index" 506 | checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" 507 | 508 | [[package]] 509 | name = "windows_x86_64_gnullvm" 510 | version = "0.48.0" 511 | source = "registry+https://github.com/rust-lang/crates.io-index" 512 | checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" 513 | 514 | [[package]] 515 | name = "windows_x86_64_gnullvm" 516 | version = "0.52.6" 517 | source = "registry+https://github.com/rust-lang/crates.io-index" 518 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 519 | 520 | [[package]] 521 | name = "windows_x86_64_msvc" 522 | version = "0.42.2" 523 | source = "registry+https://github.com/rust-lang/crates.io-index" 524 | checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" 525 | 526 | [[package]] 527 | name = "windows_x86_64_msvc" 528 | version = "0.48.0" 529 | source = "registry+https://github.com/rust-lang/crates.io-index" 530 | checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" 531 | 532 | [[package]] 533 | name = "windows_x86_64_msvc" 534 | version = "0.52.6" 535 | source = "registry+https://github.com/rust-lang/crates.io-index" 536 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 537 | 538 | [[package]] 539 | name = "zeroize" 540 | version = "1.6.0" 541 | source = "registry+https://github.com/rust-lang/crates.io-index" 542 | checksum = "2a0956f1ba7c7909bfb66c2e9e4124ab6f6482560f6628b5aaeba39207c9aad9" 543 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lineselect" 3 | version = "0.1.1" 4 | edition = "2021" 5 | description = "Interactive Line Selector" 6 | authors = ["Gilson Urbano "] 7 | readme = "README.md" 8 | license = "MIT" 9 | repository = "https://github.com/urbanogilson/lineselect" 10 | keywords = ["cli"] 11 | categories = ["command-line-utilities"] 12 | 13 | [dependencies] 14 | clap = "4.5.27" 15 | colored = "3.0.0" 16 | dialoguer = "0.11.0" 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Gilson Urbano 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Line Select 2 | 3 | [![CI](https://github.com/urbanogilson/lineselect/actions/workflows/rust.yml/badge.svg?branch=main)](https://github.com/urbanogilson/lineselect/actions/workflows/rust.yml) 4 | [![Crates.io](https://img.shields.io/crates/v/lineselect.svg)](https://crates.io/crates/lineselect) 5 | [![CI](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/urbanogilson/lineselect/blob/main/LICENSE) 6 | 7 | Elevate your command-line pipelines using the Interactive Line Selector – a potent utility enabling interactive line selection from stdin. Seamlessly integrate, pause, select, and refine your pipeline, enhancing data processing precision. 8 | 9 | # Features 10 | - Interactive Selection: Pause the pipeline's execution to manually select specific lines from the input stream. 11 | - Seamless Integration: Easily integrate the Interactive Line Selector into your existing command-line pipelines. 12 | - Optimized Workflow: Curate data on-the-fly for more accurate and meaningful results. 13 | 14 | # Usage 15 | 16 | Incorporate the Interactive Line Selector into your pipeline: 17 | 18 |
19 | <command producing input> | lineselect | <subsequent command>
20 | 
21 | 22 | Use arrow keys to navigate, press `Space` to select/deselect lines, and press `Enter` to proceed with the selected lines. 23 | 24 | # Example 25 | 26 | Imagine you have a list of files in a directory and you want to selectively remove them using `rm`. Instead of using a complex find command, you can utilize the Interactive Line Selector to streamline the process: 27 | 28 |
29 | ls | lineselect | xargs rm
30 | 
31 | 32 | ![Example](https://github.com/urbanogilson/lineselect/blob/main/.github/example.gif) 33 | 34 | # Installation 35 | 36 | ## Cargo 37 | 38 | ```bash 39 | cargo install lineselect 40 | ``` 41 | 42 | ## Debian 43 | 44 | ```bash 45 | wget https://github.com/urbanogilson/lineselect/releases/download/v0.1.1/lineselect_0.1.1_amd64.deb 46 | apt install ./lineselect_0.1.1_amd64.deb 47 | ``` 48 | 49 | # Contributions 50 | 51 | Contributions are welcome! If you have ideas for improvements or new features, please feel free to submit a pull request. 52 | 53 | # Acknowledgments 54 | 55 | This project builds upon the fantastic work of the following projects: 56 | 57 | - [Clap](https://github.com/clap-rs/clap) - A full featured, fast Command Line Argument Parser for Rust. 58 | - [Dialoguer](https://github.com/console-rs/dialoguer) - Rust utility library for nice command line prompts and similar things. 59 | - [Colored](https://github.com/colored-rs/colored) - Coloring terminal so simple you already know how to do it! 60 | 61 | ## Previous Implementation 62 | 63 | This idea has been implemented before by [chfritz/lineselect](https://github.com/chfritz/lineselect) using JavaScript. Our project aims to provide an option in Rust with a single binary. 64 | 65 | # License 66 | 67 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 68 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | use clap::Command; 2 | use colored::Colorize; 3 | use dialoguer::{console::Term, theme::SimpleTheme, MultiSelect}; 4 | use std::io; 5 | 6 | fn cmd() -> clap::Command { 7 | let name = "lineselect"; 8 | 9 | Command::new(name) 10 | .override_usage(format!( 11 | " | {} | ", 12 | name.bold() 13 | )) 14 | .version("0.1.1") 15 | .author("Gilson Urbano ") 16 | .about("Select lines") 17 | } 18 | 19 | fn read_lines(reader: R) -> Vec { 20 | let mut lines = Vec::new(); 21 | 22 | for line in reader.lines() { 23 | match line { 24 | Ok(line) => lines.push(line), 25 | Err(error) => { 26 | eprintln!("Error: {}", error); 27 | break; 28 | } 29 | } 30 | } 31 | 32 | lines 33 | } 34 | 35 | fn main() -> Result<(), Box> { 36 | cmd().get_matches(); 37 | 38 | let stdin = io::stdin(); 39 | 40 | let lines = read_lines(stdin.lock()); 41 | 42 | if let Some(positions) = MultiSelect::with_theme(&SimpleTheme) 43 | .with_prompt(format!("{} {}", "?".red().bold(), "Pick some lines".bold())) 44 | .report(false) 45 | .items(&lines) 46 | .interact_on_opt(&Term::stderr())? 47 | { 48 | positions 49 | .iter() 50 | .for_each(|position| println!("{}", lines[*position])); 51 | } 52 | 53 | Ok(()) 54 | } 55 | 56 | #[test] 57 | fn test_cmd() { 58 | cmd().debug_assert(); 59 | } 60 | 61 | #[test] 62 | fn test_read_lines() { 63 | use std::io::Cursor; 64 | let input = "Line 1\nLine 2\nLine 3\n"; 65 | let reader = Cursor::new(input); 66 | 67 | let lines = read_lines(reader); 68 | 69 | assert_eq!(lines.len(), 3); 70 | assert_eq!(lines[0], "Line 1"); 71 | assert_eq!(lines[1], "Line 2"); 72 | assert_eq!(lines[2], "Line 3"); 73 | } 74 | --------------------------------------------------------------------------------