Add clippy check to travis

This commit adds clippy as a required step of the build process. To make
this possible, all existing clippy issues have been resolved.
This commit is contained in:
Christian Duerr 2018-01-06 01:42:55 +00:00 committed by GitHub
parent 650b5a0cba
commit 2920cbe710
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 212 additions and 210 deletions

View File

@ -11,10 +11,19 @@ rust:
- stable
- nightly
env:
- FEATURES="clippy"
- FEATURES=""
matrix:
fast_finish: true
exclude:
- rust: stable
env: FEATURES="clippy"
- rust: nightly
env: FEATURES=""
allow_failures:
- rust: nightly
script:
- cargo test --no-default-features
- cargo test --no-default-features --features "$FEATURES"

View File

@ -360,6 +360,9 @@ pub enum CursorStyle {
/// Cursor is a vertical bar `⎸`
Beam,
/// Cursor is a box like `☐`
HollowBlock,
}
impl Default for CursorStyle {
@ -731,18 +734,16 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
// TODO replace OSC parsing with parser combinators
#[inline]
fn osc_dispatch(&mut self, params: &[&[u8]]) {
macro_rules! unhandled {
() => {{
let mut buf = String::new();
for items in params {
buf.push_str("[");
for item in *items {
buf.push_str(&format!("{:?},", *item as char));
}
buf.push_str("],");
fn unhandled(params: &[&[u8]]) {
let mut buf = String::new();
for items in params {
buf.push_str("[");
for item in *items {
buf.push_str(&format!("{:?},", *item as char));
}
warn!("[unhandled osc_dispatch]: [{}] at line {}", &buf, line!());
}}
buf.push_str("],");
}
warn!("[unhandled osc_dispatch]: [{}] at line {}", &buf, line!());
}
if params.is_empty() || params[0].is_empty() {
@ -752,13 +753,13 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
match params[0] {
// Set window title
b"0" | b"2" => {
if params.len() < 2 {
return unhandled!();
}
if let Ok(utf8_title) = str::from_utf8(params[1]) {
self.handler.set_title(utf8_title);
if params.len() >= 2 {
if let Ok(utf8_title) = str::from_utf8(params[1]) {
self.handler.set_title(utf8_title);
return;
}
}
unhandled(params);
},
// Set icon name
@ -767,70 +768,60 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
// Set color index
b"4" => {
if params.len() == 1 || params.len() % 2 == 0 {
return unhandled!();
}
for chunk in params[1..].chunks(2) {
if let Some(index) = parse_number(chunk[0]) {
if let Some(color) = parse_rgb_color(chunk[1]) {
self.handler.set_color(index as usize, color);
} else {
unhandled!();
if params.len() > 1 && params.len() % 2 != 0 {
for chunk in params[1..].chunks(2) {
let index = parse_number(chunk[0]);
let color = parse_rgb_color(chunk[0]);
if let (Some(i), Some(c)) = (index, color) {
self.handler.set_color(i as usize, c);
return;
}
} else {
unhandled!();
}
}
unhandled(params);
}
// Set foreground color
b"10" => {
if params.len() < 2 {
return unhandled!();
}
if let Some(color) = parse_rgb_color(params[1]) {
self.handler.set_color(NamedColor::Foreground as usize, color);
} else {
unhandled!()
if params.len() >= 2 {
if let Some(color) = parse_rgb_color(params[1]) {
self.handler.set_color(NamedColor::Foreground as usize, color);
return;
}
}
unhandled(params);
}
// Set background color
b"11" => {
if params.len() < 2 {
return unhandled!();
}
if let Some(color) = parse_rgb_color(params[1]) {
self.handler.set_color(NamedColor::Background as usize, color);
} else {
unhandled!()
if params.len() >= 2 {
if let Some(color) = parse_rgb_color(params[1]) {
self.handler.set_color(NamedColor::Background as usize, color);
return;
}
}
unhandled(params);
}
// Set text cursor color
b"12" => {
if params.len() < 2 {
return unhandled!();
}
if let Some(color) = parse_rgb_color(params[1]) {
self.handler.set_color(NamedColor::Cursor as usize, color);
} else {
unhandled!()
if params.len() >= 2 {
if let Some(color) = parse_rgb_color(params[1]) {
self.handler.set_color(NamedColor::Cursor as usize, color);
return;
}
}
unhandled(params);
}
// Set clipboard
b"52" => {
if params.len() < 3 {
return unhandled!();
return unhandled(params);
}
match params[2] {
b"?" => unhandled!(),
b"?" => unhandled(params),
selection => {
if let Ok(string) = base64::decode(selection) {
if let Ok(utf8_string) = str::from_utf8(&string) {
@ -855,29 +846,21 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
for param in &params[1..] {
match parse_number(param) {
Some(index) => self.handler.reset_color(index as usize),
None => unhandled!(),
None => unhandled(params),
}
}
}
// Reset foreground color
b"110" => {
self.handler.reset_color(NamedColor::Foreground as usize);
}
b"110" => self.handler.reset_color(NamedColor::Foreground as usize),
// Reset background color
b"111" => {
self.handler.reset_color(NamedColor::Background as usize);
}
b"111" => self.handler.reset_color(NamedColor::Background as usize),
// Reset text cursor color
b"112" => {
self.handler.reset_color(NamedColor::Cursor as usize);
}
b"112" => self.handler.reset_color(NamedColor::Cursor as usize),
_ => {
unhandled!();
}
_ => unhandled(params),
}
}
@ -1389,7 +1372,7 @@ mod tests {
use super::{Processor, Handler, Attr, TermInfo, Color, StandardCharset, CharsetIndex, parse_rgb_color, parse_number};
use ::Rgb;
/// The /dev/null of io::Write
/// The /dev/null of `io::Write`
struct Void;
impl io::Write for Void {

View File

@ -178,7 +178,7 @@ impl VisualBellConfig {
/// Visual bell duration in milliseconds
#[inline]
pub fn duration(&self) -> Duration {
Duration::from_millis(self.duration as u64)
Duration::from_millis(u64::from(self.duration))
}
}
@ -240,7 +240,7 @@ impl Alpha {
self.0 = Self::clamp_to_valid_range(value);
}
#[inline(always)]
#[inline]
pub fn get(&self) -> f32 {
self.0
}
@ -1152,8 +1152,7 @@ impl FromStr for Rgb {
impl ::std::error::Error for Error {
fn cause(&self) -> Option<&::std::error::Error> {
match *self {
Error::NotFound => None,
Error::Empty => None,
Error::NotFound | Error::Empty => None,
Error::ReadingEnvHome(ref err) => Some(err),
Error::Io(ref err) => Some(err),
Error::Yaml(ref err) => Some(err),
@ -1174,8 +1173,7 @@ impl ::std::error::Error for Error {
impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
match *self {
Error::NotFound => write!(f, "{}", ::std::error::Error::description(self)),
Error::Empty => write!(f, "{}", ::std::error::Error::description(self)),
Error::NotFound | Error::Empty => write!(f, "{}", ::std::error::Error::description(self)),
Error::ReadingEnvHome(ref err) => {
write!(f, "could not read $HOME environment variable: {}", err)
},
@ -1218,7 +1216,7 @@ impl Config {
/// 2. $XDG_CONFIG_HOME/alacritty.yml
/// 3. $HOME/.config/alacritty/alacritty.yml
/// 4. $HOME/.alacritty.yml
pub fn installed_config() -> Option<Cow<'static, Path>> {
pub fn installed_config<'a>() -> Option<Cow<'a, Path>> {
// Try using XDG location by default
::xdg::BaseDirectories::with_prefix("alacritty")
.ok()

View File

@ -228,7 +228,7 @@ impl Display {
})?;
let stop = init_start.elapsed();
let stop_f = stop.as_secs() as f64 + stop.subsec_nanos() as f64 / 1_000_000_000f64;
let stop_f = stop.as_secs() as f64 + f64::from(stop.subsec_nanos()) / 1_000_000_000f64;
info!("Finished initializing glyph cache in {}", stop_f);
cache
@ -238,8 +238,8 @@ impl Display {
// font metrics should be computed before creating the window in the first
// place so that a resize is not needed.
let metrics = glyph_cache.font_metrics();
let cell_width = (metrics.average_advance + font.offset().x as f64) as u32;
let cell_height = (metrics.line_height + font.offset().y as f64) as u32;
let cell_width = (metrics.average_advance + f64::from(font.offset().x)) as u32;
let cell_height = (metrics.line_height + f64::from(font.offset().y)) as u32;
Ok((glyph_cache, cell_width as f32, cell_height as f32))
}
@ -252,8 +252,8 @@ impl Display {
});
let metrics = cache.font_metrics();
self.size_info.cell_width = ((metrics.average_advance + config.font().offset().x as f64) as f32).floor();
self.size_info.cell_height = ((metrics.line_height + config.font().offset().y as f64) as f32).floor();
self.size_info.cell_width = ((metrics.average_advance + f64::from(config.font().offset().x)) as f32).floor();
self.size_info.cell_height = ((metrics.line_height + f64::from(config.font().offset().y)) as f32).floor();
}
#[inline]

View File

@ -56,8 +56,8 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
}
fn copy_selection(&self, buffer: ::copypasta::Buffer) {
if let &mut Some(ref selection) = self.selection {
selection.to_span(self.terminal as &Term)
if let Some(ref selection) = *self.selection {
selection.to_span(self.terminal)
.map(|span| {
let buf = self.terminal.string_from_selection(&span);
if !buf.is_empty() {
@ -79,7 +79,7 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
fn update_selection(&mut self, point: Point, side: Side) {
self.selection_modified = true;
// Update selection if one exists
if let &mut Some(ref mut selection) = self.selection {
if let Some(ref mut selection) = *self.selection {
selection.update(point, side);
return;
}
@ -94,7 +94,7 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
}
fn semantic_selection(&mut self, point: Point) {
*self.selection = Some(Selection::semantic(point, self.terminal as &Term));
*self.selection = Some(Selection::semantic(point, self.terminal));
self.selection_modified = true;
}
@ -255,8 +255,7 @@ impl<N: Notify> Processor<N> {
) {
match event {
// Pass on device events
Event::DeviceEvent { .. } => (),
Event::Suspended { .. } => (),
Event::DeviceEvent { .. } | Event::Suspended { .. } => (),
Event::WindowEvent { event, .. } => {
use glutin::WindowEvent::*;
match event {

View File

@ -90,9 +90,8 @@ impl event::Notify for Notifier {
if bytes.len() == 0 {
return
}
match self.0.send(Msg::Input(bytes)) {
Ok(_) => (),
Err(_) => panic!("expected send event loop msg"),
if self.0.send(Msg::Input(bytes)).is_err() {
panic!("expected send event loop msg");
}
}
}

View File

@ -151,14 +151,14 @@ impl<T> Grid<T> {
}
#[inline]
pub fn scroll_down(&mut self, region: Range<index::Line>, positions: index::Line) {
pub fn scroll_down(&mut self, region: &Range<index::Line>, positions: index::Line) {
for line in IndexRange((region.start + positions)..region.end).rev() {
self.swap_lines(line, line - positions);
}
}
#[inline]
pub fn scroll_up(&mut self, region: Range<index::Line>, positions: index::Line) {
pub fn scroll_up(&mut self, region: &Range<index::Line>, positions: index::Line) {
for line in IndexRange(region.start..(region.end - positions)) {
self.swap_lines(line, line + positions);
}
@ -618,7 +618,7 @@ mod tests {
info!("grid: {:?}", grid);
grid.scroll_up(Line(0)..Line(10), Line(2));
grid.scroll_up(&(Line(0)..Line(10)), Line(2));
info!("grid: {:?}", grid);
@ -652,7 +652,7 @@ mod tests {
info!("grid: {:?}", grid);
grid.scroll_down(Line(0)..Line(10), Line(2));
grid.scroll_down(&(Line(0)..Line(10)), Line(2));
info!("grid: {:?}", grid);

View File

@ -88,18 +88,18 @@ impl fmt::Display for Linear {
}
}
/// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
/// file at the top-level directory of this distribution and at
/// http://rust-lang.org/COPYRIGHT.
///
/// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
/// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
/// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
/// option. This file may not be copied, modified, or distributed
/// except according to those terms.
///
/// implements binary operators "&T op U", "T op &U", "&T op &U"
/// based on "T op U" where T and U are expected to be `Copy`able
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// implements binary operators "&T op U", "T op &U", "&T op &U"
// based on "T op U" where T and U are expected to be `Copy`able
macro_rules! forward_ref_binop {
(impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
impl<'a> $imp<$u> for &'a $t {

View File

@ -436,7 +436,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
let mut content = Vec::with_capacity(faux_scrollback_lines * 3);
for _ in 0..faux_scrollback_lines {
content.push(0x1b);
content.push('O' as u8);
content.push(b'O');
content.push(cmd);
}
self.ctx.write_to_pty(content);

View File

@ -15,6 +15,7 @@
//! Alacritty - The GPU Enhanced Terminal
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
#![cfg_attr(feature = "clippy", deny(clippy))]
#![cfg_attr(feature = "clippy", deny(enum_glob_use))]
#![cfg_attr(feature = "clippy", deny(if_not_else))]
#![cfg_attr(feature = "clippy", deny(wrong_pub_self_convention))]
@ -82,7 +83,7 @@ use std::ops::Mul;
pub use grid::Grid;
pub use term::Term;
/// Facade around [winit's MouseCursor](glutin::MouseCursor)
/// Facade around [winit's `MouseCursor`](glutin::MouseCursor)
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum MouseCursor {
Arrow,
@ -102,9 +103,9 @@ impl Mul<f32> for Rgb {
fn mul(self, rhs: f32) -> Rgb {
let result = Rgb {
r: (self.r as f32 * rhs).max(0.0).min(255.0) as u8,
g: (self.g as f32 * rhs).max(0.0).min(255.0) as u8,
b: (self.b as f32 * rhs).max(0.0).min(255.0) as u8
r: (f32::from(self.r) * rhs).max(0.0).min(255.0) as u8,
g: (f32::from(self.g) * rhs).max(0.0).min(255.0) as u8,
b: (f32::from(self.b) * rhs).max(0.0).min(255.0) as u8
};
trace!("Scaling RGB by {} from {:?} to {:?}", rhs, self, result);

View File

@ -28,6 +28,8 @@ pub struct Logger<T> {
}
impl<T: Send + io::Write> Logger<T> {
// False positive, see: https://github.com/rust-lang-nursery/rust-clippy/issues/734
#[cfg_attr(feature = "clippy", allow(new_ret_no_self))]
pub fn new(output: T, level: log::LogLevelFilter) -> Logger<io::LineWriter<T>> {
Logger {
level: level,

View File

@ -13,8 +13,14 @@
// limitations under the License.
//
//! Alacritty - The GPU Enhanced Terminal
#![cfg_attr(feature = "clippy", plugin(clippy))]
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
#![cfg_attr(feature = "clippy", deny(clippy))]
#![cfg_attr(feature = "clippy", deny(enum_glob_use))]
#![cfg_attr(feature = "clippy", deny(if_not_else))]
#![cfg_attr(feature = "clippy", deny(wrong_pub_self_convention))]
#![cfg_attr(feature = "nightly", feature(core_intrinsics))]
#![cfg_attr(all(test, feature = "bench"), feature(test))]
#[macro_use]
extern crate alacritty;
@ -64,7 +70,7 @@ fn main() {
/// /dev/null, we load the compiled-in defaults.
fn load_config(options: &cli::Options) -> Config {
let config_path = options.config_path()
.or_else(|| Config::installed_config())
.or_else(Config::installed_config)
.unwrap_or_else(|| {
Config::write_defaults()
.unwrap_or_else(|err| die!("Write defaults config failure: {}", err))
@ -116,7 +122,7 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> {
// The pty forks a process to run the shell on the slave side of the
// pseudoterminal. A file descriptor for the master side is retained for
// reading/writing to the shell.
let mut pty = tty::new(&config, options, display.size(), window_id);
let mut pty = tty::new(&config, options, &display.size(), window_id);
// Create the pseudoterminal I/O loop
//

View File

@ -103,7 +103,7 @@ impl Meter {
fn add_sample(&mut self, sample: Duration) {
let mut usec = 0f64;
usec += (sample.subsec_nanos() as f64) / 1e3;
usec += f64::from(sample.subsec_nanos()) / 1e3;
usec += (sample.as_secs() as f64) * 1e6;
let prev = self.times[self.index];

View File

@ -390,7 +390,7 @@ pub struct PackedVertex {
y: f32,
}
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Batch {
tex: GLuint,
instances: Vec<InstanceData>,
@ -428,13 +428,13 @@ impl Batch {
uv_width: glyph.uv_width,
uv_height: glyph.uv_height,
r: cell.fg.r as f32,
g: cell.fg.g as f32,
b: cell.fg.b as f32,
r: f32::from(cell.fg.r),
g: f32::from(cell.fg.g),
b: f32::from(cell.fg.b),
bg_r: cell.bg.r as f32,
bg_g: cell.bg.g as f32,
bg_b: cell.bg.b as f32,
bg_r: f32::from(cell.bg.r),
bg_g: f32::from(cell.bg.g),
bg_b: f32::from(cell.bg.b),
bg_a: cell.bg_alpha,
});
}
@ -739,9 +739,9 @@ impl<'a> RenderApi<'a> {
let alpha = self.config.background_opacity().get();
unsafe {
gl::ClearColor(
(self.visual_bell_intensity + color.r as f32 / 255.0).min(1.0) * alpha,
(self.visual_bell_intensity + color.g as f32 / 255.0).min(1.0) * alpha,
(self.visual_bell_intensity + color.b as f32 / 255.0).min(1.0) * alpha,
(self.visual_bell_intensity + f32::from(color.r) / 255.0).min(1.0) * alpha,
(self.visual_bell_intensity + f32::from(color.g) / 255.0).min(1.0) * alpha,
(self.visual_bell_intensity + f32::from(color.b) / 255.0).min(1.0) * alpha,
alpha
);
gl::Clear(gl::COLOR_BUFFER_BIT);
@ -1089,7 +1089,7 @@ impl ShaderProgram {
let mut success: GLint = 0;
gl::GetProgramiv(program, gl::LINK_STATUS, &mut success);
if success == (gl::TRUE as GLint) {
if success == i32::from(gl::TRUE) {
Ok(program)
} else {
Err(ShaderCreationError::Link(get_program_info_log(program)))
@ -1125,7 +1125,7 @@ impl ShaderProgram {
gl::GetShaderiv(shader, gl::COMPILE_STATUS, &mut success);
}
if success == (gl::TRUE as GLint) {
if success == GLint::from(gl::TRUE) {
Ok(shader)
} else {
// Read log

View File

@ -106,7 +106,7 @@ impl Selection {
}
}
pub fn semantic<G: SemanticSearch>(point: Point, grid: G) -> Selection {
pub fn semantic<G: SemanticSearch>(point: Point, grid: &G) -> Selection {
let (start, end) = (grid.semantic_search_left(point), grid.semantic_search_right(point));
Selection::Semantic {
region: Region {
@ -136,25 +136,24 @@ impl Selection {
Selection::Simple { ref mut region } => {
region.end = Anchor::new(location, side);
},
Selection::Semantic { ref mut region, .. } => {
Selection::Semantic { ref mut region, .. } |
Selection::Lines { ref mut region, .. } =>
{
region.end = location;
},
Selection::Lines { ref mut region, .. } => {
region.end = location;
}
}
}
pub fn to_span<G: SemanticSearch + Dimensions>(&self, grid: G) -> Option<Span> {
pub fn to_span<G: SemanticSearch + Dimensions>(&self, grid: &G) -> Option<Span> {
match *self {
Selection::Simple { ref region } => {
Selection::span_simple(&grid, region)
Selection::span_simple(grid, region)
},
Selection::Semantic { ref region, ref initial_expansion } => {
Selection::span_semantic(&grid, region, initial_expansion)
Selection::span_semantic(grid, region, initial_expansion)
},
Selection::Lines { ref region, ref initial_line } => {
Selection::span_lines(&grid, region, initial_line)
Selection::span_lines(grid, region, initial_line)
}
}
}
@ -409,7 +408,7 @@ mod test {
use super::{Selection, Span, SpanType};
struct Dimensions(Point);
impl<'a> super::Dimensions for &'a Dimensions {
impl super::Dimensions for Dimensions {
fn dimensions(&self) -> Point {
self.0
}
@ -424,7 +423,7 @@ mod test {
}
}
impl<'a> super::SemanticSearch for &'a Dimensions {
impl super::SemanticSearch for Dimensions {
fn semantic_search_left(&self, _: Point) -> Point { unimplemented!(); }
fn semantic_search_right(&self, _: Point) -> Point { unimplemented!(); }
}

View File

@ -18,15 +18,15 @@ use index::Column;
bitflags! {
#[derive(Serialize, Deserialize)]
pub struct Flags: u32 {
const INVERSE = 0b00000001;
const BOLD = 0b00000010;
const ITALIC = 0b00000100;
const UNDERLINE = 0b00001000;
const WRAPLINE = 0b00010000;
const WIDE_CHAR = 0b00100000;
const WIDE_CHAR_SPACER = 0b01000000;
const DIM = 0b10000000;
const DIM_BOLD = 0b10000010;
const INVERSE = 0b0000_0001;
const BOLD = 0b0000_0010;
const ITALIC = 0b0000_0100;
const UNDERLINE = 0b0000_1000;
const WRAPLINE = 0b0001_0000;
const WIDE_CHAR = 0b0010_0000;
const WIDE_CHAR_SPACER = 0b0100_0000;
const DIM = 0b1000_0000;
const DIM_BOLD = 0b1000_0010;
}
}
@ -92,7 +92,7 @@ impl Cell {
pub fn new(c: char, fg: Color, bg: Color) -> Cell {
Cell {
c: c.into(),
c: c,
bg: bg,
fg: fg,
flags: Flags::empty(),

View File

@ -36,7 +36,7 @@ pub mod color;
pub use self::cell::Cell;
use self::cell::LineLength;
impl<'a> selection::SemanticSearch for &'a Term {
impl selection::SemanticSearch for Term {
fn semantic_search_left(&self, mut point: Point) -> Point {
let mut iter = self.grid.iter_from(point);
let last_col = self.grid.num_cols() - Column(1);
@ -76,7 +76,7 @@ impl<'a> selection::SemanticSearch for &'a Term {
}
}
impl<'a> selection::Dimensions for &'a Term {
impl selection::Dimensions for Term {
fn dimensions(&self) -> Point {
Point {
col: self.grid.num_cols(),
@ -119,7 +119,6 @@ impl<'a> RenderableCellsIter<'a> {
config: &'b Config,
selection: Option<RangeInclusive<index::Linear>>,
cursor_style: CursorStyle,
window_focused: bool,
) -> RenderableCellsIter<'b> {
let cursor_index = Linear(cursor.line.0 * grid.num_cols().0 + cursor.col.0);
@ -134,7 +133,7 @@ impl<'a> RenderableCellsIter<'a> {
config: config,
colors: colors,
cursor_cells: ArrayDeque::new(),
}.initialize(cursor_style, window_focused)
}.initialize(cursor_style)
}
fn push_cursor_cells(
@ -214,6 +213,10 @@ impl<'a> RenderableCellsIter<'a> {
self.populate_char_cursor(font::BEAM_CURSOR_CHAR, ' ');
}
fn populate_box_cursor(&mut self) {
self.populate_char_cursor(font::BOX_CURSOR_CHAR, ' ');
}
#[inline]
fn is_wide_cursor(&self, cell: &Cell) -> bool {
cell.flags.contains(cell::Flags::WIDE_CHAR) && (self.cursor.col + 1) < self.grid.num_cols()
@ -237,22 +240,20 @@ impl<'a> RenderableCellsIter<'a> {
});
}
fn initialize(mut self, cursor_style: CursorStyle, window_focused: bool) -> Self {
fn initialize(mut self, cursor_style: CursorStyle) -> Self {
if self.cursor_is_visible() {
if !window_focused {
// Render the box cursor if the window is not focused
self.populate_char_cursor(font::BOX_CURSOR_CHAR, ' ');
} else {
match cursor_style {
CursorStyle::Block => {
self.populate_block_cursor();
},
CursorStyle::Beam => {
self.populate_beam_cursor();
},
CursorStyle::Underline => {
self.populate_underline_cursor();
}
match cursor_style {
CursorStyle::HollowBlock => {
self.populate_box_cursor();
},
CursorStyle::Block => {
self.populate_block_cursor();
},
CursorStyle::Beam => {
self.populate_beam_cursor();
},
CursorStyle::Underline => {
self.populate_underline_cursor();
}
}
} else {
@ -417,20 +418,20 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
pub mod mode {
bitflags! {
pub struct TermMode: u16 {
const SHOW_CURSOR = 0b0000000000001;
const APP_CURSOR = 0b0000000000010;
const APP_KEYPAD = 0b0000000000100;
const MOUSE_REPORT_CLICK = 0b0000000001000;
const BRACKETED_PASTE = 0b0000000010000;
const SGR_MOUSE = 0b0000000100000;
const MOUSE_MOTION = 0b0000001000000;
const LINE_WRAP = 0b0000010000000;
const LINE_FEED_NEW_LINE = 0b0000100000000;
const ORIGIN = 0b0001000000000;
const INSERT = 0b0010000000000;
const FOCUS_IN_OUT = 0b0100000000000;
const ALT_SCREEN = 0b1000000000000;
const ANY = 0b1111111111111;
const SHOW_CURSOR = 0b0_0000_0000_0001;
const APP_CURSOR = 0b0_0000_0000_0010;
const APP_KEYPAD = 0b0_0000_0000_0100;
const MOUSE_REPORT_CLICK = 0b0_0000_0000_1000;
const BRACKETED_PASTE = 0b0_0000_0001_0000;
const SGR_MOUSE = 0b0_0000_0010_0000;
const MOUSE_MOTION = 0b0_0000_0100_0000;
const LINE_WRAP = 0b0_0000_1000_0000;
const LINE_FEED_NEW_LINE = 0b0_0001_0000_0000;
const ORIGIN = 0b0_0010_0000_0000;
const INSERT = 0b0_0100_0000_0000;
const FOCUS_IN_OUT = 0b0_1000_0000_0000;
const ALT_SCREEN = 0b1_0000_0000_0000;
const ANY = 0b1_1111_1111_1111;
const NONE = 0;
}
}
@ -603,9 +604,9 @@ impl VisualBell {
let elapsed = instant.duration_since(earlier);
let elapsed_f = elapsed.as_secs() as f64 +
elapsed.subsec_nanos() as f64 / 1e9f64;
f64::from(elapsed.subsec_nanos()) / 1e9f64;
let duration_f = self.duration.as_secs() as f64 +
self.duration.subsec_nanos() as f64 / 1e9f64;
f64::from(self.duration.subsec_nanos()) / 1e9f64;
// Otherwise, we compute a value `time` from 0.0 to 1.0
// inclusive that represents the ratio of `elapsed` time to the
@ -616,8 +617,9 @@ impl VisualBell {
// VisualBell. When `time` is 0.0, `inverse_intensity` is 0.0,
// and when `time` is 1.0, `inverse_intensity` is 1.0.
let inverse_intensity = match self.animation {
VisualBellAnimation::Ease => cubic_bezier(0.25, 0.1, 0.25, 1.0, time),
VisualBellAnimation::EaseOut => cubic_bezier(0.25, 0.1, 0.25, 1.0, time),
VisualBellAnimation::Ease | VisualBellAnimation::EaseOut => {
cubic_bezier(0.25, 0.1, 0.25, 1.0, time)
},
VisualBellAnimation::EaseOutSine => cubic_bezier(0.39, 0.575, 0.565, 1.0, time),
VisualBellAnimation::EaseOutQuad => cubic_bezier(0.25, 0.46, 0.45, 0.94, time),
VisualBellAnimation::EaseOutCubic => cubic_bezier(0.215, 0.61, 0.355, 1.0, time),
@ -840,7 +842,7 @@ impl Term {
pub fn change_font_size(&mut self, delta: i8) {
// Saturating addition with minimum font size 1
let new_size = self.font_size + Size::new(delta as f32);
let new_size = self.font_size + Size::new(f32::from(delta));
self.font_size = max(new_size, Size::new(1.));
self.dirty = true;
}
@ -993,6 +995,11 @@ impl Term {
) -> RenderableCellsIter {
let selection = selection.and_then(|s| s.to_span(self))
.map(|span| span.to_range());
let cursor = if window_focused {
self.cursor_style.unwrap_or(self.default_cursor_style)
} else {
CursorStyle::HollowBlock
};
RenderableCellsIter::new(
&self.grid,
@ -1001,8 +1008,7 @@ impl Term {
self.mode,
config,
selection,
self.cursor_style.unwrap_or(self.default_cursor_style),
window_focused,
cursor,
)
}
@ -1046,13 +1052,13 @@ impl Term {
// Scroll up to keep cursor in terminal
if self.cursor.point.line >= num_lines {
let lines = self.cursor.point.line - num_lines + 1;
self.grid.scroll_up(Line(0)..old_lines, lines);
self.grid.scroll_up(&(Line(0)..old_lines), lines);
}
// Scroll up alt grid as well
if self.cursor_save_alt.point.line >= num_lines {
let lines = self.cursor_save_alt.point.line - num_lines + 1;
self.alt_grid.scroll_up(Line(0)..old_lines, lines);
self.alt_grid.scroll_up(&(Line(0)..old_lines), lines);
}
debug!("num_cols, num_lines = {}, {}", num_cols, num_lines);
@ -1131,7 +1137,7 @@ impl Term {
}
// Scroll between origin and bottom
self.grid.scroll_down(origin..self.scroll_region.end, lines);
self.grid.scroll_down(&(origin..self.scroll_region.end), lines);
}
/// Scroll screen up
@ -1153,7 +1159,7 @@ impl Term {
}
// Scroll from origin to bottom less number of lines
self.grid.scroll_up(origin..self.scroll_region.end, lines);
self.grid.scroll_up(&(origin..self.scroll_region.end), lines);
}
fn deccolm(&mut self) {
@ -1262,13 +1268,11 @@ impl ansi::Handler for Term {
}
// Set spacer cell for wide chars.
if width == 2 {
if self.cursor.point.col + 1 < num_cols {
self.cursor.point.col += 1;
let spacer = &mut self.grid[&self.cursor.point];
*spacer = self.cursor.template;
spacer.flags.insert(cell::Flags::WIDE_CHAR_SPACER);
}
if width == 2 && self.cursor.point.col + 1 < num_cols {
self.cursor.point.col += 1;
let spacer = &mut self.grid[&self.cursor.point];
*spacer = self.cursor.template;
spacer.flags.insert(cell::Flags::WIDE_CHAR_SPACER);
}
}
}
@ -1987,9 +1991,8 @@ mod tests {
mem::swap(&mut term.grid, &mut grid);
let selection = Selection::lines(Point { line: Line(0), col: Column(3) });
match selection.to_span(&term) {
Some(span) => assert_eq!(term.string_from_selection(&span), "\"aa\"a\n"),
_ => ()
if let Some(span) = selection.to_span(&term) {
assert_eq!(term.string_from_selection(&span), "\"aa\"a\n");
}
}

View File

@ -70,8 +70,8 @@ fn openpty(rows: u8, cols: u8) -> (c_int, c_int) {
let mut slave: c_int = 0;
let win = winsize {
ws_row: rows as libc::c_ushort,
ws_col: cols as libc::c_ushort,
ws_row: libc::c_ushort::from(rows),
ws_col: libc::c_ushort::from(cols),
ws_xpixel: 0,
ws_ypixel: 0,
};
@ -93,8 +93,8 @@ fn openpty(rows: u8, cols: u8) -> (c_int, c_int) {
let mut slave: c_int = 0;
let mut win = winsize {
ws_row: rows as libc::c_ushort,
ws_col: cols as libc::c_ushort,
ws_row: libc::c_ushort::from(rows),
ws_col: libc::c_ushort::from(cols),
ws_xpixel: 0,
ws_ypixel: 0,
};
@ -113,7 +113,10 @@ fn openpty(rows: u8, cols: u8) -> (c_int, c_int) {
/// Really only needed on BSD, but should be fine elsewhere
fn set_controlling_terminal(fd: c_int) {
let res = unsafe {
libc::ioctl(fd, TIOCSCTTY as _, 0)
// Cross platform issue because on linux this is u64 as u64 (does nothing)
// But on macos this is u32 as u64, asking for u64::from(u32)
#[cfg_attr(feature = "clippy", allow(cast_lossless))]
libc::ioctl(fd, TIOCSCTTY as u64, 0)
};
if res < 0 {
@ -174,7 +177,7 @@ fn get_pw_entry(buf: &mut [i8; 1024]) -> Passwd {
}
/// Create a new tty and return a handle to interact with it.
pub fn new<T: ToWinsize>(config: &Config, options: &Options, size: T, window_id: Option<usize>) -> Pty {
pub fn new<T: ToWinsize>(config: &Config, options: &Options, size: &T, window_id: Option<usize>) -> Pty {
let win = size.to_winsize();
let mut buf = [0; 1024];
let pw = get_pw_entry(&mut buf);
@ -262,7 +265,7 @@ pub fn new<T: ToWinsize>(config: &Config, options: &Options, size: T, window_id:
}
let pty = Pty { fd: master };
pty.resize(&size);
pty.resize(size);
pty
},
Err(err) => {