diff --git a/Cargo.toml b/Cargo.toml index 0c55292..a2c4d30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "crossterm" -version = "0.8.1" +version = "0.8.2" authors = ["T. Post"] description = "An crossplatform terminal library for manipulating terminals." repository = "https://github.com/TimonPost/crossterm" diff --git a/crossterm_cursor/LICENSE b/crossterm_cursor/LICENSE new file mode 100644 index 0000000..8b02a7f --- /dev/null +++ b/crossterm_cursor/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Timon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crossterm_input/Cargo.toml b/crossterm_input/Cargo.toml index c4447c3..310c318 100644 --- a/crossterm_input/Cargo.toml +++ b/crossterm_input/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "crossterm_input" -version = "0.2.0" +version = "0.2.1" authors = ["T. Post"] description = "A cross-platform library for reading userinput." repository = "https://github.com/TimonPost/crossterm" diff --git a/crossterm_input/LICENSE b/crossterm_input/LICENSE new file mode 100644 index 0000000..8b02a7f --- /dev/null +++ b/crossterm_input/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Timon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crossterm_input/README.md b/crossterm_input/README.md index 3903d54..6ae215c 100644 --- a/crossterm_input/README.md +++ b/crossterm_input/README.md @@ -118,7 +118,7 @@ let stdin = input.read_async(); if let Some(key_event) = stdin.next() { match key_event { - InputEvent::Keyboard(event: KeyEvent) => matche vent { /* check key event */ } + InputEvent::Keyboard(event: KeyEvent) => match event { /* check key event */ } InputEvent::Mouse(event: MouseEvent) => match event { /* check mouse event */ } } } diff --git a/crossterm_input/examples/key_events.rs b/crossterm_input/examples/key_events.rs index ab18e7f..d4e876a 100644 --- a/crossterm_input/examples/key_events.rs +++ b/crossterm_input/examples/key_events.rs @@ -175,6 +175,6 @@ fn main() { // un-comment below and run with // `cargo run --example key_events`: - // read_synchronously(); - read_asynchronously(); + read_synchronously(); + // read_asynchronously(); } diff --git a/crossterm_input/src/input/mod.rs b/crossterm_input/src/input/mod.rs index b41877f..af4efde 100644 --- a/crossterm_input/src/input/mod.rs +++ b/crossterm_input/src/input/mod.rs @@ -8,8 +8,13 @@ mod unix_input; #[cfg(target_os = "windows")] mod windows_input; +#[cfg(not(target_os = "windows"))] +pub use self::unix_input::SyncReader; #[cfg(not(target_os = "windows"))] use self::unix_input::UnixInput; + +#[cfg(target_os = "windows")] +pub use self::windows_input::SyncReader; #[cfg(target_os = "windows")] use self::windows_input::WindowsInput; @@ -108,13 +113,6 @@ pub enum KeyEvent { Esc, } -/// This type allows you to read input synchronously, which means that reading call will be blocking ones. -/// -/// This type is an iterator, and could be used to iterate over input events. -/// -/// If you don't want to block your calls use [AsyncReader](./LINK), which will read input on the background and queue it for you to read. -pub struct SyncReader; - /// This type allows you to read the input asynchronously which means that input events are gathered on the background and will be queued for you to read. /// /// **[SyncReader](./LINK)** diff --git a/crossterm_input/src/input/unix_input.rs b/crossterm_input/src/input/unix_input.rs index befa78e..9d4f7d9 100644 --- a/crossterm_input/src/input/unix_input.rs +++ b/crossterm_input/src/input/unix_input.rs @@ -44,7 +44,9 @@ impl ITerminalInput for UnixInput { } fn read_sync(&self) -> SyncReader { - SyncReader + SyncReader { + bytes: Box::new(get_tty().unwrap().bytes().flatten()), + } } fn read_until_async(&self, delimiter: u8) -> AsyncReader { @@ -90,6 +92,15 @@ impl ITerminalInput for UnixInput { } } +/// This type allows you to read input synchronously, which means that reading call will be blocking ones. +/// +/// This type is an iterator, and could be used to iterate over input events. +/// +/// If you don't want to block your calls use [AsyncReader](./LINK), which will read input on the background and queue it for you to read. +pub struct SyncReader { + bytes: Box>, +} + impl Iterator for SyncReader { type Item = InputEvent; /// Read input from the user. @@ -97,10 +108,8 @@ impl Iterator for SyncReader { /// If there are no keys pressed this will be a blocking call until there are. /// This will return `None` in case of a failure and `Some(InputEvent) in case of an occurred input event.` fn next(&mut self) -> Option { - let mut iterator = get_tty().unwrap().bytes().flatten(); - + let mut iterator = self.bytes.as_mut(); match iterator.next() { - None => None, Some(byte) => { if let Ok(event) = parse_event(byte, &mut iterator) { Some(event) @@ -108,6 +117,7 @@ impl Iterator for SyncReader { None } } + None => None, } } } diff --git a/crossterm_input/src/input/windows_input.rs b/crossterm_input/src/input/windows_input.rs index ed45402..e66f5ad 100644 --- a/crossterm_input/src/input/windows_input.rs +++ b/crossterm_input/src/input/windows_input.rs @@ -123,6 +123,13 @@ impl ITerminalInput for WindowsInput { } } +/// This type allows you to read input synchronously, which means that reading call will be blocking ones. +/// +/// This type is an iterator, and could be used to iterate over input events. +/// +/// If you don't want to block your calls use [AsyncReader](./LINK), which will read input on the background and queue it for you to read. +pub struct SyncReader; + impl Iterator for SyncReader { type Item = InputEvent; diff --git a/crossterm_screen/LICENSE b/crossterm_screen/LICENSE new file mode 100644 index 0000000..8b02a7f --- /dev/null +++ b/crossterm_screen/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Timon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crossterm_style/LICENSE b/crossterm_style/LICENSE new file mode 100644 index 0000000..8b02a7f --- /dev/null +++ b/crossterm_style/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Timon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crossterm_terminal/LICENSE b/crossterm_terminal/LICENSE new file mode 100644 index 0000000..8b02a7f --- /dev/null +++ b/crossterm_terminal/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Timon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crossterm_utils/LICENSE b/crossterm_utils/LICENSE new file mode 100644 index 0000000..8b02a7f --- /dev/null +++ b/crossterm_utils/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Timon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/crossterm_winapi/LICENSE b/crossterm_winapi/LICENSE new file mode 100644 index 0000000..8b02a7f --- /dev/null +++ b/crossterm_winapi/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Timon + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE.