mirror of
https://github.com/TECHNOFAB11/tmux-copyrat.git
synced 2025-12-12 16:10:07 +01:00
refactor: simpler names
This commit is contained in:
parent
4eca53fd85
commit
0d45a2872a
5 changed files with 276 additions and 139 deletions
118
Cargo.lock
generated
118
Cargo.lock
generated
|
|
@ -45,6 +45,14 @@ dependencies = [
|
||||||
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.1.12"
|
version = "0.1.12"
|
||||||
|
|
@ -73,6 +81,46 @@ name = "numtoa"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-error"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"proc-macro2 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"syn 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro-error-attr"
|
||||||
|
version = "1.0.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"syn 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.1.56"
|
version = "0.1.56"
|
||||||
|
|
@ -107,6 +155,48 @@ name = "strsim"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "structopt"
|
||||||
|
version = "0.3.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"structopt-derive 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "structopt-derive"
|
||||||
|
version = "0.4.7"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"proc-macro-error 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"proc-macro2 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"syn 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "1.0.23"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn-mid"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"syn 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "termion"
|
name = "termion"
|
||||||
version = "1.5.5"
|
version = "1.5.5"
|
||||||
|
|
@ -140,19 +230,35 @@ version = "0.4.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"structopt 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
"termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-segmentation"
|
||||||
|
version = "1.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unicode-width"
|
name = "unicode-width"
|
||||||
version = "0.1.7"
|
version = "0.1.7"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-xid"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vec_map"
|
name = "vec_map"
|
||||||
version = "0.8.1"
|
version = "0.8.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "version_check"
|
||||||
|
version = "0.9.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "winapi"
|
name = "winapi"
|
||||||
version = "0.3.8"
|
version = "0.3.8"
|
||||||
|
|
@ -178,21 +284,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
"checksum atty 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
|
||||||
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
|
||||||
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
|
"checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9"
|
||||||
|
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
|
||||||
"checksum hermit-abi 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4"
|
"checksum hermit-abi 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "61565ff7aaace3525556587bd2dc31d4a07071957be715e63ce7b1eccf51a8f4"
|
||||||
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
|
||||||
"checksum libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)" = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
|
"checksum libc 0.2.69 (registry+https://github.com/rust-lang/crates.io-index)" = "99e85c08494b21a9054e7fe1374a732aeadaff3980b6990b94bfd3a70f690005"
|
||||||
"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
|
"checksum memchr 2.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3728d817d99e5ac407411fa471ff9800a778d88a24685968b36824eaf4bee400"
|
||||||
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef"
|
||||||
|
"checksum proc-macro-error 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98e9e4b82e0ef281812565ea4751049f1bdcdfccda7d3f459f2e138a40c08678"
|
||||||
|
"checksum proc-macro-error-attr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4f5444ead4e9935abd7f27dc51f7e852a0569ac888096d5ec2499470794e2e53"
|
||||||
|
"checksum proc-macro2 1.0.14 (registry+https://github.com/rust-lang/crates.io-index)" = "de40dd4ff82d9c9bab6dae29dbab1167e515f8df9ed17d2987cb6012db206933"
|
||||||
|
"checksum quote 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "54a21852a652ad6f610c9510194f398ff6f8692e334fd1145fed931f7fbe44ea"
|
||||||
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
|
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
|
||||||
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
|
"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
|
||||||
"checksum regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692"
|
"checksum regex 1.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a6020f034922e3194c711b82a627453881bc4682166cabb07134a10c26ba7692"
|
||||||
"checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae"
|
"checksum regex-syntax 0.6.17 (registry+https://github.com/rust-lang/crates.io-index)" = "7fe5bd57d1d7414c6b5ed48563a2c855d995ff777729dcd91c369ec7fea395ae"
|
||||||
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
"checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
|
||||||
|
"checksum structopt 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "863246aaf5ddd0d6928dfeb1a9ca65f505599e4e1b399935ef7e75107516b4ef"
|
||||||
|
"checksum structopt-derive 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "d239ca4b13aee7a2142e6795cbd69e457665ff8037aed33b3effdc430d2f927a"
|
||||||
|
"checksum syn 1.0.23 (registry+https://github.com/rust-lang/crates.io-index)" = "95b5f192649e48a5302a13f2feb224df883b98933222369e4b3b0fe2a5447269"
|
||||||
|
"checksum syn-mid 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7be3539f6c128a931cf19dcee741c1af532c7fd387baa739c03dd2e96479338a"
|
||||||
"checksum termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c22cec9d8978d906be5ac94bceb5a010d885c626c4c8855721a4dbd20e3ac905"
|
"checksum termion 1.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c22cec9d8978d906be5ac94bceb5a010d885c626c4c8855721a4dbd20e3ac905"
|
||||||
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
"checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
|
||||||
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
|
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
|
||||||
|
"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
|
||||||
"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
|
"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
|
||||||
|
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
|
||||||
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
|
"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a"
|
||||||
|
"checksum version_check 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "078775d0255232fb988e6fccf26ddc9d1ac274299aaedcedce21c6f72cc533ce"
|
||||||
"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
|
"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
|
||||||
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
|
||||||
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ license = "MIT"
|
||||||
termion = "1.5"
|
termion = "1.5"
|
||||||
regex = "1.3.1"
|
regex = "1.3.1"
|
||||||
clap = "2.33.0"
|
clap = "2.33.0"
|
||||||
|
structopt = { version = "0.3", default-features = false }
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "thumbs"
|
name = "thumbs"
|
||||||
|
|
|
||||||
|
|
@ -15,20 +15,6 @@ pub fn get_color(color_name: &str) -> Box<&dyn color::Color> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Holds color-related data, for clarity.
|
|
||||||
///
|
|
||||||
/// - `focus_*` colors are used to render the currently focused matched text.
|
|
||||||
/// - `normal_*` colors are used to render other matched text.
|
|
||||||
/// - `hint_*` colors are used to render the hints.
|
|
||||||
pub struct RenderingColors<'a> {
|
|
||||||
pub focus_fg_color: Box<&'a dyn color::Color>,
|
|
||||||
pub focus_bg_color: Box<&'a dyn color::Color>,
|
|
||||||
pub normal_fg_color: Box<&'a dyn color::Color>,
|
|
||||||
pub normal_bg_color: Box<&'a dyn color::Color>,
|
|
||||||
pub hint_fg_color: Box<&'a dyn color::Color>,
|
|
||||||
pub hint_bg_color: Box<&'a dyn color::Color>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
46
src/main.rs
46
src/main.rs
|
|
@ -11,9 +11,27 @@ use clap::crate_version;
|
||||||
use std::fs::OpenOptions;
|
use std::fs::OpenOptions;
|
||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::io::{self, Read};
|
use std::io::{self, Read};
|
||||||
|
use structopt::StructOpt;
|
||||||
|
|
||||||
// TODO: position as an enum ::Leading ::Trailing
|
// TODO: position as an enum ::Leading ::Trailing
|
||||||
|
|
||||||
|
/// A lightning fast version copy/pasting like vimium/vimperator.
|
||||||
|
#[derive(StructOpt, Debug)]
|
||||||
|
#[structopt(name = "thumbs")]
|
||||||
|
struct Opt {
|
||||||
|
/// Sets the alphabet.
|
||||||
|
#[structopt(short, long, default_value = "qwerty")]
|
||||||
|
alphabet: String,
|
||||||
|
|
||||||
|
/// Sets the foreground color for matches.
|
||||||
|
#[structopt(long, default_value = "green")]
|
||||||
|
fg_color: String,
|
||||||
|
|
||||||
|
/// Sets the background color for matches.
|
||||||
|
#[structopt(long, default_value = "black")]
|
||||||
|
bg_color: String,
|
||||||
|
}
|
||||||
|
|
||||||
fn app_args<'a>() -> clap::ArgMatches<'a> {
|
fn app_args<'a>() -> clap::ArgMatches<'a> {
|
||||||
App::new("thumbs")
|
App::new("thumbs")
|
||||||
.version(crate_version!())
|
.version(crate_version!())
|
||||||
|
|
@ -151,23 +169,23 @@ fn main() {
|
||||||
|
|
||||||
let mut state = state::State::new(&lines, alphabet, ®exp);
|
let mut state = state::State::new(&lines, alphabet, ®exp);
|
||||||
|
|
||||||
let rendering_edge = if position == "left" {
|
let hint_alignment = if position == "left" {
|
||||||
view::RenderingEdge::Leading
|
view::HintAlignment::Leading
|
||||||
} else {
|
} else {
|
||||||
view::RenderingEdge::Trailing
|
view::HintAlignment::Trailing
|
||||||
};
|
};
|
||||||
|
|
||||||
let rendering_colors = colors::RenderingColors {
|
let rendering_colors = view::ViewColors {
|
||||||
focus_fg_color: select_foreground_color,
|
focus_fg: select_foreground_color,
|
||||||
focus_bg_color: select_background_color,
|
focus_bg: select_background_color,
|
||||||
normal_fg_color: foreground_color,
|
match_fg: foreground_color,
|
||||||
normal_bg_color: background_color,
|
match_bg: background_color,
|
||||||
hint_fg_color: hint_foreground_color,
|
hint_fg: hint_foreground_color,
|
||||||
hint_bg_color: hint_background_color,
|
hint_bg: hint_background_color,
|
||||||
};
|
};
|
||||||
|
|
||||||
let contrast_style = if contrast {
|
let hint_style = if contrast {
|
||||||
Some(view::ContrastStyle::Surrounded('[', ']'))
|
Some(view::HintStyle::Surrounded('[', ']'))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
@ -178,9 +196,9 @@ fn main() {
|
||||||
multi,
|
multi,
|
||||||
reverse,
|
reverse,
|
||||||
unique,
|
unique,
|
||||||
rendering_edge,
|
hint_alignment,
|
||||||
&rendering_colors,
|
&rendering_colors,
|
||||||
contrast_style,
|
hint_style,
|
||||||
);
|
);
|
||||||
|
|
||||||
viewbox.present()
|
viewbox.present()
|
||||||
|
|
|
||||||
236
src/view.rs
236
src/view.rs
|
|
@ -13,14 +13,28 @@ pub struct View<'a> {
|
||||||
matches: Vec<state::Match<'a>>,
|
matches: Vec<state::Match<'a>>,
|
||||||
focus_index: usize,
|
focus_index: usize,
|
||||||
multi: bool,
|
multi: bool,
|
||||||
rendering_edge: RenderingEdge,
|
hint_alignment: HintAlignment,
|
||||||
rendering_colors: &'a colors::RenderingColors<'a>,
|
rendering_colors: &'a ViewColors<'a>,
|
||||||
contrast_style: Option<ContrastStyle>,
|
hint_style: Option<HintStyle>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Holds color-related data, for clarity.
|
||||||
|
///
|
||||||
|
/// - `focus_*` colors are used to render the currently focused matched text.
|
||||||
|
/// - `normal_*` colors are used to render other matched text.
|
||||||
|
/// - `hint_*` colors are used to render the hints.
|
||||||
|
pub struct ViewColors<'a> {
|
||||||
|
pub focus_fg: Box<&'a dyn color::Color>,
|
||||||
|
pub focus_bg: Box<&'a dyn color::Color>,
|
||||||
|
pub match_fg: Box<&'a dyn color::Color>,
|
||||||
|
pub match_bg: Box<&'a dyn color::Color>,
|
||||||
|
pub hint_fg: Box<&'a dyn color::Color>,
|
||||||
|
pub hint_bg: Box<&'a dyn color::Color>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Describes if, during rendering, a hint should aligned to the leading edge of
|
/// Describes if, during rendering, a hint should aligned to the leading edge of
|
||||||
/// the matched text, or to its trailing edge.
|
/// the matched text, or to its trailing edge.
|
||||||
pub enum RenderingEdge {
|
pub enum HintAlignment {
|
||||||
Leading,
|
Leading,
|
||||||
Trailing,
|
Trailing,
|
||||||
}
|
}
|
||||||
|
|
@ -30,7 +44,7 @@ pub enum RenderingEdge {
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// In practice, this is wrapped in an `Option`, so that the hint's text can be rendered with no style.
|
/// In practice, this is wrapped in an `Option`, so that the hint's text can be rendered with no style.
|
||||||
pub enum ContrastStyle {
|
pub enum HintStyle {
|
||||||
/// The hint's text will be underlined (leveraging `termion::style::Underline`).
|
/// The hint's text will be underlined (leveraging `termion::style::Underline`).
|
||||||
Underlined,
|
Underlined,
|
||||||
/// The hint's text will be surrounded by these chars.
|
/// The hint's text will be surrounded by these chars.
|
||||||
|
|
@ -51,9 +65,9 @@ impl<'a> View<'a> {
|
||||||
multi: bool,
|
multi: bool,
|
||||||
reversed: bool,
|
reversed: bool,
|
||||||
unique: bool,
|
unique: bool,
|
||||||
rendering_edge: RenderingEdge,
|
hint_alignment: HintAlignment,
|
||||||
rendering_colors: &'a colors::RenderingColors,
|
rendering_colors: &'a ViewColors,
|
||||||
contrast_style: Option<ContrastStyle>,
|
hint_style: Option<HintStyle>,
|
||||||
) -> View<'a> {
|
) -> View<'a> {
|
||||||
let matches = state.matches(reversed, unique);
|
let matches = state.matches(reversed, unique);
|
||||||
let focus_index = if reversed { matches.len() - 1 } else { 0 };
|
let focus_index = if reversed { matches.len() - 1 } else { 0 };
|
||||||
|
|
@ -63,9 +77,9 @@ impl<'a> View<'a> {
|
||||||
matches,
|
matches,
|
||||||
focus_index,
|
focus_index,
|
||||||
multi,
|
multi,
|
||||||
rendering_edge,
|
hint_alignment,
|
||||||
rendering_colors,
|
rendering_colors,
|
||||||
contrast_style,
|
hint_style,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -117,13 +131,13 @@ impl<'a> View<'a> {
|
||||||
text: &str,
|
text: &str,
|
||||||
focused: bool,
|
focused: bool,
|
||||||
offset: (usize, usize),
|
offset: (usize, usize),
|
||||||
colors: &colors::RenderingColors,
|
colors: &ViewColors,
|
||||||
) {
|
) {
|
||||||
// To help identify it, the match thas has focus is rendered with a dedicated color.
|
// To help identify it, the match thas has focus is rendered with a dedicated color.
|
||||||
let (text_fg_color, text_bg_color) = if focused {
|
let (text_fg_color, text_bg_color) = if focused {
|
||||||
(&colors.focus_fg_color, &colors.focus_bg_color)
|
(&colors.focus_fg, &colors.focus_bg)
|
||||||
} else {
|
} else {
|
||||||
(&colors.normal_fg_color, &colors.normal_bg_color)
|
(&colors.match_fg, &colors.match_bg)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Render just the Match's text on top of existing content.
|
// Render just the Match's text on top of existing content.
|
||||||
|
|
@ -146,7 +160,7 @@ impl<'a> View<'a> {
|
||||||
/// - just colors
|
/// - just colors
|
||||||
/// - underlined with colors
|
/// - underlined with colors
|
||||||
/// - surrounding the hint's text with some delimiters, see
|
/// - surrounding the hint's text with some delimiters, see
|
||||||
/// `ContrastStyle::Delimited`.
|
/// `HintStyle::Delimited`.
|
||||||
///
|
///
|
||||||
/// # Note
|
/// # Note
|
||||||
/// This writes directly on the writer, avoiding extra allocation.
|
/// This writes directly on the writer, avoiding extra allocation.
|
||||||
|
|
@ -154,15 +168,15 @@ impl<'a> View<'a> {
|
||||||
stdout: &mut dyn Write,
|
stdout: &mut dyn Write,
|
||||||
hint_text: &str,
|
hint_text: &str,
|
||||||
offset: (usize, usize),
|
offset: (usize, usize),
|
||||||
colors: &colors::RenderingColors,
|
colors: &ViewColors,
|
||||||
contrast_style: &Option<ContrastStyle>,
|
hint_style: &Option<HintStyle>,
|
||||||
) {
|
) {
|
||||||
let fg_color = color::Fg(*colors.hint_fg_color);
|
let fg_color = color::Fg(*colors.hint_fg);
|
||||||
let bg_color = color::Bg(*colors.hint_bg_color);
|
let bg_color = color::Bg(*colors.hint_bg);
|
||||||
let fg_reset = color::Fg(color::Reset);
|
let fg_reset = color::Fg(color::Reset);
|
||||||
let bg_reset = color::Bg(color::Reset);
|
let bg_reset = color::Bg(color::Reset);
|
||||||
|
|
||||||
match contrast_style {
|
match hint_style {
|
||||||
None => {
|
None => {
|
||||||
write!(
|
write!(
|
||||||
stdout,
|
stdout,
|
||||||
|
|
@ -176,8 +190,8 @@ impl<'a> View<'a> {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
Some(contrast_style) => match contrast_style {
|
Some(hint_style) => match hint_style {
|
||||||
ContrastStyle::Underlined => {
|
HintStyle::Underlined => {
|
||||||
write!(
|
write!(
|
||||||
stdout,
|
stdout,
|
||||||
"{goto}{bg_color}{fg_color}{sty}{hint}{sty_reset}{fg_reset}{bg_reset}",
|
"{goto}{bg_color}{fg_color}{sty}{hint}{sty_reset}{fg_reset}{bg_reset}",
|
||||||
|
|
@ -192,7 +206,7 @@ impl<'a> View<'a> {
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
ContrastStyle::Surrounded(opening, closing) => {
|
HintStyle::Surrounded(opening, closing) => {
|
||||||
write!(
|
write!(
|
||||||
stdout,
|
stdout,
|
||||||
"{goto}{bg_color}{fg_color}{bra}{hint}{bra_close}{fg_reset}{bg_reset}",
|
"{goto}{bg_color}{fg_color}{bra}{hint}{bra_close}{fg_reset}{bg_reset}",
|
||||||
|
|
@ -218,7 +232,7 @@ impl<'a> View<'a> {
|
||||||
/// - each Match's `text` is rendered as an overlay on top of it
|
/// - each Match's `text` is rendered as an overlay on top of it
|
||||||
/// - each Match's `hint` text is rendered as a final overlay
|
/// - each Match's `hint` text is rendered as a final overlay
|
||||||
///
|
///
|
||||||
/// Depending on the value of `self.rendering_edge`, the hint can be rendered
|
/// Depending on the value of `self.hint_alignment`, the hint can be rendered
|
||||||
/// on the leading edge of the underlying Match's `text`,
|
/// on the leading edge of the underlying Match's `text`,
|
||||||
/// or on the trailing edge.
|
/// or on the trailing edge.
|
||||||
///
|
///
|
||||||
|
|
@ -255,9 +269,9 @@ impl<'a> View<'a> {
|
||||||
// 3. Render the hint (e.g. "eo") as an overlay on top of the rendered matched text,
|
// 3. Render the hint (e.g. "eo") as an overlay on top of the rendered matched text,
|
||||||
// aligned at its leading or the trailing edge.
|
// aligned at its leading or the trailing edge.
|
||||||
if let Some(ref hint) = mat.hint {
|
if let Some(ref hint) = mat.hint {
|
||||||
let extra_offset = match self.rendering_edge {
|
let extra_offset = match self.hint_alignment {
|
||||||
RenderingEdge::Leading => 0,
|
HintAlignment::Leading => 0,
|
||||||
RenderingEdge::Trailing => text.len() - hint.len(),
|
HintAlignment::Trailing => text.len() - hint.len(),
|
||||||
};
|
};
|
||||||
|
|
||||||
View::render_matched_hint(
|
View::render_matched_hint(
|
||||||
|
|
@ -265,7 +279,7 @@ impl<'a> View<'a> {
|
||||||
hint,
|
hint,
|
||||||
(offset_x + extra_offset, offset_y),
|
(offset_x + extra_offset, offset_y),
|
||||||
&self.rendering_colors,
|
&self.rendering_colors,
|
||||||
&self.contrast_style,
|
&self.hint_style,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -446,13 +460,13 @@ path: /usr/local/bin/cargo";
|
||||||
let text = "https://en.wikipedia.org/wiki/Barcelona";
|
let text = "https://en.wikipedia.org/wiki/Barcelona";
|
||||||
let focused = true;
|
let focused = true;
|
||||||
let offset: (usize, usize) = (3, 1);
|
let offset: (usize, usize) = (3, 1);
|
||||||
let colors = colors::RenderingColors {
|
let colors = ViewColors {
|
||||||
focus_fg_color: Box::new(&(color::Red)),
|
focus_fg: Box::new(&(color::Red)),
|
||||||
focus_bg_color: Box::new(&(color::Blue)),
|
focus_bg: Box::new(&(color::Blue)),
|
||||||
normal_fg_color: Box::new(&color::Green),
|
match_fg: Box::new(&color::Green),
|
||||||
normal_bg_color: Box::new(&color::Magenta),
|
match_bg: Box::new(&color::Magenta),
|
||||||
hint_fg_color: Box::new(&color::Yellow),
|
hint_fg: Box::new(&color::Yellow),
|
||||||
hint_bg_color: Box::new(&color::Cyan),
|
hint_bg: Box::new(&color::Cyan),
|
||||||
};
|
};
|
||||||
|
|
||||||
View::render_matched_text(&mut writer, text, focused, offset, &colors);
|
View::render_matched_text(&mut writer, text, focused, offset, &colors);
|
||||||
|
|
@ -462,8 +476,8 @@ path: /usr/local/bin/cargo";
|
||||||
format!(
|
format!(
|
||||||
"{goto}{bg}{fg}{text}{fg_reset}{bg_reset}",
|
"{goto}{bg}{fg}{text}{fg_reset}{bg_reset}",
|
||||||
goto = cursor::Goto(4, 2),
|
goto = cursor::Goto(4, 2),
|
||||||
fg = color::Fg(*colors.focus_fg_color),
|
fg = color::Fg(*colors.focus_fg),
|
||||||
bg = color::Bg(*colors.focus_bg_color),
|
bg = color::Bg(*colors.focus_bg),
|
||||||
fg_reset = color::Fg(color::Reset),
|
fg_reset = color::Fg(color::Reset),
|
||||||
bg_reset = color::Bg(color::Reset),
|
bg_reset = color::Bg(color::Reset),
|
||||||
text = &text,
|
text = &text,
|
||||||
|
|
@ -478,13 +492,13 @@ path: /usr/local/bin/cargo";
|
||||||
let text = "https://en.wikipedia.org/wiki/Barcelona";
|
let text = "https://en.wikipedia.org/wiki/Barcelona";
|
||||||
let focused = false;
|
let focused = false;
|
||||||
let offset: (usize, usize) = (3, 1);
|
let offset: (usize, usize) = (3, 1);
|
||||||
let colors = colors::RenderingColors {
|
let colors = ViewColors {
|
||||||
focus_fg_color: Box::new(&(color::Red)),
|
focus_fg: Box::new(&(color::Red)),
|
||||||
focus_bg_color: Box::new(&(color::Blue)),
|
focus_bg: Box::new(&(color::Blue)),
|
||||||
normal_fg_color: Box::new(&color::Green),
|
match_fg: Box::new(&color::Green),
|
||||||
normal_bg_color: Box::new(&color::Magenta),
|
match_bg: Box::new(&color::Magenta),
|
||||||
hint_fg_color: Box::new(&color::Yellow),
|
hint_fg: Box::new(&color::Yellow),
|
||||||
hint_bg_color: Box::new(&color::Cyan),
|
hint_bg: Box::new(&color::Cyan),
|
||||||
};
|
};
|
||||||
|
|
||||||
View::render_matched_text(&mut writer, text, focused, offset, &colors);
|
View::render_matched_text(&mut writer, text, focused, offset, &colors);
|
||||||
|
|
@ -494,8 +508,8 @@ path: /usr/local/bin/cargo";
|
||||||
format!(
|
format!(
|
||||||
"{goto}{bg}{fg}{text}{fg_reset}{bg_reset}",
|
"{goto}{bg}{fg}{text}{fg_reset}{bg_reset}",
|
||||||
goto = cursor::Goto(4, 2),
|
goto = cursor::Goto(4, 2),
|
||||||
fg = color::Fg(*colors.normal_fg_color),
|
fg = color::Fg(*colors.match_fg),
|
||||||
bg = color::Bg(*colors.normal_bg_color),
|
bg = color::Bg(*colors.match_bg),
|
||||||
fg_reset = color::Fg(color::Reset),
|
fg_reset = color::Fg(color::Reset),
|
||||||
bg_reset = color::Bg(color::Reset),
|
bg_reset = color::Bg(color::Reset),
|
||||||
text = &text,
|
text = &text,
|
||||||
|
|
@ -509,24 +523,24 @@ path: /usr/local/bin/cargo";
|
||||||
let mut writer = vec![];
|
let mut writer = vec![];
|
||||||
let hint_text = "eo";
|
let hint_text = "eo";
|
||||||
let offset: (usize, usize) = (3, 1);
|
let offset: (usize, usize) = (3, 1);
|
||||||
let colors = colors::RenderingColors {
|
let colors = ViewColors {
|
||||||
focus_fg_color: Box::new(&(color::Red)),
|
focus_fg: Box::new(&(color::Red)),
|
||||||
focus_bg_color: Box::new(&(color::Blue)),
|
focus_bg: Box::new(&(color::Blue)),
|
||||||
normal_fg_color: Box::new(&color::Green),
|
match_fg: Box::new(&color::Green),
|
||||||
normal_bg_color: Box::new(&color::Magenta),
|
match_bg: Box::new(&color::Magenta),
|
||||||
hint_fg_color: Box::new(&color::Yellow),
|
hint_fg: Box::new(&color::Yellow),
|
||||||
hint_bg_color: Box::new(&color::Cyan),
|
hint_bg: Box::new(&color::Cyan),
|
||||||
};
|
};
|
||||||
|
|
||||||
let extra_offset = 0;
|
let extra_offset = 0;
|
||||||
let contrast_style = None;
|
let hint_style = None;
|
||||||
|
|
||||||
View::render_matched_hint(
|
View::render_matched_hint(
|
||||||
&mut writer,
|
&mut writer,
|
||||||
hint_text,
|
hint_text,
|
||||||
(offset.0 + extra_offset, offset.1),
|
(offset.0 + extra_offset, offset.1),
|
||||||
&colors,
|
&colors,
|
||||||
&contrast_style,
|
&hint_style,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -534,8 +548,8 @@ path: /usr/local/bin/cargo";
|
||||||
format!(
|
format!(
|
||||||
"{goto}{bg}{fg}{text}{fg_reset}{bg_reset}",
|
"{goto}{bg}{fg}{text}{fg_reset}{bg_reset}",
|
||||||
goto = cursor::Goto(4, 2),
|
goto = cursor::Goto(4, 2),
|
||||||
fg = color::Fg(*colors.hint_fg_color),
|
fg = color::Fg(*colors.hint_fg),
|
||||||
bg = color::Bg(*colors.hint_bg_color),
|
bg = color::Bg(*colors.hint_bg),
|
||||||
fg_reset = color::Fg(color::Reset),
|
fg_reset = color::Fg(color::Reset),
|
||||||
bg_reset = color::Bg(color::Reset),
|
bg_reset = color::Bg(color::Reset),
|
||||||
text = "eo",
|
text = "eo",
|
||||||
|
|
@ -549,24 +563,24 @@ path: /usr/local/bin/cargo";
|
||||||
let mut writer = vec![];
|
let mut writer = vec![];
|
||||||
let hint_text = "eo";
|
let hint_text = "eo";
|
||||||
let offset: (usize, usize) = (3, 1);
|
let offset: (usize, usize) = (3, 1);
|
||||||
let colors = colors::RenderingColors {
|
let colors = ViewColors {
|
||||||
focus_fg_color: Box::new(&(color::Red)),
|
focus_fg: Box::new(&(color::Red)),
|
||||||
focus_bg_color: Box::new(&(color::Blue)),
|
focus_bg: Box::new(&(color::Blue)),
|
||||||
normal_fg_color: Box::new(&color::Green),
|
match_fg: Box::new(&color::Green),
|
||||||
normal_bg_color: Box::new(&color::Magenta),
|
match_bg: Box::new(&color::Magenta),
|
||||||
hint_fg_color: Box::new(&color::Yellow),
|
hint_fg: Box::new(&color::Yellow),
|
||||||
hint_bg_color: Box::new(&color::Cyan),
|
hint_bg: Box::new(&color::Cyan),
|
||||||
};
|
};
|
||||||
|
|
||||||
let extra_offset = 0;
|
let extra_offset = 0;
|
||||||
let contrast_style = Some(ContrastStyle::Underlined);
|
let hint_style = Some(HintStyle::Underlined);
|
||||||
|
|
||||||
View::render_matched_hint(
|
View::render_matched_hint(
|
||||||
&mut writer,
|
&mut writer,
|
||||||
hint_text,
|
hint_text,
|
||||||
(offset.0 + extra_offset, offset.1),
|
(offset.0 + extra_offset, offset.1),
|
||||||
&colors,
|
&colors,
|
||||||
&contrast_style,
|
&hint_style,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -574,8 +588,8 @@ path: /usr/local/bin/cargo";
|
||||||
format!(
|
format!(
|
||||||
"{goto}{bg}{fg}{sty}{text}{sty_reset}{fg_reset}{bg_reset}",
|
"{goto}{bg}{fg}{sty}{text}{sty_reset}{fg_reset}{bg_reset}",
|
||||||
goto = cursor::Goto(4, 2),
|
goto = cursor::Goto(4, 2),
|
||||||
fg = color::Fg(*colors.hint_fg_color),
|
fg = color::Fg(*colors.hint_fg),
|
||||||
bg = color::Bg(*colors.hint_bg_color),
|
bg = color::Bg(*colors.hint_bg),
|
||||||
fg_reset = color::Fg(color::Reset),
|
fg_reset = color::Fg(color::Reset),
|
||||||
bg_reset = color::Bg(color::Reset),
|
bg_reset = color::Bg(color::Reset),
|
||||||
sty = style::Underline,
|
sty = style::Underline,
|
||||||
|
|
@ -591,24 +605,24 @@ path: /usr/local/bin/cargo";
|
||||||
let mut writer = vec![];
|
let mut writer = vec![];
|
||||||
let hint_text = "eo";
|
let hint_text = "eo";
|
||||||
let offset: (usize, usize) = (3, 1);
|
let offset: (usize, usize) = (3, 1);
|
||||||
let colors = colors::RenderingColors {
|
let colors = ViewColors {
|
||||||
focus_fg_color: Box::new(&(color::Red)),
|
focus_fg: Box::new(&(color::Red)),
|
||||||
focus_bg_color: Box::new(&(color::Blue)),
|
focus_bg: Box::new(&(color::Blue)),
|
||||||
normal_fg_color: Box::new(&color::Green),
|
match_fg: Box::new(&color::Green),
|
||||||
normal_bg_color: Box::new(&color::Magenta),
|
match_bg: Box::new(&color::Magenta),
|
||||||
hint_fg_color: Box::new(&color::Yellow),
|
hint_fg: Box::new(&color::Yellow),
|
||||||
hint_bg_color: Box::new(&color::Cyan),
|
hint_bg: Box::new(&color::Cyan),
|
||||||
};
|
};
|
||||||
|
|
||||||
let extra_offset = 0;
|
let extra_offset = 0;
|
||||||
let contrast_style = Some(ContrastStyle::Surrounded('{', '}'));
|
let hint_style = Some(HintStyle::Surrounded('{', '}'));
|
||||||
|
|
||||||
View::render_matched_hint(
|
View::render_matched_hint(
|
||||||
&mut writer,
|
&mut writer,
|
||||||
hint_text,
|
hint_text,
|
||||||
(offset.0 + extra_offset, offset.1),
|
(offset.0 + extra_offset, offset.1),
|
||||||
&colors,
|
&colors,
|
||||||
&contrast_style,
|
&hint_style,
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
|
@ -616,8 +630,8 @@ path: /usr/local/bin/cargo";
|
||||||
format!(
|
format!(
|
||||||
"{goto}{bg}{fg}{bra}{text}{bra_close}{fg_reset}{bg_reset}",
|
"{goto}{bg}{fg}{bra}{text}{bra_close}{fg_reset}{bg_reset}",
|
||||||
goto = cursor::Goto(4, 2),
|
goto = cursor::Goto(4, 2),
|
||||||
fg = color::Fg(*colors.hint_fg_color),
|
fg = color::Fg(*colors.hint_fg),
|
||||||
bg = color::Bg(*colors.hint_bg_color),
|
bg = color::Bg(*colors.hint_bg),
|
||||||
fg_reset = color::Fg(color::Reset),
|
fg_reset = color::Fg(color::Reset),
|
||||||
bg_reset = color::Bg(color::Reset),
|
bg_reset = color::Bg(color::Reset),
|
||||||
bra = '{',
|
bra = '{',
|
||||||
|
|
@ -640,15 +654,15 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - ";
|
||||||
let custom_regexes = [].to_vec();
|
let custom_regexes = [].to_vec();
|
||||||
let alphabet = "abcd";
|
let alphabet = "abcd";
|
||||||
let mut state = state::State::new(&lines, alphabet, &custom_regexes);
|
let mut state = state::State::new(&lines, alphabet, &custom_regexes);
|
||||||
let rendering_colors = colors::RenderingColors {
|
let rendering_colors = ViewColors {
|
||||||
focus_fg_color: Box::new(&(color::Red)),
|
focus_fg: Box::new(&(color::Red)),
|
||||||
focus_bg_color: Box::new(&(color::Blue)),
|
focus_bg: Box::new(&(color::Blue)),
|
||||||
normal_fg_color: Box::new(&color::Green),
|
match_fg: Box::new(&color::Green),
|
||||||
normal_bg_color: Box::new(&color::Magenta),
|
match_bg: Box::new(&color::Magenta),
|
||||||
hint_fg_color: Box::new(&color::Yellow),
|
hint_fg: Box::new(&color::Yellow),
|
||||||
hint_bg_color: Box::new(&color::Cyan),
|
hint_bg: Box::new(&color::Cyan),
|
||||||
};
|
};
|
||||||
let rendering_edge = RenderingEdge::Leading;
|
let hint_alignment = HintAlignment::Leading;
|
||||||
|
|
||||||
// create a view without any match
|
// create a view without any match
|
||||||
let view = View {
|
let view = View {
|
||||||
|
|
@ -656,9 +670,9 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - ";
|
||||||
matches: vec![], // no matches
|
matches: vec![], // no matches
|
||||||
focus_index: 0,
|
focus_index: 0,
|
||||||
multi: false,
|
multi: false,
|
||||||
rendering_edge,
|
hint_alignment,
|
||||||
rendering_colors: &rendering_colors,
|
rendering_colors: &rendering_colors,
|
||||||
contrast_style: None,
|
hint_style: None,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut writer = vec![];
|
let mut writer = vec![];
|
||||||
|
|
@ -701,25 +715,25 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - ";
|
||||||
let reversed = true;
|
let reversed = true;
|
||||||
let unique = false;
|
let unique = false;
|
||||||
|
|
||||||
let rendering_colors = colors::RenderingColors {
|
let rendering_colors = ViewColors {
|
||||||
focus_fg_color: Box::new(&(color::Red)),
|
focus_fg: Box::new(&(color::Red)),
|
||||||
focus_bg_color: Box::new(&(color::Blue)),
|
focus_bg: Box::new(&(color::Blue)),
|
||||||
normal_fg_color: Box::new(&color::Green),
|
match_fg: Box::new(&color::Green),
|
||||||
normal_bg_color: Box::new(&color::Magenta),
|
match_bg: Box::new(&color::Magenta),
|
||||||
hint_fg_color: Box::new(&color::Yellow),
|
hint_fg: Box::new(&color::Yellow),
|
||||||
hint_bg_color: Box::new(&color::Cyan),
|
hint_bg: Box::new(&color::Cyan),
|
||||||
};
|
};
|
||||||
let rendering_edge = RenderingEdge::Leading;
|
let hint_alignment = HintAlignment::Leading;
|
||||||
let contrast_style = None;
|
let hint_style = None;
|
||||||
|
|
||||||
let view = View::new(
|
let view = View::new(
|
||||||
&mut state,
|
&mut state,
|
||||||
multi,
|
multi,
|
||||||
reversed,
|
reversed,
|
||||||
unique,
|
unique,
|
||||||
rendering_edge,
|
hint_alignment,
|
||||||
&rendering_colors,
|
&rendering_colors,
|
||||||
contrast_style,
|
hint_style,
|
||||||
);
|
);
|
||||||
|
|
||||||
let mut writer = vec![];
|
let mut writer = vec![];
|
||||||
|
|
@ -742,10 +756,10 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - ";
|
||||||
let expected_match1_text = {
|
let expected_match1_text = {
|
||||||
let goto7_1 = cursor::Goto(7, 1);
|
let goto7_1 = cursor::Goto(7, 1);
|
||||||
format!(
|
format!(
|
||||||
"{goto7_1}{normal_bg_color}{normal_fg_color}127.0.0.1{fg_reset}{bg_reset}",
|
"{goto7_1}{match_bg}{match_fg}127.0.0.1{fg_reset}{bg_reset}",
|
||||||
goto7_1 = goto7_1,
|
goto7_1 = goto7_1,
|
||||||
normal_fg_color = color::Fg(*rendering_colors.normal_fg_color),
|
match_fg = color::Fg(*rendering_colors.match_fg),
|
||||||
normal_bg_color = color::Bg(*rendering_colors.normal_bg_color),
|
match_bg = color::Bg(*rendering_colors.match_bg),
|
||||||
fg_reset = color::Fg(color::Reset),
|
fg_reset = color::Fg(color::Reset),
|
||||||
bg_reset = color::Bg(color::Reset)
|
bg_reset = color::Bg(color::Reset)
|
||||||
)
|
)
|
||||||
|
|
@ -755,10 +769,10 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - ";
|
||||||
let goto7_1 = cursor::Goto(7, 1);
|
let goto7_1 = cursor::Goto(7, 1);
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{goto7_1}{hint_bg_color}{hint_fg_color}b{fg_reset}{bg_reset}",
|
"{goto7_1}{hint_bg}{hint_fg}b{fg_reset}{bg_reset}",
|
||||||
goto7_1 = goto7_1,
|
goto7_1 = goto7_1,
|
||||||
hint_fg_color = color::Fg(*rendering_colors.hint_fg_color),
|
hint_fg = color::Fg(*rendering_colors.hint_fg),
|
||||||
hint_bg_color = color::Bg(*rendering_colors.hint_bg_color),
|
hint_bg = color::Bg(*rendering_colors.hint_bg),
|
||||||
fg_reset = color::Fg(color::Reset),
|
fg_reset = color::Fg(color::Reset),
|
||||||
bg_reset = color::Bg(color::Reset)
|
bg_reset = color::Bg(color::Reset)
|
||||||
)
|
)
|
||||||
|
|
@ -767,10 +781,10 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - ";
|
||||||
let expected_match2_text = {
|
let expected_match2_text = {
|
||||||
let goto11_3 = cursor::Goto(11, 3);
|
let goto11_3 = cursor::Goto(11, 3);
|
||||||
format!(
|
format!(
|
||||||
"{goto11_3}{focus_bg_color}{focus_fg_color}https://en.wikipedia.org/wiki/Barcelona{fg_reset}{bg_reset}",
|
"{goto11_3}{focus_bg}{focus_fg}https://en.wikipedia.org/wiki/Barcelona{fg_reset}{bg_reset}",
|
||||||
goto11_3 = goto11_3,
|
goto11_3 = goto11_3,
|
||||||
focus_fg_color = color::Fg(*rendering_colors.focus_fg_color),
|
focus_fg = color::Fg(*rendering_colors.focus_fg),
|
||||||
focus_bg_color = color::Bg(*rendering_colors.focus_bg_color),
|
focus_bg = color::Bg(*rendering_colors.focus_bg),
|
||||||
fg_reset = color::Fg(color::Reset),
|
fg_reset = color::Fg(color::Reset),
|
||||||
bg_reset = color::Bg(color::Reset)
|
bg_reset = color::Bg(color::Reset)
|
||||||
)
|
)
|
||||||
|
|
@ -780,10 +794,10 @@ Barcelona https://en.wikipedia.org/wiki/Barcelona - ";
|
||||||
let goto11_3 = cursor::Goto(11, 3);
|
let goto11_3 = cursor::Goto(11, 3);
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{goto11_3}{hint_bg_color}{hint_fg_color}a{fg_reset}{bg_reset}",
|
"{goto11_3}{hint_bg}{hint_fg}a{fg_reset}{bg_reset}",
|
||||||
goto11_3 = goto11_3,
|
goto11_3 = goto11_3,
|
||||||
hint_fg_color = color::Fg(*rendering_colors.hint_fg_color),
|
hint_fg = color::Fg(*rendering_colors.hint_fg),
|
||||||
hint_bg_color = color::Bg(*rendering_colors.hint_bg_color),
|
hint_bg = color::Bg(*rendering_colors.hint_bg),
|
||||||
fg_reset = color::Fg(color::Reset),
|
fg_reset = color::Fg(color::Reset),
|
||||||
bg_reset = color::Bg(color::Reset)
|
bg_reset = color::Bg(color::Reset)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue