From ef90532d123834e82d471b62b65b4395c5f1a44f Mon Sep 17 00:00:00 2001 From: Joseph Ferano Date: Mon, 5 Jun 2023 11:24:18 +0700 Subject: [PATCH] WIP: TextArea form to add a new TODO item, switch to ratatui --- Cargo.lock | 311 ++++++++++++++++++++++++++++++++++++--------------- Cargo.toml | 5 +- src/app.rs | 19 ++-- src/input.rs | 89 ++++++++++----- src/main.rs | 2 +- src/ui.rs | 22 ++-- 6 files changed, 311 insertions(+), 137 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 187504c..122eff1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "anyhow" -version = "1.0.66" +version = "1.0.71" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" +checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8" [[package]] name = "autocfg" @@ -34,9 +34,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "crossterm" -version = "0.25.0" +version = "0.26.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" +checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13" dependencies = [ "bitflags", "crossterm_winapi", @@ -57,6 +57,22 @@ dependencies = [ "winapi", ] +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown", +] + [[package]] name = "int-enum" version = "0.5.0" @@ -75,14 +91,14 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "syn", + "syn 1.0.109", ] [[package]] name = "itoa" -version = "1.0.4" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" +checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" [[package]] name = "kanban-tui" @@ -91,17 +107,18 @@ dependencies = [ "anyhow", "crossterm", "int-enum", + "ratatui", "serde", "serde_json", "thiserror", - "tui", + "tui-textarea", ] [[package]] name = "libc" -version = "0.2.137" +version = "0.2.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" +checksum = "fc86cde3ff845662b8f4ef6cb50ea0e20c524eb3d29ae048287e06a1b3fa6a81" [[package]] name = "lock_api" @@ -115,30 +132,33 @@ dependencies = [ [[package]] name = "log" -version = "0.4.17" +version = "0.4.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] +checksum = "518ef76f2f87365916b142844c16d8fefd85039bc5699050210a7778ee1cd1de" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mio" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5d732bc30207a6423068df043e3d02e0735b155ad7ce1a6f76fe2baa5b158de" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] name = "once_cell" -version = "1.16.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "parking_lot" @@ -152,46 +172,58 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.5" +version = "0.9.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ff9f3fef3968a3ec5945535ed654cb38ff72d7495a25619e2247fb15a2ed9ba" +checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" dependencies = [ "cfg-if", "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] name = "proc-macro-crate" -version = "1.2.1" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eda0fc3b0fb7c975631757e14d9049da17374063edb6ebbcbc54d880d4fe94e9" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" dependencies = [ "once_cell", - "thiserror", - "toml", + "toml_edit", ] [[package]] name = "proc-macro2" -version = "1.0.47" +version = "1.0.59" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ea3d908b0e36316caf9e9e2c4625cdde190a7e6f440d794667ed17a1855e725" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.21" +version = "1.0.28" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" dependencies = [ "proc-macro2", ] +[[package]] +name = "ratatui" +version = "0.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcc0d032bccba900ee32151ec0265667535c230169f5a011154cdcd984e16829" +dependencies = [ + "bitflags", + "cassowary", + "crossterm", + "unicode-segmentation", + "unicode-width", +] + [[package]] name = "redox_syscall" version = "0.2.16" @@ -203,9 +235,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.11" +version = "1.0.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" +checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" [[package]] name = "scopeguard" @@ -215,29 +247,29 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.148" +version = "1.0.163" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e53f64bb4ba0191d6d0676e1b141ca55047d83b74f5607e6d8eb88126c52c2dc" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.148" +version = "1.0.163" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55492425aa53521babf6137309e7d34c20bbfbbfcfe2c7f3a047fd1f6b92c0c" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.18", ] [[package]] name = "serde_json" -version = "1.0.89" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "020ff22c755c2ed3f8cf162dbb41a7268d934702f3ed3631656ea597e08fc3db" +checksum = "057d394a50403bcac12672b2b18fb387ab6d289d957dab67dd201875391e52f1" dependencies = [ "itoa", "ryu", @@ -246,9 +278,9 @@ dependencies = [ [[package]] name = "signal-hook" -version = "0.3.14" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a253b5e89e2698464fc26b545c9edceb338e18a89effeeecfea192c3025be29d" +checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" dependencies = [ "libc", "signal-hook-registry", @@ -267,9 +299,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.0" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51e73328dc4ac0c7ccbda3a494dfa03df1de2f46018127f60c693f2648455b0" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" dependencies = [ "libc", ] @@ -282,9 +314,20 @@ checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "syn" -version = "1.0.105" +version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b9b43d45702de4c839cb9b51d9f529c5dd26a4aff255b42b1ebc03e88ee908" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" dependencies = [ "proc-macro2", "quote", @@ -293,57 +336,61 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.37" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" +checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.37" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" +checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.18", ] [[package]] -name = "toml" -version = "0.5.9" +name = "toml_datetime" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" +checksum = "5a76a9312f5ba4c2dec6b9161fdf25d87ad8a09256ccea5a556fef03c706a10f" + +[[package]] +name = "toml_edit" +version = "0.19.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380d56e8670370eee6566b0bfd4265f65b3f432e8c6d85623f728d4fa31f739" dependencies = [ - "serde", + "indexmap", + "toml_datetime", + "winnow", ] [[package]] -name = "tui" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1" +name = "tui-textarea" +version = "0.2.0" +source = "git+https://github.com/rhysd/tui-textarea.git#525070f52ccd96866267b6dbcd7d096178ff5163" dependencies = [ - "bitflags", - "cassowary", "crossterm", - "unicode-segmentation", - "unicode-width", + "ratatui", ] [[package]] name = "unicode-ident" -version = "1.0.5" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ceab39d59e4c9499d4e5a8ee0e2735b891bb7308ac83dfb4e80cad195c9f6f3" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" [[package]] name = "unicode-segmentation" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fdbf052a0783de01e944a6ce7a8cb939e295b1e7be835a1112c3b9a7f047a5a" +checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" [[package]] name = "unicode-width" @@ -381,57 +428,141 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" -version = "0.42.0" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" [[package]] name = "windows_aarch64_msvc" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" [[package]] name = "windows_i686_gnu" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" [[package]] name = "windows_i686_msvc" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" [[package]] name = "windows_x86_64_gnu" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" [[package]] name = "windows_x86_64_msvc" -version = "0.42.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + +[[package]] +name = "winnow" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61de7bac303dc551fe038e2b3cef0f571087a47571ea6e79a87692ac99b99699" +dependencies = [ + "memchr", +] diff --git a/Cargo.toml b/Cargo.toml index 9b24982..4306c8d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,8 +6,9 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -tui = "0.19.0" -crossterm = "0.25" +tui = { package = "ratatui", version = "0.20.1" } +tui-textarea = { version = "0.2.0", git = "https://github.com/rhysd/tui-textarea.git", features = ["ratatui-crossterm"], default-features=false } +crossterm = "0.26.1" serde = { version = "1.0.148" , features = [ "derive" ] } serde_json = "1.0.89" int-enum = "0.5.0" diff --git a/src/app.rs b/src/app.rs index ba6c704..bdc1435 100644 --- a/src/app.rs +++ b/src/app.rs @@ -2,6 +2,7 @@ // use int_enum::IntEnum; use serde::{Deserialize, Serialize}; use std::cmp::min; +use tui_textarea::TextArea; #[cfg(test)] mod tests; @@ -62,30 +63,30 @@ pub enum NewTaskFocus { Buttons } -pub struct NewTask { - pub title: String, - pub description: String, +pub struct NewTask<'a> { + pub title: TextArea<'a>, + pub description: TextArea<'a>, pub focus: NewTaskFocus } -impl Default for NewTask { +impl Default for NewTask<'_> { fn default() -> Self { NewTask { - title: String::new(), - description: String::new(), + title: TextArea::default(), + description: TextArea::default(), focus: NewTaskFocus::Title } } } -pub struct AppState { +pub struct AppState<'a> { pub project: Project, pub quit: bool, pub columns: Vec, - pub new_task_state: Option, + pub new_task_state: Option>, } -impl AppState { +impl AppState<'_> { pub fn new(project: Project) -> Self { AppState { quit: false, diff --git a/src/input.rs b/src/input.rs index 737fae1..699bb4b 100644 --- a/src/input.rs +++ b/src/input.rs @@ -1,38 +1,75 @@ +#![allow(unused_imports)] use crossterm::event; use crossterm::event::{Event, KeyCode}; -use crate::app::{NewTask, AppState}; +use crate::app::{NewTask, AppState, NewTaskFocus}; +use std::io::{stdout, Write}; +use tui_textarea::TextArea; pub fn handle_input(state: &mut AppState) -> Result<(), std::io::Error> { let project = &mut state.project; let column = project.get_selected_column_mut(); if let Event::Key(key) = event::read()? { - match key.code { - // KeyCode::BackTab => - // KeyCode::Tab => - KeyCode::Char('q') => state.quit = true, - KeyCode::Char('h') | - KeyCode::Left => { project.select_previous_column(); }, - KeyCode::Char('j') | - KeyCode::Down => column.select_next_task(), - KeyCode::Char('k') | - KeyCode::Up => column.select_previous_task(), - KeyCode::Char('l') | - KeyCode::Right => { project.select_next_column(); }, - KeyCode::Char('<') | - KeyCode::Char('H') => project.move_task_previous_column(), - KeyCode::Char('>') | - KeyCode::Char('L') => project.move_task_next_column(), - KeyCode::Char('=') | - KeyCode::Char('J') => project.move_task_down(), - KeyCode::Char('-') | - KeyCode::Char('K') => project.move_task_up(), - KeyCode::Char('p') => { - match state.new_task_state { - None => state.new_task_state = Some(NewTask::default()), - Some(_) => state.new_task_state = None, + match &mut state.new_task_state { + Some(task) => { + match task.focus { + // TODO: Handle wrapping around the enum rather than doing it manually + NewTaskFocus::Title => { + match key.code { + KeyCode::Tab => task.focus = NewTaskFocus::Description, + KeyCode::BackTab => task.focus = NewTaskFocus::Buttons, + _ => { task.title.input(key); } + } + } + NewTaskFocus::Description => { + match key.code { + KeyCode::Tab => task.focus = NewTaskFocus::Buttons, + KeyCode::BackTab => task.focus = NewTaskFocus::Title, + _ => { task.description.input(key); } + } + } + + NewTaskFocus::Buttons => { + match key.code { + KeyCode::Tab => task.focus = NewTaskFocus::Title, + KeyCode::BackTab => task.focus = NewTaskFocus::Description, + KeyCode::Enter => { + // TODO: Need a function that clears state and adds a new TODO + // into the right column + state.new_task_state = None + } + _ => (), + } + } + }; + } + None => { + match key.code { + KeyCode::Char('q') => state.quit = true, + KeyCode::Char('h') | + KeyCode::Left => { project.select_previous_column(); }, + KeyCode::Char('j') | + KeyCode::Down => column.select_next_task(), + KeyCode::Char('k') | + KeyCode::Up => column.select_previous_task(), + KeyCode::Char('l') | + KeyCode::Right => { project.select_next_column(); }, + KeyCode::Char('<') | + KeyCode::Char('H') => project.move_task_previous_column(), + KeyCode::Char('>') | + KeyCode::Char('L') => project.move_task_next_column(), + KeyCode::Char('=') | + KeyCode::Char('J') => project.move_task_down(), + KeyCode::Char('-') | + KeyCode::Char('K') => project.move_task_up(), + KeyCode::Char('p') => { + match state.new_task_state { + None => state.new_task_state = Some(NewTask::default()), + Some(_) => state.new_task_state = None, + } + } + _ => {} } } - _ => {} } } Ok(()) diff --git a/src/main.rs b/src/main.rs index a8d5365..9d443fa 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ +#![allow(unused_imports)] #![allow(dead_code)] use kanban_tui::*; - use crossterm::{ event::*, terminal::{disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen}, diff --git a/src/ui.rs b/src/ui.rs index 867bf57..192de00 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -92,7 +92,7 @@ fn centered_rect_for_popup(percent_x: u16, percent_y: u16, r: Rect) -> Rect { pub fn draw_new_task_popup(f: &mut Frame, state: &mut AppState) { let area = centered_rect_for_popup(45, 60, f.size()); f.render_widget(Clear, area); - match &state.new_task_state { + match &mut state.new_task_state { None => {} Some(task) => { let block = Block::default() @@ -100,7 +100,7 @@ pub fn draw_new_task_popup(f: &mut Frame, state: &mut AppState) { .title_alignment(Alignment::Center) .borders(Borders::ALL); let block_inner = block.inner(area); - let main = Paragraph::new(task.description.as_ref()).block(block); + // let main = Paragraph::new(task.description.clone()).block(block); let layout = Layout::default() .direction(Direction::Vertical) .constraints( @@ -113,18 +113,22 @@ pub fn draw_new_task_popup(f: &mut Frame, state: &mut AppState) { ) .split(block_inner); let b1 = Block::default().title("Title").borders(Borders::ALL); - let title = Paragraph::new("Hello I am text") + // let title = Paragraph::new("Hello I am text") // .style(Style::default().fg(Color::Yellow)) - .block(b1); + // .block(b1); let b2 = Block::default().title("Description").borders(Borders::ALL); - let description = Paragraph::new("Fill this out") + // let description = Paragraph::new("Fill this out") // .style(Style::default().fg(Color::Yellow)) - .block(b2); + // .block(b2); let b3 = Block::default().title("Keys").borders(Borders::TOP); let footer = Paragraph::new("p : Cancel").block(b3); - f.render_widget(main, area); - f.render_widget(title, layout[0]); - f.render_widget(description, layout[1]); + // f.render_widget(main, area); + // f.render_widget(title, layout[0]); + task.title.set_block(b1); + f.render_widget(task.title.widget(), layout[0]); + // f.render_widget(description, layout[1]); + task.description.set_block(b2); + f.render_widget(task.description.widget(), layout[1]); f.render_widget(footer, layout[2]); } }