From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/termize/.cargo-checksum.json | 1 + vendor/termize/CHANGELOG.md | 9 ++ vendor/termize/CODE_OF_CONDUCT.md | 76 ++++++++++ vendor/termize/CONTRIBUTING.md | 22 +++ vendor/termize/Cargo.toml | 56 +++++++ vendor/termize/LICENSE-APACHE | 201 +++++++++++++++++++++++++ vendor/termize/LICENSE-MIT | 22 +++ vendor/termize/README.md | 51 +++++++ vendor/termize/src/lib.rs | 34 +++++ vendor/termize/src/platform/mod.rs | 15 ++ vendor/termize/src/platform/unix.rs | 232 +++++++++++++++++++++++++++++ vendor/termize/src/platform/unsupported.rs | 12 ++ vendor/termize/src/platform/windows.rs | 107 +++++++++++++ 13 files changed, 838 insertions(+) create mode 100644 vendor/termize/.cargo-checksum.json create mode 100644 vendor/termize/CHANGELOG.md create mode 100644 vendor/termize/CODE_OF_CONDUCT.md create mode 100644 vendor/termize/CONTRIBUTING.md create mode 100644 vendor/termize/Cargo.toml create mode 100644 vendor/termize/LICENSE-APACHE create mode 100644 vendor/termize/LICENSE-MIT create mode 100644 vendor/termize/README.md create mode 100644 vendor/termize/src/lib.rs create mode 100644 vendor/termize/src/platform/mod.rs create mode 100644 vendor/termize/src/platform/unix.rs create mode 100644 vendor/termize/src/platform/unsupported.rs create mode 100644 vendor/termize/src/platform/windows.rs (limited to 'vendor/termize') diff --git a/vendor/termize/.cargo-checksum.json b/vendor/termize/.cargo-checksum.json new file mode 100644 index 000000000..301f8ae9b --- /dev/null +++ b/vendor/termize/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"CHANGELOG.md":"9809268178a89f40adabf0ccd6145fdb3742367c3c603b2047fe4cdff0262c62","CODE_OF_CONDUCT.md":"e3334b644bfab253193019119b34b833c8733b1ce32034372a00bfbb746ae355","CONTRIBUTING.md":"58454fb3db5a9df077ce7dea1b333b7f7327db33a57bcfd695d18c904b76281e","Cargo.toml":"4d32ede02b13a48756ef81ae21d3512838c16f07378fcf5b3ab6287b38f717f4","LICENSE-APACHE":"a60eea817514531668d7e00765731449fe14d059d3249e0bc93b36de45f759f2","LICENSE-MIT":"526045f49bd068c0f156a8cb406ac6470db580ce1605fecb9c35bc21e30fdaa8","README.md":"09de69ee4d93b2f9db71682133ae6161e408ed2cf066c8b8b0c62c55f3028950","src/lib.rs":"8950e7748f8594fd184e9deecea0e264c66857eb104426406e397da30a6bc6a0","src/platform/mod.rs":"0c113921402db5c12c99b34df7fe4dc8749630e465bc050f8da9c5803d441d32","src/platform/unix.rs":"ec957972c6f31a4a42dcc3380eb166109b10297f18225121451de8971d143d8e","src/platform/unsupported.rs":"1f151670229c96252fe3bb0a5b49f344e12b3e68b384aecb6ba93f5e07848a5c","src/platform/windows.rs":"5560353eeac04f5bc31850611ec89f15c146bcfa966582bd34cde98b5e4ce63c"},"package":"1706be6b564323ce7092f5f7e6b118a14c8ef7ed0e69c8c5329c914a9f101295"} \ No newline at end of file diff --git a/vendor/termize/CHANGELOG.md b/vendor/termize/CHANGELOG.md new file mode 100644 index 000000000..d80a2f1ee --- /dev/null +++ b/vendor/termize/CHANGELOG.md @@ -0,0 +1,9 @@ +# Changes + +## 0.1.1 + +- Fix cargo metadata + +## 0.1.0 + +Initial release. diff --git a/vendor/termize/CODE_OF_CONDUCT.md b/vendor/termize/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..a9e4ad85d --- /dev/null +++ b/vendor/termize/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, nationality, personal +appearance, race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting the project team at huyuumi.dev@gmail.com. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see +https://www.contributor-covenant.org/faq diff --git a/vendor/termize/CONTRIBUTING.md b/vendor/termize/CONTRIBUTING.md new file mode 100644 index 000000000..188f263d8 --- /dev/null +++ b/vendor/termize/CONTRIBUTING.md @@ -0,0 +1,22 @@ +# How to contribute + +Thanks for reading this! + +## Bugs/Feature Requests/Questions + +You can submit bug reports, feature requests, and questions to +[issue tracker](https://github.com/JohnTitor/termize). + +## Submitting changes + +You can submit patches as a pull request. The commit title should start with +the base verb whose first letter is a capital letter. + +We follow no merge policy. You should resolve merge conflicts by rebase, +not merge. + +## Coding conventions + + * Use four spaces (not hard tabs) on Rust files(*.rs) + * Use two spaces (not hard tabs) on other files basically + * Run clippy and rustfmt before submitting pull requests if possible diff --git a/vendor/termize/Cargo.toml b/vendor/termize/Cargo.toml new file mode 100644 index 000000000..d248f4db5 --- /dev/null +++ b/vendor/termize/Cargo.toml @@ -0,0 +1,56 @@ +# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO +# +# When uploading crates to the registry Cargo will automatically +# "normalize" Cargo.toml files for maximal compatibility +# with all versions of Cargo and also rewrite `path` dependencies +# to registry (e.g., crates.io) dependencies +# +# If you believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + +[package] +edition = "2018" +name = "termize" +version = "0.1.1" +authors = ["Yuki Okushi "] +exclude = [".github/*", ".travis.yml", ".cirrus.yml"] +description = "functions for determining terminal sizes and dimensions" +documentation = "https://docs.rs/termize" +readme = "README.md" +keywords = ["term", "terminal", "size", "width", "dimension"] +categories = ["command-line-interface"] +license = "MIT OR Apache-2.0" +repository = "https://github.com/JohnTitor/termize" +[profile.dev] +opt-level = 0 +lto = false +codegen-units = 4 +debug = true +debug-assertions = true +rpath = false + +[profile.release] +opt-level = 3 +lto = true +debug = false +debug-assertions = false +rpath = false + +[profile.test] +opt-level = 1 +lto = false +codegen-units = 2 +debug = true +debug-assertions = true +rpath = false + +[dependencies] +[target."cfg(unix)".dependencies.libc] +version = "0.2.66" +[target."cfg(windows)".dependencies.winapi] +version = "0.3.8" +features = ["handleapi", "processenv", "wincon", "winbase"] +[badges.cirrus-ci] +repository = "JohnTitor/termize" diff --git a/vendor/termize/LICENSE-APACHE b/vendor/termize/LICENSE-APACHE new file mode 100644 index 000000000..16fe87b06 --- /dev/null +++ b/vendor/termize/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + +Copyright [yyyy] [name of copyright owner] + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/vendor/termize/LICENSE-MIT b/vendor/termize/LICENSE-MIT new file mode 100644 index 000000000..8a060d217 --- /dev/null +++ b/vendor/termize/LICENSE-MIT @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2015-2019 Kevin B. Knapp +Copyright (c) 2019 Yuki Okushi + +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/vendor/termize/README.md b/vendor/termize/README.md new file mode 100644 index 000000000..1c5ce32d3 --- /dev/null +++ b/vendor/termize/README.md @@ -0,0 +1,51 @@ +termize +==== + +[![Crates.io](https://img.shields.io/crates/v/termize.svg)](https://crates.io/crates/termize) [![Crates.io](https://img.shields.io/crates/d/termize.svg)](https://crates.io/crates/termize) [![license](http://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/JohnTitor/termize/blob/master/LICENSE-MIT) [![license](http://img.shields.io/badge/license-Apache2.0-blue.svg)](https://github.com/JohnTitor/termize/blob/master/LICENSE-APACHE) [![Actions](https://github.com/JohnTitor/termize/workflows/CI/badge.svg)](https://github.com/JohnTitor/termize/workflows/CI) [![Cirrus CI](https://api.cirrus-ci.com/github/JohnTitor/termize.svg)](https://cirrus-ci.com/github/JohnTitor/termize) + +A Rust library to enable getting terminal sizes and dimensions + +**This is a fork repository, original is [here](https://github.com/clap-rs/term_size-rs).** + +MSRV (Minimum Supported Rust Version): 1.31.1 + +[Documentation](https://docs.rs/termize) + +## Usage + +First, add the following to your `Cargo.toml`: + +```toml +[dependencies] +termize = "0.1" +``` + +To get the dimensions of your terminal window, simply use the following: + +```rust +fn main() { + if let Some((w, h)) = termize::dimensions() { + println!("Width: {}\nHeight: {}", w, h); + } else { + println!("Unable to get term size :("); + } +} +``` + +## License + +Copyright Benjamin Sago, Kevin Knapp, Yuki Okushi, and `term_size`/`termize` contributors. + +Licensed under either of + +* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) +* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) + +at your option. Unless you explicitly state otherwise, any contribution intentionally +submitted for inclusion in the work by you, as defined in the +Apache-2.0 license, shall be dual licensed as above, without any +additional terms or conditions. + +## Contributing + +Contributions are welcome! Here is our [CONTRIBUTING GUIDE](./CONTRIBUTING.md). diff --git a/vendor/termize/src/lib.rs b/vendor/termize/src/lib.rs new file mode 100644 index 000000000..87be69413 --- /dev/null +++ b/vendor/termize/src/lib.rs @@ -0,0 +1,34 @@ +//! System calls for getting the terminal size. +//! +//! Getting the terminal size is performed using an ioctl command that takes +//! the file handle to the terminal -- which in this case, is stdout -- and +//! populates a structure containing the values. +//! +//! The size is needed when the user wants the output formatted into columns: +//! the default grid view, or the hybrid grid-details view. +//! +//! # Example +//! +//! To get the dimensions of your terminal window, simply use the following: +//! +//! ```no_run +//! if let Some((w, h)) = termize::dimensions() { +//! println!("Width: {}\nHeight: {}", w, h); +//! } else { +//! println!("Unable to get term size :("); +//! } +//! ``` +#![deny( + missing_docs, + missing_debug_implementations, + missing_copy_implementations, + trivial_casts, + unused_import_braces, + unused_allocation, + unused_qualifications, + trivial_numeric_casts +)] + +// A facade to allow exposing functions depending on the platform +mod platform; +pub use crate::platform::{dimensions, dimensions_stderr, dimensions_stdin, dimensions_stdout}; diff --git a/vendor/termize/src/platform/mod.rs b/vendor/termize/src/platform/mod.rs new file mode 100644 index 000000000..c48d001e9 --- /dev/null +++ b/vendor/termize/src/platform/mod.rs @@ -0,0 +1,15 @@ +#[cfg(unix)] +mod unix; +#[cfg(unix)] +pub use self::unix::{dimensions, dimensions_stderr, dimensions_stdin, dimensions_stdout}; + +#[cfg(windows)] +mod windows; +#[cfg(windows)] +pub use self::windows::{dimensions, dimensions_stderr, dimensions_stdin, dimensions_stdout}; + +// makes project compilable on unsupported platforms +#[cfg(not(any(unix, windows)))] +mod unsupported; +#[cfg(not(any(unix, windows)))] +pub use self::unsupported::{dimensions, dimensions_stderr, dimensions_stdin, dimensions_stdout}; diff --git a/vendor/termize/src/platform/unix.rs b/vendor/termize/src/platform/unix.rs new file mode 100644 index 000000000..0420789b7 --- /dev/null +++ b/vendor/termize/src/platform/unix.rs @@ -0,0 +1,232 @@ +// Supress warnings for `TIOCGWINSZ.into()` since freebsd requires it. +#![allow(clippy::identity_conversion)] + +use libc::{ioctl, winsize, STDERR_FILENO, STDIN_FILENO, STDOUT_FILENO, TIOCGWINSZ}; +use std::mem::zeroed; + +/// Runs the ioctl command. Returns (0, 0) if all of the streams are not to a terminal, or +/// there is an error. (0, 0) is an invalid size to have anyway, which is why +/// it can be used as a nil value. +unsafe fn get_dimensions_any() -> winsize { + let mut window: winsize = zeroed(); + let mut result = ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &mut window); + + if result == -1 { + window = zeroed(); + result = ioctl(STDIN_FILENO, TIOCGWINSZ.into(), &mut window); + if result == -1 { + window = zeroed(); + result = ioctl(STDERR_FILENO, TIOCGWINSZ.into(), &mut window); + if result == -1 { + return zeroed(); + } + } + } + window +} + +/// Runs the ioctl command. Returns (0, 0) if the output is not to a terminal, or +/// there is an error. (0, 0) is an invalid size to have anyway, which is why +/// it can be used as a nil value. +unsafe fn get_dimensions_out() -> winsize { + let mut window: winsize = zeroed(); + let result = ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &mut window); + + if result != -1 { + return window; + } + zeroed() +} + +/// Runs the ioctl command. Returns (0, 0) if the input is not to a terminal, or +/// there is an error. (0, 0) is an invalid size to have anyway, which is why +/// it can be used as a nil value. +unsafe fn get_dimensions_in() -> winsize { + let mut window: winsize = zeroed(); + let result = ioctl(STDIN_FILENO, TIOCGWINSZ.into(), &mut window); + + if result != -1 { + return window; + } + zeroed() +} + +/// Runs the ioctl command. Returns (0, 0) if the error is not to a terminal, or +/// there is an error. (0, 0) is an invalid size to have anyway, which is why +/// it can be used as a nil value. +unsafe fn get_dimensions_err() -> winsize { + let mut window: winsize = zeroed(); + let result = ioctl(STDERR_FILENO, TIOCGWINSZ.into(), &mut window); + + if result != -1 { + return window; + } + zeroed() +} + +/// Query the current processes's output (`stdout`), input (`stdin`), and error (`stderr`) in +/// that order, in the attempt to determine terminal width. If one of those streams is actually +/// a tty, this function returns its width and height as a number of characters. +/// +/// # Errors +/// +/// If *all* of the streams are not ttys or return any errors this function will return `None`. +/// +/// # Example +/// +/// To get the dimensions of your terminal window, simply use the following: +/// +/// ```no_run +/// if let Some((w, h)) = termize::dimensions() { +/// println!("Width: {}\nHeight: {}", w, h); +/// } else { +/// println!("Unable to get term size :("); +/// } +/// ``` +pub fn dimensions() -> Option<(usize, usize)> { + let w = unsafe { get_dimensions_any() }; + + if w.ws_col == 0 || w.ws_row == 0 { + None + } else { + Some((w.ws_col as usize, w.ws_row as usize)) + } +} + +/// Query the current processes's output (`stdout`) *only*, in the attempt to determine +/// terminal width. If that stream is actually a tty, this function returns its width +/// and height as a number of characters. +/// +/// # Errors +/// +/// If the stream is not a tty or return any errors this function will return `None`. +/// +/// # Example +/// +/// To get the dimensions of your terminal window, simply use the following: +/// +/// ```no_run +/// if let Some((w, h)) = termize::dimensions_stdout() { +/// println!("Width: {}\nHeight: {}", w, h); +/// } else { +/// println!("Unable to get term size :("); +/// } +/// ``` +pub fn dimensions_stdout() -> Option<(usize, usize)> { + let w = unsafe { get_dimensions_out() }; + + if w.ws_col == 0 || w.ws_row == 0 { + None + } else { + Some((w.ws_col as usize, w.ws_row as usize)) + } +} + +/// Query the current processes's input (`stdin`) *only*, in the attempt to determine +/// terminal width. If that stream is actually a tty, this function returns its width +/// and height as a number of characters. +/// +/// # Errors +/// +/// If the stream is not a tty or return any errors this function will return `None`. +/// +/// # Example +/// +/// To get the dimensions of your terminal window, simply use the following: +/// +/// ```no_run +/// if let Some((w, h)) = termize::dimensions_stdin() { +/// println!("Width: {}\nHeight: {}", w, h); +/// } else { +/// println!("Unable to get term size :("); +/// } +/// ``` +pub fn dimensions_stdin() -> Option<(usize, usize)> { + let w = unsafe { get_dimensions_in() }; + + if w.ws_col == 0 || w.ws_row == 0 { + None + } else { + Some((w.ws_col as usize, w.ws_row as usize)) + } +} + +/// Query the current processes's error output (`stderr`) *only*, in the attempt to dtermine +/// terminal width. If that stream is actually a tty, this function returns its width +/// and height as a number of characters. +/// +/// # Errors +/// +/// If the stream is not a tty or return any errors this function will return `None`. +/// +/// # Example +/// +/// To get the dimensions of your terminal window, simply use the following: +/// +/// ```no_run +/// if let Some((w, h)) = termize::dimensions_stderr() { +/// println!("Width: {}\nHeight: {}", w, h); +/// } else { +/// println!("Unable to get term size :("); +/// } +/// ``` +pub fn dimensions_stderr() -> Option<(usize, usize)> { + let w = unsafe { get_dimensions_err() }; + + if w.ws_col == 0 || w.ws_row == 0 { + None + } else { + Some((w.ws_col as usize, w.ws_row as usize)) + } +} + +#[cfg(test)] +mod tests { + use super::dimensions; + use std::process::{Command, Output, Stdio}; + + #[cfg(target_os = "macos")] + fn stty_size() -> Output { + Command::new("stty") + .arg("-f") + .arg("/dev/stderr") + .arg("size") + .stderr(Stdio::inherit()) + .output() + .unwrap() + } + + #[cfg(not(target_os = "macos"))] + fn stty_size() -> Output { + Command::new("stty") + .arg("-F") + .arg("/dev/stderr") + .arg("size") + .stderr(Stdio::inherit()) + .output() + .expect("failed to run `stty_size()`") + } + + #[test] + fn test_shell() { + let output = stty_size(); + let stdout = String::from_utf8(output.stdout).expect("failed to turn into String"); + let mut data = stdout.split_whitespace(); + let rs = data + .next() + .unwrap_or("0") + .parse::() + .expect("failed to parse rows"); + let cs = data + .next() + .unwrap_or("0") + .parse::() + .expect("failed to parse cols"); + println!("stdout: {}", stdout); + println!("rows: {}\ncols: {}", rs, cs); + if let Some((w, h)) = dimensions() { + assert_eq!(rs, h); + assert_eq!(cs, w); + } + } +} diff --git a/vendor/termize/src/platform/unsupported.rs b/vendor/termize/src/platform/unsupported.rs new file mode 100644 index 000000000..a246eee58 --- /dev/null +++ b/vendor/termize/src/platform/unsupported.rs @@ -0,0 +1,12 @@ +pub fn dimensions() -> Option<(usize, usize)> { + None +} +pub fn dimensions_stdout() -> Option<(usize, usize)> { + None +} +pub fn dimensions_stdin() -> Option<(usize, usize)> { + None +} +pub fn dimensions_stderr() -> Option<(usize, usize)> { + None +} diff --git a/vendor/termize/src/platform/windows.rs b/vendor/termize/src/platform/windows.rs new file mode 100644 index 000000000..6d9d0c1a2 --- /dev/null +++ b/vendor/termize/src/platform/windows.rs @@ -0,0 +1,107 @@ +use winapi::um::handleapi::INVALID_HANDLE_VALUE; +use winapi::um::processenv::GetStdHandle; +use winapi::um::winbase::STD_OUTPUT_HANDLE; +use winapi::um::wincon::GetConsoleScreenBufferInfo; +use winapi::um::wincon::{CONSOLE_SCREEN_BUFFER_INFO, COORD, SMALL_RECT}; + +/// Query the current processes's output, returning its width and height as a +/// number of characters. +/// +/// # Errors +/// +/// Returns `None` if the output isn't to a terminal. +/// +/// # Example +/// +/// To get the dimensions of your terminal window, simply use the following: +/// +/// ```no_run +/// if let Some((w, h)) = termize::dimensions() { +/// println!("Width: {}\nHeight: {}", w, h); +/// } else { +/// println!("Unable to get term size :("); +/// } +/// ``` +pub fn dimensions() -> Option<(usize, usize)> { + let null_coord = COORD { X: 0, Y: 0 }; + let null_smallrect = SMALL_RECT { + Left: 0, + Top: 0, + Right: 0, + Bottom: 0, + }; + + let stdout_h = unsafe { GetStdHandle(STD_OUTPUT_HANDLE) }; + if stdout_h == INVALID_HANDLE_VALUE { + return None; + } + + let mut console_data = CONSOLE_SCREEN_BUFFER_INFO { + dwSize: null_coord, + dwCursorPosition: null_coord, + wAttributes: 0, + srWindow: null_smallrect, + dwMaximumWindowSize: null_coord, + }; + + if unsafe { GetConsoleScreenBufferInfo(stdout_h, &mut console_data) } != 0 { + Some(( + (console_data.srWindow.Right - console_data.srWindow.Left + 1) as usize, + (console_data.srWindow.Bottom - console_data.srWindow.Top + 1) as usize, + )) + } else { + None + } +} + +/// Query the current processes's output, returning its width and height as a +/// number of characters. Returns `None` if the output isn't to a terminal. +/// +/// # Errors +/// +/// Returns `None` if the output isn't to a terminal. +/// +/// # Example +/// +/// To get the dimensions of your terminal window, simply use the following: +/// +/// ```no_run +/// if let Some((w, h)) = termize::dimensions() { +/// println!("Width: {}\nHeight: {}", w, h); +/// } else { +/// println!("Unable to get term size :("); +/// } +/// ``` +pub fn dimensions_stdout() -> Option<(usize, usize)> { + dimensions() +} + +/// This isn't implemented for Windows +/// +/// # Panics +/// +/// This function `panic!`s unconditionally with the `unimplemented!` +/// macro +pub fn dimensions_stdin() -> Option<(usize, usize)> { + unimplemented!() +} + +/// This isn't implemented for Windows +/// +/// # Panics +/// +/// This function `panic!`s unconditionally with the `unimplemented!` +/// macro +pub fn dimensions_stderr() -> Option<(usize, usize)> { + unimplemented!() +} + +// Just check if function works well. `dimensions()` on no terminal always +// returns `None` like CI so don't check with `is_some()`. Please test with +// with `--nocapture` on local, to check terminal size. +#[test] +fn just_check_work() { + if let Some((w, h)) = dimensions() { + println!("width: {}\nheight: {}", w, h); + } +} -- cgit v1.2.3