mirror of
https://github.com/alacritty/alacritty.git
synced 2024-11-18 13:55:23 -05:00
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:
parent
650b5a0cba
commit
2920cbe710
18 changed files with 212 additions and 210 deletions
11
.travis.yml
11
.travis.yml
|
@ -11,10 +11,19 @@ rust:
|
||||||
- stable
|
- stable
|
||||||
- nightly
|
- nightly
|
||||||
|
|
||||||
|
env:
|
||||||
|
- FEATURES="clippy"
|
||||||
|
- FEATURES=""
|
||||||
|
|
||||||
matrix:
|
matrix:
|
||||||
fast_finish: true
|
fast_finish: true
|
||||||
|
exclude:
|
||||||
|
- rust: stable
|
||||||
|
env: FEATURES="clippy"
|
||||||
|
- rust: nightly
|
||||||
|
env: FEATURES=""
|
||||||
allow_failures:
|
allow_failures:
|
||||||
- rust: nightly
|
- rust: nightly
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- cargo test --no-default-features
|
- cargo test --no-default-features --features "$FEATURES"
|
||||||
|
|
89
src/ansi.rs
89
src/ansi.rs
|
@ -360,6 +360,9 @@ pub enum CursorStyle {
|
||||||
|
|
||||||
/// Cursor is a vertical bar `⎸`
|
/// Cursor is a vertical bar `⎸`
|
||||||
Beam,
|
Beam,
|
||||||
|
|
||||||
|
/// Cursor is a box like `☐`
|
||||||
|
HollowBlock,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CursorStyle {
|
impl Default for CursorStyle {
|
||||||
|
@ -731,8 +734,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
|
||||||
// TODO replace OSC parsing with parser combinators
|
// TODO replace OSC parsing with parser combinators
|
||||||
#[inline]
|
#[inline]
|
||||||
fn osc_dispatch(&mut self, params: &[&[u8]]) {
|
fn osc_dispatch(&mut self, params: &[&[u8]]) {
|
||||||
macro_rules! unhandled {
|
fn unhandled(params: &[&[u8]]) {
|
||||||
() => {{
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
for items in params {
|
for items in params {
|
||||||
buf.push_str("[");
|
buf.push_str("[");
|
||||||
|
@ -742,7 +744,6 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
|
||||||
buf.push_str("],");
|
buf.push_str("],");
|
||||||
}
|
}
|
||||||
warn!("[unhandled osc_dispatch]: [{}] at line {}", &buf, line!());
|
warn!("[unhandled osc_dispatch]: [{}] at line {}", &buf, line!());
|
||||||
}}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.is_empty() || params[0].is_empty() {
|
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] {
|
match params[0] {
|
||||||
// Set window title
|
// Set window title
|
||||||
b"0" | b"2" => {
|
b"0" | b"2" => {
|
||||||
if params.len() < 2 {
|
if params.len() >= 2 {
|
||||||
return unhandled!();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Ok(utf8_title) = str::from_utf8(params[1]) {
|
if let Ok(utf8_title) = str::from_utf8(params[1]) {
|
||||||
self.handler.set_title(utf8_title);
|
self.handler.set_title(utf8_title);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
unhandled(params);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set icon name
|
// Set icon name
|
||||||
|
@ -767,70 +768,60 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
|
||||||
|
|
||||||
// Set color index
|
// Set color index
|
||||||
b"4" => {
|
b"4" => {
|
||||||
if params.len() == 1 || params.len() % 2 == 0 {
|
if params.len() > 1 && params.len() % 2 != 0 {
|
||||||
return unhandled!();
|
|
||||||
}
|
|
||||||
|
|
||||||
for chunk in params[1..].chunks(2) {
|
for chunk in params[1..].chunks(2) {
|
||||||
if let Some(index) = parse_number(chunk[0]) {
|
let index = parse_number(chunk[0]);
|
||||||
if let Some(color) = parse_rgb_color(chunk[1]) {
|
let color = parse_rgb_color(chunk[0]);
|
||||||
self.handler.set_color(index as usize, color);
|
if let (Some(i), Some(c)) = (index, color) {
|
||||||
} else {
|
self.handler.set_color(i as usize, c);
|
||||||
unhandled!();
|
return;
|
||||||
}
|
|
||||||
} else {
|
|
||||||
unhandled!();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unhandled(params);
|
||||||
|
}
|
||||||
|
|
||||||
// Set foreground color
|
// Set foreground color
|
||||||
b"10" => {
|
b"10" => {
|
||||||
if params.len() < 2 {
|
if params.len() >= 2 {
|
||||||
return unhandled!();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(color) = parse_rgb_color(params[1]) {
|
if let Some(color) = parse_rgb_color(params[1]) {
|
||||||
self.handler.set_color(NamedColor::Foreground as usize, color);
|
self.handler.set_color(NamedColor::Foreground as usize, color);
|
||||||
} else {
|
return;
|
||||||
unhandled!()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unhandled(params);
|
||||||
|
}
|
||||||
|
|
||||||
// Set background color
|
// Set background color
|
||||||
b"11" => {
|
b"11" => {
|
||||||
if params.len() < 2 {
|
if params.len() >= 2 {
|
||||||
return unhandled!();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(color) = parse_rgb_color(params[1]) {
|
if let Some(color) = parse_rgb_color(params[1]) {
|
||||||
self.handler.set_color(NamedColor::Background as usize, color);
|
self.handler.set_color(NamedColor::Background as usize, color);
|
||||||
} else {
|
return;
|
||||||
unhandled!()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unhandled(params);
|
||||||
|
}
|
||||||
|
|
||||||
// Set text cursor color
|
// Set text cursor color
|
||||||
b"12" => {
|
b"12" => {
|
||||||
if params.len() < 2 {
|
if params.len() >= 2 {
|
||||||
return unhandled!();
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(color) = parse_rgb_color(params[1]) {
|
if let Some(color) = parse_rgb_color(params[1]) {
|
||||||
self.handler.set_color(NamedColor::Cursor as usize, color);
|
self.handler.set_color(NamedColor::Cursor as usize, color);
|
||||||
} else {
|
return;
|
||||||
unhandled!()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unhandled(params);
|
||||||
|
}
|
||||||
|
|
||||||
// Set clipboard
|
// Set clipboard
|
||||||
b"52" => {
|
b"52" => {
|
||||||
if params.len() < 3 {
|
if params.len() < 3 {
|
||||||
return unhandled!();
|
return unhandled(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
match params[2] {
|
match params[2] {
|
||||||
b"?" => unhandled!(),
|
b"?" => unhandled(params),
|
||||||
selection => {
|
selection => {
|
||||||
if let Ok(string) = base64::decode(selection) {
|
if let Ok(string) = base64::decode(selection) {
|
||||||
if let Ok(utf8_string) = str::from_utf8(&string) {
|
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 ¶ms[1..] {
|
for param in ¶ms[1..] {
|
||||||
match parse_number(param) {
|
match parse_number(param) {
|
||||||
Some(index) => self.handler.reset_color(index as usize),
|
Some(index) => self.handler.reset_color(index as usize),
|
||||||
None => unhandled!(),
|
None => unhandled(params),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset foreground color
|
// Reset foreground color
|
||||||
b"110" => {
|
b"110" => self.handler.reset_color(NamedColor::Foreground as usize),
|
||||||
self.handler.reset_color(NamedColor::Foreground as usize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset background color
|
// Reset background color
|
||||||
b"111" => {
|
b"111" => self.handler.reset_color(NamedColor::Background as usize),
|
||||||
self.handler.reset_color(NamedColor::Background as usize);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset text cursor color
|
// Reset text cursor color
|
||||||
b"112" => {
|
b"112" => self.handler.reset_color(NamedColor::Cursor as usize),
|
||||||
self.handler.reset_color(NamedColor::Cursor as usize);
|
|
||||||
}
|
|
||||||
|
|
||||||
_ => {
|
_ => unhandled(params),
|
||||||
unhandled!();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1389,7 +1372,7 @@ mod tests {
|
||||||
use super::{Processor, Handler, Attr, TermInfo, Color, StandardCharset, CharsetIndex, parse_rgb_color, parse_number};
|
use super::{Processor, Handler, Attr, TermInfo, Color, StandardCharset, CharsetIndex, parse_rgb_color, parse_number};
|
||||||
use ::Rgb;
|
use ::Rgb;
|
||||||
|
|
||||||
/// The /dev/null of io::Write
|
/// The /dev/null of `io::Write`
|
||||||
struct Void;
|
struct Void;
|
||||||
|
|
||||||
impl io::Write for Void {
|
impl io::Write for Void {
|
||||||
|
|
|
@ -178,7 +178,7 @@ impl VisualBellConfig {
|
||||||
/// Visual bell duration in milliseconds
|
/// Visual bell duration in milliseconds
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn duration(&self) -> Duration {
|
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);
|
self.0 = Self::clamp_to_valid_range(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline]
|
||||||
pub fn get(&self) -> f32 {
|
pub fn get(&self) -> f32 {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
|
@ -1152,8 +1152,7 @@ impl FromStr for Rgb {
|
||||||
impl ::std::error::Error for Error {
|
impl ::std::error::Error for Error {
|
||||||
fn cause(&self) -> Option<&::std::error::Error> {
|
fn cause(&self) -> Option<&::std::error::Error> {
|
||||||
match *self {
|
match *self {
|
||||||
Error::NotFound => None,
|
Error::NotFound | Error::Empty => None,
|
||||||
Error::Empty => None,
|
|
||||||
Error::ReadingEnvHome(ref err) => Some(err),
|
Error::ReadingEnvHome(ref err) => Some(err),
|
||||||
Error::Io(ref err) => Some(err),
|
Error::Io(ref err) => Some(err),
|
||||||
Error::Yaml(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 {
|
impl ::std::fmt::Display for Error {
|
||||||
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||||
match *self {
|
match *self {
|
||||||
Error::NotFound => write!(f, "{}", ::std::error::Error::description(self)),
|
Error::NotFound | Error::Empty => write!(f, "{}", ::std::error::Error::description(self)),
|
||||||
Error::Empty => write!(f, "{}", ::std::error::Error::description(self)),
|
|
||||||
Error::ReadingEnvHome(ref err) => {
|
Error::ReadingEnvHome(ref err) => {
|
||||||
write!(f, "could not read $HOME environment variable: {}", err)
|
write!(f, "could not read $HOME environment variable: {}", err)
|
||||||
},
|
},
|
||||||
|
@ -1218,7 +1216,7 @@ impl Config {
|
||||||
/// 2. $XDG_CONFIG_HOME/alacritty.yml
|
/// 2. $XDG_CONFIG_HOME/alacritty.yml
|
||||||
/// 3. $HOME/.config/alacritty/alacritty.yml
|
/// 3. $HOME/.config/alacritty/alacritty.yml
|
||||||
/// 4. $HOME/.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
|
// Try using XDG location by default
|
||||||
::xdg::BaseDirectories::with_prefix("alacritty")
|
::xdg::BaseDirectories::with_prefix("alacritty")
|
||||||
.ok()
|
.ok()
|
||||||
|
|
|
@ -228,7 +228,7 @@ impl Display {
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let stop = init_start.elapsed();
|
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);
|
info!("Finished initializing glyph cache in {}", stop_f);
|
||||||
|
|
||||||
cache
|
cache
|
||||||
|
@ -238,8 +238,8 @@ impl Display {
|
||||||
// font metrics should be computed before creating the window in the first
|
// font metrics should be computed before creating the window in the first
|
||||||
// place so that a resize is not needed.
|
// place so that a resize is not needed.
|
||||||
let metrics = glyph_cache.font_metrics();
|
let metrics = glyph_cache.font_metrics();
|
||||||
let cell_width = (metrics.average_advance + font.offset().x as f64) as u32;
|
let cell_width = (metrics.average_advance + f64::from(font.offset().x)) as u32;
|
||||||
let cell_height = (metrics.line_height + font.offset().y as f64) 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))
|
Ok((glyph_cache, cell_width as f32, cell_height as f32))
|
||||||
}
|
}
|
||||||
|
@ -252,8 +252,8 @@ impl Display {
|
||||||
});
|
});
|
||||||
|
|
||||||
let metrics = cache.font_metrics();
|
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_width = ((metrics.average_advance + f64::from(config.font().offset().x)) as f32).floor();
|
||||||
self.size_info.cell_height = ((metrics.line_height + config.font().offset().y as f64) as f32).floor();
|
self.size_info.cell_height = ((metrics.line_height + f64::from(config.font().offset().y)) as f32).floor();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
11
src/event.rs
11
src/event.rs
|
@ -56,8 +56,8 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn copy_selection(&self, buffer: ::copypasta::Buffer) {
|
fn copy_selection(&self, buffer: ::copypasta::Buffer) {
|
||||||
if let &mut Some(ref selection) = self.selection {
|
if let Some(ref selection) = *self.selection {
|
||||||
selection.to_span(self.terminal as &Term)
|
selection.to_span(self.terminal)
|
||||||
.map(|span| {
|
.map(|span| {
|
||||||
let buf = self.terminal.string_from_selection(&span);
|
let buf = self.terminal.string_from_selection(&span);
|
||||||
if !buf.is_empty() {
|
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) {
|
fn update_selection(&mut self, point: Point, side: Side) {
|
||||||
self.selection_modified = true;
|
self.selection_modified = true;
|
||||||
// Update selection if one exists
|
// 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);
|
selection.update(point, side);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -94,7 +94,7 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn semantic_selection(&mut self, point: Point) {
|
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;
|
self.selection_modified = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -255,8 +255,7 @@ impl<N: Notify> Processor<N> {
|
||||||
) {
|
) {
|
||||||
match event {
|
match event {
|
||||||
// Pass on device events
|
// Pass on device events
|
||||||
Event::DeviceEvent { .. } => (),
|
Event::DeviceEvent { .. } | Event::Suspended { .. } => (),
|
||||||
Event::Suspended { .. } => (),
|
|
||||||
Event::WindowEvent { event, .. } => {
|
Event::WindowEvent { event, .. } => {
|
||||||
use glutin::WindowEvent::*;
|
use glutin::WindowEvent::*;
|
||||||
match event {
|
match event {
|
||||||
|
|
|
@ -90,9 +90,8 @@ impl event::Notify for Notifier {
|
||||||
if bytes.len() == 0 {
|
if bytes.len() == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
match self.0.send(Msg::Input(bytes)) {
|
if self.0.send(Msg::Input(bytes)).is_err() {
|
||||||
Ok(_) => (),
|
panic!("expected send event loop msg");
|
||||||
Err(_) => panic!("expected send event loop msg"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,14 +151,14 @@ impl<T> Grid<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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() {
|
for line in IndexRange((region.start + positions)..region.end).rev() {
|
||||||
self.swap_lines(line, line - positions);
|
self.swap_lines(line, line - positions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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)) {
|
for line in IndexRange(region.start..(region.end - positions)) {
|
||||||
self.swap_lines(line, line + positions);
|
self.swap_lines(line, line + positions);
|
||||||
}
|
}
|
||||||
|
@ -618,7 +618,7 @@ mod tests {
|
||||||
|
|
||||||
info!("grid: {:?}", grid);
|
info!("grid: {:?}", grid);
|
||||||
|
|
||||||
grid.scroll_up(Line(0)..Line(10), Line(2));
|
grid.scroll_up(&(Line(0)..Line(10)), Line(2));
|
||||||
|
|
||||||
info!("grid: {:?}", grid);
|
info!("grid: {:?}", grid);
|
||||||
|
|
||||||
|
@ -652,7 +652,7 @@ mod tests {
|
||||||
|
|
||||||
info!("grid: {:?}", grid);
|
info!("grid: {:?}", grid);
|
||||||
|
|
||||||
grid.scroll_down(Line(0)..Line(10), Line(2));
|
grid.scroll_down(&(Line(0)..Line(10)), Line(2));
|
||||||
|
|
||||||
info!("grid: {:?}", grid);
|
info!("grid: {:?}", grid);
|
||||||
|
|
||||||
|
|
24
src/index.rs
24
src/index.rs
|
@ -88,18 +88,18 @@ impl fmt::Display for Linear {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
||||||
/// file at the top-level directory of this distribution and at
|
// file at the top-level directory of this distribution and at
|
||||||
/// http://rust-lang.org/COPYRIGHT.
|
// http://rust-lang.org/COPYRIGHT.
|
||||||
///
|
//
|
||||||
/// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||||
/// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||||
/// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||||
/// option. This file may not be copied, modified, or distributed
|
// option. This file may not be copied, modified, or distributed
|
||||||
/// except according to those terms.
|
// except according to those terms.
|
||||||
///
|
//
|
||||||
/// implements binary operators "&T op U", "T op &U", "&T op &U"
|
// 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
|
// based on "T op U" where T and U are expected to be `Copy`able
|
||||||
macro_rules! forward_ref_binop {
|
macro_rules! forward_ref_binop {
|
||||||
(impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
|
(impl $imp:ident, $method:ident for $t:ty, $u:ty) => {
|
||||||
impl<'a> $imp<$u> for &'a $t {
|
impl<'a> $imp<$u> for &'a $t {
|
||||||
|
|
|
@ -436,7 +436,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
|
||||||
let mut content = Vec::with_capacity(faux_scrollback_lines * 3);
|
let mut content = Vec::with_capacity(faux_scrollback_lines * 3);
|
||||||
for _ in 0..faux_scrollback_lines {
|
for _ in 0..faux_scrollback_lines {
|
||||||
content.push(0x1b);
|
content.push(0x1b);
|
||||||
content.push('O' as u8);
|
content.push(b'O');
|
||||||
content.push(cmd);
|
content.push(cmd);
|
||||||
}
|
}
|
||||||
self.ctx.write_to_pty(content);
|
self.ctx.write_to_pty(content);
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
//! Alacritty - The GPU Enhanced Terminal
|
//! Alacritty - The GPU Enhanced Terminal
|
||||||
#![cfg_attr(feature = "clippy", feature(plugin))]
|
#![cfg_attr(feature = "clippy", feature(plugin))]
|
||||||
#![cfg_attr(feature = "clippy", plugin(clippy))]
|
#![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(enum_glob_use))]
|
||||||
#![cfg_attr(feature = "clippy", deny(if_not_else))]
|
#![cfg_attr(feature = "clippy", deny(if_not_else))]
|
||||||
#![cfg_attr(feature = "clippy", deny(wrong_pub_self_convention))]
|
#![cfg_attr(feature = "clippy", deny(wrong_pub_self_convention))]
|
||||||
|
@ -82,7 +83,7 @@ use std::ops::Mul;
|
||||||
pub use grid::Grid;
|
pub use grid::Grid;
|
||||||
pub use term::Term;
|
pub use term::Term;
|
||||||
|
|
||||||
/// Facade around [winit's MouseCursor](glutin::MouseCursor)
|
/// Facade around [winit's `MouseCursor`](glutin::MouseCursor)
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||||
pub enum MouseCursor {
|
pub enum MouseCursor {
|
||||||
Arrow,
|
Arrow,
|
||||||
|
@ -102,9 +103,9 @@ impl Mul<f32> for Rgb {
|
||||||
|
|
||||||
fn mul(self, rhs: f32) -> Rgb {
|
fn mul(self, rhs: f32) -> Rgb {
|
||||||
let result = Rgb {
|
let result = Rgb {
|
||||||
r: (self.r 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: (self.g as f32 * rhs).max(0.0).min(255.0) as u8,
|
g: (f32::from(self.g) * rhs).max(0.0).min(255.0) as u8,
|
||||||
b: (self.b as f32 * 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);
|
trace!("Scaling RGB by {} from {:?} to {:?}", rhs, self, result);
|
||||||
|
|
|
@ -28,6 +28,8 @@ pub struct Logger<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: Send + io::Write> 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>> {
|
pub fn new(output: T, level: log::LogLevelFilter) -> Logger<io::LineWriter<T>> {
|
||||||
Logger {
|
Logger {
|
||||||
level: level,
|
level: level,
|
||||||
|
|
12
src/main.rs
12
src/main.rs
|
@ -13,8 +13,14 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
//
|
//
|
||||||
//! Alacritty - The GPU Enhanced Terminal
|
//! Alacritty - The GPU Enhanced Terminal
|
||||||
#![cfg_attr(feature = "clippy", plugin(clippy))]
|
|
||||||
#![cfg_attr(feature = "clippy", feature(plugin))]
|
#![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]
|
#[macro_use]
|
||||||
extern crate alacritty;
|
extern crate alacritty;
|
||||||
|
@ -64,7 +70,7 @@ fn main() {
|
||||||
/// /dev/null, we load the compiled-in defaults.
|
/// /dev/null, we load the compiled-in defaults.
|
||||||
fn load_config(options: &cli::Options) -> Config {
|
fn load_config(options: &cli::Options) -> Config {
|
||||||
let config_path = options.config_path()
|
let config_path = options.config_path()
|
||||||
.or_else(|| Config::installed_config())
|
.or_else(Config::installed_config)
|
||||||
.unwrap_or_else(|| {
|
.unwrap_or_else(|| {
|
||||||
Config::write_defaults()
|
Config::write_defaults()
|
||||||
.unwrap_or_else(|err| die!("Write defaults config failure: {}", err))
|
.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
|
// 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
|
// pseudoterminal. A file descriptor for the master side is retained for
|
||||||
// reading/writing to the shell.
|
// 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
|
// Create the pseudoterminal I/O loop
|
||||||
//
|
//
|
||||||
|
|
|
@ -103,7 +103,7 @@ impl Meter {
|
||||||
fn add_sample(&mut self, sample: Duration) {
|
fn add_sample(&mut self, sample: Duration) {
|
||||||
let mut usec = 0f64;
|
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;
|
usec += (sample.as_secs() as f64) * 1e6;
|
||||||
|
|
||||||
let prev = self.times[self.index];
|
let prev = self.times[self.index];
|
||||||
|
|
|
@ -390,7 +390,7 @@ pub struct PackedVertex {
|
||||||
y: f32,
|
y: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct Batch {
|
pub struct Batch {
|
||||||
tex: GLuint,
|
tex: GLuint,
|
||||||
instances: Vec<InstanceData>,
|
instances: Vec<InstanceData>,
|
||||||
|
@ -428,13 +428,13 @@ impl Batch {
|
||||||
uv_width: glyph.uv_width,
|
uv_width: glyph.uv_width,
|
||||||
uv_height: glyph.uv_height,
|
uv_height: glyph.uv_height,
|
||||||
|
|
||||||
r: cell.fg.r as f32,
|
r: f32::from(cell.fg.r),
|
||||||
g: cell.fg.g as f32,
|
g: f32::from(cell.fg.g),
|
||||||
b: cell.fg.b as f32,
|
b: f32::from(cell.fg.b),
|
||||||
|
|
||||||
bg_r: cell.bg.r as f32,
|
bg_r: f32::from(cell.bg.r),
|
||||||
bg_g: cell.bg.g as f32,
|
bg_g: f32::from(cell.bg.g),
|
||||||
bg_b: cell.bg.b as f32,
|
bg_b: f32::from(cell.bg.b),
|
||||||
bg_a: cell.bg_alpha,
|
bg_a: cell.bg_alpha,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -739,9 +739,9 @@ impl<'a> RenderApi<'a> {
|
||||||
let alpha = self.config.background_opacity().get();
|
let alpha = self.config.background_opacity().get();
|
||||||
unsafe {
|
unsafe {
|
||||||
gl::ClearColor(
|
gl::ClearColor(
|
||||||
(self.visual_bell_intensity + color.r 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 + color.g as f32 / 255.0).min(1.0) * alpha,
|
(self.visual_bell_intensity + f32::from(color.g) / 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.b) / 255.0).min(1.0) * alpha,
|
||||||
alpha
|
alpha
|
||||||
);
|
);
|
||||||
gl::Clear(gl::COLOR_BUFFER_BIT);
|
gl::Clear(gl::COLOR_BUFFER_BIT);
|
||||||
|
@ -1089,7 +1089,7 @@ impl ShaderProgram {
|
||||||
let mut success: GLint = 0;
|
let mut success: GLint = 0;
|
||||||
gl::GetProgramiv(program, gl::LINK_STATUS, &mut success);
|
gl::GetProgramiv(program, gl::LINK_STATUS, &mut success);
|
||||||
|
|
||||||
if success == (gl::TRUE as GLint) {
|
if success == i32::from(gl::TRUE) {
|
||||||
Ok(program)
|
Ok(program)
|
||||||
} else {
|
} else {
|
||||||
Err(ShaderCreationError::Link(get_program_info_log(program)))
|
Err(ShaderCreationError::Link(get_program_info_log(program)))
|
||||||
|
@ -1125,7 +1125,7 @@ impl ShaderProgram {
|
||||||
gl::GetShaderiv(shader, gl::COMPILE_STATUS, &mut success);
|
gl::GetShaderiv(shader, gl::COMPILE_STATUS, &mut success);
|
||||||
}
|
}
|
||||||
|
|
||||||
if success == (gl::TRUE as GLint) {
|
if success == GLint::from(gl::TRUE) {
|
||||||
Ok(shader)
|
Ok(shader)
|
||||||
} else {
|
} else {
|
||||||
// Read log
|
// Read log
|
||||||
|
|
|
@ -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));
|
let (start, end) = (grid.semantic_search_left(point), grid.semantic_search_right(point));
|
||||||
Selection::Semantic {
|
Selection::Semantic {
|
||||||
region: Region {
|
region: Region {
|
||||||
|
@ -136,25 +136,24 @@ impl Selection {
|
||||||
Selection::Simple { ref mut region } => {
|
Selection::Simple { ref mut region } => {
|
||||||
region.end = Anchor::new(location, side);
|
region.end = Anchor::new(location, side);
|
||||||
},
|
},
|
||||||
Selection::Semantic { ref mut region, .. } => {
|
Selection::Semantic { ref mut region, .. } |
|
||||||
|
Selection::Lines { ref mut region, .. } =>
|
||||||
|
{
|
||||||
region.end = location;
|
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 {
|
match *self {
|
||||||
Selection::Simple { ref region } => {
|
Selection::Simple { ref region } => {
|
||||||
Selection::span_simple(&grid, region)
|
Selection::span_simple(grid, region)
|
||||||
},
|
},
|
||||||
Selection::Semantic { ref region, ref initial_expansion } => {
|
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::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};
|
use super::{Selection, Span, SpanType};
|
||||||
|
|
||||||
struct Dimensions(Point);
|
struct Dimensions(Point);
|
||||||
impl<'a> super::Dimensions for &'a Dimensions {
|
impl super::Dimensions for Dimensions {
|
||||||
fn dimensions(&self) -> Point {
|
fn dimensions(&self) -> Point {
|
||||||
self.0
|
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_left(&self, _: Point) -> Point { unimplemented!(); }
|
||||||
fn semantic_search_right(&self, _: Point) -> Point { unimplemented!(); }
|
fn semantic_search_right(&self, _: Point) -> Point { unimplemented!(); }
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,15 +18,15 @@ use index::Column;
|
||||||
bitflags! {
|
bitflags! {
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
pub struct Flags: u32 {
|
pub struct Flags: u32 {
|
||||||
const INVERSE = 0b00000001;
|
const INVERSE = 0b0000_0001;
|
||||||
const BOLD = 0b00000010;
|
const BOLD = 0b0000_0010;
|
||||||
const ITALIC = 0b00000100;
|
const ITALIC = 0b0000_0100;
|
||||||
const UNDERLINE = 0b00001000;
|
const UNDERLINE = 0b0000_1000;
|
||||||
const WRAPLINE = 0b00010000;
|
const WRAPLINE = 0b0001_0000;
|
||||||
const WIDE_CHAR = 0b00100000;
|
const WIDE_CHAR = 0b0010_0000;
|
||||||
const WIDE_CHAR_SPACER = 0b01000000;
|
const WIDE_CHAR_SPACER = 0b0100_0000;
|
||||||
const DIM = 0b10000000;
|
const DIM = 0b1000_0000;
|
||||||
const DIM_BOLD = 0b10000010;
|
const DIM_BOLD = 0b1000_0010;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ impl Cell {
|
||||||
|
|
||||||
pub fn new(c: char, fg: Color, bg: Color) -> Cell {
|
pub fn new(c: char, fg: Color, bg: Color) -> Cell {
|
||||||
Cell {
|
Cell {
|
||||||
c: c.into(),
|
c: c,
|
||||||
bg: bg,
|
bg: bg,
|
||||||
fg: fg,
|
fg: fg,
|
||||||
flags: Flags::empty(),
|
flags: Flags::empty(),
|
||||||
|
|
|
@ -36,7 +36,7 @@ pub mod color;
|
||||||
pub use self::cell::Cell;
|
pub use self::cell::Cell;
|
||||||
use self::cell::LineLength;
|
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 {
|
fn semantic_search_left(&self, mut point: Point) -> Point {
|
||||||
let mut iter = self.grid.iter_from(point);
|
let mut iter = self.grid.iter_from(point);
|
||||||
let last_col = self.grid.num_cols() - Column(1);
|
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 {
|
fn dimensions(&self) -> Point {
|
||||||
Point {
|
Point {
|
||||||
col: self.grid.num_cols(),
|
col: self.grid.num_cols(),
|
||||||
|
@ -119,7 +119,6 @@ impl<'a> RenderableCellsIter<'a> {
|
||||||
config: &'b Config,
|
config: &'b Config,
|
||||||
selection: Option<RangeInclusive<index::Linear>>,
|
selection: Option<RangeInclusive<index::Linear>>,
|
||||||
cursor_style: CursorStyle,
|
cursor_style: CursorStyle,
|
||||||
window_focused: bool,
|
|
||||||
) -> RenderableCellsIter<'b> {
|
) -> RenderableCellsIter<'b> {
|
||||||
let cursor_index = Linear(cursor.line.0 * grid.num_cols().0 + cursor.col.0);
|
let cursor_index = Linear(cursor.line.0 * grid.num_cols().0 + cursor.col.0);
|
||||||
|
|
||||||
|
@ -134,7 +133,7 @@ impl<'a> RenderableCellsIter<'a> {
|
||||||
config: config,
|
config: config,
|
||||||
colors: colors,
|
colors: colors,
|
||||||
cursor_cells: ArrayDeque::new(),
|
cursor_cells: ArrayDeque::new(),
|
||||||
}.initialize(cursor_style, window_focused)
|
}.initialize(cursor_style)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_cursor_cells(
|
fn push_cursor_cells(
|
||||||
|
@ -214,6 +213,10 @@ impl<'a> RenderableCellsIter<'a> {
|
||||||
self.populate_char_cursor(font::BEAM_CURSOR_CHAR, ' ');
|
self.populate_char_cursor(font::BEAM_CURSOR_CHAR, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn populate_box_cursor(&mut self) {
|
||||||
|
self.populate_char_cursor(font::BOX_CURSOR_CHAR, ' ');
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_wide_cursor(&self, cell: &Cell) -> bool {
|
fn is_wide_cursor(&self, cell: &Cell) -> bool {
|
||||||
cell.flags.contains(cell::Flags::WIDE_CHAR) && (self.cursor.col + 1) < self.grid.num_cols()
|
cell.flags.contains(cell::Flags::WIDE_CHAR) && (self.cursor.col + 1) < self.grid.num_cols()
|
||||||
|
@ -237,13 +240,12 @@ 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 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 {
|
match cursor_style {
|
||||||
|
CursorStyle::HollowBlock => {
|
||||||
|
self.populate_box_cursor();
|
||||||
|
},
|
||||||
CursorStyle::Block => {
|
CursorStyle::Block => {
|
||||||
self.populate_block_cursor();
|
self.populate_block_cursor();
|
||||||
},
|
},
|
||||||
|
@ -254,7 +256,6 @@ impl<'a> RenderableCellsIter<'a> {
|
||||||
self.populate_underline_cursor();
|
self.populate_underline_cursor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
self.populate_no_cursor();
|
self.populate_no_cursor();
|
||||||
}
|
}
|
||||||
|
@ -417,20 +418,20 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
|
||||||
pub mod mode {
|
pub mod mode {
|
||||||
bitflags! {
|
bitflags! {
|
||||||
pub struct TermMode: u16 {
|
pub struct TermMode: u16 {
|
||||||
const SHOW_CURSOR = 0b0000000000001;
|
const SHOW_CURSOR = 0b0_0000_0000_0001;
|
||||||
const APP_CURSOR = 0b0000000000010;
|
const APP_CURSOR = 0b0_0000_0000_0010;
|
||||||
const APP_KEYPAD = 0b0000000000100;
|
const APP_KEYPAD = 0b0_0000_0000_0100;
|
||||||
const MOUSE_REPORT_CLICK = 0b0000000001000;
|
const MOUSE_REPORT_CLICK = 0b0_0000_0000_1000;
|
||||||
const BRACKETED_PASTE = 0b0000000010000;
|
const BRACKETED_PASTE = 0b0_0000_0001_0000;
|
||||||
const SGR_MOUSE = 0b0000000100000;
|
const SGR_MOUSE = 0b0_0000_0010_0000;
|
||||||
const MOUSE_MOTION = 0b0000001000000;
|
const MOUSE_MOTION = 0b0_0000_0100_0000;
|
||||||
const LINE_WRAP = 0b0000010000000;
|
const LINE_WRAP = 0b0_0000_1000_0000;
|
||||||
const LINE_FEED_NEW_LINE = 0b0000100000000;
|
const LINE_FEED_NEW_LINE = 0b0_0001_0000_0000;
|
||||||
const ORIGIN = 0b0001000000000;
|
const ORIGIN = 0b0_0010_0000_0000;
|
||||||
const INSERT = 0b0010000000000;
|
const INSERT = 0b0_0100_0000_0000;
|
||||||
const FOCUS_IN_OUT = 0b0100000000000;
|
const FOCUS_IN_OUT = 0b0_1000_0000_0000;
|
||||||
const ALT_SCREEN = 0b1000000000000;
|
const ALT_SCREEN = 0b1_0000_0000_0000;
|
||||||
const ANY = 0b1111111111111;
|
const ANY = 0b1_1111_1111_1111;
|
||||||
const NONE = 0;
|
const NONE = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -603,9 +604,9 @@ impl VisualBell {
|
||||||
|
|
||||||
let elapsed = instant.duration_since(earlier);
|
let elapsed = instant.duration_since(earlier);
|
||||||
let elapsed_f = elapsed.as_secs() as f64 +
|
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 +
|
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
|
// Otherwise, we compute a value `time` from 0.0 to 1.0
|
||||||
// inclusive that represents the ratio of `elapsed` time to the
|
// 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,
|
// VisualBell. When `time` is 0.0, `inverse_intensity` is 0.0,
|
||||||
// and when `time` is 1.0, `inverse_intensity` is 1.0.
|
// and when `time` is 1.0, `inverse_intensity` is 1.0.
|
||||||
let inverse_intensity = match self.animation {
|
let inverse_intensity = match self.animation {
|
||||||
VisualBellAnimation::Ease => cubic_bezier(0.25, 0.1, 0.25, 1.0, time),
|
VisualBellAnimation::Ease | VisualBellAnimation::EaseOut => {
|
||||||
VisualBellAnimation::EaseOut => cubic_bezier(0.25, 0.1, 0.25, 1.0, time),
|
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::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::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),
|
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) {
|
pub fn change_font_size(&mut self, delta: i8) {
|
||||||
// Saturating addition with minimum font size 1
|
// 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.font_size = max(new_size, Size::new(1.));
|
||||||
self.dirty = true;
|
self.dirty = true;
|
||||||
}
|
}
|
||||||
|
@ -993,6 +995,11 @@ impl Term {
|
||||||
) -> RenderableCellsIter {
|
) -> RenderableCellsIter {
|
||||||
let selection = selection.and_then(|s| s.to_span(self))
|
let selection = selection.and_then(|s| s.to_span(self))
|
||||||
.map(|span| span.to_range());
|
.map(|span| span.to_range());
|
||||||
|
let cursor = if window_focused {
|
||||||
|
self.cursor_style.unwrap_or(self.default_cursor_style)
|
||||||
|
} else {
|
||||||
|
CursorStyle::HollowBlock
|
||||||
|
};
|
||||||
|
|
||||||
RenderableCellsIter::new(
|
RenderableCellsIter::new(
|
||||||
&self.grid,
|
&self.grid,
|
||||||
|
@ -1001,8 +1008,7 @@ impl Term {
|
||||||
self.mode,
|
self.mode,
|
||||||
config,
|
config,
|
||||||
selection,
|
selection,
|
||||||
self.cursor_style.unwrap_or(self.default_cursor_style),
|
cursor,
|
||||||
window_focused,
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1046,13 +1052,13 @@ impl Term {
|
||||||
// Scroll up to keep cursor in terminal
|
// Scroll up to keep cursor in terminal
|
||||||
if self.cursor.point.line >= num_lines {
|
if self.cursor.point.line >= num_lines {
|
||||||
let lines = self.cursor.point.line - num_lines + 1;
|
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
|
// Scroll up alt grid as well
|
||||||
if self.cursor_save_alt.point.line >= num_lines {
|
if self.cursor_save_alt.point.line >= num_lines {
|
||||||
let lines = self.cursor_save_alt.point.line - num_lines + 1;
|
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);
|
debug!("num_cols, num_lines = {}, {}", num_cols, num_lines);
|
||||||
|
@ -1131,7 +1137,7 @@ impl Term {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll between origin and bottom
|
// 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
|
/// Scroll screen up
|
||||||
|
@ -1153,7 +1159,7 @@ impl Term {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll from origin to bottom less number of lines
|
// 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) {
|
fn deccolm(&mut self) {
|
||||||
|
@ -1262,8 +1268,7 @@ impl ansi::Handler for Term {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set spacer cell for wide chars.
|
// Set spacer cell for wide chars.
|
||||||
if width == 2 {
|
if width == 2 && self.cursor.point.col + 1 < num_cols {
|
||||||
if self.cursor.point.col + 1 < num_cols {
|
|
||||||
self.cursor.point.col += 1;
|
self.cursor.point.col += 1;
|
||||||
let spacer = &mut self.grid[&self.cursor.point];
|
let spacer = &mut self.grid[&self.cursor.point];
|
||||||
*spacer = self.cursor.template;
|
*spacer = self.cursor.template;
|
||||||
|
@ -1271,7 +1276,6 @@ impl ansi::Handler for Term {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (self.cursor.point.col + 1) < self.grid.num_cols() {
|
if (self.cursor.point.col + 1) < self.grid.num_cols() {
|
||||||
self.cursor.point.col += 1;
|
self.cursor.point.col += 1;
|
||||||
|
@ -1987,9 +1991,8 @@ mod tests {
|
||||||
mem::swap(&mut term.grid, &mut grid);
|
mem::swap(&mut term.grid, &mut grid);
|
||||||
|
|
||||||
let selection = Selection::lines(Point { line: Line(0), col: Column(3) });
|
let selection = Selection::lines(Point { line: Line(0), col: Column(3) });
|
||||||
match selection.to_span(&term) {
|
if let Some(span) = selection.to_span(&term) {
|
||||||
Some(span) => assert_eq!(term.string_from_selection(&span), "\"aa\"a\n"),
|
assert_eq!(term.string_from_selection(&span), "\"aa\"a\n");
|
||||||
_ => ()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
17
src/tty.rs
17
src/tty.rs
|
@ -70,8 +70,8 @@ fn openpty(rows: u8, cols: u8) -> (c_int, c_int) {
|
||||||
let mut slave: c_int = 0;
|
let mut slave: c_int = 0;
|
||||||
|
|
||||||
let win = winsize {
|
let win = winsize {
|
||||||
ws_row: rows as libc::c_ushort,
|
ws_row: libc::c_ushort::from(rows),
|
||||||
ws_col: cols as libc::c_ushort,
|
ws_col: libc::c_ushort::from(cols),
|
||||||
ws_xpixel: 0,
|
ws_xpixel: 0,
|
||||||
ws_ypixel: 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 slave: c_int = 0;
|
||||||
|
|
||||||
let mut win = winsize {
|
let mut win = winsize {
|
||||||
ws_row: rows as libc::c_ushort,
|
ws_row: libc::c_ushort::from(rows),
|
||||||
ws_col: cols as libc::c_ushort,
|
ws_col: libc::c_ushort::from(cols),
|
||||||
ws_xpixel: 0,
|
ws_xpixel: 0,
|
||||||
ws_ypixel: 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
|
/// Really only needed on BSD, but should be fine elsewhere
|
||||||
fn set_controlling_terminal(fd: c_int) {
|
fn set_controlling_terminal(fd: c_int) {
|
||||||
let res = unsafe {
|
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 {
|
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.
|
/// 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 win = size.to_winsize();
|
||||||
let mut buf = [0; 1024];
|
let mut buf = [0; 1024];
|
||||||
let pw = get_pw_entry(&mut buf);
|
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 };
|
let pty = Pty { fd: master };
|
||||||
pty.resize(&size);
|
pty.resize(size);
|
||||||
pty
|
pty
|
||||||
},
|
},
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
|
|
Loading…
Reference in a new issue