diff --git a/Cargo.lock b/Cargo.lock index 2c119e99..4455bddf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -300,6 +300,31 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossterm" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e64e6c0fbe2c17357405f7c758c1ef960fce08bdfb2c03d88d2a18d7e09c4b67" +dependencies = [ + "bitflags 1.3.2", + "crossterm_winapi", + "libc", + "mio", + "parking_lot", + "signal-hook", + "signal-hook-mio", + "winapi", +] + +[[package]] +name = "crossterm_winapi" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b" +dependencies = [ + "winapi", +] + [[package]] name = "crypto-bigint" version = "0.4.9" @@ -918,6 +943,16 @@ dependencies = [ "serde", ] +[[package]] +name = "lock_api" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" +dependencies = [ + "autocfg", + "scopeguard", +] + [[package]] name = "log" version = "0.4.19" @@ -939,6 +974,18 @@ dependencies = [ "adler", ] +[[package]] +name = "mio" +version = "0.8.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "927a765cd3fc26206e66b296465fa9d3e5ab003e651c1b3c060e7956d96b19d2" +dependencies = [ + "libc", + "log", + "wasi 0.11.0+wasi-snapshot-preview1", + "windows-sys", +] + [[package]] name = "multibase" version = "0.9.1" @@ -1062,6 +1109,29 @@ dependencies = [ "sha2 0.10.7", ] +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall 0.3.5", + "smallvec", + "windows-targets", +] + [[package]] name = "pbkdf2" version = "0.11.0" @@ -1336,6 +1406,7 @@ dependencies = [ "textwrap 0.16.0", "timeago", "tui-realm-stdlib", + "tui-realm-textarea", "tuirealm", ] @@ -1522,6 +1593,12 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "sec1" version = "0.3.0" @@ -1602,6 +1679,36 @@ dependencies = [ "keccak", ] +[[package]] +name = "signal-hook" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801" +dependencies = [ + "libc", + "signal-hook-registry", +] + +[[package]] +name = "signal-hook-mio" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af" +dependencies = [ + "libc", + "mio", + "signal-hook", +] + +[[package]] +name = "signal-hook-registry" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +dependencies = [ + "libc", +] + [[package]] name = "signature" version = "1.6.4" @@ -1902,6 +2009,7 @@ checksum = "ccdd26cbd674007e649a272da4475fb666d3aa0ad0531da7136db6fab0e5bad1" dependencies = [ "bitflags 1.3.2", "cassowary", + "crossterm", "termion 1.5.6", "unicode-segmentation", "unicode-width", @@ -1918,6 +2026,26 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "tui-realm-textarea" +version = "1.1.1" +source = "git+https://github.com/erak/tui-realm-textarea.git?branch=no-borders#07f8344e0d7c6448abb9df96e900bac65b8856ad" +dependencies = [ + "lazy-regex", + "tui-textarea", + "tuirealm", +] + +[[package]] +name = "tui-textarea" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7a086dc7ddcec25bfb9c47d5f3d85e3313c0c67eebe645d9e6b883452e56cc" +dependencies = [ + "crossterm", + "tui", +] + [[package]] name = "tuirealm" version = "1.8.0" diff --git a/Cargo.toml b/Cargo.toml index 38097051..a32350d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,3 +22,4 @@ timeago = { version = "0.4.1" } textwrap = { version = "0.16.0" } tuirealm = { version = "1.8.0", default-features = false, features = [ "with-termion" ] } tui-realm-stdlib = { version = "1.2.0", default-features = false, features = [ "with-termion" ] } +tui-realm-textarea = { git = "https://github.com/erak/tui-realm-textarea.git", branch = "no-borders", default-features = false, features = [ "with-termion" ] } diff --git a/src/app/event.rs b/src/app/event.rs index 51765c42..d0f3924d 100644 --- a/src/app/event.rs +++ b/src/app/event.rs @@ -6,6 +6,7 @@ use radicle_tui::ui::widget::common::container::{ AppHeader, GlobalListener, LabeledContainer, Popup, }; use radicle_tui::ui::widget::common::context::{ContextBar, Shortcuts}; +use radicle_tui::ui::widget::common::form::TextInput; use radicle_tui::ui::widget::common::list::PropertyList; use radicle_tui::ui::widget::home::{Dashboard, IssueBrowser, PatchBrowser}; use radicle_tui::ui::widget::{issue, patch}; @@ -148,12 +149,18 @@ impl tuirealm::Component for Widget { Some(Message::Tick) } Event::Keyboard(KeyEvent { - code: Key::Char(ch), - modifiers: KeyModifiers::NONE, + code: Key::Enter, .. }) => { - self.perform(Cmd::Type(ch)); + self.perform(Cmd::Custom(TextInput::CMD_NEWLINE)); Some(Message::Tick) } + Event::Keyboard(KeyEvent { + code: Key::Char('s'), + modifiers: KeyModifiers::ALT, + }) => { + self.perform(Cmd::Submit); + None + } Event::Keyboard(KeyEvent { code: Key::Esc, .. }) => { Some(Message::Issue(IssueMessage::ClosePopup(IssueCid::NewForm))) } @@ -168,11 +175,18 @@ impl tuirealm::Component for Widget { Some(Message::Tick) } Event::Keyboard(KeyEvent { - code: Key::Char('s'), - modifiers: KeyModifiers::ALT, + code: Key::Char(ch), + modifiers: KeyModifiers::SHIFT, }) => { - self.perform(Cmd::Submit); - None + self.perform(Cmd::Type(ch.to_ascii_uppercase())); + Some(Message::Tick) + } + Event::Keyboard(KeyEvent { + code: Key::Char(ch), + .. + }) => { + self.perform(Cmd::Type(ch)); + Some(Message::Tick) } _ => None, } diff --git a/src/app/page.rs b/src/app/page.rs index d8425b7f..44014478 100644 --- a/src/app/page.rs +++ b/src/app/page.rs @@ -439,7 +439,9 @@ impl ViewPage for IssuePage { app.umount(&Cid::Issue(IssueCid::List))?; app.umount(&Cid::Issue(IssueCid::Details))?; app.umount(&Cid::Issue(IssueCid::Context))?; - app.umount(&Cid::Issue(IssueCid::NewForm))?; + if app.mounted(&Cid::Issue(IssueCid::NewForm)) { + app.umount(&Cid::Issue(IssueCid::NewForm))?; + } app.umount(&Cid::Issue(IssueCid::Shortcuts))?; Ok(()) } diff --git a/src/ui/widget/common/form.rs b/src/ui/widget/common/form.rs index 88940abb..d0db11dc 100644 --- a/src/ui/widget/common/form.rs +++ b/src/ui/widget/common/form.rs @@ -1,21 +1,94 @@ -use tui_realm_stdlib::Input; +use tui_realm_textarea::TextArea; + use tuirealm::command::{Cmd, CmdResult}; -use tuirealm::tui::layout::{Constraint, Direction, Rect}; -use tuirealm::{AttrValue, Attribute, Frame, MockComponent, Props, State}; +use tuirealm::props::Style; +use tuirealm::tui::layout::{Constraint, Direction, Margin, Rect}; +use tuirealm::{AttrValue, Attribute, Frame, MockComponent, Props, State, StateValue}; use crate::ui::state::FormState; use crate::ui::theme::Theme; -use crate::ui::widget::WidgetComponent; +use crate::ui::widget::{Widget, WidgetComponent}; + +use super::container::Container; +use super::label::Label; + +pub struct TextInput { + input: Widget, + placeholder: Widget