Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • redox-os/termion
  • NateDogg1232/termion
  • lemarcuspoilus/termion
  • nixpulvis/termion
  • Jezza/termion
  • mneumann/termion
  • ParadoxSpiral/termion
  • mdevlamynck/termion
  • jocutajar/termion
  • d-e-s-o/termion
  • karliss/termion
  • scauligi/termion
  • mwilbur/termion
  • curious/termion
  • xPMo/termion
  • lovasoa/termion
  • stillinbeta/termion
  • mjbshaw/termion
  • rabite0/termion
  • akitsu-sanae/termion
  • joshhansen/termion
  • lilydjwg/termion
  • kivimango/termion
  • gintsp/termion
  • 4lDO2/termion
  • denis/termion
  • needle/termion
  • rw_van/termion
  • nfachan2/termion
  • FuchsiaFrog/termion-horizontal-scroll
  • haraguroicha/termion
  • bugnano/termion
  • nolan1299/termion
  • zethra/termion
  • proehlen/termion
  • kankri/termion
  • ridcully/termion
  • TheLostLambda/termion
  • khs26/termion
  • lassipulkkinen/termion
  • amigo-rich/termion
  • nbdd0121/termion
  • jean-airoldie/termion
  • andreasblum/termion
  • luqmana/termion
  • orhun/termion
  • joshka/termion
  • nicholasdower/termion
48 results
Show changes
Commits on Source (253)
Showing with 696 additions and 234 deletions
image: "redoxos/redoxer"
stages:
- build
- test
variables:
REDOXER_USE_FUSE: no
before_script:
cargo install redoxer --git "https://gitlab.redox-os.org/redox-os/redoxer.git"
cache:
paths:
- target/
build:linux:stable:
stage: build
script:
- rustup update stable
- 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
- script -c "cargo +stable test --verbose"
test:linux:
stage: test
dependencies:
- build:linux
script: script -c "cargo +nightly test --verbose"
test:redox:
stage: test
dependencies:
- build:redox
script: redoxer test --verbose
language: rust
cache: cargo
rust:
- stable
- beta
- nightly
os:
- linux
- osx
script:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then FAKETTY="script -q /dev/null"; fi
- $FAKETTY cargo build --verbose
- $FAKETTY cargo test --verbose
- $FAKETTY cargo test --release --verbose
# 4.0.4
- Remove debug printing when parsing CSI sequences
- Support NO\_COLOR environment variable
# 4.0.3
Remove unused code and update dependencies.
# 4.0.2
Fixes an error check in Ctrl-Arrow code, no difference in behavior. Cleaned up examples.
# 4.0.1
Fixes a regression in function keys F5 and above.
# 4.0.0
4.0.0 adds support for horizontal scrolling when working with `MouseTerminal`.
## 3.0.0 to 4.0.0 guide
A change is only necessary if you were matching on all variants of the `MouseEvent` enum without a wildcard.
In this case, you need to either handle the two new variants, `MouseLeft` and `MouseRight`, or add a wildcard.
# 3.0.0
v3 release improves `raw` terminal API and enables support of any TTY target.
## 2.0.0 to 3.0.0 guide
Changes are only required if you were using `IntoRawMode` on generic terminals `W: Write`. Now, terminal
is also required to implement [`AsFd` trait][AsFd-trait]. So replacing generic bounds with `W: Write + AsFd`
should be sufficient.
[AsFd-trait]: https://doc.rust-lang.org/std/os/fd/trait.AsFd.html
# 1.0.0
Termion 1.0.0 is out! This release is breaking, which is also the reason for the semver bump.
## Highlights
Lot'ta goodies.
- **Mouse support:** If you enabled mouse mode through the `MouseTerminal` struct, you can get mouse events (thanks to IGI-111).
- **TrueColor support:** You can now use true color, by the `Rgb` struct.
- **A complete revision of the way escapes are handled:** Everything is now done through `Display` instead of custom traits.
- **`isatty` wrapper:** `termion::is_tty` takes any `T: AsRawFd` and gives you a `bool`.
- **Crates.io release:** Previously, it was distributed solely through git. This turns out to be very convinient, but quite critical whenever making breaking changes (that is, major semver bumps).
## 0.1.0 to 1.0.0 guide
This sample table gives an idea of how to go bu converting to the new major
version of Termion.
| 0.1.0 | 1.0.0
|--------------------------------|---------------------------
| `use termion::IntoRawMode` | `use termion::raw::IntoRawMode`
| `stdout.color(color::Red);` | `write!(stdout, "{}", color::Fg(color::Red));`
| `stdout.color_bg(color::Red);` | `write!(stdout, "{}", color::Bg(color::Red));`
| `stdout.goto(x, y);` | `write!(stdout, "{}", cursor::Goto(x, y));`
| `color::rgb(r, g, b);` | `color::Rgb(r, g, b)` (truecolor)
| `x.with_mouse()` | `MouseTerminal::from(x)`
## An example
```rust
#![feature(step_by)]
extern crate termion;
use termion::event::Key;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use std::io::{Write, stdout, stdin};
fn rainbow<W: Write>(stdout: &mut W, blue: u8) {
write!(stdout, "{}{}", termion::cursor::Goto(1, 1), termion::clear::All).unwrap();
for red in (0..255).step_by(8 as u8) {
for green in (0..255).step_by(4) {
write!(stdout, "{} ", termion::color::Bg(termion::color::Rgb(red, green, blue))).unwrap();
}
write!(stdout, "\n\r").unwrap();
}
writeln!(stdout, "{}b = {}", termion::style::Reset, blue).unwrap();
}
fn main() {
let stdin = stdin();
let mut stdout = stdout().into_raw_mode().unwrap();
writeln!(stdout, "{}{}{}Use the arrow keys to change the blue in the rainbow.",
termion::clear::All,
termion::cursor::Goto(1, 1),
termion::cursor::Hide).unwrap();
let mut blue = 172u8;
for c in stdin.keys() {
match c.unwrap() {
Key::Up => {
blue = blue.saturating_add(4);
rainbow(&mut stdout, blue);
},
Key::Down => {
blue = blue.saturating_sub(4);
rainbow(&mut stdout, blue);
},
Key::Char('q') => break,
_ => {},
}
stdout.flush().unwrap();
}
write!(stdout, "{}", termion::cursor::Show).unwrap();
}
```
[package]
name = "termion"
version = "0.1.0"
authors = ["Ticki <Ticki@users.noreply.github.com>"]
version = "4.0.4"
authors = [
"ticki <Ticki@users.noreply.github.com>",
"gycos <alexandre.bury@gmail.com>",
"IGI-111 <igi-111@protonmail.com>",
"Jeremy Soller <jackpot51@gmail.com>",
]
description = "A bindless library for manipulating terminals."
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"]
[target.'cfg(unix)'.dependencies]
libc = "0.2.8"
[dependencies]
numtoa = { version = "0.2.4"}
serde = { version = "1.0", features = ["derive"], optional = true }
[features]
nightly = []
[target.'cfg(not(target_os = "redox"))'.dependencies]
libc = "0.2"
[target.'cfg(target_os = "redox")'.dependencies]
redox_termios = "0.1.3"
libredox = "0.1.3"
{
"drips": {
"ethereum": {
"ownedBy": "0x083e29156955A4c0f7eAA406e1167Bd1bE88933E"
}
}
}
# Termion
<p align="center">
<img alt="Termion logo" src="https://rawgit.com/redox-os/termion/master/logo.svg" />
</p>
Termion is a pure Rust, bindless library for low-level handling, manipulating
[![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/)
|----|----|----|----|----
**Termion** is a pure Rust, bindless library for low-level handling, manipulating
and reading information about terminals. This provides a full-featured
alternative to Termbox.
......@@ -8,61 +14,176 @@ Termion aims to be simple and yet expressive. It is bindless, meaning that it
is not a front-end to some other library (e.g., ncurses or termbox), but a
standalone library directly talking to the TTY.
Supports Redox, Mac OS X, and Linux (or, in general, ANSI terminals).
Termion is quite convenient, due to its complete coverage of essential TTY
features, providing one consistent API. Termion is rather low-level containing
only abstraction aligned with what actually happens behind the scenes. For
something more high-level, refer to inquirer-rs, which uses Termion as backend.
Termion generates escapes and API calls for the user. This makes it a whole lot
cleaner to use escapes.
[Documentation.](http://ticki.github.io/termion/termion/) | [Examples.](https://github.com/Ticki/termion/tree/master/examples)
Supports Redox, Mac OS X, BSD, and Linux (or, in general, ANSI terminals).
## A note on stability
Although small breaking changes might happen, I will try my best to avoid them,
and this crate can generally be considered stable.
This crate is stable.
## Cargo.toml
```toml
[dependencies]
termion = "*"
```
## 3.0.0 to 4.0.0 guide
A change is only necessary if you were matching on all variants of the `MouseEvent` enum without a wildcard.
In this case, you need to either handle the two new variants, `MouseLeft` and `MouseRight`, or add a wildcard.
## 2.0.0 to 3.0.0 guide
Changes are only required if you were using `IntoRawMode` on generic terminals `W: Write`. Now, terminal
is also required to implement [`AsFd` trait][AsFd-trait]. So replacing generic bounds with `W: Write + AsFd`
should be sufficient.
[AsFd-trait]: https://doc.rust-lang.org/std/os/fd/trait.AsFd.html
## 1.0.0 to 2.0.0 guide
| 1.0.0 | 2.0.0
|--------------------------------|---------------------------
| `AlternativeScreen::from(x)` | `x.into_alternative_screen()`
## 0.1.0 to 1.0.0 guide
This sample table gives an idea of how to go about converting to the new major
version of Termion.
| 0.1.0 | 1.0.0
|--------------------------------|---------------------------
| `use termion::IntoRawMode` | `use termion::raw::IntoRawMode`
| `use termion::TermRead` | `use termion::input::TermRead`
| `stdout.color(color::Red);` | `write!(stdout, "{}", color::Fg(color::Red));`
| `stdout.color_bg(color::Red);` | `write!(stdout, "{}", color::Bg(color::Red));`
| `stdout.goto(x, y);` | `write!(stdout, "{}", cursor::Goto(x, y));`
| `color::rgb(r, g, b);` | `color::Rgb(r, g, b)` (truecolor)
| `x.with_mouse()` | `MouseTerminal::from(x)`
## Features
- Raw mode.
- TrueColor.
- 256-color mode.
- Cursor movement.
- Color output.
- Calculating ANSI escapes.
- Text formatting.
- Console size.
- TTY-only stream.
- Control sequences.
- Termios control.
- Password input.
- Redox support.
- Safe `isatty` wrapper.
- Panic-free error handling.
- Special keys events (modifiers, special keys, etc.).
- Allocation-free.
- Asynchronous key events.
- Mouse input.
- Carefully tested.
- Detailed documentation on every item.
and much more.
## Example
## Examples
### Style and colors.
```rust
extern crate termion;
use termion::{TermWrite, color, Style};
use termion::{color, style};
use std::io;
fn main() {
let stdout = io::stdout();
let mut stdout = stdout.lock();
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);
}
```
### Moving the cursor
```rust
extern crate termion;
stdout.color(color::Red).unwrap();
println!("Red");
fn main() {
print!("{}{}Stuff", termion::clear::All, termion::cursor::Goto(1, 1));
}
```
### Mouse
```rust
extern crate termion;
use termion::event::{Key, Event, MouseEvent};
use termion::input::{TermRead, MouseTerminal};
use termion::raw::IntoRawMode;
use std::io::{Write, stdout, stdin};
fn main() {
let stdin = stdin();
let mut stdout = MouseTerminal::from(stdout().into_raw_mode().unwrap());
write!(stdout, "{}{}q to exit. Click, click, click!", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap();
stdout.flush().unwrap();
for c in stdin.events() {
let evt = c.unwrap();
match evt {
Event::Key(Key::Char('q')) => break,
Event::Mouse(me) => {
match me {
MouseEvent::Press(_, x, y) => {
write!(stdout, "{}x", termion::cursor::Goto(x, y)).unwrap();
},
_ => (),
}
}
_ => {}
}
stdout.flush().unwrap();
}
}
```
### Read a password
```rust
extern crate termion;
use termion::input::TermRead;
use std::io::{Write, stdout, stdin};
stdout.color(color::Blue).unwrap();
println!("Blue");
fn main() {
let stdout = stdout();
let mut stdout = stdout.lock();
let stdin = stdin();
let mut stdin = stdin.lock();
stdout.write_all(b"password: ").unwrap();
stdout.flush().unwrap();
stdout.style(Style::Bold).unwrap();
println!("Blue'n'Bold");
let pass = stdin.read_passwd(&mut stdout);
stdout.reset().unwrap();
stdout.style(Style::Italic).unwrap();
println!("Just plain italic")
if let Ok(Some(pass)) = pass {
stdout.write_all(pass.as_bytes()).unwrap();
stdout.write_all(b"\n").unwrap();
} else {
stdout.write_all(b"Error\n").unwrap();
}
}
```
......@@ -74,11 +195,6 @@ For a more complete example, see [a minesweeper implementation](https://github.c
<img src="image.png" width="200">
## TODO
- Mouse input
## License
MIT/X11.
extern crate termion;
use std::io::{stdout, Write};
use std::{thread, time};
use termion::screen::IntoAlternateScreen;
fn main() {
{
let mut screen = stdout().into_alternate_screen().unwrap();
write!(screen, "Welcome to the alternate screen.\n\nPlease wait patiently until we arrive back at the main screen in a about three seconds.").unwrap();
screen.flush().unwrap();
thread::sleep(time::Duration::from_secs(3));
}
println!("Phew! We are back.");
}
extern crate termion;
use std::io::{stdin, stdout, Write};
use termion::event::Key;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use termion::screen::{IntoAlternateScreen, ToAlternateScreen, ToMainScreen};
fn write_alt_screen_msg<W: Write>(screen: &mut W) {
write!(screen, "{}{}Welcome to the alternate screen.{}Press '1' to switch to the main screen or '2' to switch to the alternate screen.{}Press 'q' to exit (and switch back to the main screen).",
termion::clear::All,
termion::cursor::Goto(1, 1),
termion::cursor::Goto(1, 3),
termion::cursor::Goto(1, 4)).unwrap();
}
fn main() {
let stdin = stdin();
let mut screen = stdout()
.into_raw_mode()
.unwrap()
.into_alternate_screen()
.unwrap();
write!(screen, "{}", termion::cursor::Hide).unwrap();
write_alt_screen_msg(&mut screen);
screen.flush().unwrap();
for c in stdin.keys() {
match c.unwrap() {
Key::Char('q') => break,
Key::Char('1') => {
write!(screen, "{}", ToMainScreen).unwrap();
}
Key::Char('2') => {
write!(screen, "{}", ToAlternateScreen).unwrap();
write_alt_screen_msg(&mut screen);
}
_ => {}
}
screen.flush().unwrap();
}
write!(screen, "{}", termion::cursor::Show).unwrap();
}
extern crate termion;
use termion::{TermWrite, IntoRawMode, async_stdin};
use std::io::{Read, Write, stdout, stdin};
use std::io::{stdout, Read, Write};
use std::thread;
use std::time::Duration;
use termion::async_stdin;
use termion::raw::IntoRawMode;
fn main() {
let stdout = stdout();
let mut stdout = stdout.lock().into_raw_mode().unwrap();
let mut stdin = async_stdin().bytes();
stdout.clear().unwrap();
stdout.goto(0, 0).unwrap();
write!(
stdout,
"{}{}",
termion::clear::All,
termion::cursor::Goto(1, 1)
)
.unwrap();
loop {
stdout.clear_line().unwrap();
write!(stdout, "{}", termion::clear::CurrentLine).unwrap();
let b = stdin.next();
write!(stdout, "\r{:?} <- This demonstrates the async read input char. Between each update a 100 ms. is waited, simply to demonstrate the async fashion. \n\r", b).unwrap();
......@@ -25,11 +31,11 @@ fn main() {
stdout.flush().unwrap();
thread::sleep(Duration::from_millis(50));
stdout.write(b"# ").unwrap();
stdout.write_all(b"# ").unwrap();
stdout.flush().unwrap();
thread::sleep(Duration::from_millis(50));
stdout.write(b"\r #").unwrap();
stdout.goto(0, 0).unwrap();
stdout.write_all(b"\r #").unwrap();
write!(stdout, "{}", termion::cursor::Goto(1, 1)).unwrap();
stdout.flush().unwrap();
}
}
extern crate termion;
use std::io::{stdin, stdout, Write};
use termion::event::{Event, Key, MouseEvent};
use termion::input::{MouseTerminal, TermRead};
use termion::raw::IntoRawMode;
fn main() {
let stdin = stdin();
let mut stdout = MouseTerminal::from(stdout().into_raw_mode().unwrap());
write!(
stdout,
"{}{}q to exit. Click, click, click!",
termion::clear::All,
termion::cursor::Goto(1, 1)
)
.unwrap();
stdout.flush().unwrap();
for c in stdin.events() {
let evt = c.unwrap();
match evt {
Event::Key(Key::Char('q')) => break,
Event::Mouse(me) => match me {
MouseEvent::Press(_, x, y) => {
write!(stdout, "{}x", termion::cursor::Goto(x, y)).unwrap();
}
_ => (),
},
_ => {}
}
stdout.flush().unwrap();
}
}
extern crate termion;
use termion::{TermWrite, color, Style};
use std::io;
use termion::{color, style};
fn main() {
let stdout = io::stdout();
let mut stdout = stdout.lock();
stdout.color(color::Red).unwrap();
println!("Red");
stdout.color(color::Blue).unwrap();
println!("Blue");
stdout.style(Style::Bold).unwrap();
println!("Blue'n'Bold");
stdout.reset().unwrap();
stdout.style(Style::Italic).unwrap();
println!("Just plain italic")
println!("{}Gray background", color::Bg(color::LightBlack));
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, style::Reset);
}
extern crate termion;
use std::io::stdout;
use termion::color::{AnsiValue, Bg, DetectColors};
use termion::raw::IntoRawMode;
fn main() {
let count;
{
let mut term = stdout().into_raw_mode().unwrap();
count = term.available_colors().unwrap();
}
println!("This terminal supports {} colors.", count);
for i in 0..count {
print!("{} {}", Bg(AnsiValue(i as u8)), Bg(AnsiValue(0)));
}
println!();
}
extern crate termion;
use std::fs;
fn main() {
if termion::is_tty(&fs::File::create("/dev/stdout").unwrap()) {
println!("This is a TTY!");
} else {
println!("This is not a TTY :(");
}
}
extern crate termion;
#[cfg(feature = "nightly")]
fn main() {
use termion::{TermRead, TermWrite, IntoRawMode, Key};
use std::io::{Write, stdout, stdin};
use std::io::{stdin, stdout, Write};
use termion::event::Key;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
fn main() {
let stdin = stdin();
let mut stdout = stdout().into_raw_mode().unwrap();
stdout.clear().unwrap();
stdout.goto(0, 0).unwrap();
stdout.write(b"q to exit. Type stuff, use alt, and so on.").unwrap();
stdout.hide_cursor().unwrap();
write!(
stdout,
"{}{}q to exit. Type stuff, use alt, and so on.{}",
termion::clear::All,
termion::cursor::Goto(1, 1),
termion::cursor::Hide
)
.unwrap();
stdout.flush().unwrap();
for c in stdin.keys() {
stdout.goto(5, 5).unwrap();
stdout.clear_line().unwrap();
match c.unwrap() {
for k in stdin.keys() {
write!(
stdout,
"{}{}",
termion::cursor::Goto(1, 1),
termion::clear::CurrentLine
)
.unwrap();
match k.as_ref().unwrap() {
Key::Char('q') => break,
Key::Char(c) => println!("{}", c),
Key::Alt(c) => println!("^{}", c),
Key::Ctrl(c) => println!("*{}", c),
Key::Esc => println!("ESC"),
Key::Left => println!("←"),
Key::Right => println!("→"),
Key::Up => println!("↑"),
Key::Down => println!("↓"),
Key::Backspace => println!("×"),
Key::Invalid => println!("???"),
_ => {},
_ => {
println!("{:?}", k)
}
}
stdout.flush().unwrap();
}
stdout.show_cursor().unwrap();
}
#[cfg(not(feature = "nightly"))]
fn main() {
println!("To run this example, you need to enable the `nightly` feature. Use Rust nightly and compile with `--features nightly`.")
write!(stdout, "{}", termion::cursor::Show).unwrap();
}
extern crate termion;
use std::io::{self, Write};
use termion::cursor::{self, DetectCursorPos};
use termion::event::*;
use termion::input::{MouseTerminal, TermRead};
use termion::raw::IntoRawMode;
fn main() {
let stdin = io::stdin();
let mut stdout = MouseTerminal::from(io::stdout().into_raw_mode().unwrap());
writeln!(
stdout,
"{}{}q to exit. Type stuff, use alt, click around...",
termion::clear::All,
termion::cursor::Goto(1, 1)
)
.unwrap();
for c in stdin.events() {
let evt = c.unwrap();
match evt {
Event::Key(Key::Char('q')) => break,
Event::Mouse(me) => match me {
MouseEvent::Press(_, a, b) | MouseEvent::Release(a, b) | MouseEvent::Hold(a, b) => {
write!(stdout, "{}", cursor::Goto(a, b)).unwrap();
let (x, y) = stdout.cursor_pos().unwrap();
write!(
stdout,
"{}{}Cursor is at: ({},{}){}",
cursor::Goto(5, 5),
termion::clear::UntilNewline,
x,
y,
cursor::Goto(a, b)
)
.unwrap();
}
},
_ => {}
}
stdout.flush().unwrap();
}
}
extern crate termion;
use std::io::{stdin, stdout, Write};
use termion::event::Key;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
fn rainbow<W: Write>(stdout: &mut W, blue: u8) {
write!(
stdout,
"{}{}",
termion::cursor::Goto(1, 1),
termion::clear::All
)
.unwrap();
for red in 0..32 {
let red = red * 8;
for green in 0..64 {
let green = green * 4;
write!(
stdout,
"{} ",
termion::color::Bg(termion::color::Rgb(red, green, blue))
)
.unwrap();
}
write!(stdout, "\n\r").unwrap();
}
writeln!(stdout, "{}b = {}", termion::style::Reset, blue).unwrap();
}
fn main() {
let stdin = stdin();
let mut stdout = stdout().into_raw_mode().unwrap();
writeln!(
stdout,
"{}{}{}Use the up/down arrow keys to change the blue in the rainbow.",
termion::clear::All,
termion::cursor::Goto(1, 1),
termion::cursor::Hide
)
.unwrap();
let mut blue = 172u8;
for c in stdin.keys() {
match c.unwrap() {
Key::Up => {
blue = blue.saturating_add(4);
rainbow(&mut stdout, blue);
}
Key::Down => {
blue = blue.saturating_sub(4);
rainbow(&mut stdout, blue);
}
Key::Char('q') => break,
_ => {}
}
stdout.flush().unwrap();
}
write!(stdout, "{}", termion::cursor::Show).unwrap();
}
extern crate termion;
use termion::TermRead;
use std::io::{Write, stdout, stdin};
use std::io::{stdin, stdout, Write};
use termion::input::TermRead;
fn main() {
let stdout = stdout();
......@@ -9,15 +9,15 @@ fn main() {
let stdin = stdin();
let mut stdin = stdin.lock();
stdout.write(b"password: ").unwrap();
stdout.write_all(b"password: ").unwrap();
stdout.flush().unwrap();
let pass = stdin.read_passwd(&mut stdout);
if let Ok(Some(pass)) = pass {
stdout.write(pass.as_bytes()).unwrap();
stdout.write(b"\n").unwrap();
stdout.write_all(pass.as_bytes()).unwrap();
stdout.write_all(b"\n").unwrap();
} else {
stdout.write(b"Error\n").unwrap();
stdout.write_all(b"Error\n").unwrap();
}
}
extern crate termion;
use termion::{TermWrite, color, Style};
use std::io::{self, Write};
use termion::{color, style};
fn main() {
let line_num_bg: color::AnsiValue = color::grayscale(3);
let line_num_fg: color::AnsiValue = color::grayscale(18);
let error_fg: color::AnsiValue = color::grayscale(17);
let info_line: &'static str = "| ";
let stdout = io::stdout();
let mut stdout = stdout.lock();
stdout.color(color::LightGreen).unwrap();
stdout.write("-- src/test/ui/borrow-errors.rs at 82:18 --\n".as_bytes()).unwrap();
stdout.reset().unwrap();
stdout.color(color::Red).unwrap();
stdout.style(Style::Bold).unwrap();
stdout.write(b"error: ").unwrap();
stdout.reset().unwrap();
stdout.style(Style::Bold).unwrap();
stdout.write(b"two closures require unique access to `vec` at the same time").unwrap();
stdout.reset().unwrap();
stdout.style(Style::Bold).unwrap();
stdout.color(color::Magenta).unwrap();
stdout.write(b" [E0524]\n").unwrap();
stdout.reset().unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(b"79 ").unwrap();
stdout.reset().unwrap();
stdout.write(b" let append = |e| {\n").unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(info_line.as_bytes()).unwrap();
stdout.reset().unwrap();
stdout.color(color::Red).unwrap();
stdout.write(" ^^^ ".as_bytes()).unwrap();
stdout.reset().unwrap();
stdout.color(error_fg).unwrap();
stdout.write(b"first closure is constructed here\n").unwrap();
stdout.reset().unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(b"80 ").unwrap();
stdout.reset().unwrap();
stdout.write(b" vec.push(e)\n").unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(info_line.as_bytes()).unwrap();
stdout.reset().unwrap();
stdout.color(color::Red).unwrap();
stdout.write(" ^^^ ".as_bytes()).unwrap();
stdout.reset().unwrap();
stdout.color(error_fg).unwrap();
stdout.write(b"previous borrow occurs due to use of `vec` in closure\n").unwrap();
stdout.reset().unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(b"81 ").unwrap();
stdout.reset().unwrap();
stdout.write(b" };\n").unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(b"82 ").unwrap();
stdout.reset().unwrap();
stdout.write(b" let append = |e| {\n").unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(info_line.as_bytes()).unwrap();
stdout.reset().unwrap();
stdout.color(color::Red).unwrap();
stdout.write(" ^^^ ".as_bytes()).unwrap();
stdout.reset().unwrap();
stdout.color(error_fg).unwrap();
stdout.write(b"second closure is constructed here\n").unwrap();
stdout.reset().unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(b"83 ").unwrap();
stdout.reset().unwrap();
stdout.write(b" vec.push(e)\n").unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(info_line.as_bytes()).unwrap();
stdout.reset().unwrap();
stdout.color(color::Red).unwrap();
stdout.write(" ^^^ ".as_bytes()).unwrap();
stdout.reset().unwrap();
stdout.color(error_fg).unwrap();
stdout.write(b"borrow occurs due to use of `vec` in closure\n").unwrap();
stdout.reset().unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(b"84 ").unwrap();
stdout.reset().unwrap();
stdout.write(b" };\n").unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(b"85 ").unwrap();
stdout.reset().unwrap();
stdout.write(b" }\n").unwrap();
stdout.color(line_num_fg).unwrap();
stdout.bg_color(line_num_bg).unwrap();
stdout.write(info_line.as_bytes()).unwrap();
stdout.reset().unwrap();
stdout.color(color::Red).unwrap();
stdout.write(" ^ ".as_bytes()).unwrap();
stdout.reset().unwrap();
stdout.color(error_fg).unwrap();
stdout.write(b"borrow from first closure ends here\n").unwrap();
stdout.reset().unwrap();
println!("{lighgreen}-- src/test/ui/borrow-errors.rs at 82:18 --\n\
{red}error: {reset}{bold}two closures require unique access to `vec` at the same time {reset}{bold}{magenta}[E0524]{reset}\n\
{line_num_fg}{line_num_bg}79 {reset} let append = |e| {{\n\
{line_num_fg}{line_num_bg}{info_line}{reset} {red}^^^{reset} {error_fg}first closure is constructed here\n\
{line_num_fg}{line_num_bg}80 {reset} vec.push(e)\n\
{line_num_fg}{line_num_bg}{info_line}{reset} {red}^^^{reset} {error_fg}previous borrow occurs due to use of `vec` in closure\n\
{line_num_fg}{line_num_bg}84 {reset} }};\n\
{line_num_fg}{line_num_bg}85 {reset} }}\n\
{line_num_fg}{line_num_bg}{info_line}{reset} {red}^{reset} {error_fg}borrow from first closure ends here",
lighgreen = color::Fg(color::LightGreen),
red = color::Fg(color::Red),
bold = style::Bold,
reset = style::Reset,
magenta = color::Fg(color::Magenta),
line_num_bg = color::Bg(color::AnsiValue::grayscale(3)),
line_num_fg = color::Fg(color::AnsiValue::grayscale(18)),
info_line = "| ",
error_fg = color::Fg(color::AnsiValue::grayscale(17)))
}
extern crate termion;
use termion::{TermWrite, IntoRawMode, Color, Style};
use std::io::{Read, Write, stdout, stdin};
use std::io::{stdin, stdout, Read, Write};
use termion::color;
use termion::raw::IntoRawMode;
fn main() {
// Initialize 'em all.
......@@ -10,19 +11,17 @@ fn main() {
let stdin = stdin();
let stdin = stdin.lock();
// Move the cursor to (5, 5)
stdout.goto(5, 5).unwrap();
// Clear the screen.
stdout.clear().unwrap();
// Set style to bold.
stdout.style(Style::Bold).unwrap();
// Write some guiding stuff
stdout.write(b"yo, 'q' will exit.").unwrap();
// Reset the style.
stdout.reset().unwrap();
// Flush and goto (20, 10)
write!(
stdout,
"{}{}{}yo, 'q' will exit.{}{}",
termion::clear::All,
termion::cursor::Goto(5, 5),
termion::style::Bold,
termion::style::Reset,
termion::cursor::Goto(20, 10)
)
.unwrap();
stdout.flush().unwrap();
stdout.goto(20, 10).unwrap();
let mut bytes = stdin.bytes();
loop {
......@@ -32,12 +31,13 @@ fn main() {
// Quit
b'q' => return,
// Clear the screen
b'c' => stdout.clear(),
b'c' => write!(stdout, "{}", termion::clear::All),
// Set red color
b'r' => stdout.color(Color::Rgb(5, 0, 0)),
b'r' => write!(stdout, "{}", color::Fg(color::Rgb(255, 0, 0))),
// Write it to stdout.
a => stdout.write(&[a]),
}.unwrap();
a => write!(stdout, "{}", a),
}
.unwrap();
stdout.flush().unwrap();
}
......
extern crate termion;
use std::{thread, time};
use termion::{clear, color, cursor};
fn main() {
for r in 0..255 {
let c = color::Rgb(r, !r, 2 * ((r % 128) as i8 - 64).abs() as u8);
println!("{}{}{}wow", cursor::Goto(1, 1), color::Bg(c), clear::All);
thread::sleep(time::Duration::from_millis(100));
}
}