From 8b1f988da37a28c2bd7143049a52f64caeabe559 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20D=C3=BCrr?= Date: Mon, 5 Feb 2018 16:07:13 +0100 Subject: [PATCH] WIP --- Cargo.lock | 57 +++++++++++++------------- alacritty.yml | 26 ++++++------ alacritty_macos.yml | 26 ++++++------ src/config.rs | 98 +++++++++------------------------------------ src/event.rs | 2 +- src/term/mod.rs | 8 ++-- 6 files changed, 79 insertions(+), 138 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f1ac3b3a..10600d50 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,8 +14,8 @@ dependencies = [ "base64 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "cgmath 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", - "clap 2.29.2 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy 0.0.184 (registry+https://github.com/rust-lang/crates.io-index)", + "clap 2.29.3 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy 0.0.186 (registry+https://github.com/rust-lang/crates.io-index)", "copypasta 0.0.1", "env_logger 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "errno 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -173,13 +173,13 @@ dependencies = [ [[package]] name = "clap" -version = "2.29.2" +version = "2.29.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ansi_term 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -187,17 +187,17 @@ dependencies = [ [[package]] name = "clippy" -version = "0.0.184" +version = "0.0.186" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cargo_metadata 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "clippy_lints 0.0.184 (registry+https://github.com/rust-lang/crates.io-index)", + "clippy_lints 0.0.186 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "clippy_lints" -version = "0.0.184" +version = "0.0.186" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "if_chain 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -493,7 +493,7 @@ name = "gl_generator" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "khronos_api 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "khronos_api 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "xml-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -503,7 +503,7 @@ name = "gl_generator" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "khronos_api 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "khronos_api 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "xml-rs 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -600,7 +600,7 @@ dependencies = [ [[package]] name = "khronos_api" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -801,7 +801,7 @@ dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "walkdir 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -899,7 +899,7 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -935,11 +935,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rand" -version = "0.3.20" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1116,7 +1117,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "strsim" -version = "0.6.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1144,7 +1145,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1154,7 +1155,7 @@ name = "termcolor" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wincolor 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "wincolor 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1292,10 +1293,11 @@ dependencies = [ [[package]] name = "walkdir" -version = "2.0.1" +version = "2.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "same-file 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1392,11 +1394,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wincolor" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1482,9 +1483,9 @@ dependencies = [ "checksum cgl 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "86765cb42c2a2c497e142af72517c1b4d7ae5bb2f25dfa77a5c69642f2342d89" "checksum cgmath 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6f3f4e27f2647652606e9faab058dd8686513a23b276fcd16e85eb0927838ddc" "checksum chrono 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7c20ebe0b2b08b0aeddba49c609fe7957ba2e33449882cb186a180bc60682fa9" -"checksum clap 2.29.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4151c5790817c7d21bbdc6c3530811f798172915f93258244948b93ba19604a6" -"checksum clippy 0.0.184 (registry+https://github.com/rust-lang/crates.io-index)" = "1e70c0ea9c5ad3eaab76ec3c4351d8d415c257093173416b0e2ed75e9be5cb74" -"checksum clippy_lints 0.0.184 (registry+https://github.com/rust-lang/crates.io-index)" = "b86054e0d81947d1db08e5931521dbea49619079c5fad91583d710c854a0e994" +"checksum clap 2.29.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b20c599c9bf11cf6c30d251a54dbfc86949c99c5d28ccc05f076eeaecafae8b8" +"checksum clippy 0.0.186 (registry+https://github.com/rust-lang/crates.io-index)" = "fa7b79c57f831e752f3667ae6115d02ed2d9e97a986ff76e5f04d613a8c0842a" +"checksum clippy_lints 0.0.186 (registry+https://github.com/rust-lang/crates.io-index)" = "a3864104a4e6092e644b985dd7543e5f24e99aa7262f5ee400bcb17cfeec1bf5" "checksum cmake 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "56d741ea7a69e577f6d06b36b7dff4738f680593dc27a701ffa8506b73ce28bb" "checksum cocoa 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac0d785ff4faf0ff23d7b5561346bb50dc7ef9a11cb0e65e07ef776b7752938f" "checksum core-foundation 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8047f547cd6856d45b1cdd75ef8d2f21f3d0e4bf1dab0a0041b0ae9a5dda9c0e" @@ -1525,7 +1526,7 @@ dependencies = [ "checksum itertools 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d3f2be4da1690a039e9ae5fd575f706a63ad5a2120f161b1d653c9da3930dd21" "checksum itoa 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8324a32baf01e2ae060e9de58ed0bc2320c9a2833491ee36cd3b4c414de4db8c" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum khronos_api 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d867c645cfeb8a7fec503731679eac03ac11b7105aa5a71cb8f8ee5271636add" +"checksum khronos_api 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d9ef23fcc4059260c5936f638c9805ebfc87cb172fa6661d130cba7f97d58f55" "checksum lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" "checksum lazycell 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce12306c4739d86ee97c23139f3a34ddf0387bbf181bc7929d287025a8c3ef6b" "checksum lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" @@ -1565,7 +1566,7 @@ dependencies = [ "checksum pulldown-cmark 0.0.15 (registry+https://github.com/rust-lang/crates.io-index)" = "378e941dbd392c101f2cb88097fa4d7167bc421d4b88de3ff7dbee503bc3233b" "checksum quine-mc_cluskey 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "07589615d719a60c8dd8a4622e7946465dfef20d1a428f969e3443e7386d5f45" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" -"checksum rand 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "512870020642bb8c221bf68baa1b2573da814f6ccfe5c9699b1c303047abe9b1" +"checksum rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "15a732abf9d20f0ad8eeb6f909bf6868722d9a06e1e50802b6a70351f40b4eb1" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" "checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" @@ -1588,7 +1589,7 @@ dependencies = [ "checksum slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17b4fcaed89ab08ef143da37bc52adbcc04d4a69014f4c1208d6b51f0c47bc23" "checksum smallvec 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44db0ecb22921ef790d17ae13a3f6d15784183ff5f2a01aa32098c7498d2b4b9" "checksum stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "15132e0e364248108c5e2c02e3ab539be8d6f5d52a01ca9bbf27ed657316f02b" -"checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" +"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum tempfile 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "11ce2fe9db64b842314052e2421ac61a73ce41b898dc8e3750398b219c5fc1e0" @@ -1612,7 +1613,7 @@ dependencies = [ "checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum vte 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a01634c75db59478405de08d8567c40c578bba80c565217ee709934b551720d8" -"checksum walkdir 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "40b6d201f4f8998a837196b6de9c73e35af14c992cbb92c4ab641d2c2dce52de" +"checksum walkdir 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b167e9a4420d8dddb260e70c90a4a375a1e5691f21f70e715553da87b6c2503a" "checksum wayland-client 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2b90adf943117ee4930d7944fe103dcb6f36ba05421f46521cb5adbf6bf0fbc8" "checksum wayland-kbd 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe0fb1c9917da9529d781659e456d84a693d74fe873d1658109758444616f76" "checksum wayland-protocols 0.12.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fb5942dd2fc79d934db437c9ea3aabffceb49b546046ea453bcba531005e5537" @@ -1624,7 +1625,7 @@ dependencies = [ "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "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 wincolor 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a39ee4464208f6430992ff20154216ab2357772ac871d994c51628d60e58b8b0" +"checksum wincolor 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0878187fa88838d2006c0a76f30d64797098426245b375383f60acb6aed8a203" "checksum winit 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "491e1305250e728fd9b8ef86ecef4e17a3293e87e51c7bc31e7a3913ec957d37" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum x11-dl 2.17.2 (registry+https://github.com/rust-lang/crates.io-index)" = "28ec50063128cfdbdfe683b0504a3740e07b779c7c75fa26e941218b5f95e098" diff --git a/alacritty.yml b/alacritty.yml index 90a27254..c87b7ce9 100644 --- a/alacritty.yml +++ b/alacritty.yml @@ -101,10 +101,6 @@ font: # Should display the render timer render_timer: false -# Use custom cursor colors. If true, display the cursor in the cursor.foreground -# and cursor.background colors, otherwise invert the colors of the cursor. -custom_cursor_colors: false - # Colors (Tomorrow Night Bright) colors: # Default colors @@ -114,6 +110,10 @@ colors: # Colors the cursor will use if `custom_cursor_colors` is true cursor: + # Use custom cursor colors. If true, always display the cursor in the + # `colors.cursor.text` and `colors.cursor.cursor` colors, + # otherwise invert the colors of the background and foreground. + custom_colors: false text: '0x000000' cursor: '0xffffff' @@ -221,15 +221,15 @@ selection: dynamic_title: true -hide_cursor_when_typing: false - -# Style of the cursor -# -# Values for 'cursor_style': -# - Block -# - Underline -# - Beam -cursor_style: Block +cursor: + # Style of the cursor + # + # Values for 'cursor_style': + # - Block + # - Underline + # - Beam + style: Block + hide_when_typing: false # Live config reload (changes require restart) live_config_reload: true diff --git a/alacritty_macos.yml b/alacritty_macos.yml index 7593cabe..b5e54d2a 100644 --- a/alacritty_macos.yml +++ b/alacritty_macos.yml @@ -81,10 +81,6 @@ font: # Should display the render timer render_timer: false -# Use custom cursor colors. If true, display the cursor in the cursor.foreground -# and cursor.background colors, otherwise invert the colors of the cursor. -custom_cursor_colors: false - # Colors (Tomorrow Night Bright) colors: # Default colors @@ -94,6 +90,10 @@ colors: # Colors the cursor will use if `custom_cursor_colors` is true cursor: + # Use custom cursor colors. If true, always display the cursor in the + # `colors.cursor.text` and `colors.cursor.cursor` colors, + # otherwise invert the colors of the background and foreground. + custom_colors: false text: '0x000000' cursor: '0xffffff' @@ -202,15 +202,15 @@ selection: dynamic_title: true -hide_cursor_when_typing: false - -# Style of the cursor -# -# Values for 'cursor_style': -# - Block -# - Underline -# - Beam -cursor_style: Block +cursor: + # Style of the cursor + # + # Values for 'cursor_style': + # - Block + # - Underline + # - Beam + style: Block + hide_when_typing: false # Live config reload (changes require restart) live_config_reload: true diff --git a/src/config.rs b/src/config.rs index be967150..4295c2ce 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,8 +27,6 @@ use input::{Action, Binding, MouseBinding, KeyBinding}; use index::{Line, Column}; use ansi::CursorStyle; -use util::fmt::Yellow; - /// Function that returns true for serde default fn true_bool() -> bool { true @@ -332,10 +330,6 @@ pub struct Config { #[serde(default, deserialize_with = "failure_default")] render_timer: bool, - /// Should use custom cursor colors - #[serde(default, deserialize_with = "failure_default")] - custom_cursor_colors: bool, - /// Should draw bold text with brighter colors instead of bold font #[serde(default="true_bool", deserialize_with = "default_true_bool")] draw_bold_text_with_bright_colors: bool, @@ -381,13 +375,9 @@ pub struct Config { #[serde(default="true_bool", deserialize_with = "default_true_bool")] dynamic_title: bool, - /// Hide cursor when typing + /// Cursor settings #[serde(default, deserialize_with = "failure_default")] - hide_cursor_when_typing: bool, - - /// Style of the cursor - #[serde(default, deserialize_with = "failure_default")] - cursor_style: CursorStyle, + cursor: Cursor, /// Live config reload #[serde(default="true_bool", deserialize_with = "default_true_bool")] @@ -936,7 +926,7 @@ pub enum Error { pub struct Colors { #[serde(default, deserialize_with = "failure_default")] pub primary: PrimaryColors, - #[serde(default, deserialize_with = "deserialize_cursor_colors")] + #[serde(default, deserialize_with = "failure_default")] pub cursor: CursorColors, pub normal: AnsiColors, pub bright: AnsiColors, @@ -944,67 +934,29 @@ pub struct Colors { pub dim: Option, } -fn deserialize_cursor_colors<'a, D>(deserializer: D) -> ::std::result::Result - where D: de::Deserializer<'a> -{ - match CursorOrPrimaryColors::deserialize(deserializer) { - Ok(either) => Ok(either.into_cursor_colors()), - Err(err) => { - eprintln!("problem with config: {}; Using default value", err); - Ok(CursorColors::default()) - }, - } +#[derive(Copy, Clone, Debug, Default, Deserialize)] +pub struct Cursor { + #[serde(default, deserialize_with = "failure_default")] + pub style: CursorStyle, + #[serde(default, deserialize_with = "failure_default")] + pub hide_when_typing: bool, } -#[derive(Deserialize)] -#[serde(untagged)] -pub enum CursorOrPrimaryColors { - Cursor { - #[serde(deserialize_with = "rgb_from_hex")] - text: Rgb, - #[serde(deserialize_with = "rgb_from_hex")] - cursor: Rgb, - }, - Primary { - #[serde(deserialize_with = "rgb_from_hex")] - foreground: Rgb, - #[serde(deserialize_with = "rgb_from_hex")] - background: Rgb, - } -} - -impl CursorOrPrimaryColors { - fn into_cursor_colors(self) -> CursorColors { - match self { - CursorOrPrimaryColors::Cursor { text, cursor } => CursorColors { - text: text, - cursor: cursor - }, - CursorOrPrimaryColors::Primary { foreground, background } => { - // Must print in config since logger isn't setup yet. - eprintln!("{}", - Yellow("Config `colors.cursor.foreground` and `colors.cursor.background` \ - are deprecated. Please use `colors.cursor.text` and \ - `colors.cursor.cursor` instead.") - ); - CursorColors { - text: foreground, - cursor: background - } - } - } - } -} - -#[derive(Debug)] +#[derive(Debug, Deserialize)] pub struct CursorColors { + /// Should use custom cursor colors + #[serde(default, deserialize_with = "failure_default")] + pub custom_colors: bool, + #[serde(deserialize_with = "rgb_from_hex")] pub text: Rgb, + #[serde(deserialize_with = "rgb_from_hex")] pub cursor: Rgb, } impl Default for CursorColors { fn default() -> Self { CursorColors { + custom_colors: false, text: Rgb { r: 0, g: 0, b: 0 }, cursor: Rgb { r: 0xff, g: 0xff, b: 0xff }, } @@ -1330,12 +1282,6 @@ impl Config { self.font.use_thin_strokes } - /// show cursor as inverted - #[inline] - pub fn custom_cursor_colors(&self) -> bool { - self.custom_cursor_colors - } - pub fn path(&self) -> Option<&Path> { self.config_path .as_ref() @@ -1350,16 +1296,10 @@ impl Config { &self.env } - /// Should hide cursor when typing + /// Cursor settings #[inline] - pub fn hide_cursor_when_typing(&self) -> bool { - self.hide_cursor_when_typing - } - - /// Style of the cursor - #[inline] - pub fn cursor_style(&self) -> CursorStyle { - self.cursor_style + pub fn cursor(&self) -> Cursor { + self.cursor } /// Live config reload diff --git a/src/event.rs b/src/event.rs index b133f8fa..50189df9 100644 --- a/src/event.rs +++ b/src/event.rs @@ -233,7 +233,7 @@ impl Processor { mouse: Default::default(), selection: None, size_info: size_info, - hide_cursor_when_typing: config.hide_cursor_when_typing(), + hide_cursor_when_typing: config.cursor().hide_when_typing, hide_cursor: false, received_count: 0, suppress_chars: false, diff --git a/src/term/mod.rs b/src/term/mod.rs index 79101540..89d9bad5 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -168,7 +168,7 @@ impl<'a> RenderableCellsIter<'a> { } fn populate_block_cursor(&mut self) { - let (text_color, cursor_color) = if self.config.custom_cursor_colors() { + let (text_color, cursor_color) = if self.config.colors().cursor.custom_colors { ( Color::Named(NamedColor::CursorText), Color::Named(NamedColor::Cursor) @@ -223,7 +223,7 @@ impl<'a> RenderableCellsIter<'a> { } fn text_cursor_color(&self, cell: &Cell) -> Color { - if self.config.custom_cursor_colors() { + if self.config.colors().cursor.custom_colors { Color::Named(NamedColor::Cursor) } else { // Cursor is same color as text @@ -834,7 +834,7 @@ impl Term { original_colors: color::List::from(config.colors()), semantic_escape_chars: config.selection().semantic_escape_chars.clone(), cursor_style: None, - default_cursor_style: config.cursor_style(), + default_cursor_style: config.cursor().style, dynamic_title: config.dynamic_title(), tabspaces, } @@ -861,7 +861,7 @@ impl Term { } } self.visual_bell.update_config(config); - self.default_cursor_style = config.cursor_style(); + self.default_cursor_style = config.cursor().style; self.dynamic_title = config.dynamic_title(); }