diff --git a/CHANGELOG.md b/CHANGELOG.md index 1dc96e3..3fc2879 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,33 @@ + +# [v0.5.1](https://github.com/rhysd/tui-textarea/releases/tag/v0.5.1) - 12 Jul 2024 + +- Add `serde` optional feature. When it is enabled, some types support the serialization/deserialization with [serde](https://crates.io/crates/serde) crate. See [the document](https://github.com/rhysd/tui-textarea?tab=readme-ov-file#serializationdeserialization-support) for more details. ([#62](https://github.com/rhysd/tui-textarea/issues/62), thanks [@cestef](https://github.com/cestef)) + ```rust + use tui_textarea::Input; + + let json = r#" + { + "key": { "Char": "a" }, + "ctrl": true, + "alt": false, + "shift": true + } + "#; + + let input: Input = serde_json::from_str(json).unwrap(); + println!("{input}"); + // Input { + // key: Key::Char('a'), + // ctrl: true, + // alt: false, + // shift: true, + // } + ``` + + +[Changes][v0.5.1] + + # [v0.5.0](https://github.com/rhysd/tui-textarea/releases/tag/v0.5.0) - 07 Jul 2024 @@ -317,6 +347,7 @@ First release :tada: [Changes][v0.1.0] +[v0.5.1]: https://github.com/rhysd/tui-textarea/compare/v0.5.0...v0.5.1 [v0.5.0]: https://github.com/rhysd/tui-textarea/compare/v0.4.0...v0.5.0 [v0.4.0]: https://github.com/rhysd/tui-textarea/compare/v0.3.1...v0.4.0 [v0.3.1]: https://github.com/rhysd/tui-textarea/compare/v0.3.0...v0.3.1 diff --git a/README.md b/README.md index cbcb831..579223d 100644 --- a/README.md +++ b/README.md @@ -660,6 +660,30 @@ Values of the following types can be serialized/deserialized: - `CursorMove` - `Scrolling` +Here is an example for deserializing key input from JSON using [serde_json][]. + +```rust +use tui_textarea::Input; + +let json = r#" + { + "key": { "Char": "a" }, + "ctrl": true, + "alt": false, + "shift": true + } +"#; + +let input: Input = serde_json::from_str(json).unwrap(); +println!("{input}"); +// Input { +// key: Key::Char('a'), +// ctrl: true, +// alt: false, +// shift: true, +// } +``` + ## Minimum Supported Rust Version MSRV of this crate is depending on `tui` crate. Currently MSRV is 1.56.1. Note that `ratatui` crate requires more recent Rust version. @@ -705,3 +729,4 @@ tui-textarea is distributed under [The MIT License](./LICENSE.txt). [pulls]: https://github.com/rhysd/tui-textarea/pulls [regex]: https://docs.rs/regex/latest/regex/ [serde]: https://crates.io/crates/serde +[serde_json]: https://crates.io/crates/serde_json