Skip to content

Commit

Permalink
Fix logic error in Ctrl-Arrow and clean up examples
Browse files Browse the repository at this point in the history
  • Loading branch information
rw-vanc authored and jackpot51 committed Jun 12, 2024
1 parent 8dfc0e6 commit 84b3dcf
Show file tree
Hide file tree
Showing 24 changed files with 262 additions and 232 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 1,7 @@
# 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.
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
[package]
name = "termion"
version = "4.0.1"
version = "4.0.2"
authors = [
"ticki <[email protected]>",
"gycos <[email protected]>",
Expand Down
4 changes: 2 additions & 2 deletions examples/alternate_screen.rs
Original file line number Diff line number Diff line change
@@ -1,8 1,8 @@
extern crate termion;

use std::io::{stdout, Write};
use std::{thread, time};
use termion::screen::IntoAlternateScreen;
use std::io::{Write, stdout};
use std::{time, thread};

fn main() {
{
Expand Down
8 changes: 6 additions & 2 deletions examples/alternate_screen_raw.rs
Original file line number Diff line number Diff line change
@@ -1,10 1,10 @@
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};
use std::io::{Write, stdout, stdin};

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).",
Expand All @@ -16,7 16,11 @@ fn write_alt_screen_msg<W: Write>(screen: &mut W) {

fn main() {
let stdin = stdin();
let mut screen = stdout().into_raw_mode().unwrap().into_alternate_screen().unwrap();
let mut screen = stdout()
.into_raw_mode()
.unwrap()
.into_alternate_screen()
.unwrap();
write!(screen, "{}", termion::cursor::Hide).unwrap();
write_alt_screen_msg(&mut screen);

Expand Down
18 changes: 10 additions & 8 deletions examples/async.rs
Original file line number Diff line number Diff line change
@@ -1,21 1,23 @@
extern crate termion;

use termion::raw::IntoRawMode;
use termion::async_stdin;
use std::io::{Read, Write, stdout};
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();

write!(stdout,
"{}{}",
termion::clear::All,
termion::cursor::Goto(1, 1))
.unwrap();
write!(
stdout,
"{}{}",
termion::clear::All,
termion::cursor::Goto(1, 1)
)
.unwrap();

loop {
write!(stdout, "{}", termion::clear::CurrentLine).unwrap();
Expand Down
30 changes: 15 additions & 15 deletions examples/click.rs
Original file line number Diff line number Diff line change
@@ -1,33 1,33 @@
extern crate termion;

use termion::event::{Key, Event, MouseEvent};
use termion::input::{TermRead, MouseTerminal};
use std::io::{stdin, stdout, Write};
use termion::event::{Event, Key, MouseEvent};
use termion::input::{MouseTerminal, TermRead};
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();
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();
}
_ => (),
Event::Mouse(me) => match me {
MouseEvent::Press(_, x, y) => {
write!(stdout, "{}x", termion::cursor::Goto(x, y)).unwrap();
}
}
_ => (),
},
_ => {}
}
stdout.flush().unwrap();
Expand Down
1 change: 1 addition & 0 deletions examples/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 3,7 @@ extern crate termion;
use termion::{color, style};

fn main() {
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);
Expand Down
51 changes: 0 additions & 51 deletions examples/commie.rs

This file was deleted.

4 changes: 2 additions & 2 deletions examples/detect_color.rs
Original file line number Diff line number Diff line change
@@ -1,8 1,8 @@
extern crate termion;

use termion::color::{DetectColors, AnsiValue, Bg};
use termion::raw::IntoRawMode;
use std::io::stdout;
use termion::color::{AnsiValue, Bg, DetectColors};
use termion::raw::IntoRawMode;

fn main() {
let count;
Expand Down
36 changes: 21 additions & 15 deletions examples/keys.rs
Original file line number Diff line number Diff line change
@@ -1,30 1,34 @@
extern crate termion;

use std::io::{stdin, stdout, Write};
use termion::event::Key;
use termion::input::TermRead;
use termion::raw::IntoRawMode;
use std::io::{Write, stdout, stdin};

fn main() {
let stdin = stdin();
let mut stdout = stdout().into_raw_mode().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();
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() {
write!(stdout,
"{}{}",
termion::cursor::Goto(1, 1),
termion::clear::CurrentLine)
.unwrap();
for k in stdin.keys() {
write!(
stdout,
"{}{}",
termion::cursor::Goto(1, 1),
termion::clear::CurrentLine
)
.unwrap();

match c.unwrap() {
match k.as_ref().unwrap() {
Key::Char('q') => break,
Key::Char(c) => println!("{}", c),
Key::Alt(c) => println!("^{}", c),
Expand All @@ -35,7 39,9 @@ fn main() {
Key::Up => println!("↑"),
Key::Down => println!("↓"),
Key::Backspace => println!("×"),
_ => {}
_ => {
println!("{:?}", k)
}
}
stdout.flush().unwrap();
}
Expand Down
50 changes: 25 additions & 25 deletions examples/mouse.rs
Original file line number Diff line number Diff line change
@@ -1,43 1,43 @@
extern crate termion;

use termion::event::*;
use std::io::{self, Write};
use termion::cursor::{self, DetectCursorPos};
use termion::input::{TermRead, MouseTerminal};
use termion::event::*;
use termion::input::{MouseTerminal, TermRead};
use termion::raw::IntoRawMode;
use std::io::{self, Write};

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();
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();
}
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();
}
}
},
_ => {}
}

Expand Down
38 changes: 22 additions & 16 deletions examples/rainbow.rs
Original file line number Diff line number Diff line change
@@ -1,25 1,29 @@
extern crate termion;

use std::io::{stdin, stdout, Write};
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();
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,
"{} ",
termion::color::Bg(termion::color::Rgb(red, green, blue))
)
.unwrap();
}
write!(stdout, "\n\r").unwrap();
}
Expand All @@ -31,12 35,14 @@ 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();
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;

Expand Down
Loading

0 comments on commit 84b3dcf

Please sign in to comment.