diff -Nru rust-termion-1.5.1/Cargo.lock rust-termion-1.5.4/Cargo.lock --- rust-termion-1.5.1/Cargo.lock 1970-01-01 00:00:00.000000000 +0000 +++ rust-termion-1.5.4/Cargo.lock 2019-11-29 16:45:59.000000000 +0000 @@ -0,0 +1,40 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "libc" +version = "0.2.66" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "numtoa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "redox_syscall" +version = "0.1.56" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "redox_termios" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "termion" +version = "1.5.4" +dependencies = [ + "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", + "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[metadata] +"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558" +"checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84" +"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" diff -Nru rust-termion-1.5.1/Cargo.toml rust-termion-1.5.4/Cargo.toml --- rust-termion-1.5.1/Cargo.toml 2017-08-03 22:12:31.000000000 +0000 +++ rust-termion-1.5.4/Cargo.toml 2019-11-29 16:45:59.000000000 +0000 @@ -3,7 +3,7 @@ # 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 +# 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 @@ -12,14 +12,17 @@ [package] name = "termion" -version = "1.5.1" +version = "1.5.4" authors = ["ticki ", "gycos ", "IGI-111 "] exclude = ["target", "CHANGELOG.md", "image.png", "Cargo.lock"] description = "A bindless library for manipulating terminals." documentation = "https://docs.rs/termion" keywords = ["tty", "color", "terminal", "password", "tui"] license = "MIT" -repository = "https://github.com/ticki/termion" +repository = "https://gitlab.redox-os.org/redox-os/termion" +[dependencies.numtoa] +version = "0.1.0" +features = ["std"] [target."cfg(not(target_os = \"redox\"))".dependencies.libc] version = "0.2.8" [target."cfg(target_os = \"redox\")".dependencies.redox_syscall] diff -Nru rust-termion-1.5.1/Cargo.toml.orig rust-termion-1.5.4/Cargo.toml.orig --- rust-termion-1.5.1/Cargo.toml.orig 2017-08-03 22:12:31.000000000 +0000 +++ rust-termion-1.5.4/Cargo.toml.orig 2019-11-29 16:45:17.000000000 +0000 @@ -1,14 +1,17 @@ [package] name = "termion" -version = "1.5.1" +version = "1.5.4" authors = ["ticki ", "gycos ", "IGI-111 "] description = "A bindless library for manipulating terminals." -repository = "https://github.com/ticki/termion" +repository = "https://gitlab.redox-os.org/redox-os/termion" documentation = "https://docs.rs/termion" license = "MIT" keywords = ["tty", "color", "terminal", "password", "tui"] exclude = ["target", "CHANGELOG.md", "image.png", "Cargo.lock"] +[dependencies] +numtoa = { version = "0.1.0", features = ["std"]} + [target.'cfg(not(target_os = "redox"))'.dependencies] libc = "0.2.8" diff -Nru rust-termion-1.5.1/.cargo_vcs_info.json rust-termion-1.5.4/.cargo_vcs_info.json --- rust-termion-1.5.1/.cargo_vcs_info.json 1970-01-01 00:00:00.000000000 +0000 +++ rust-termion-1.5.4/.cargo_vcs_info.json 2019-11-29 16:45:59.000000000 +0000 @@ -0,0 +1,5 @@ +{ + "git": { + "sha1": "c443136bdc53eb249613d1131d7586338ae73538" + } +} diff -Nru rust-termion-1.5.1/debian/cargo-checksum.json rust-termion-1.5.4/debian/cargo-checksum.json --- rust-termion-1.5.1/debian/cargo-checksum.json 2018-07-29 14:10:36.000000000 +0000 +++ rust-termion-1.5.4/debian/cargo-checksum.json 2019-12-31 06:28:39.000000000 +0000 @@ -1 +1 @@ -{"package":"689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096","files":{}} +{"package":"Could not get crate checksum","files":{}} diff -Nru rust-termion-1.5.1/debian/changelog rust-termion-1.5.4/debian/changelog --- rust-termion-1.5.1/debian/changelog 2018-07-29 14:10:36.000000000 +0000 +++ rust-termion-1.5.4/debian/changelog 2019-12-31 06:28:39.000000000 +0000 @@ -1,3 +1,21 @@ +rust-termion (1.5.4-3) unstable; urgency=medium + + * Package termion 1.5.4 from crates.io using debcargo 2.4.0 + + -- Ximin Luo Tue, 31 Dec 2019 06:28:39 +0000 + +rust-termion (1.5.4-2) unstable; urgency=medium + + * Package termion 1.5.4 from crates.io using debcargo 2.4.0 + + -- Ximin Luo Tue, 31 Dec 2019 02:48:22 +0000 + +rust-termion (1.5.4-1) unstable; urgency=medium + + * Package termion 1.5.4 from crates.io using debcargo 2.4.0 + + -- Ximin Luo Tue, 24 Dec 2019 15:02:57 +0000 + rust-termion (1.5.1-1) unstable; urgency=medium * Package termion 1.5.1 from crates.io using debcargo 2.2.4 diff -Nru rust-termion-1.5.1/debian/control rust-termion-1.5.4/debian/control --- rust-termion-1.5.1/debian/control 2018-07-29 14:10:36.000000000 +0000 +++ rust-termion-1.5.4/debian/control 2019-12-31 06:28:39.000000000 +0000 @@ -2,16 +2,19 @@ Section: rust Priority: optional Build-Depends: debhelper (>= 11), - dh-cargo (>= 6), + dh-cargo (>= 18), cargo:native , rustc:native , libstd-rust-dev , - librust-libc-0.2+default-dev (>= 0.2.8~~) , + librust-libc-0.2+default-dev (>= 0.2.8-~~) , + librust-numtoa-0.2+default-dev , librust-redox-syscall-0.1+default-dev , - librust-redox-termios-0.1+default-dev + librust-redox-termios-0.1+default-dev , + bsdutils Maintainer: Debian Rust Maintainers -Uploaders: Ximin Luo -Standards-Version: 4.1.5 +Uploaders: + Ximin Luo +Standards-Version: 4.2.0 Vcs-Git: https://salsa.debian.org/rust-team/debcargo-conf.git [src/termion] Vcs-Browser: https://salsa.debian.org/rust-team/debcargo-conf/tree/master/src/termion @@ -20,7 +23,8 @@ Multi-Arch: same Depends: ${misc:Depends}, - librust-libc-0.2+default-dev (>= 0.2.8~~), + librust-libc-0.2+default-dev (>= 0.2.8-~~), + librust-numtoa-0.2+default-dev, librust-redox-syscall-0.1+default-dev, librust-redox-termios-0.1+default-dev Provides: @@ -29,8 +33,8 @@ librust-termion-1+default-dev (= ${binary:Version}), librust-termion-1.5-dev (= ${binary:Version}), librust-termion-1.5+default-dev (= ${binary:Version}), - librust-termion-1.5.1-dev (= ${binary:Version}), - librust-termion-1.5.1+default-dev (= ${binary:Version}) + librust-termion-1.5.4-dev (= ${binary:Version}), + librust-termion-1.5.4+default-dev (= ${binary:Version}) Description: Bindless library for manipulating terminals - Rust source code This package contains the source for the Rust termion crate, packaged by debcargo for use with cargo and dh-cargo. diff -Nru rust-termion-1.5.1/debian/copyright rust-termion-1.5.4/debian/copyright --- rust-termion-1.5.1/debian/copyright 2018-07-29 14:10:36.000000000 +0000 +++ rust-termion-1.5.4/debian/copyright 2019-12-31 06:28:39.000000000 +0000 @@ -4,19 +4,19 @@ ticki gycos IGI-111 -Source: https://github.com/ticki/termion +Source: https://gitlab.redox-os.org/redox-os/termion Files: * Copyright: - 2016-2018 ticki - 2016-2018 gycos - 2016-2018 IGI-111 + 2016-2019 ticki + 2016-2019 gycos + 2016-2019 IGI-111 License: MIT Files: debian/* Copyright: - 2018 Debian Rust Maintainers - 2018 Ximin Luo + 2018-2019 Debian Rust Maintainers + 2018-2019 Ximin Luo License: MIT License: MIT diff -Nru rust-termion-1.5.1/debian/copyright.debcargo.hint rust-termion-1.5.4/debian/copyright.debcargo.hint --- rust-termion-1.5.1/debian/copyright.debcargo.hint 2018-07-29 14:10:36.000000000 +0000 +++ rust-termion-1.5.4/debian/copyright.debcargo.hint 2019-12-31 06:28:39.000000000 +0000 @@ -4,7 +4,7 @@ ticki gycos IGI-111 -Source: https://github.com/ticki/termion +Source: https://gitlab.redox-os.org/redox-os/termion Files: * Copyright: @@ -27,8 +27,8 @@ Files: debian/* Copyright: - 2018 Debian Rust Maintainers - 2018 FIXME (overlay) Your Name + 2018-2019 Debian Rust Maintainers + 2018-2019 Ximin Luo License: MIT License: MIT diff -Nru rust-termion-1.5.1/debian/debcargo.toml rust-termion-1.5.4/debian/debcargo.toml --- rust-termion-1.5.1/debian/debcargo.toml 2018-07-29 14:10:36.000000000 +0000 +++ rust-termion-1.5.4/debian/debcargo.toml 2019-12-31 06:28:39.000000000 +0000 @@ -1 +1,5 @@ overlay = "." +uploaders = ["Ximin Luo "] + +[source] +build_depends = ["bsdutils"] diff -Nru rust-termion-1.5.1/debian/patches/series rust-termion-1.5.4/debian/patches/series --- rust-termion-1.5.1/debian/patches/series 1970-01-01 00:00:00.000000000 +0000 +++ rust-termion-1.5.4/debian/patches/series 2019-12-31 06:28:39.000000000 +0000 @@ -0,0 +1 @@ +update-dep-versions.patch diff -Nru rust-termion-1.5.1/debian/patches/update-dep-versions.patch rust-termion-1.5.4/debian/patches/update-dep-versions.patch --- rust-termion-1.5.1/debian/patches/update-dep-versions.patch 1970-01-01 00:00:00.000000000 +0000 +++ rust-termion-1.5.4/debian/patches/update-dep-versions.patch 2019-12-31 06:28:39.000000000 +0000 @@ -0,0 +1,12 @@ +--- a/Cargo.toml ++++ b/Cargo.toml +@@ -21,8 +21,7 @@ + license = "MIT" + repository = "https://gitlab.redox-os.org/redox-os/termion" + [dependencies.numtoa] +-version = "0.1.0" +-features = ["std"] ++version = "0.2" + [target."cfg(not(target_os = \"redox\"))".dependencies.libc] + version = "0.2.8" + [target."cfg(target_os = \"redox\")".dependencies.redox_syscall] diff -Nru rust-termion-1.5.1/debian/rules rust-termion-1.5.4/debian/rules --- rust-termion-1.5.1/debian/rules 2018-07-29 14:10:36.000000000 +0000 +++ rust-termion-1.5.4/debian/rules 2019-12-31 06:28:39.000000000 +0000 @@ -1,3 +1,7 @@ #!/usr/bin/make -f %: dh $@ --buildsystem cargo + +override_dh_auto_test: + # tests need to be run through 'script' since they do terminal stuff + script -c 'dh_auto_test -- test --all' /dev/null diff -Nru rust-termion-1.5.1/debian/rules.debcargo.hint rust-termion-1.5.4/debian/rules.debcargo.hint --- rust-termion-1.5.1/debian/rules.debcargo.hint 1970-01-01 00:00:00.000000000 +0000 +++ rust-termion-1.5.4/debian/rules.debcargo.hint 2019-12-31 06:28:39.000000000 +0000 @@ -0,0 +1,6 @@ +#!/usr/bin/make -f +%: + dh $@ --buildsystem cargo + +override_dh_auto_test: + dh_auto_test -- test --all diff -Nru rust-termion-1.5.1/debian/tests/control rust-termion-1.5.4/debian/tests/control --- rust-termion-1.5.1/debian/tests/control 1970-01-01 00:00:00.000000000 +0000 +++ rust-termion-1.5.4/debian/tests/control 2019-12-31 06:28:39.000000000 +0000 @@ -0,0 +1,7 @@ +Test-Command: /usr/share/cargo/bin/cargo-auto-test termion 1.5.4 --all-targets --all-features +Depends: dh-cargo (>= 18), @ +Restrictions: allow-stderr, skip-not-installable + +Test-Command: /usr/share/cargo/bin/cargo-auto-test termion 1.5.4 --all-targets --no-default-features +Depends: dh-cargo (>= 18), librust-termion-dev +Restrictions: allow-stderr, skip-not-installable diff -Nru rust-termion-1.5.1/debian/watch rust-termion-1.5.4/debian/watch --- rust-termion-1.5.1/debian/watch 2018-07-29 14:10:36.000000000 +0000 +++ rust-termion-1.5.4/debian/watch 2019-12-31 06:28:39.000000000 +0000 @@ -1,4 +1,5 @@ version=4 -opts=filenamemangle=s/.*\/(.*)\/download/termion-$1\.tar\.gz/g\ - https://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=crates.io/termion .*/crates/termion/@ANY_VERSION@/download +opts=filenamemangle=s/.*\/(.*)\/download/termion-$1\.tar\.gz/g,\ +uversionmangle=s/(\d)[_\.\-\+]?((RC|rc|pre|dev|beta|alpha)\d*)$/$1~$2/ \ +https://qa.debian.org/cgi-bin/fakeupstream.cgi?upstream=crates.io/termion .*/crates/termion/@ANY_VERSION@/download diff -Nru rust-termion-1.5.1/examples/color.rs rust-termion-1.5.4/examples/color.rs --- rust-termion-1.5.1/examples/color.rs 2017-05-29 10:43:03.000000000 +0000 +++ rust-termion-1.5.4/examples/color.rs 2019-04-21 22:51:52.000000000 +0000 @@ -6,5 +6,5 @@ println!("{}Red", color::Fg(color::Red)); println!("{}Blue", color::Fg(color::Blue)); println!("{}Blue'n'Bold{}", style::Bold, style::Reset); - println!("{}Just plain italic", style::Italic); + println!("{}Just plain italic{}", style::Italic, style::Reset); } diff -Nru rust-termion-1.5.1/.gitlab-ci.yml rust-termion-1.5.4/.gitlab-ci.yml --- rust-termion-1.5.1/.gitlab-ci.yml 1970-01-01 00:00:00.000000000 +0000 +++ rust-termion-1.5.4/.gitlab-ci.yml 2019-07-06 18:05:29.000000000 +0000 @@ -0,0 +1,42 @@ +image: "redoxos/redoxer" + +stages: + - build + - test + +cache: + paths: + - target/ + +build:linux:stable: + stage: build + script: + - cargo +stable build --verbose + +build:linux: + stage: build + script: cargo +nightly build --verbose + +build:redox: + stage: build + script: redoxer build --verbose + +test:linux:stable: + stage: test + dependencies: + - build:linux:stable + script: + - rustup update stable + - cargo +stable test --verbose + +test:linux: + stage: test + dependencies: + - build:linux + script: cargo +nightly test --verbose + +test:redox: + stage: test + dependencies: + - build:redox + script: redoxer test --verbose diff -Nru rust-termion-1.5.1/README.md rust-termion-1.5.4/README.md --- rust-termion-1.5.1/README.md 2017-05-29 10:43:03.000000000 +0000 +++ rust-termion-1.5.4/README.md 2019-04-21 22:51:52.000000000 +0000 @@ -1,8 +1,8 @@

-Termion logo +Termion logo

-[![Build Status](https://travis-ci.org/ticki/termion.svg?branch=master)](https://travis-ci.org/ticki/termion) [![Latest Version](https://img.shields.io/crates/v/termion.svg)](https://crates.io/crates/termion) | [Documentation](https://docs.rs/termion) | [Examples](https://github.com/Ticki/termion/tree/master/examples) | [Changelog](https://github.com/Ticki/termion/tree/master/CHANGELOG.md) | [Tutorial](http://ticki.github.io/blog/making-terminal-applications-in-rust-with-termion/) +[![Build Status](https://travis-ci.org/redox-os/termion.svg?branch=master)](https://travis-ci.org/redox-os/termion) [![Latest Version](https://img.shields.io/crates/v/termion.svg)](https://crates.io/crates/termion) | [Documentation](https://docs.rs/termion) | [Examples](https://github.com/redox-os/termion/tree/master/examples) | [Changelog](https://github.com/redox-os/termion/tree/master/CHANGELOG.md) | [Tutorial](http://ticki.github.io/blog/making-terminal-applications-in-rust-with-termion/) |----|----|----|----|---- diff -Nru rust-termion-1.5.1/src/async.rs rust-termion-1.5.4/src/async.rs --- rust-termion-1.5.1/src/async.rs 2017-08-03 22:12:46.000000000 +0000 +++ rust-termion-1.5.4/src/async.rs 2019-04-21 22:51:52.000000000 +0000 @@ -4,6 +4,29 @@ use sys::tty::get_tty; +/// Construct an asynchronous handle to the TTY standard input, with a delimiter byte. +/// +/// This has the same advantages as async_stdin(), but also allows specifying a delimiter byte. The +/// reader will stop reading after consuming the delimiter byte. +pub fn async_stdin_until(delimiter: u8) -> AsyncReader { + let (send, recv) = mpsc::channel(); + + thread::spawn(move || for i in get_tty().unwrap().bytes() { + + match i { + Ok(byte) => { + let end_of_stream = &byte == &delimiter; + let send_error = send.send(Ok(byte)).is_err(); + + if end_of_stream || send_error { return; } + }, + Err(_) => { return; } + } + }); + + AsyncReader { recv: recv } +} + /// Construct an asynchronous handle to the TTY standard input. /// /// This allows you to read from standard input _without blocking_ the current thread. diff -Nru rust-termion-1.5.1/src/color.rs rust-termion-1.5.4/src/color.rs --- rust-termion-1.5.1/src/color.rs 2017-05-29 10:43:03.000000000 +0000 +++ rust-termion-1.5.4/src/color.rs 2019-04-21 22:51:52.000000000 +0000 @@ -18,9 +18,11 @@ use std::time::{SystemTime, Duration}; use async::async_stdin; use std::env; +use std::fmt::Debug; +use numtoa::NumToA; /// A terminal color. -pub trait Color { +pub trait Color: Debug { /// Write the foreground version of this color. fn write_fg(&self, f: &mut fmt::Formatter) -> fmt::Result; /// Write the background version of this color. @@ -36,14 +38,24 @@ impl Color for $name { #[inline] fn write_fg(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("38;5;", $value, "m")) + f.write_str(self.fg_str()) } #[inline] fn write_bg(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("48;5;", $value, "m")) + f.write_str(self.bg_str()) } } + + impl $name { + #[inline] + /// Returns the ANSI escape sequence as a string. + pub fn fg_str(&self) -> &'static str { csi!("38;5;", $value, "m") } + + #[inline] + /// Returns the ANSI escape sequences as a string. + pub fn bg_str(&self) -> &'static str { csi!("48;5;", $value, "m") } + } }; } @@ -110,15 +122,31 @@ } } +impl AnsiValue { + /// Returns the ANSI sequence as a string. + pub fn fg_string(self) -> String { + let mut x = [0u8; 20]; + let x = self.0.numtoa_str(10, &mut x); + [csi!("38;5;"), x, "m"].concat() + } + + /// Returns the ANSI sequence as a string. + pub fn bg_string(self) -> String { + let mut x = [0u8; 20]; + let x = self.0.numtoa_str(10, &mut x); + [csi!("48;5;"), x, "m"].concat() + } +} + impl Color for AnsiValue { #[inline] fn write_fg(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("38;5;{}m"), self.0) + f.write_str(&self.fg_string()) } #[inline] fn write_bg(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("48;5;{}m"), self.0) + f.write_str(&self.bg_string()) } } @@ -126,15 +154,41 @@ #[derive(Debug, Clone, Copy, PartialEq)] pub struct Rgb(pub u8, pub u8, pub u8); +impl Rgb { + /// Returns the ANSI sequence as a string. + pub fn fg_string(self) -> String { + let (mut x, mut y, mut z) = ([0u8; 20], [0u8; 20], [0u8; 20]); + let (x, y, z) = ( + self.0.numtoa_str(10, &mut x), + self.1.numtoa_str(10, &mut y), + self.2.numtoa_str(10, &mut z), + ); + + [csi!("38;2;"), x, ";", y, ";", z, "m"].concat() + } + + /// Returns the ANSI sequence as a string. + pub fn bg_string(self) -> String { + let (mut x, mut y, mut z) = ([0u8; 20], [0u8; 20], [0u8; 20]); + let (x, y, z) = ( + self.0.numtoa_str(10, &mut x), + self.1.numtoa_str(10, &mut y), + self.2.numtoa_str(10, &mut z), + ); + + [csi!("48;2;"), x, ";", y, ";", z, "m"].concat() + } +} + impl Color for Rgb { #[inline] fn write_fg(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("38;2;{};{};{}m"), self.0, self.1, self.2) + f.write_str(&self.fg_string()) } #[inline] fn write_bg(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("48;2;{};{};{}m"), self.0, self.1, self.2) + f.write_str(&self.bg_string()) } } @@ -142,15 +196,25 @@ #[derive(Debug, Clone, Copy)] pub struct Reset; +const RESET_FG: &str = csi!("39m"); +const RESET_BG: &str = csi!("49m"); + +impl Reset { + /// Returns the ANSI sequence as a string. + pub fn fg_str(self) -> &'static str { RESET_FG } + /// Returns the ANSI sequence as a string. + pub fn bg_str(self) -> &'static str { RESET_BG } +} + impl Color for Reset { #[inline] fn write_fg(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("39m")) + f.write_str(RESET_FG) } #[inline] fn write_bg(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("49m")) + f.write_str(RESET_BG) } } diff -Nru rust-termion-1.5.1/src/cursor.rs rust-termion-1.5.4/src/cursor.rs --- rust-termion-1.5.1/src/cursor.rs 2017-08-03 22:12:46.000000000 +0000 +++ rust-termion-1.5.4/src/cursor.rs 2019-04-21 22:51:52.000000000 +0000 @@ -1,10 +1,12 @@ //! Cursor movement. use std::fmt; +use std::ops; use std::io::{self, Write, Error, ErrorKind, Read}; -use async::async_stdin; +use async::async_stdin_until; use std::time::{SystemTime, Duration}; use raw::CONTROL_SEQUENCE_TIMEOUT; +use numtoa::NumToA; derive_csi_sequence!("Hide the cursor.", Hide, "?25l"); derive_csi_sequence!("Show the cursor.", Show, "?25h"); @@ -32,6 +34,13 @@ #[derive(Copy, Clone, PartialEq, Eq)] pub struct Goto(pub u16, pub u16); +impl From for String { + fn from(this: Goto) -> String { + let (mut x, mut y) = ([0u8; 20], [0u8; 20]); + ["\x1B[", this.1.numtoa_str(10, &mut x), ";", this.0.numtoa_str(10, &mut y), "H"].concat() + } +} + impl Default for Goto { fn default() -> Goto { Goto(1, 1) @@ -41,8 +50,7 @@ impl fmt::Display for Goto { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { debug_assert!(self != &Goto(0, 0), "Goto is one-based."); - - write!(f, csi!("{};{}H"), self.1, self.0) + f.write_str(&String::from(*self)) } } @@ -50,9 +58,16 @@ #[derive(Copy, Clone, PartialEq, Eq)] pub struct Left(pub u16); +impl From for String { + fn from(this: Left) -> String { + let mut buf = [0u8; 20]; + ["\x1B[", this.0.numtoa_str(10, &mut buf), "D"].concat() + } +} + impl fmt::Display for Left { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("{}D"), self.0) + f.write_str(&String::from(*self)) } } @@ -60,9 +75,16 @@ #[derive(Copy, Clone, PartialEq, Eq)] pub struct Right(pub u16); +impl From for String { + fn from(this: Right) -> String { + let mut buf = [0u8; 20]; + ["\x1B[", this.0.numtoa_str(10, &mut buf), "C"].concat() + } +} + impl fmt::Display for Right { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("{}C"), self.0) + f.write_str(&String::from(*self)) } } @@ -70,9 +92,16 @@ #[derive(Copy, Clone, PartialEq, Eq)] pub struct Up(pub u16); +impl From for String { + fn from(this: Up) -> String { + let mut buf = [0u8; 20]; + ["\x1B[", this.0.numtoa_str(10, &mut buf), "A"].concat() + } +} + impl fmt::Display for Up { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("{}A"), self.0) + f.write_str(&String::from(*self)) } } @@ -80,9 +109,16 @@ #[derive(Copy, Clone, PartialEq, Eq)] pub struct Down(pub u16); +impl From for String { + fn from(this: Down) -> String { + let mut buf = [0u8; 20]; + ["\x1B[", this.0.numtoa_str(10, &mut buf), "B"].concat() + } +} + impl fmt::Display for Down { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, csi!("{}B"), self.0) + f.write_str(&String::from(*self)) } } @@ -94,7 +130,8 @@ impl DetectCursorPos for W { fn cursor_pos(&mut self) -> io::Result<(u16, u16)> { - let mut stdin = async_stdin(); + let delimiter = b'R'; + let mut stdin = async_stdin_until(delimiter); // Where is the cursor? // Use `ESC [ 6 n`. @@ -108,13 +145,13 @@ let now = SystemTime::now(); // Either consume all data up to R or wait for a timeout. - while buf[0] != b'R' && now.elapsed().unwrap() < timeout { + while buf[0] != delimiter && now.elapsed().unwrap() < timeout { if stdin.read(&mut buf)? > 0 { read_chars.push(buf[0]); } } - if read_chars.len() == 0 { + if read_chars.is_empty() { return Err(Error::new(ErrorKind::Other, "Cursor position detection timed out.")); } @@ -138,3 +175,48 @@ Ok((cx, cy)) } } + +/// Hide the cursor for the lifetime of this struct. +/// It will hide the cursor on creation with from() and show it back on drop(). +pub struct HideCursor { + /// The output target. + output: W, +} + +impl HideCursor { + /// Create a hide cursor wrapper struct for the provided output and hides the cursor. + pub fn from(mut output: W) -> Self { + write!(output, "{}", Hide).expect("hide the cursor"); + HideCursor { output: output } + } +} + +impl Drop for HideCursor { + fn drop(&mut self) { + write!(self, "{}", Show).expect("show the cursor"); + } +} + +impl ops::Deref for HideCursor { + type Target = W; + + fn deref(&self) -> &W { + &self.output + } +} + +impl ops::DerefMut for HideCursor { + fn deref_mut(&mut self) -> &mut W { + &mut self.output + } +} + +impl Write for HideCursor { + fn write(&mut self, buf: &[u8]) -> io::Result { + self.output.write(buf) + } + + fn flush(&mut self) -> io::Result<()> { + self.output.flush() + } +} diff -Nru rust-termion-1.5.1/src/event.rs rust-termion-1.5.4/src/event.rs --- rust-termion-1.5.1/src/event.rs 2017-05-29 10:43:03.000000000 +0000 +++ rust-termion-1.5.4/src/event.rs 2019-06-13 02:00:40.000000000 +0000 @@ -1,7 +1,6 @@ //! Mouse and key events. use std::io::{Error, ErrorKind}; -use std::ascii::AsciiExt; use std::str; /// An event reported by the terminal. @@ -72,6 +71,8 @@ PageUp, /// Page Down key. PageDown, + /// Backward Tab key. + BackTab, /// Delete key. Delete, /// Insert key. @@ -156,6 +157,7 @@ Some(Ok(b'B')) => Event::Key(Key::Down), Some(Ok(b'H')) => Event::Key(Key::Home), Some(Ok(b'F')) => Event::Key(Key::End), + Some(Ok(b'Z')) => Event::Key(Key::BackTab), Some(Ok(b'M')) => { // X10 emulation mouse encoding: ESC [ CB Cx Cy (6 characters only). let mut next = || iter.next().unwrap().unwrap(); diff -Nru rust-termion-1.5.1/src/input.rs rust-termion-1.5.4/src/input.rs --- rust-termion-1.5.1/src/input.rs 2017-07-24 16:56:04.000000000 +0000 +++ rust-termion-1.5.4/src/input.rs 2019-11-29 16:45:02.000000000 +0000 @@ -19,7 +19,7 @@ match self.iter.next() { Some(Ok(Event::Key(k))) => return Some(Ok(k)), Some(Ok(_)) => continue, - e @ Some(Err(_)) => e, + Some(Err(e)) => return Some(Err(e)), None => return None, }; } @@ -49,7 +49,7 @@ type Item = Result<(Event, Vec), io::Error>; fn next(&mut self) -> Option), io::Error>> { - let mut source = &mut self.source; + let source = &mut self.source; if let Some(c) = self.leftover { // we have a leftover byte, use it diff -Nru rust-termion-1.5.1/src/lib.rs rust-termion-1.5.4/src/lib.rs --- rust-termion-1.5.1/src/lib.rs 2017-08-03 22:12:46.000000000 +0000 +++ rust-termion-1.5.4/src/lib.rs 2019-11-29 16:45:02.000000000 +0000 @@ -8,18 +8,22 @@ //! //! Supports Redox, Mac OS X, and Linux (or, in general, ANSI terminals). //! -//! For more information refer to the [README](https://github.com/ticki/termion). +//! For more information refer to the [README](https://github.com/redox-os/termion). #![warn(missing_docs)] +extern crate numtoa; + #[cfg(target_os = "redox")] #[path="sys/redox/mod.rs"] mod sys; -#[cfg(unix)] +#[cfg(all(unix, not(target_os = "redox")))] #[path="sys/unix/mod.rs"] mod sys; pub use sys::size::terminal_size; +#[cfg(all(unix, not(target_os = "redox")))] +pub use sys::size::terminal_size_pixels; pub use sys::tty::{is_tty, get_tty}; mod async; diff -Nru rust-termion-1.5.1/src/macros.rs rust-termion-1.5.4/src/macros.rs --- rust-termion-1.5.1/src/macros.rs 2017-05-29 10:43:03.000000000 +0000 +++ rust-termion-1.5.4/src/macros.rs 2019-04-21 22:51:52.000000000 +0000 @@ -15,5 +15,13 @@ write!(f, csi!($value)) } } + + impl AsRef<[u8]> for $name { + fn as_ref(&self) -> &'static [u8] { csi!($value).as_bytes() } + } + + impl AsRef for $name { + fn as_ref(&self) -> &'static str { csi!($value) } + } }; } diff -Nru rust-termion-1.5.1/src/raw.rs rust-termion-1.5.4/src/raw.rs --- rust-termion-1.5.1/src/raw.rs 2017-08-03 22:12:46.000000000 +0000 +++ rust-termion-1.5.4/src/raw.rs 2019-04-21 22:51:52.000000000 +0000 @@ -101,6 +101,20 @@ } } +impl RawTerminal { + pub fn suspend_raw_mode(&self) -> io::Result<()> { + set_terminal_attr(&self.prev_ios)?; + Ok(()) + } + + pub fn activate_raw_mode(&self) -> io::Result<()> { + let mut ios = get_terminal_attr()?; + raw_terminal_attr(&mut ios); + set_terminal_attr(&ios)?; + Ok(()) + } +} + #[cfg(test)] mod test { use super::*; diff -Nru rust-termion-1.5.1/src/sys/redox/attr.rs rust-termion-1.5.4/src/sys/redox/attr.rs --- rust-termion-1.5.1/src/sys/redox/attr.rs 2017-08-03 22:12:46.000000000 +0000 +++ rust-termion-1.5.4/src/sys/redox/attr.rs 2019-06-12 22:59:54.000000000 +0000 @@ -5,7 +5,7 @@ pub fn get_terminal_attr() -> io::Result { let mut termios = Termios::default(); - let fd = cvt(syscall::dup(0, b"termios"))?; + let fd = cvt(syscall::dup(1, b"termios"))?; let res = cvt(syscall::read(fd, &mut termios)); let _ = syscall::close(fd); @@ -17,7 +17,7 @@ } pub fn set_terminal_attr(termios: &Termios) -> io::Result<()> { - let fd = cvt(syscall::dup(0, b"termios"))?; + let fd = cvt(syscall::dup(1, b"termios"))?; let res = cvt(syscall::write(fd, termios)); let _ = syscall::close(fd); diff -Nru rust-termion-1.5.1/src/sys/redox/tty.rs rust-termion-1.5.4/src/sys/redox/tty.rs --- rust-termion-1.5.1/src/sys/redox/tty.rs 2017-08-03 22:12:46.000000000 +0000 +++ rust-termion-1.5.4/src/sys/redox/tty.rs 2019-04-21 22:57:00.000000000 +0000 @@ -5,7 +5,7 @@ /// Is this stream a TTY? pub fn is_tty(stream: &T) -> bool { - if let Ok(fd) = syscall::dup(stream.as_raw_fd(), b"termios") { + if let Ok(fd) = syscall::dup(stream.as_raw_fd() as _, b"termios") { let _ = syscall::close(fd); true } else { diff -Nru rust-termion-1.5.1/src/sys/unix/attr.rs rust-termion-1.5.4/src/sys/unix/attr.rs --- rust-termion-1.5.1/src/sys/unix/attr.rs 2017-08-03 22:12:46.000000000 +0000 +++ rust-termion-1.5.4/src/sys/unix/attr.rs 2019-06-12 22:59:54.000000000 +0000 @@ -9,7 +9,7 @@ } unsafe { let mut termios = mem::zeroed(); - cvt(tcgetattr(0, &mut termios))?; + cvt(tcgetattr(1, &mut termios))?; Ok(termios) } } @@ -18,7 +18,7 @@ extern "C" { pub fn tcsetattr(fd: c_int, opt: c_int, termptr: *const Termios) -> c_int; } - cvt(unsafe { tcsetattr(0, 0, termios) }).and(Ok(())) + cvt(unsafe { tcsetattr(1, 0, termios) }).and(Ok(())) } pub fn raw_terminal_attr(termios: &mut Termios) { diff -Nru rust-termion-1.5.1/src/sys/unix/size.rs rust-termion-1.5.4/src/sys/unix/size.rs --- rust-termion-1.5.1/src/sys/unix/size.rs 2017-08-03 22:12:46.000000000 +0000 +++ rust-termion-1.5.4/src/sys/unix/size.rs 2019-11-29 16:45:02.000000000 +0000 @@ -1,48 +1,29 @@ use std::{io, mem}; use super::cvt; -use super::libc::{c_ushort, ioctl, STDOUT_FILENO}; +use super::libc::{c_ushort, ioctl, STDOUT_FILENO, TIOCGWINSZ}; #[repr(C)] struct TermSize { row: c_ushort, col: c_ushort, - _x: c_ushort, - _y: c_ushort, + x: c_ushort, + y: c_ushort, } - -#[cfg(target_os = "linux")] -pub const TIOCGWINSZ: usize = 0x00005413; - -#[cfg(not(target_os = "linux"))] -pub const TIOCGWINSZ: usize = 0x40087468; - -// Since attributes on non-item statements is not stable yet, we use a function. -#[cfg(not(target_os = "android"))] -#[cfg(not(target_os = "redox"))] -#[cfg(target_pointer_width = "64")] -#[cfg(not(target_env = "musl"))] -fn tiocgwinsz() -> u64 { - TIOCGWINSZ as u64 -} -#[cfg(not(target_os = "android"))] -#[cfg(not(target_os = "redox"))] -#[cfg(target_pointer_width = "32")] -#[cfg(not(target_env = "musl"))] -fn tiocgwinsz() -> u32 { - TIOCGWINSZ as u32 -} - -#[cfg(any(target_env = "musl", target_os = "android"))] -fn tiocgwinsz() -> i32 { - TIOCGWINSZ as i32 -} - /// Get the size of the terminal. pub fn terminal_size() -> io::Result<(u16, u16)> { unsafe { let mut size: TermSize = mem::zeroed(); - cvt(ioctl(STDOUT_FILENO, tiocgwinsz(), &mut size as *mut _))?; + cvt(ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &mut size as *mut _))?; Ok((size.col as u16, size.row as u16)) } } + +/// Get the size of the terminal, in pixels +pub fn terminal_size_pixels() -> io::Result<(u16, u16)> { + unsafe { + let mut size: TermSize = mem::zeroed(); + cvt(ioctl(STDOUT_FILENO, TIOCGWINSZ.into(), &mut size as *mut _))?; + Ok((size.x as u16, size.y as u16)) + } +}