Skip to content

Commit

Permalink
0.24 (#686)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimonPost authored Jul 2, 2022
1 parent fe37c89 commit 0c20590
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 15 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# Version 0.24.0
- Add DoubleUnderlined, Undercurled, Underdots the text, Underdotted, Underdashes, Underdashed attributes and allow coloring their foreground / background color.
- Fix windows unicode character parsing, this fixed various key combinations and support typing unicode characters.
- Consistency and better documentation on mouse cursor operations (BREAKING CHANGE).
- MoveTo, MoveToColumn, MoveToRow are 0-based. (left top most cell is 0,0). Moving like this is absolute
- MoveToNextLine, MoveToPreviousLine, MoveUp, MoveDown, MoveRight, MoveLeft are 1-based,. Moving like this is relative. Moving 1 left means moving 1 left. Moving 0 to the left is not possible, wikipedia states that most terminals will just default to 1.
- terminal::size returns error when previously it returned (0,0).
- Remove println from serialisation code.
- Fix mouse up for middle and right buttons.
- Fix escape codes on Git-Bash + Windows Terminal / Alacritty / WezTerm.
- Add support for cursor keys in application mode.
# Version 0.23.2
- Update signal-hook and mio to version 0.8.

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 = "crossterm"
version = "0.23.2"
version = "0.24.0"
authors = ["T. Post"]
description = "A crossplatform terminal library for manipulating terminals."
repository = "https://github.com/crossterm-rs/crossterm"
Expand Down
3 changes: 2 additions & 1 deletion examples/interactive-demo/src/test/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use crate::Result;
use crossterm::{cursor, queue, style};
use std::io::Write;

const ATTRIBUTES: [(style::Attribute, style::Attribute); 6] = [
const ATTRIBUTES: [(style::Attribute, style::Attribute); 10] = [
(style::Attribute::Bold, style::Attribute::NormalIntensity),
(style::Attribute::Italic, style::Attribute::NoItalic),
(style::Attribute::Underlined, style::Attribute::NoUnderline),

(style::Attribute::DoubleUnderlined, style::Attribute::NoUnderline),
(style::Attribute::Undercurled, style::Attribute::NoUnderline),
(style::Attribute::Underdotted, style::Attribute::NoUnderline),
Expand Down
6 changes: 5 additions & 1 deletion examples/is_tty.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use crossterm::{tty::IsTty, terminal::{size, SetSize}, execute};
use crossterm::{
execute,
terminal::{size, SetSize},
tty::IsTty,
};
use std::io::{stdin, stdout};

pub fn main() {
Expand Down
24 changes: 18 additions & 6 deletions src/event/sys/unix/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,24 @@ pub(crate) fn parse_event(buffer: &[u8], input_available: bool) -> Result<Option
Ok(None)
} else {
match buffer[2] {
b'D' => Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Left.into())))),
b'C' => Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Right.into())))),
b'A' => Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Up.into())))),
b'B' => Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Down.into())))),
b'H' => Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Home.into())))),
b'F' => Ok(Some(InternalEvent::Event(Event::Key(KeyCode::End.into())))),
b'D' => {
Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Left.into()))))
}
b'C' => Ok(Some(InternalEvent::Event(Event::Key(
KeyCode::Right.into(),
)))),
b'A' => {
Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Up.into()))))
}
b'B' => {
Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Down.into()))))
}
b'H' => {
Ok(Some(InternalEvent::Event(Event::Key(KeyCode::Home.into()))))
}
b'F' => {
Ok(Some(InternalEvent::Event(Event::Key(KeyCode::End.into()))))
}
// F1-F4
val @ b'P'..=b'S' => Ok(Some(InternalEvent::Event(Event::Key(
KeyCode::F(1 + val - b'P').into(),
Expand Down
8 changes: 8 additions & 0 deletions src/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,14 @@ impl Command for SetUnderlineColor {
fn write_ansi(&self, f: &mut impl fmt::Write) -> fmt::Result {
write!(f, csi!("{}m"), Colored::UnderlineColor(self.0))
}

#[cfg(windows)]
fn execute_winapi(&self) -> Result<()> {
Err(std::io::Error::new(
std::io::ErrorKind::Other,
"SetUnderlineColor not supported by winapi.",
))
}
}

/// A command that optionally sets the foreground and/or background color.
Expand Down
1 change: 1 addition & 0 deletions src/style/sys/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl From<Colored> for u16 {
Color::AnsiValue(_val) => 0,
}
}
Colored::UnderlineColor(_) => 0,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/style/types/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ impl Attribute {
/// See <https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters>
pub fn sgr(self) -> String {
if (self as usize) > 4 && (self as usize) < 9 {
return "4:".to_string() + SGR[self as usize].to_string().as_str()
return "4:".to_string() + SGR[self as usize].to_string().as_str();
}
SGR[self as usize].to_string()
}
Expand Down
1 change: 1 addition & 0 deletions src/style/types/colored.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub enum Colored {
/// A background color.
BackgroundColor(Color),
/// An underline color.
/// Imporant: doesnt work on windows 10 or lower.
UnderlineColor(Color),
}

Expand Down
2 changes: 1 addition & 1 deletion src/style/types/colors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl From<Colored> for Colors {
Colored::UnderlineColor(color) => Colors {
foreground: None,
background: Some(color),
}
},
}
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/terminal/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ pub(crate) fn size() -> Result<(u16, u16)> {
STDOUT_FILENO
};

if wrap_with_result(unsafe { ioctl(fd, TIOCGWINSZ.into(), &mut size) }).is_ok() {
if size.ws_col != 0 && size.ws_row != 0 {
return Ok((size.ws_col, size.ws_row));
}
if wrap_with_result(unsafe { ioctl(fd, TIOCGWINSZ.into(), &mut size) }).is_ok()
&& size.ws_col != 0
&& size.ws_row != 0
{
return Ok((size.ws_col, size.ws_row));
}

tput_size().ok_or_else(|| std::io::Error::last_os_error().into())
}

Expand Down

0 comments on commit 0c20590

Please sign in to comment.