Docs, cargo, last updates before release (#71)

* Docs, cargo, last updates before release
This commit is contained in:
Timon 2019-01-02 07:53:47 -08:00 committed by GitHub
parent 5515c1433d
commit a0464a041d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 142 additions and 78 deletions

View File

@ -2,11 +2,11 @@
language: rust language: rust
rust: rust:
- stable - stable
- beta
- nightly - nightly
before_script: before_script:
- export PATH=$PATH:/home/travis/.cargo/bin - export PATH=$PATH:/home/travis/.cargo/bin
- rustup component add rustfmt-preview
os: os:
- linux - linux
@ -19,3 +19,4 @@ branches:
script: script:
- cargo build - cargo build
- cargo fmt -- --check

View File

@ -1,6 +1,6 @@
[package] [package]
name = "crossterm" name = "crossterm"
version = "0.5.1" version = "0.6.0"
authors = ["T. Post"] authors = ["T. Post"]
description = "An crossplatform terminal library for manipulating terminals." description = "An crossplatform terminal library for manipulating terminals."
repository = "https://github.com/TimonPost/crossterm" repository = "https://github.com/TimonPost/crossterm"
@ -12,7 +12,7 @@ readme = "README.md"
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.5", features = ["winbase","winuser","consoleapi","processenv","wincon", "handleapi","errhandlingapi"] } winapi = { version = "0.3.5", features = ["winbase","winuser","consoleapi","processenv","wincon", "handleapi","errhandlingapi"] }
crossterm_winapi = { version = "0.0.0", git="https://github.com/TimonPost/crossterm_winapi" } crossterm_winapi = "0.1.0"
[target.'cfg(unix)'.dependencies] [target.'cfg(unix)'.dependencies]
libc = "0.2.43" libc = "0.2.43"

View File

@ -49,7 +49,7 @@ Add the Crossterm package to your `Cargo.toml` file.
``` ```
[dependencies] [dependencies]
crossterm = "0.5.0" crossterm = "0.6"
``` ```
And import the Crossterm modules you want to use. And import the Crossterm modules you want to use.
@ -95,7 +95,7 @@ These are the features from this crate:
- Background color (16 base colors) - Background color (16 base colors)
- 256 color support (Windows 10 and UNIX only) - 256 color support (Windows 10 and UNIX only)
- RGB support (Windows 10 and UNIX only) - RGB support (Windows 10 and UNIX only)
- Text Attributes like: bold, italic, underscore and crossed word ect (unix only) - Text Attributes like: bold, italic, underscore and crossed word ect (Windows 10 and UNIX only)
- Terminal - Terminal
- Clearing (all lines, current line, from cursor down and up, until new line) - Clearing (all lines, current line, from cursor down and up, until new line)
- Scrolling (Up, down) - Scrolling (Up, down)
@ -139,7 +139,7 @@ use crossterm::style::{Color, style};
let style1 = style("Some Blue font on Black background").with(Color::Blue).on(Color::Black); let style1 = style("Some Blue font on Black background").with(Color::Blue).on(Color::Black);
let style2 = style("Some Red font on Yellow background").with(Color::Red).on(Color::Yellow); let style2 = style("Some Red font on Yellow background").with(Color::Red).on(Color::Yellow);
// attributes are only supported for UNIX terminals. // syling font with (Windows 10 and UNIX systems)
let normal = style("Normal text"); let normal = style("Normal text");
let bold = style("Bold text").bold(); let bold = style("Bold text").bold();
let italic = style("Italic text").italic(); let italic = style("Italic text").italic();
@ -158,14 +158,14 @@ println!("{}", bold);
println!("{}", hidden); println!("{}", hidden);
... ...
// cursom rgb value // cursom rgb value (Windows 10 and UNIX systems)
style("RGB color (10,10,10) ").with(Color::Rgb { style("RGB color (10,10,10) ").with(Color::Rgb {
r: 10, r: 10,
g: 10, g: 10,
b: 10 b: 10
})); }));
// custom ansi color value // custom ansi color value (Windows 10 and UNIX systems)
style("ANSI color value (50) ").with(Color::AnsiValue(50)); style("ANSI color value (50) ").with(Color::AnsiValue(50));
``` ```

View File

@ -1,3 +1,11 @@
# Changes crossterm 0.6.0
- WinApi rewrite and correctly error handled [PR 67](https://github.com/TimonPost/crossterm/pull/67)
- Windows attribute support [PR 62](https://github.com/TimonPost/crossterm/pull/62)
- Readline bug fix windows systems [PR 62](https://github.com/TimonPost/crossterm/pull/62)
- Error handling improvement.
- General refactoring, all warnings removed.
- Documentation improvement.
# Changes crossterm 0.5.1 # Changes crossterm 0.5.1
- Documentation refactor. - Documentation refactor.
- Fixed broken API documentation [PR 53](https://github.com/TimonPost/crossterm/pull/53). - Fixed broken API documentation [PR 53](https://github.com/TimonPost/crossterm/pull/53).

View File

@ -2,7 +2,7 @@
***WARNING*** ***WARNING***
I workded on making the user API more conviniant therefore I had to make some chages to the user API. The problem with `0.4` is that you need to pass a `Screen` to the modules: `cursor(), color(), terminal()`. I workded on making the user API more convenient therefore I had to make some changes to the user API. The problem with `0.4` is that you need to pass a `Screen` to the modules: `cursor(), color(), terminal()`.
In the new situation you only have to do this when working with raw or alternate screen. When you just want to perform actions like styling on the main screen you don't have to to pass in the `Screen` any more. This will look like the following: In the new situation you only have to do this when working with raw or alternate screen. When you just want to perform actions like styling on the main screen you don't have to to pass in the `Screen` any more. This will look like the following:

8
docs/know_problems.md Normal file
View File

@ -0,0 +1,8 @@
There are some problems I discovered during development.
And I don't think it has to do anything with crossterm but it has to do whit how terminals handle ANSI or WinApi.
# Winapi-problems
- Power shell does not interpreter 'DarkYellow' and is instead using gray instead, cmd is working perfectly fine.
# UNIX-terminals
The Arc and Manjaro KDE Konsole's are not seeming to resize the terminal instead they are resizing the buffer.

View File

@ -45,7 +45,7 @@ This thread send all input via an 'mpsc' channel to the `AsyncReader` we got bac
By calling `bytes()` on the `AsyncReader` we get an iterator back over the characters (bytes). By calling `bytes()` on the `AsyncReader` we get an iterator back over the characters (bytes).
``` ```rust
let mut stdin = input.read_async().bytes(); let mut stdin = input.read_async().bytes();
/* next code here */ /* next code here */
@ -55,7 +55,7 @@ Now we got an iterator back we can call `next()` on it to get the next pressed c
If an character is pressed we will get `Some(Ok(u8))` back which we compare to see if 'x' is pressed. If an character is pressed we will get `Some(Ok(u8))` back which we compare to see if 'x' is pressed.
If the 'x' is pressed we break the loop. If the 'x' is pressed we break the loop.
``` ```rust
loop { loop {
let pressed_char: Option<Result<u8>> = stdin.next(); let pressed_char: Option<Result<u8>> = stdin.next();

View File

@ -1,2 +0,0 @@
Power shell does not interpreter 'DarkYellow' and is instead using gray Winapi.
Arc and manjaro konsole are not seeming to resize the terminal instead they are resizeing the buffer.

View File

@ -3,10 +3,10 @@
#[macro_use] #[macro_use]
pub mod macros; pub mod macros;
pub mod commands; pub mod commands;
pub mod error;
pub mod functions; pub mod functions;
pub mod screen; pub mod screen;
pub mod traits; pub mod traits;
pub mod error;
mod crossterm; mod crossterm;

View File

@ -44,7 +44,8 @@ impl AlternateScreen {
functions::get_module::<Box<commands::IAlternateScreenCommand + Sync + Send>>( functions::get_module::<Box<commands::IAlternateScreenCommand + Sync + Send>>(
Box::from(commands::win_commands::ToAlternateScreenCommand::new()), Box::from(commands::win_commands::ToAlternateScreenCommand::new()),
Box::from(commands::shared_commands::ToAlternateScreenCommand::new()), Box::from(commands::shared_commands::ToAlternateScreenCommand::new()),
).unwrap(); )
.unwrap();
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
let command = Box::from(commands::shared_commands::ToAlternateScreenCommand::new()); let command = Box::from(commands::shared_commands::ToAlternateScreenCommand::new());

View File

@ -1,9 +1,9 @@
//! This module contains the `windows` (unsafe) logic. //! This module contains the `windows` (unsafe) logic.
#[allow(unused)]
mod reading;
pub mod ansi_support; pub mod ansi_support;
mod cursor; mod cursor;
#[allow(unused)]
mod reading;
pub mod writing; pub mod writing;
pub use self::cursor::Cursor; pub use self::cursor::Cursor;

View File

@ -302,10 +302,10 @@ extern crate libc;
#[cfg(unix)] #[cfg(unix)]
extern crate termios; extern crate termios;
#[cfg(windows)]
extern crate winapi;
#[cfg(windows)] #[cfg(windows)]
extern crate crossterm_winapi; extern crate crossterm_winapi;
#[cfg(windows)]
extern crate winapi;
#[macro_use] #[macro_use]
mod common; mod common;

View File

@ -133,7 +133,9 @@ impl<'stdout> TerminalCursor<'stdout> {
/// cursor.move_right(3); /// cursor.move_right(3);
/// ``` /// ```
pub fn move_right(&mut self, count: u16) -> &mut TerminalCursor<'stdout> { pub fn move_right(&mut self, count: u16) -> &mut TerminalCursor<'stdout> {
self.terminal_cursor.move_right(count, &self.stdout).unwrap(); self.terminal_cursor
.move_right(count, &self.stdout)
.unwrap();
self self
} }

View File

@ -17,8 +17,8 @@ use self::ansi_cursor::AnsiCursor;
use self::winapi_cursor::WinApiCursor; use self::winapi_cursor::WinApiCursor;
pub use self::cursor::{cursor, from_screen, TerminalCursor}; pub use self::cursor::{cursor, from_screen, TerminalCursor};
use common::error::Result;
use super::functions; use super::functions;
use common::error::Result;
use std::sync::Arc; use std::sync::Arc;
use TerminalOutput; use TerminalOutput;

View File

@ -2,9 +2,9 @@
//! This module is used for Windows terminals that do not support ANSI escape codes. //! This module is used for Windows terminals that do not support ANSI escape codes.
//! Note that the cursor position is 0 based. This means that we start counting at 0 when setting the cursor position. //! Note that the cursor position is 0 based. This means that we start counting at 0 when setting the cursor position.
use kernel::windows_kernel::{Cursor, Handle};
use common::error::Result;
use super::*; use super::*;
use common::error::Result;
use kernel::windows_kernel::{Cursor, Handle};
/// This struct is a windows implementation for cursor related actions. /// This struct is a windows implementation for cursor related actions.
pub struct WinApiCursor; pub struct WinApiCursor;
@ -71,5 +71,7 @@ impl ITerminalCursor for WinApiCursor {
Ok(()) Ok(())
} }
fn blink(&self, _blink: bool, _stdout: &Option<&Arc<TerminalOutput>>) -> Result<()> { Ok(()) } fn blink(&self, _blink: bool, _stdout: &Option<&Arc<TerminalOutput>>) -> Result<()> {
Ok(())
}
} }

View File

@ -22,7 +22,7 @@ pub use self::color::{color, from_screen, TerminalColor};
pub use self::objectstyle::ObjectStyle; pub use self::objectstyle::ObjectStyle;
pub use self::styledobject::DisplayableObject; pub use self::styledobject::DisplayableObject;
pub use self::styledobject::StyledObject; pub use self::styledobject::StyledObject;
use common::{functions, error::Result}; use common::{error::Result, functions};
use TerminalOutput; use TerminalOutput;

View File

@ -3,9 +3,9 @@
use super::{color, from_screen, Color, ObjectStyle}; use super::{color, from_screen, Color, ObjectStyle};
use Screen; use Screen;
use common::error::Result;
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
use std::io::Write; use std::io::Write;
use common::error::Result;
use std::result; use std::result;
use super::Attribute; use super::Attribute;

View File

@ -2,11 +2,11 @@
//! This module is used for non supporting `ANSI` Windows terminals. //! This module is used for non supporting `ANSI` Windows terminals.
use super::*; use super::*;
use common::error::Result;
use kernel::windows_kernel::{Console, Handle, HandleType, ScreenBuffer}; use kernel::windows_kernel::{Console, Handle, HandleType, ScreenBuffer};
use std::io; use std::io;
use std::sync::{Once, ONCE_INIT}; use std::sync::{Once, ONCE_INIT};
use winapi::um::wincon; use winapi::um::wincon;
use common::error::Result;
/// This struct is a WinApi implementation for color related actions. /// This struct is a WinApi implementation for color related actions.
pub struct WinApiColor; pub struct WinApiColor;
@ -40,8 +40,7 @@ impl ITerminalColor for WinApiColor {
color = color | wincon::BACKGROUND_INTENSITY as u16; color = color | wincon::BACKGROUND_INTENSITY as u16;
} }
Console::from(**screen_buffer.get_handle()) Console::from(**screen_buffer.get_handle()).set_text_attribute(color)?;
.set_text_attribute(color)?;
Ok(()) Ok(())
} }
@ -68,8 +67,7 @@ impl ITerminalColor for WinApiColor {
color = color | wincon::FOREGROUND_INTENSITY as u16; color = color | wincon::FOREGROUND_INTENSITY as u16;
} }
Console::from(**screen_buffer.get_handle()) Console::from(**screen_buffer.get_handle()).set_text_attribute(color)?;
.set_text_attribute(color)?;
Ok(()) Ok(())
} }

View File

@ -51,7 +51,12 @@ impl ITerminal for AnsiTerminal {
Ok(()) Ok(())
} }
fn set_size(&self, width: i16, height: i16, stdout: &Option<&Arc<TerminalOutput>>) -> Result<()> { fn set_size(
&self,
width: i16,
height: i16,
stdout: &Option<&Arc<TerminalOutput>>,
) -> Result<()> {
functions::write(&stdout, format!(csi!("8;{};{}t"), height, width))?; functions::write(&stdout, format!(csi!("8;{};{}t"), height, width))?;
Ok(()) Ok(())
} }

View File

@ -15,7 +15,7 @@ use self::winapi_terminal::WinApiTerminal;
pub use self::terminal::{from_screen, terminal, Terminal}; pub use self::terminal::{from_screen, terminal, Terminal};
use common::{functions, error}; use common::{error, functions};
use std::sync::Arc; use std::sync::Arc;
use {Screen, TerminalOutput}; use {Screen, TerminalOutput};
@ -38,7 +38,11 @@ pub enum ClearType {
/// so that terminal related actions can be preformed on both Unix and Windows systems. /// so that terminal related actions can be preformed on both Unix and Windows systems.
trait ITerminal { trait ITerminal {
/// Clear the current cursor by specifying the clear type /// Clear the current cursor by specifying the clear type
fn clear(&self, clear_type: ClearType, stdout: &Option<&Arc<TerminalOutput>>) -> error::Result<()>; fn clear(
&self,
clear_type: ClearType,
stdout: &Option<&Arc<TerminalOutput>>,
) -> error::Result<()>;
/// Get the terminal size (x,y) /// Get the terminal size (x,y)
fn terminal_size(&self, stdout: &Option<&Arc<TerminalOutput>>) -> (u16, u16); fn terminal_size(&self, stdout: &Option<&Arc<TerminalOutput>>) -> (u16, u16);
/// Scroll `n` lines up in the current terminal. /// Scroll `n` lines up in the current terminal.
@ -46,7 +50,12 @@ trait ITerminal {
/// Scroll `n` lines down in the current terminal. /// Scroll `n` lines down in the current terminal.
fn scroll_down(&self, count: i16, stdout: &Option<&Arc<TerminalOutput>>) -> error::Result<()>; fn scroll_down(&self, count: i16, stdout: &Option<&Arc<TerminalOutput>>) -> error::Result<()>;
/// Resize terminal to the given width and height. /// Resize terminal to the given width and height.
fn set_size(&self, width: i16, height: i16, stdout: &Option<&Arc<TerminalOutput>>) -> error::Result<()>; fn set_size(
&self,
width: i16,
height: i16,
stdout: &Option<&Arc<TerminalOutput>>,
) -> error::Result<()>;
/// Close the current terminal /// Close the current terminal
fn exit(&self, stdout: &Option<&Arc<TerminalOutput>>); fn exit(&self, stdout: &Option<&Arc<TerminalOutput>>);
} }

View File

@ -4,7 +4,7 @@
//! Windows versions lower then windows 10 are not supporting ANSI codes. Those versions will use this implementation instead. //! Windows versions lower then windows 10 are not supporting ANSI codes. Those versions will use this implementation instead.
use super::*; use super::*;
use common::error::{Result, ErrorKind}; use common::error::{ErrorKind, Result};
use kernel::windows_kernel::{Console, Coord, Cursor, Handle, ScreenBuffer, Size}; use kernel::windows_kernel::{Console, Coord, Cursor, Handle, ScreenBuffer, Size};
/// This struct is an winapi implementation for terminal related actions. /// This struct is an winapi implementation for terminal related actions.
@ -67,20 +67,28 @@ impl ITerminal for WinApiTerminal {
window.top += count; // move top down window.top += count; // move top down
window.bottom += count; // move bottom down window.bottom += count; // move bottom down
Console::new()? Console::new()?.set_console_info(false, window)?;
.set_console_info(false, window)?;
} }
Ok(()) Ok(())
} }
/// Set the current terminal size /// Set the current terminal size
fn set_size(&self, width: i16, height: i16, _stdout: &Option<&Arc<TerminalOutput>>) -> Result<()> { fn set_size(
&self,
width: i16,
height: i16,
_stdout: &Option<&Arc<TerminalOutput>>,
) -> Result<()> {
if width <= 0 { if width <= 0 {
return Err(ErrorKind::ResizingTerminalFailure(String::from("Cannot set the terminal width lower than 1"))); return Err(ErrorKind::ResizingTerminalFailure(String::from(
"Cannot set the terminal width lower than 1",
)));
} }
if height <= 0 { if height <= 0 {
return Err(ErrorKind::ResizingTerminalFailure(String::from("Cannot set the terminal height lower then 1"))); return Err(ErrorKind::ResizingTerminalFailure(String::from(
"Cannot set the terminal height lower then 1",
)));
} }
// Get the position of the current console window // Get the position of the current console window
@ -99,7 +107,9 @@ impl ITerminal for WinApiTerminal {
if current_size.width < window.left + width { if current_size.width < window.left + width {
if window.left >= i16::max_value() - width { if window.left >= i16::max_value() - width {
return Err(ErrorKind::ResizingTerminalFailure(String::from("Argument out of range when setting terminal width."))); return Err(ErrorKind::ResizingTerminalFailure(String::from(
"Argument out of range when setting terminal width.",
)));
} }
new_size.width = window.left + width; new_size.width = window.left + width;
@ -107,7 +117,9 @@ impl ITerminal for WinApiTerminal {
} }
if current_size.height < window.top + height { if current_size.height < window.top + height {
if window.top >= i16::max_value() - height { if window.top >= i16::max_value() - height {
return Err(ErrorKind::ResizingTerminalFailure(String::from("Argument out of range when setting terminal height."))); return Err(ErrorKind::ResizingTerminalFailure(String::from(
"Argument out of range when setting terminal height.",
)));
} }
new_size.height = window.top + height; new_size.height = window.top + height;
@ -116,7 +128,9 @@ impl ITerminal for WinApiTerminal {
if resize_buffer { if resize_buffer {
if let Err(_) = screen_buffer.set_size(new_size.width, new_size.height) { if let Err(_) = screen_buffer.set_size(new_size.width, new_size.height) {
return Err(ErrorKind::ResizingTerminalFailure(String::from("Something went wrong when setting screen buffer size."))); return Err(ErrorKind::ResizingTerminalFailure(String::from(
"Something went wrong when setting screen buffer size.",
)));
} }
} }
@ -129,17 +143,25 @@ impl ITerminal for WinApiTerminal {
// If we resized the buffer, un-resize it. // If we resized the buffer, un-resize it.
if resize_buffer { if resize_buffer {
if let Err(_) = screen_buffer.set_size(current_size.width, current_size.height) { if let Err(_) = screen_buffer.set_size(current_size.width, current_size.height) {
return Err(ErrorKind::ResizingTerminalFailure(String::from("Something went wrong when setting screen buffer size."))); return Err(ErrorKind::ResizingTerminalFailure(String::from(
"Something went wrong when setting screen buffer size.",
)));
} }
} }
let bounds = console.largest_window_size(); let bounds = console.largest_window_size();
if width > bounds.x { if width > bounds.x {
return Err(ErrorKind::ResizingTerminalFailure(format!("Argument width: {} out of range when setting terminal width.", width))); return Err(ErrorKind::ResizingTerminalFailure(format!(
"Argument width: {} out of range when setting terminal width.",
width
)));
} }
if height > bounds.y { if height > bounds.y {
return Err(ErrorKind::ResizingTerminalFailure(format!("Argument height: {} out of range when setting terminal height", width))); return Err(ErrorKind::ResizingTerminalFailure(format!(
"Argument height: {} out of range when setting terminal height",
width
)));
} }
Ok(()) Ok(())
@ -155,7 +177,11 @@ impl ITerminal for WinApiTerminal {
} }
} }
pub fn clear_after_cursor(location: Coord, buffer_size: Size, current_attribute: u16) -> Result<()> { pub fn clear_after_cursor(
location: Coord,
buffer_size: Size,
current_attribute: u16,
) -> Result<()> {
let (mut x, mut y) = (location.x, location.y); let (mut x, mut y) = (location.x, location.y);
// if cursor position is at the outer right position // if cursor position is at the outer right position
@ -173,7 +199,11 @@ pub fn clear_after_cursor(location: Coord, buffer_size: Size, current_attribute:
clear(start_location, cells_to_write, current_attribute) clear(start_location, cells_to_write, current_attribute)
} }
pub fn clear_before_cursor(location: Coord, buffer_size: Size, current_attribute: u16) -> Result<()> { pub fn clear_before_cursor(
location: Coord,
buffer_size: Size,
current_attribute: u16,
) -> Result<()> {
let (xpos, ypos) = (location.x, location.y); let (xpos, ypos) = (location.x, location.y);
// one cell after cursor position // one cell after cursor position
@ -207,7 +237,11 @@ pub fn clear_entire_screen(buffer_size: Size, current_attribute: u16) -> Result<
Ok(()) Ok(())
} }
pub fn clear_current_line(location: Coord, buffer_size: Size, current_attribute: u16) -> Result<()> { pub fn clear_current_line(
location: Coord,
buffer_size: Size,
current_attribute: u16,
) -> Result<()> {
// location where to start clearing // location where to start clearing
let start_location = Coord::new(0, location.y); let start_location = Coord::new(0, location.y);
@ -243,10 +277,8 @@ pub fn clear_until_line(location: Coord, buffer_size: Size, current_attribute: u
fn clear(start_location: Coord, cells_to_write: u32, current_attribute: u16) -> Result<()> { fn clear(start_location: Coord, cells_to_write: u32, current_attribute: u16) -> Result<()> {
let console = Console::from(Handle::current_out_handle()?); let console = Console::from(Handle::current_out_handle()?);
let _ = console let _ = console.fill_whit_character(start_location, cells_to_write, ' ')?;
.fill_whit_character(start_location, cells_to_write, ' ')?; console.fill_whit_attribute(start_location, cells_to_write, current_attribute)?;
console
.fill_whit_attribute(start_location, cells_to_write, current_attribute)?;
Ok(()) Ok(())
} }