summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Duerr <chrisduerr@users.noreply.github.com>2019-03-30 16:48:36 +0000
committerGitHub <noreply@github.com>2019-03-30 16:48:36 +0000
commitcfd025b5289bc305470a96657868c982a2b13bc2 (patch)
tree093b9105c881e28b909e031c46d2054016b643b3 /src
parent91aa683bcd060b2ac2f621a388a6448f564d0537 (diff)
downloadalacritty-cfd025b5289bc305470a96657868c982a2b13bc2.tar.gz
alacritty-cfd025b5289bc305470a96657868c982a2b13bc2.zip
Add rustfmt style guidev0.3.0-rc1
Diffstat (limited to 'src')
-rw-r--r--src/ansi.rs270
-rw-r--r--src/cli.rs169
-rw-r--r--src/config/bindings.rs6
-rw-r--r--src/config/mod.rs489
-rw-r--r--src/display.rs72
-rw-r--r--src/event.rs57
-rw-r--r--src/event_loop.rs72
-rw-r--r--src/grid/mod.rs159
-rw-r--r--src/grid/row.rs22
-rw-r--r--src/grid/storage.rs110
-rw-r--r--src/grid/tests.rs19
-rw-r--r--src/index.rs27
-rw-r--r--src/input.rs132
-rw-r--r--src/lib.rs10
-rw-r--r--src/locale.rs28
-rw-r--r--src/logging.rs27
-rw-r--r--src/main.rs44
-rw-r--r--src/message_bar.rs86
-rw-r--r--src/meter.rs7
-rw-r--r--src/renderer/mod.rs211
-rw-r--r--src/renderer/rects.rs46
-rw-r--r--src/selection.rs129
-rw-r--r--src/sync.rs5
-rw-r--r--src/term/cell.rs19
-rw-r--r--src/term/color.rs99
-rw-r--r--src/term/mod.rs376
-rw-r--r--src/tty/mod.rs10
-rw-r--r--src/tty/unix.rs91
-rw-r--r--src/tty/windows/conpty.rs15
-rw-r--r--src/tty/windows/mod.rs66
-rw-r--r--src/tty/windows/winpty.rs42
-rw-r--r--src/url.rs36
-rw-r--r--src/util.rs19
-rw-r--r--src/window.rs76
34 files changed, 1348 insertions, 1698 deletions
diff --git a/src/ansi.rs b/src/ansi.rs
index dce83dac..eb8764ac 100644
--- a/src/ansi.rs
+++ b/src/ansi.rs
@@ -17,10 +17,10 @@ use std::io;
use std::ops::Range;
use std::str;
-use vte;
+use crate::index::{Column, Contains, Line};
use base64;
use glutin::MouseCursor;
-use crate::index::{Column, Line, Contains};
+use vte;
use crate::term::color::Rgb;
@@ -33,7 +33,7 @@ fn parse_rgb_color(color: &[u8]) -> Option<Rgb> {
macro_rules! next {
() => {
iter.next().map(|v| *v as char)
- }
+ };
}
macro_rules! parse_hex {
@@ -50,32 +50,36 @@ fn parse_rgb_color(color: &[u8]) -> Option<Rgb> {
digit += value as u8;
}
digit
- }}
+ }};
}
match next!() {
Some('r') => {
- if next!() != Some('g') { return None; }
- if next!() != Some('b') { return None; }
- if next!() != Some(':') { return None; }
+ if next!() != Some('g') {
+ return None;
+ }
+ if next!() != Some('b') {
+ return None;
+ }
+ if next!() != Some(':') {
+ return None;
+ }
let r = parse_hex!();
let val = next!();
- if val != Some('/') { return None; }
+ if val != Some('/') {
+ return None;
+ }
let g = parse_hex!();
- if next!() != Some('/') { return None; }
+ if next!() != Some('/') {
+ return None;
+ }
let b = parse_hex!();
Some(Rgb { r, g, b })
- }
- Some('#') => {
- Some(Rgb {
- r: parse_hex!(),
- g: parse_hex!(),
- b: parse_hex!(),
- })
- }
- _ => None
+ },
+ Some('#') => Some(Rgb { r: parse_hex!(), g: parse_hex!(), b: parse_hex!() }),
+ _ => None,
}
}
@@ -106,7 +110,7 @@ pub struct Processor {
/// Internal state for VTE processor
struct ProcessorState {
- preceding_char: Option<char>
+ preceding_char: Option<char>,
}
/// Helper type that implements `vte::Perform`.
@@ -116,7 +120,7 @@ struct ProcessorState {
struct Performer<'a, H: Handler + TermInfo, W: io::Write> {
_state: &'a mut ProcessorState,
handler: &'a mut H,
- writer: &'a mut W
+ writer: &'a mut W,
}
impl<'a, H: Handler + TermInfo + 'a, W: io::Write> Performer<'a, H, W> {
@@ -127,20 +131,13 @@ impl<'a, H: Handler + TermInfo + 'a, W: io::Write> Performer<'a, H, W> {
handler: &'b mut H,
writer: &'b mut W,
) -> Performer<'b, H, W> {
- Performer {
- _state: state,
- handler,
- writer,
- }
+ Performer { _state: state, handler, writer }
}
}
impl Default for Processor {
fn default() -> Processor {
- Processor {
- state: ProcessorState { preceding_char: None },
- parser: vte::Parser::new(),
- }
+ Processor { state: ProcessorState { preceding_char: None }, parser: vte::Parser::new() }
}
}
@@ -150,21 +147,16 @@ impl Processor {
}
#[inline]
- pub fn advance<H, W>(
- &mut self,
- handler: &mut H,
- byte: u8,
- writer: &mut W
- )
- where H: Handler + TermInfo,
- W: io::Write
+ pub fn advance<H, W>(&mut self, handler: &mut H, byte: u8, writer: &mut W)
+ where
+ H: Handler + TermInfo,
+ W: io::Write,
{
let mut performer = Performer::new(&mut self.state, handler, writer);
self.parser.advance(&mut performer, byte);
}
}
-
/// Trait that provides properties of terminal
pub trait TermInfo {
fn lines(&self) -> Line;
@@ -447,14 +439,14 @@ impl Mode {
2004 => Mode::BracketedPaste,
_ => {
trace!("[unimplemented] primitive mode: {}", num);
- return None
- }
+ return None;
+ },
})
} else {
Some(match num {
4 => Mode::Insert,
20 => Mode::LineFeedNewLine,
- _ => return None
+ _ => return None,
})
}
}
@@ -485,7 +477,7 @@ pub enum ClearMode {
/// Clear entire terminal
All,
/// Clear 'saved' lines (scrollback)
- Saved
+ Saved,
}
/// Mode for clearing tab stops
@@ -586,7 +578,7 @@ impl NamedColor {
NamedColor::DimMagenta => NamedColor::Magenta,
NamedColor::DimCyan => NamedColor::Cyan,
NamedColor::DimWhite => NamedColor::White,
- val => val
+ val => val,
}
}
@@ -610,7 +602,7 @@ impl NamedColor {
NamedColor::BrightCyan => NamedColor::Cyan,
NamedColor::BrightWhite => NamedColor::White,
NamedColor::BrightForeground => NamedColor::Foreground,
- val => val
+ val => val,
}
}
}
@@ -697,8 +689,9 @@ impl Default for StandardCharset {
}
impl<'a, H, W> vte::Perform for Performer<'a, H, W>
- where H: Handler + TermInfo + 'a,
- W: io::Write + 'a
+where
+ H: Handler + TermInfo + 'a,
+ W: io::Write + 'a,
{
#[inline]
fn print(&mut self, c: char) {
@@ -720,14 +713,16 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
C1::NEL => self.handler.newline(),
C1::HTS => self.handler.set_horizontal_tabstop(),
C1::DECID => self.handler.identify_terminal(self.writer),
- _ => debug!("[unhandled] execute byte={:02x}", byte)
+ _ => debug!("[unhandled] execute byte={:02x}", byte),
}
}
#[inline]
fn hook(&mut self, params: &[i64], intermediates: &[u8], ignore: bool) {
- debug!("[unhandled hook] params={:?}, ints: {:?}, ignore: {:?}",
- params, intermediates, ignore);
+ debug!(
+ "[unhandled hook] params={:?}, ints: {:?}, ignore: {:?}",
+ params, intermediates, ignore
+ );
}
#[inline]
@@ -788,7 +783,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
}
}
unhandled(params);
- }
+ },
// Set foreground color
b"10" => {
@@ -799,7 +794,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
}
}
unhandled(params);
- }
+ },
// Set background color
b"11" => {
@@ -810,7 +805,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
}
}
unhandled(params);
- }
+ },
// Set text cursor color
b"12" => {
@@ -821,11 +816,14 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
}
}
unhandled(params);
- }
+ },
// Set cursor style
b"50" => {
- if params.len() >= 2 && params[1].len() >= 13 && params[1][0..12] == *b"CursorShape=" {
+ if params.len() >= 2
+ && params[1].len() >= 13
+ && params[1][0..12] == *b"CursorShape="
+ {
let style = match params[1][12] as char {
'0' => CursorStyle::Block,
'1' => CursorStyle::Beam,
@@ -836,7 +834,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
return;
}
unhandled(params);
- }
+ },
// Set clipboard
b"52" => {
@@ -852,9 +850,9 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
self.handler.set_clipboard(utf8_string);
}
}
- }
+ },
}
- }
+ },
// Reset color index
b"104" => {
@@ -873,7 +871,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
None => unhandled(params),
}
}
- }
+ },
// Reset foreground color
b"110" => self.handler.reset_color(NamedColor::Foreground as usize),
@@ -889,35 +887,27 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
}
#[inline]
- fn csi_dispatch(
- &mut self,
- args: &[i64],
- intermediates: &[u8],
- _ignore: bool,
- action: char
- ) {
+ fn csi_dispatch(&mut self, args: &[i64], intermediates: &[u8], _ignore: bool, action: char) {
let private = intermediates.get(0).map(|b| *b == b'?').unwrap_or(false);
let handler = &mut self.handler;
let writer = &mut self.writer;
macro_rules! unhandled {
() => {{
- debug!("[Unhandled CSI] action={:?}, args={:?}, intermediates={:?}",
- action, args, intermediates);
+ debug!(
+ "[Unhandled CSI] action={:?}, args={:?}, intermediates={:?}",
+ action, args, intermediates
+ );
return;
- }}
+ }};
}
macro_rules! arg_or_default {
(idx: $idx:expr, default: $default:expr) => {
- args.get($idx).and_then(|v| {
- if *v == 0 {
- None
- } else {
- Some(*v)
- }
- }).unwrap_or($default)
- }
+ args.get($idx)
+ .and_then(|v| if *v == 0 { None } else { Some(*v) })
+ .unwrap_or($default)
+ };
}
match action {
@@ -930,8 +920,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
for _ in 0..arg_or_default!(idx: 0, default: 1) {
handler.input(c);
}
- }
- else {
+ } else {
debug!("tried to repeat with no preceding char");
}
},
@@ -1012,7 +1001,8 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
return;
}
loop {
- if i >= args.len() { // C-for condition
+ if i >= args.len() {
+ // C-for condition
break;
}
@@ -1061,7 +1051,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
45 => Attr::Background(Color::Named(NamedColor::Magenta)),
46 => Attr::Background(Color::Named(NamedColor::Cyan)),
47 => Attr::Background(Color::Named(NamedColor::White)),
- 48 => {
+ 48 => {
let mut start = 0;
if let Some(color) = parse_color(&args[i..], &mut start) {
i += start;
@@ -1094,7 +1084,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
i += 1; // C-for expr
}
- }
+ },
'n' => handler.device_status(writer, arg_or_default!(idx: 0, default: 0) as usize),
'r' => {
if private {
@@ -1119,29 +1109,25 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
1 | 2 => Some(CursorStyle::Block),
3 | 4 => Some(CursorStyle::Underline),
5 | 6 => Some(CursorStyle::Beam),
- _ => unhandled!()
+ _ => unhandled!(),
};
handler.set_cursor_style(style);
- }
+ },
_ => unhandled!(),
}
}
#[inline]
- fn esc_dispatch(
- &mut self,
- params: &[i64],
- intermediates: &[u8],
- _ignore: bool,
- byte: u8
- ) {
+ fn esc_dispatch(&mut self, params: &[i64], intermediates: &[u8], _ignore: bool, byte: u8) {
macro_rules! unhandled {
() => {{
- debug!("[unhandled] esc_dispatch params={:?}, ints={:?}, byte={:?} ({:02x})",
- params, intermediates, byte as char, byte);
+ debug!(
+ "[unhandled] esc_dispatch params={:?}, ints={:?}, byte={:?} ({:02x})",
+ params, intermediates, byte as char, byte
+ );
return;
- }}
+ }};
}
macro_rules! configure_charset {
@@ -1154,7 +1140,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
_ => unhandled!(),
};
self.handler.configure_charset(index, $charset)
- }}
+ }};
}
match byte {
@@ -1163,7 +1149,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
b'E' => {
self.handler.linefeed();
self.handler.carriage_return();
- }
+ },
b'H' => self.handler.set_horizontal_tabstop(),
b'M' => self.handler.reverse_index(),
b'Z' => self.handler.identify_terminal(self.writer),
@@ -1176,7 +1162,7 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
} else {
self.handler.restore_cursor_position();
}
- }
+ },
b'=' => self.handler.set_keypad_application_mode(),
b'>' => self.handler.unset_keypad_application_mode(),
b'\\' => (), // String terminator, do nothing (parser handles as string terminator)
@@ -1185,14 +1171,13 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W>
}
}
-
/// Parse a color specifier from list of attributes
fn parse_color(attrs: &[i64], i: &mut usize) -> Option<Color> {
if attrs.len() < 2 {
return None;
}
- match attrs[*i+1] {
+ match attrs[*i + 1] {
2 => {
// RGB color spec
if attrs.len() < 5 {
@@ -1200,9 +1185,9 @@ fn parse_color(attrs: &[i64], i: &mut usize) -> Option<Color> {
return None;
}
- let r = attrs[*i+2];
- let g = attrs[*i+3];
- let b = attrs[*i+4];
+ let r = attrs[*i + 2];
+ let g = attrs[*i + 3];
+ let b = attrs[*i + 4];
*i += 4;
@@ -1212,11 +1197,7 @@ fn parse_color(attrs: &[i64], i: &mut usize) -> Option<Color> {
return None;
}
- Some(Color::Spec(Rgb {
- r: r as u8,
- g: g as u8,
- b: b as u8
- }))
+ Some(Color::Spec(Rgb { r: r as u8, g: g as u8, b: b as u8 }))
},
5 => {
if attrs.len() < 3 {
@@ -1226,20 +1207,18 @@ fn parse_color(attrs: &[i64], i: &mut usize) -> Option<Color> {
*i += 2;
let idx = attrs[*i];
match idx {
- 0 ..= 255 => {
- Some(Color::Indexed(idx as u8))
- },
+ 0..=255 => Some(Color::Indexed(idx as u8)),
_ => {
debug!("Invalid color index: {}", idx);
None
- }
+ },
}
}
},
_ => {
- debug!("Unexpected color attr: {}", attrs[*i+1]);
+ debug!("Unexpected color attr: {}", attrs[*i + 1]);
None
- }
+ },
}
}
@@ -1314,7 +1293,6 @@ pub mod C0 {
pub const DEL: u8 = 0x7f;
}
-
/// C1 set of 8-bit control characters (from ANSI X3.64-1979)
///
/// 0x80 (@), 0x81 (A), 0x82 (B), 0x83 (C) are reserved
@@ -1393,10 +1371,13 @@ pub mod C1 {
// Byte sequences used in these tests are recording of pty stdout.
#[cfg(test)]
mod tests {
- use std::io;
- use crate::index::{Line, Column};
- use super::{Processor, Handler, Attr, TermInfo, Color, StandardCharset, CharsetIndex, parse_rgb_color, parse_number};
+ use super::{
+ parse_number, parse_rgb_color, Attr, CharsetIndex, Color, Handler, Processor,
+ StandardCharset, TermInfo,
+ };
+ use crate::index::{Column, Line};
use crate::term::color::Rgb;
+ use std::io;
/// The /dev/null of `io::Write`
struct Void;
@@ -1434,9 +1415,7 @@ mod tests {
#[test]
fn parse_control_attribute() {
- static BYTES: &'static [u8] = &[
- 0x1b, 0x5b, 0x31, 0x6d
- ];
+ static BYTES: &'static [u8] = &[0x1b, 0x5b, 0x31, 0x6d];
let mut parser = Processor::new();
let mut handler = AttrHandler::default();
@@ -1451,8 +1430,8 @@ mod tests {
#[test]
fn parse_truecolor_attr() {
static BYTES: &'static [u8] = &[
- 0x1b, 0x5b, 0x33, 0x38, 0x3b, 0x32, 0x3b, 0x31, 0x32,
- 0x38, 0x3b, 0x36, 0x36, 0x3b, 0x32, 0x35, 0x35, 0x6d
+ 0x1b, 0x5b, 0x33, 0x38, 0x3b, 0x32, 0x3b, 0x31, 0x32, 0x38, 0x3b, 0x36, 0x36, 0x3b,
+ 0x32, 0x35, 0x35, 0x6d,
];
let mut parser = Processor::new();
@@ -1462,11 +1441,7 @@ mod tests {
parser.advance(&mut handler, *byte, &mut Void);
}
- let spec = Rgb {
- r: 128,
- g: 66,
- b: 255
- };
+ let spec = Rgb { r: 128, g: 66, b: 255 };
assert_eq!(handler.attr, Some(Attr::Foreground(Color::Spec(spec))));
}
@@ -1475,22 +1450,19 @@ mod tests {
#[test]
fn parse_zsh_startup() {
static BYTES: &'static [u8] = &[
- 0x1b, 0x5b, 0x31, 0x6d, 0x1b, 0x5b, 0x37, 0x6d, 0x25, 0x1b, 0x5b,
- 0x32, 0x37, 0x6d, 0x1b, 0x5b, 0x31, 0x6d, 0x1b, 0x5b, 0x30, 0x6d,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
- 0x20, 0x20, 0x0d, 0x20, 0x0d, 0x0d, 0x1b, 0x5b, 0x30, 0x6d, 0x1b,
- 0x5b, 0x32, 0x37, 0x6d, 0x1b, 0x5b, 0x32, 0x34, 0x6d, 0x1b, 0x5b,
- 0x4a, 0x6a, 0x77, 0x69, 0x6c, 0x6d, 0x40, 0x6a, 0x77, 0x69, 0x6c,
- 0x6d, 0x2d, 0x64, 0x65, 0x73, 0x6b, 0x20, 0x1b, 0x5b, 0x30, 0x31,
- 0x3b, 0x33, 0x32, 0x6d, 0xe2, 0x9e, 0x9c, 0x20, 0x1b, 0x5b, 0x30,
- 0x31, 0x3b, 0x33, 0x32, 0x6d, 0x20, 0x1b, 0x5b, 0x33, 0x36, 0x6d,
- 0x7e, 0x2f, 0x63, 0x6f, 0x64, 0x65
+ 0x1b, 0x5b, 0x31, 0x6d, 0x1b, 0x5b, 0x37, 0x6d, 0x25, 0x1b, 0x5b, 0x32, 0x37, 0x6d,
+ 0x1b, 0x5b, 0x31, 0x6d, 0x1b, 0x5b, 0x30, 0x6d, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
+ 0x20, 0x20, 0x20, 0x0d, 0x20, 0x0d, 0x0d, 0x1b, 0x5b, 0x30, 0x6d, 0x1b, 0x5b, 0x32,
+ 0x37, 0x6d, 0x1b, 0x5b, 0x32, 0x34, 0x6d, 0x1b, 0x5b, 0x4a, 0x6a, 0x77, 0x69, 0x6c,
+ 0x6d, 0x40, 0x6a, 0x77, 0x69, 0x6c, 0x6d, 0x2d, 0x64, 0x65, 0x73, 0x6b, 0x20, 0x1b,
+ 0x5b, 0x30, 0x31, 0x3b, 0x33, 0x32, 0x6d, 0xe2, 0x9e, 0x9c, 0x20, 0x1b, 0x5b, 0x30,
+ 0x31, 0x3b, 0x33, 0x32, 0x6d, 0x20, 0x1b, 0x5b, 0x33, 0x36, 0x6d, 0x7e, 0x2f, 0x63,
+ 0x6f, 0x64, 0x65,
];
let mut handler = AttrHandler::default();
@@ -1508,10 +1480,7 @@ mod tests {
impl Default for CharsetHandler {
fn default() -> CharsetHandler {
- CharsetHandler {
- index: CharsetIndex::G0,
- charset: StandardCharset::Ascii,
- }
+ CharsetHandler { index: CharsetIndex::G0, charset: StandardCharset::Ascii }
}
}
@@ -1527,8 +1496,13 @@ mod tests {
}
impl TermInfo for CharsetHandler {
- fn lines(&self) -> Line { Line(200) }
- fn cols(&self) -> Column { Column(90) }
+ fn lines(&self) -> Line {
+ Line(200)
+ }
+
+ fn cols(&self) -> Column {
+ Column(90)
+ }
}
#[test]
diff --git a/src/cli.rs b/src/cli.rs
index f134f358..6089ac2d 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -11,14 +11,14 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-use ::log;
-use clap::{Arg, App, crate_name, crate_version, crate_authors, crate_description};
+use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg};
+use log;
-use crate::index::{Line, Column};
-use crate::config::{Dimensions, Delta, Shell};
-use crate::window::{DEFAULT_NAME};
-use std::path::{Path, PathBuf};
+use crate::config::{Delta, Dimensions, Shell};
+use crate::index::{Column, Line};
+use crate::window::DEFAULT_NAME;
use std::borrow::Cow;
+use std::path::{Path, PathBuf};
/// Options specified on the command line
pub struct Options {
@@ -64,70 +64,95 @@ impl Options {
.version(crate_version!())
.author(crate_authors!("\n"))
.about(crate_description!())
- .arg(Arg::with_name("ref-test")
- .long("ref-test")
- .help("Generates ref test"))
- .arg(Arg::with_name("live-config-reload")
- .long("live-config-reload")
- .help("Enable automatic config reloading"))
- .arg(Arg::with_name("no-live-config-reload")
- .long("no-live-config-reload")
- .help("Disable automatic config reloading")
- .conflicts_with("live-config-reload"))
- .arg(Arg::with_name("print-events")
- .long("print-events")
- .help("Print all events to stdout"))
- .arg(Arg::with_name("persistent-logging")
- .long("persistent-logging")
- .help("Keep the log file after quitting Alacritty"))
- .arg(Arg::with_name("dimensions")
- .long("dimensions")
- .short("d")
- .value_names(&["columns", "lines"])
- .help("Defines the window dimensions. Falls back to size specified by \
- window manager if set to 0x0 [default: 0x0]"))
- .arg(Arg::with_name("position")
- .long("position")
- .allow_hyphen_values(true)
- .value_names(&["x-pos", "y-pos"])
- .help("Defines the window position. Falls back to position specified by \
- window manager if unset [default: unset]"))
- .arg(Arg::with_name("title")
- .long("title")
- .short("t")
- .takes_value(true)
- .help(&format!("Defines the window title [default: {}]", DEFAULT_NAME)))
- .arg(Arg::with_name("class")
- .long("class")
- .takes_value(true)
- .help(&format!("Defines window class on Linux [default: {}]", DEFAULT_NAME)))
- .arg(Arg::with_name("q")
- .short("q")
- .multiple(true)
- .conflicts_with("v")
- .help("Reduces the level of verbosity (the min level is -qq)"))
- .arg(Arg::with_name("v")
- .short("v")
- .multiple(true)
- .conflicts_with("q")
- .help("Increases the level of verbosity (the max level is -vvv)"))
- .arg(Arg::with_name("working-directory")
- .long("working-directory")
- .takes_value(true)
- .help("Start the shell in the specified working directory"))
- .arg(Arg::with_name("config-file")
- .long("config-file")
- .takes_value(true)
- .help("Specify alternative configuration file \
- [default: $XDG_CONFIG_HOME/alacritty/alacritty.yml]"))
- .arg(Arg::with_name("command")
- .long("command")
- .short("e")
- .multiple(true)
- .takes_value(true)
- .min_values(1)
- .allow_hyphen_values(true)
- .help("Command and args to execute (must be last argument)"))
+ .arg(Arg::with_name("ref-test").long("ref-test").help("Generates ref test"))
+ .arg(
+ Arg::with_name("live-config-reload")
+ .long("live-config-reload")
+ .help("Enable automatic config reloading"),
+ )
+ .arg(
+ Arg::with_name("no-live-config-reload")
+ .long("no-live-config-reload")
+ .help("Disable automatic config reloading")
+ .conflicts_with("live-config-reload"),
+ )
+ .arg(
+ Arg::with_name("print-events")
+ .long("print-events")
+ .help("Print all events to stdout"),
+ )
+ .arg(
+ Arg::with_name("persistent-logging")
+ .long("persistent-logging")
+ .help("Keep the log file after quitting Alacritty"),
+ )
+ .arg(
+ Arg::with_name("dimensions")
+ .long("dimensions")
+ .short("d")
+ .value_names(&["columns", "lines"])
+ .help(
+ "Defines the window dimensions. Falls back to size specified by window \
+ manager if set to 0x0 [default: 0x0]",
+ ),
+ )
+ .arg(
+ Arg::with_name("position")
+ .long("position")
+ .allow_hyphen_values(true)
+ .value_names(&["x-pos", "y-pos"])
+ .help(
+ "Defines the window position. Falls back to position specified by window \
+ manager if unset [default: unset]",
+ ),
+ )
+ .arg(
+ Arg::with_name("title")
+ .long("title")
+ .short("t")
+ .takes_value(true)
+ .help(&format!("Defines the window title [default: {}]", DEFAULT_NAME)),
+ )
+ .arg(
+ Arg::with_name("class")
+ .long("class")
+ .takes_value(true)
+ .help(&format!("Defines window class on Linux [default: {}]", DEFAULT_NAME)),
+ )
+ .arg(
+ Arg::with_name("q")
+ .short("q")
+ .multiple(true)
+ .conflicts_with("v")
+ .help("Reduces the level of verbosity (the min level is -qq)"),
+ )
+ .arg(
+ Arg::with_name("v")
+ .short("v")
+ .multiple(true)
+ .conflicts_with("q")
+ .help("Increases the level of verbosity (the max level is -vvv)"),
+ )
+ .arg(
+ Arg::with_name("working-directory")
+ .long("working-directory")
+ .takes_value(true)
+ .help("Start the shell in the specified working directory"),
+ )
+ .arg(Arg::with_name("config-file").long("config-file").takes_value(true).help(
+ "Specify alternative configuration file [default: \
+ $XDG_CONFIG_HOME/alacritty/alacritty.yml]",
+ ))
+ .arg(
+ Arg::with_name("command")
+ .long("command")
+ .short("e")
+ .multiple(true)
+ .takes_value(true)
+ .min_values(1)
+ .allow_hyphen_values(true)
+ .help("Command and args to execute (must be last argument)"),
+ )
.get_matches();
if matches.is_present("ref-test") {
@@ -170,14 +195,14 @@ impl Options {
match matches.occurrences_of("q") {
0 => {},
1 => options.log_level = log::LevelFilter::Error,
- 2 | _ => options.log_level = log::LevelFilter::Off
+ 2 | _ => options.log_level = log::LevelFilter::Off,
}
match matches.occurrences_of("v") {
0 if !options.print_events => {},
0 | 1 => options.log_level = log::LevelFilter::Info,
2 => options.log_level = log::LevelFilter::Debug,
- 3 | _ => options.log_level = log::LevelFilter::Trace
+ 3 | _ => options.log_level = log::LevelFilter::Trace,
}
if let Some(dir) = matches.value_of("working-directory") {
diff --git a/src/config/bindings.rs b/src/config/bindings.rs
index 3e76acc1..0e00f6fe 100644
--- a/src/config/bindings.rs
+++ b/src/config/bindings.rs
@@ -11,11 +11,11 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
-use glutin::{MouseButton, ModifiersState};
+use glutin::{ModifiersState, MouseButton};
-use crate::input::{MouseBinding, KeyBinding, Action};
-use crate::term::TermMode;
use super::Key;
+use crate::input::{Action, KeyBinding, MouseBinding};
+use crate::term::TermMode;
macro_rules! bindings {
(
diff --git a/src/config/mod.rs b/src/config/mod.rs
index 2fa60dad..94e74e41 100644
--- a/src/config/mod.rs
+++ b/src/config/mod.rs
@@ -4,27 +4,27 @@
//! parameters including font family and style, font size, etc. In the future,
//! the config file will also hold user and platform specific keybindings.
use std::borrow::Cow;
-use std::{env, fmt};
+use std::collections::HashMap;
use std::fs::File;
use std::io::{self, Read, Write};
use std::path::{Path, PathBuf};
use std::str::FromStr;
use std::sync::mpsc;
use std::time::Duration;
-use std::collections::HashMap;
+use std::{env, fmt};
use font::Size;
-use serde_yaml;
-use serde::{self, de, Deserialize};
-use serde::de::Error as SerdeError;
-use serde::de::{Visitor, MapAccess, Unexpected};
-use notify::{Watcher, watcher, DebouncedEvent, RecursiveMode};
use glutin::ModifiersState;
+use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
+use serde::de::Error as SerdeError;
+use serde::de::{MapAccess, Unexpected, Visitor};
+use serde::{self, de, Deserialize};
+use serde_yaml;
+use crate::ansi::{Color, CursorStyle, NamedColor};
use crate::cli::Options;
-use crate::input::{Action, Binding, MouseBinding, KeyBinding};
-use crate::index::{Line, Column};
-use crate::ansi::{CursorStyle, NamedColor, Color};
+use crate::index::{Column, Line};
+use crate::input::{Action, Binding, KeyBinding, MouseBinding};
use crate::term::color::Rgb;
mod bindings;
@@ -53,7 +53,8 @@ impl Default for Selection {
}
fn deserialize_escape_chars<'a, D>(deserializer: D) -> ::std::result::Result<String, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
match String::deserialize(deserializer) {
Ok(escape_chars) => Ok(escape_chars),
@@ -86,7 +87,8 @@ fn default_threshold_ms() -> Duration {
}
fn deserialize_duration_ms<'a, D>(deserializer: D) -> ::std::result::Result<Duration, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
match u64::deserialize(deserializer) {
Ok(threshold_ms) => Ok(Duration::from_millis(threshold_ms)),
@@ -125,8 +127,11 @@ pub struct Url {
pub modifiers: ModifiersState,
}
-fn deserialize_launcher<'a, D>(deserializer: D) -> ::std::result::Result<Option<CommandWrapper>, D::Error>
- where D: de::Deserializer<'a>
+fn deserialize_launcher<'a, D>(
+ deserializer: D,
+) -> ::std::result::Result<Option<CommandWrapper>, D::Error>
+where
+ D: de::Deserializer<'a>,
{
let default = Url::default().launcher;
@@ -168,7 +173,8 @@ impl Default for Url {
}
fn deserialize_modifiers<'a, D>(deserializer: D) -> ::std::result::Result<ModifiersState, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
ModsWrapper::deserialize(deserializer).map(ModsWrapper::into_inner)
}
@@ -177,15 +183,15 @@ fn deserialize_modifiers<'a, D>(deserializer: D) -> ::std::result::Result<Modifi
/// Penner's Easing Functions.
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Eq)]
pub enum VisualBellAnimation {
- Ease, // CSS
- EaseOut, // CSS
- EaseOutSine, // Penner
- EaseOutQuad, // Penner
- EaseOutCubic, // Penner
- EaseOutQuart, // Penner
- EaseOutQuint, // Penner
- EaseOutExpo, // Penner
- EaseOutCirc, // Penner
+ Ease, // CSS
+ EaseOut, // CSS
+ EaseOutSine, // Penner
+ EaseOutQuad, // Penner
+ EaseOutCubic, // Penner
+ EaseOutQuart, // Penner
+ EaseOutQuint, // Penner
+ EaseOutExpo, // Penner
+ EaseOutCirc, // Penner
Linear,
}
@@ -255,21 +261,17 @@ pub struct Shell<'a> {
impl<'a> Shell<'a> {
pub fn new<S>(program: S) -> Shell<'a>
- where S: Into<Cow<'a, str>>
+ where
+ S: Into<Cow<'a, str>>,
{
- Shell {
- program: program.into(),
- args: Vec::new(),
- }
+ Shell { program: program.into(), args: Vec::new() }
}
pub fn new_with_args<S>(program: S, args: Vec<String>) -> Shell<'a>
- where S: Into<Cow<'a, str>>
+ where
+ S: Into<Cow<'a, str>>,
{
- Shell {
- program: program.into(),
- args,
- }
+ Shell { program: program.into(), args }
}
pub fn program(&self) -> &str {
@@ -332,9 +334,9 @@ impl Default for Decorations {
impl<'de> Deserialize<'de> for Decorations {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Decorations, D::Error>
- where D: de::Deserializer<'de>
+ where
+ D: de::Deserializer<'de>,
{
-
struct DecorationsVisitor;
impl<'de> Visitor<'de> for DecorationsVisitor {
@@ -346,7 +348,8 @@ impl<'de> Deserialize<'de> for Decorations {
#[cfg(target_os = "macos")]
fn visit_str<E>(self, value: &str) -> ::std::result::Result<Decorations, E>
- where E: de::Error
+ where
+ E: de::Error,
{
match value.to_lowercase().as_str() {
"transparent" => Ok(Decorations::Transparent),
@@ -354,41 +357,46 @@ impl<'de> Deserialize<'de> for Decorations {
"none" => Ok(Decorations::None),
"full" => Ok(Decorations::Full),
"true" => {
- error!("Deprecated decorations boolean value, \
- use one of transparent|buttonless|none|full instead; \
- falling back to \"full\"");
+ error!(
+ "Deprecated decorations boolean value, use one of \
+ transparent|buttonless|none|full instead; falling back to \"full\""
+ );
Ok(Decorations::Full)
},
"false" => {
- error!("Deprecated decorations boolean value, \
- use one of transparent|buttonless|none|full instead; \
- falling back to \"none\"");
+ error!(
+ "Deprecated decorations boolean value, use one of \
+ transparent|buttonless|none|full instead; falling back to \"none\""
+ );
Ok(Decorations::None)
},
_ => {
error!("Invalid decorations value: {}; using default value", value);
Ok(Decorations::Full)
- }
+ },
}
}
#[cfg(not(target_os = "macos"))]
fn visit_str<E>(self, value: &str) -> ::std::result::Result<Decorations, E>
- where E: de::Error
+ where
+ E: de::Error,
{
match value.to_lowercase().as_str() {
"none" => Ok(Decorations::None),
"full" => Ok(Decorations::Full),
"true" => {
- error!("Deprecated decorations boolean value, \
- use one of none|full instead; \
- falling back to \"full\"");
+ error!(
+ "Deprecated decorations boolean value, use one of none|full instead; \
+ falling back to \"full\""
+ );
Ok(Decorations::Full)
},
"false" => {
- error!("Deprecated decorations boolean value, \
- use one of none|full instead; \
- falling back to \"none\"");
+ error!(
+ "Deprecated decorations boolean value, use one of none|full instead; \
+ falling back to \"none\""
+ );
Ok(Decorations::None)
},
"transparent" | "buttonless" => {
@@ -398,7 +406,7 @@ impl<'de> Deserialize<'de> for Decorations {
_ => {
error!("Invalid decorations value: {}; using default value", value);
Ok(Decorations::Full)
- }
+ },
}
}
}
@@ -437,7 +445,7 @@ pub struct WindowConfig {
impl Default for WindowConfig {
fn default() -> Self {
- WindowConfig{
+ WindowConfig {
dimensions: Default::default(),
position: Default::default(),
padding: default_padding(),
@@ -453,7 +461,8 @@ fn default_padding() -> Delta<u8> {
}
fn deserialize_padding<'a, D>(deserializer: D) -> ::std::result::Result<Delta<u8>, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
match Delta::deserialize(deserializer) {
Ok(delta) => Ok(delta),
@@ -513,11 +522,11 @@ pub struct Config {
window: WindowConfig,
/// Keybindings
- #[serde(default="default_key_bindings", deserialize_with = "deserialize_key_bindings")]
+ #[serde(default = "default_key_bindings", deserialize_with = "deserialize_key_bindings")]
key_bindings: Vec<KeyBinding>,
/// Bindings for the mouse
- #[serde(default="default_mouse_bindings", deserialize_with = "deserialize_mouse_bindings")]
+ #[serde(default = "default_mouse_bindings", deserialize_with = "deserialize_mouse_bindings")]
mouse_bindings: Vec<MouseBinding>,
#[serde(default, deserialize_with = "failure_default")]
@@ -590,8 +599,7 @@ pub struct Config {
impl Default for Config {
fn default() -> Self {
- serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG)
- .expect("default config is invalid")
+ serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG).expect("default config is invalid")
}
}
@@ -603,24 +611,28 @@ fn default_mouse_bindings() -> Vec<MouseBinding> {
bindings::default_mouse_bindings()
}
-fn deserialize_key_bindings<'a, D>(deserializer: D)
- -> ::std::result::Result<Vec<KeyBinding>, D::Error>
+fn deserialize_key_bindings<'a, D>(
+ deserializer: D,
+) -> ::std::result::Result<Vec<KeyBinding>, D::Error>
where
D: de::Deserializer<'a>,
{
deserialize_bindings(deserializer, bindings::default_key_bindings())
}
-fn deserialize_mouse_bindings<'a, D>(deserializer: D)
- -> ::std::result::Result<Vec<MouseBinding>, D::Error>
+fn deserialize_mouse_bindings<'a, D>(
+ deserializer: D,
+) -> ::std::result::Result<Vec<MouseBinding>, D::Error>
where
D: de::Deserializer<'a>,
{
deserialize_bindings(deserializer, bindings::default_mouse_bindings())
}
-fn deserialize_bindings<'a, D, T>(deserializer: D, mut default: Vec<Binding<T>>)
- -> ::std::result::Result<Vec<Binding<T>>, D::Error>
+fn deserialize_bindings<'a, D, T>(
+ deserializer: D,
+ mut default: Vec<Binding<T>>,
+) -> ::std::result::Result<Vec<Binding<T>>, D::Error>
where
D: de::Deserializer<'a>,
T: Copy + Eq + std::hash::Hash + std::fmt::Debug,
@@ -638,8 +650,9 @@ where
}
fn failure_default_vec<'a, D, T>(deserializer: D) -> ::std::result::Result<Vec<T>, D::Error>
- where D: de::Deserializer<'a>,
- T: Deserialize<'a>
+where
+ D: de::Deserializer<'a>,
+ T: Deserialize<'a>,
{
// Deserialize as generic vector
let vec = match Vec::<serde_yaml::Value>::deserialize(deserializer) {
@@ -669,7 +682,8 @@ fn default_tabspaces() -> usize {
}
fn deserialize_tabspaces<'a, D>(deserializer: D) -> ::std::result::Result<usize, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
match usize::deserialize(deserializer) {
Ok(value) => Ok(value),
@@ -681,7 +695,8 @@ fn deserialize_tabspaces<'a, D>(deserializer: D) -> ::std::result::Result<usize,
}
fn deserialize_true_bool<'a, D>(deserializer: D) -> ::std::result::Result<bool, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
match bool::deserialize(deserializer) {
Ok(value) => Ok(value),
@@ -696,10 +711,10 @@ fn default_true_bool() -> bool {
true
}
-fn failure_default<'a, D, T>(deserializer: D)
- -> ::std::result::Result<T, D::Error>
- where D: de::Deserializer<'a>,
- T: Deserialize<'a> + Default
+fn failure_default<'a, D, T>(deserializer: D) -> ::std::result::Result<T, D::Error>
+where
+ D: de::Deserializer<'a>,
+ T: Deserialize<'a> + Default,
{
match T::deserialize(deserializer) {
Ok(value) => Ok(value),
@@ -745,7 +760,8 @@ fn default_scrolling_multiplier() -> u8 {
}
fn deserialize_scrolling_history<'a, D>(deserializer: D) -> ::std::result::Result<u32, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
match u32::deserialize(deserializer) {
Ok(lines) => {
@@ -768,7 +784,8 @@ fn deserialize_scrolling_history<'a, D>(deserializer: D) -> ::std::result::Resul
}
fn deserialize_scrolling_multiplier<'a, D>(deserializer: D) -> ::std::result::Result<u8, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
match u8::deserialize(deserializer) {
Ok(lines) => Ok(lines),
@@ -794,7 +811,8 @@ impl ModsWrapper {
impl<'a> de::Deserialize<'a> for ModsWrapper {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where D: de::Deserializer<'a>
+ where
+ D: de::Deserializer<'a>,
{
struct ModsVisitor;
@@ -806,7 +824,8 @@ impl<'a> de::Deserialize<'a> for ModsWrapper {
}
fn visit_str<E>(self, value: &str) -> ::std::result::Result<ModsWrapper, E>
- where E: de::Error,
+ where
+ E: de::Error,
{
let mut res = ModifiersState::default();
for modifier in value.split('|') {
@@ -838,7 +857,8 @@ impl ActionWrapper {
impl<'a> de::Deserialize<'a> for ActionWrapper {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where D: de::Deserializer<'a>
+ where
+ D: de::Deserializer<'a>,
{
struct ActionVisitor;
@@ -846,14 +866,16 @@ impl<'a> de::Deserialize<'a> for ActionWrapper {
type Value = ActionWrapper;
fn expecting(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- f.write_str("Paste, Copy, PasteSelection, IncreaseFontSize, DecreaseFontSize, \
- ResetFontSize, ScrollPageUp, ScrollPageDown, ScrollToTop, \
- ScrollToBottom, ClearHistory, Hide, ClearLogNotice, SpawnNewInstance, \
- None or Quit")
+ f.write_str(
+ "Paste, Copy, PasteSelection, IncreaseFontSize, DecreaseFontSize, \
+ ResetFontSize, ScrollPageUp, ScrollPageDown, ScrollToTop, ScrollToBottom, \
+ ClearHistory, Hide, ClearLogNotice, SpawnNewInstance, None or Quit",
+ )
}
fn visit_str<E>(self, value: &str) -> ::std::result::Result<ActionWrapper, E>
- where E: de::Error,
+ where
+ E: de::Error,
{
Ok(ActionWrapper(match value {
"Paste" => Action::Paste,
@@ -915,8 +937,9 @@ struct ModeWrapper {
}
impl<'a> de::Deserialize<'a> for ModeWrapper {
- fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where D: de::Deserializer<'a>
+ fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
+ where
+ D: de::Deserializer<'a>,
{
struct ModeVisitor;
@@ -928,12 +951,10 @@ impl<'a> de::Deserialize<'a> for ModeWrapper {
}
fn visit_str<E>(self, value: &str) -> ::std::result::Result<ModeWrapper, E>
- where E: de::Error,
+ where
+ E: de::Error,
{
- let mut res = ModeWrapper {
- mode: TermMode::empty(),
- not_mode: TermMode::empty()
- };
+ let mut res = ModeWrapper { mode: TermMode::empty(), not_mode: TermMode::empty() };
for modifier in value.split('|') {
match modifier.trim() {
@@ -964,7 +985,8 @@ impl MouseButton {
impl<'a> de::Deserialize<'a> for MouseButton {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where D: de::Deserializer<'a>
+ where
+ D: de::Deserializer<'a>,
{
struct MouseButtonVisitor;
@@ -976,7 +998,8 @@ impl<'a> de::Deserialize<'a> for MouseButton {
}
fn visit_str<E>(self, value: &str) -> ::std::result::Result<MouseButton, E>
- where E: de::Error,
+ where
+ E: de::Error,
{
match value {
"Left" => Ok(MouseButton(::glutin::MouseButton::Left)),
@@ -988,7 +1011,7 @@ impl<'a> de::Deserialize<'a> for MouseButton {
} else {
Err(E::invalid_value(Unexpected::Str(value), &self))
}
- }
+ },
}
}
}
@@ -1041,7 +1064,8 @@ impl RawBinding {
impl<'a> de::Deserialize<'a> for RawBinding {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where D: de::Deserializer<'a>
+ where
+ D: de::Deserializer<'a>,
{
enum Field {
Key,
@@ -1055,13 +1079,13 @@ impl<'a> de::Deserialize<'a> for RawBinding {
impl<'a> de::Deserialize<'a> for Field {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Field, D::Error>
- where D: de::Deserializer<'a>
+ where
+ D: de::Deserializer<'a>,
{
struct FieldVisitor;
- static FIELDS: &'static [&'static str] = &[
- "key", "mods", "mode", "action", "chars", "mouse", "command",
- ];
+ static FIELDS: &'static [&'static str] =
+ &["key", "mods", "mode", "action", "chars", "mouse", "command"];
impl<'a> Visitor<'a> for FieldVisitor {
type Value = Field;
@@ -1071,7 +1095,8 @@ impl<'a> de::Deserialize<'a> for RawBinding {
}
fn visit_str<E>(self, value: &str) -> ::std::result::Result<Field, E>
- where E: de::Error,
+ where
+ E: de::Error,
{
match value {
"key" => Ok(Field::Key),
@@ -1098,11 +1123,9 @@ impl<'a> de::Deserialize<'a> for RawBinding {
f.write_str("binding specification")
}
- fn visit_map<V>(
- self,
- mut map: V
- ) -> ::std::result::Result<RawBinding, V::Error>
- where V: MapAccess<'a>,
+ fn visit_map<V>(self, mut map: V) -> ::std::result::Result<RawBinding, V::Error>
+ where
+ V: MapAccess<'a>,
{
let mut mods: Option<ModifiersState> = None;
let mut key: Option<Key> = None;
@@ -1133,8 +1156,7 @@ impl<'a> de::Deserialize<'a> for RawBinding {
}
key = Some(Key::Scancode(scancode as u32));
} else {
- let k = Key::deserialize(val)
- .map_err(V::Error::custom)?;
+ let k = Key::deserialize(val).map_err(V::Error::custom)?;
key = Some(k);
}
},
@@ -1188,18 +1210,18 @@ impl<'a> de::Deserialize<'a> for RawBinding {
let action = match (action, chars, command) {
(Some(action), None, None) => action,
(None, Some(chars), None) => Action::Esc(chars),
- (None, None, Some(cmd)) => {
- match cmd {
- CommandWrapper::Just(program) => {
- Action::Command(program, vec![])
- },
- CommandWrapper::WithArgs { program, args } => {
- Action::Command(program, args)
- },
- }
+ (None, None, Some(cmd)) => match cmd {
+ CommandWrapper::Just(program) => Action::Command(program, vec![]),
+ CommandWrapper::WithArgs { program, args } => {
+ Action::Command(program, args)
+ },
+ },
+ (None, None, None) => {
+ return Err(V::Error::custom("must specify chars, action or command"));
+ },
+ _ => {
+ return Err(V::Error::custom("must specify only chars, action or command"))
},
- (None, None, None) => return Err(V::Error::custom("must specify chars, action or command")),
- _ => return Err(V::Error::custom("must specify only chars, action or command")),
};
let mode = mode.unwrap_or_else(TermMode::empty);
@@ -1210,29 +1232,20 @@ impl<'a> de::Deserialize<'a> for RawBinding {
return Err(V::Error::custom("bindings require mouse button or key"));
}
- Ok(RawBinding {
- mode,
- notmode: not_mode,
- action,
- key,
- mouse,
- mods,
- })
+ Ok(RawBinding { mode, notmode: not_mode, action, key, mouse, mods })
}
}
- const FIELDS: &[&str] = &[
- "key", "mods", "mode", "action", "chars", "mouse", "command",
- ];
+ const FIELDS: &[&str] = &["key", "mods", "mode", "action", "chars", "mouse", "command"];
deserializer.deserialize_struct("RawBinding", FIELDS, RawBindingVisitor)
}
}
-
impl<'a> de::Deserialize<'a> for Alpha {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where D: de::Deserializer<'a>
+ where
+ D: de::Deserializer<'a>,
{
let value = f32::deserialize(deserializer)?;
Ok(Alpha::new(value))
@@ -1241,21 +1254,21 @@ impl<'a> de::Deserialize<'a> for Alpha {
impl<'a> de::Deserialize<'a> for MouseBinding {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where D: de::Deserializer<'a>
+ where
+ D: de::Deserializer<'a>,
{
let raw = RawBinding::deserialize(deserializer)?;
- raw.into_mouse_binding()
- .map_err(|_| D::Error::custom("expected mouse binding"))
+ raw.into_mouse_binding().map_err(|_| D::Error::custom("expected mouse binding"))
}
}
impl<'a> de::Deserialize<'a> for KeyBinding {
fn deserialize<D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where D: de::Deserializer<'a>
+ where
+ D: de::Deserializer<'a>,
{
let raw = RawBinding::deserialize(deserializer)?;
- raw.into_key_binding()
- .map_err(|_| D::Error::custom("expected key binding"))
+ raw.into_key_binding().map_err(|_| D::Error::custom("expected key binding"))
}
}
@@ -1313,32 +1326,33 @@ impl Default for Colors {
fn default_normal_colors() -> AnsiColors {
AnsiColors {
- black: Rgb {r: 0x00, g: 0x00, b: 0x00},
- red: Rgb {r: 0xd5, g: 0x4e, b: 0x53},
- green: Rgb {r: 0xb9, g: 0xca, b: 0x4a},
- yellow: Rgb {r: 0xe6, g: 0xc5, b: 0x47},
- blue: Rgb {r: 0x7a, g: 0xa6, b: 0xda},
- magenta: Rgb {r: 0xc3, g: 0x97, b: 0xd8},
- cyan: Rgb {r: 0x70, g: 0xc0, b: 0xba},
- white: Rgb {r: 0xea, g: 0xea, b: 0xea},
+ black: Rgb { r: 0x00, g: 0x00, b: 0x00 },
+ red: Rgb { r: 0xd5, g: 0x4e, b: 0x53 },
+ green: Rgb { r: 0xb9, g: 0xca, b: 0x4a },
+ yellow: Rgb { r: 0xe6, g: 0xc5, b: 0x47 },
+ blue: Rgb { r: 0x7a, g: 0xa6, b: 0xda },
+ magenta: Rgb { r: 0xc3, g: 0x97, b: 0xd8 },
+ cyan: Rgb { r: 0x70, g: 0xc0, b: 0xba },
+ white: Rgb { r: 0xea, g: 0xea, b: 0xea },
}
}
fn default_bright_colors() -> AnsiColors {
AnsiColors {
- black: Rgb {r: 0x66, g: 0x66, b: 0x66},
- red: Rgb {r: 0xff, g: 0x33, b: 0x34},
- green: Rgb {r: 0x9e, g: 0xc4, b: 0x00},
- yellow: Rgb {r: 0xe7, g: 0xc5, b: 0x47},
- blue: Rgb {r: 0x7a, g: 0xa6, b: 0xda},
- magenta: Rgb {r: 0xb7, g: 0x7e, b: 0xe0},
- cyan: Rgb {r: 0x54, g: 0xce, b: 0xd6},
- white: Rgb {r: 0xff, g: 0xff, b: 0xff},
+ black: Rgb { r: 0x66, g: 0x66, b: 0x66 },
+ red: Rgb { r: 0xff, g: 0x33, b: 0x34 },
+ green: Rgb { r: 0x9e, g: 0xc4, b: 0x00 },
+ yellow: Rgb { r: 0xe7, g: 0xc5, b: 0x47 },
+ blue: Rgb { r: 0x7a, g: 0xa6, b: 0xda },
+ magenta: Rgb { r: 0xb7, g: 0x7e, b: 0xe0 },
+ cyan: Rgb { r: 0x54, g: 0xce, b: 0xd6 },
+ white: Rgb { r: 0xff, g: 0xff, b: 0xff },
}
}
fn deserialize_normal_colors<'a, D>(deserializer: D) -> ::std::result::Result<AnsiColors, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
match AnsiColors::deserialize(deserializer) {
Ok(escape_chars) => Ok(escape_chars),
@@ -1350,7 +1364,8 @@ fn deserialize_normal_colors<'a, D>(deserializer: D) -> ::std::result::Result<An
}
fn deserialize_bright_colors<'a, D>(deserializer: D) -> ::std::result::Result<AnsiColors, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
match AnsiColors::deserialize(deserializer) {
Ok(escape_chars) => Ok(escape_chars),
@@ -1370,15 +1385,15 @@ pub struct IndexedColor {
}
fn deserialize_color_index<'a, D>(deserializer: D) -> ::std::result::Result<u8, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
match u8::deserialize(deserializer) {
Ok(index) => {
if index < 16 {
error!(
- "Problem with config: indexed_color's index is {}, \
- but a value bigger than 15 was expected; \
- ignoring setting",
+ "Problem with config: indexed_color's index is {}, but a value bigger than 15 \
+ was expected; ignoring setting",
index
);
@@ -1408,10 +1423,7 @@ pub struct Cursor {
impl Default for Cursor {
fn default() -> Self {
- Self {
- style: Default::default(),
- unfocused_hollow: true,
- }
+ Self { style: Default::default(), unfocused_hollow: true }
}
}
@@ -1457,8 +1469,11 @@ impl Default for PrimaryColors {
}
}
-fn deserialize_optional_color<'a, D>(deserializer: D) -> ::std::result::Result<Option<Rgb>, D::Error>
- where D: de::Deserializer<'a>
+fn deserialize_optional_color<'a, D>(
+ deserializer: D,
+) -> ::std::result::Result<Option<Rgb>, D::Error>
+where
+ D: de::Deserializer<'a>,
{
match Option::deserialize(deserializer) {
Ok(Some(color)) => {
@@ -1507,7 +1522,8 @@ pub struct AnsiColors {
/// This is *not* the deserialize impl for Rgb since we want a symmetric
/// serialize/deserialize impl for ref tests.
fn rgb_from_hex<'a, D>(deserializer: D) -> ::std::result::Result<Rgb, D::Error>
- where D: de::Deserializer<'a>
+where
+ D: de::Deserializer<'a>,
{
struct RgbVisitor;
@@ -1519,7 +1535,8 @@ fn rgb_from_hex<'a, D>(deserializer: D) -> ::std::result::Result<Rgb, D::Error>
}
fn visit_str<E>(self, value: &str) -> ::std::result::Result<Rgb, E>
- where E: ::serde::de::Error
+ where
+ E: ::serde::de::Error,
{
Rgb::from_str(&value[..])
.map_err(|_| E::custom("failed to parse rgb; expected hex color like 0xff00ff"))
@@ -1540,6 +1557,7 @@ fn rgb_from_hex<'a, D>(deserializer: D) -> ::std::result::Result<Rgb, D::Error>
impl FromStr for Rgb {
type Err = ();
+
fn from_str(s: &str) -> ::std::result::Result<Rgb, ()> {
let mut chars = s.chars();
let mut rgb = Rgb::default();
@@ -1561,7 +1579,11 @@ impl FromStr for Rgb {
}
match chars.next() {
- Some('0') => if chars.next() != Some('x') { return Err(()); },
+ Some('0') => {
+ if chars.next() != Some('x') {
+ return Err(());
+ }
+ },
Some('#') => (),
_ => return Err(()),
}
@@ -1596,7 +1618,9 @@ 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 | 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, "Couldn't read $HOME environment variable: {}", err)
},
@@ -1646,9 +1670,9 @@ impl Config {
.ok()
.and_then(|xdg| xdg.find_config_file("alacritty.yml"))
.or_else(|| {
- ::xdg::BaseDirectories::new().ok().and_then(|fallback| {
- fallback.find_config_file("alacritty.yml")
- })
+ ::xdg::BaseDirectories::new()
+ .ok()
+ .and_then(|fallback| fallback.find_config_file("alacritty.yml"))
})
.or_else(|| {
if let Ok(home) = env::var("HOME") {
@@ -1671,10 +1695,8 @@ impl Config {
// TODO: Remove old configuration location warning (Deprecated 03/12/2018)
#[cfg(windows)]
pub fn installed_config<'a>() -> Option<Cow<'a, Path>> {
- let old = dirs::home_dir()
- .map(|path| path.join("alacritty.yml"));
- let new = dirs::config_dir()
- .map(|path| path.join("alacritty\\alacritty.yml"));
+ let old = dirs::home_dir().map(|path| path.join("alacritty.yml"));
+ let new = dirs::config_dir().map(|path| path.join("alacritty\\alacritty.yml"));
if let Some(old_path) = old.as_ref().filter(|old| old.exists()) {
warn!(
@@ -1702,11 +1724,9 @@ impl Config {
#[cfg(windows)]
pub fn write_defaults() -> io::Result<Cow<'static, Path>> {
- let mut path = dirs::config_dir()
- .ok_or_else(|| {
- io::Error::new(io::ErrorKind::NotFound, "Couldn't find profile directory")
- }
- )?;
+ let mut path = dirs::config_dir().ok_or_else(|| {
+ io::Error::new(io::ErrorKind::NotFound, "Couldn't find profile directory")
+ })?;
path = path.join("alacritty/alacritty.yml");
@@ -1751,8 +1771,7 @@ impl Config {
}
pub fn padding(&self) -> &Delta<u8> {
- self.padding.as_ref()
- .unwrap_or(&self.window.padding)
+ self.padding.as_ref().unwrap_or(&self.window.padding)
}
#[inline]
@@ -1808,9 +1827,7 @@ impl Config {
}
pub fn path(&self) -> Option<&Path> {
- self.config_path
- .as_ref()
- .map(PathBuf::as_path)
+ self.config_path.as_ref().map(PathBuf::as_path)
}
pub fn shell(&self) -> Option<&Shell<'_>> {
@@ -1912,7 +1929,7 @@ impl Config {
Err(err) => {
error!("Unable to load config {:?}: {}", path, err);
Err(err)
- }
+ },
}
}
@@ -1933,18 +1950,18 @@ impl Config {
fn print_deprecation_warnings(&mut self) {
if self.dimensions.is_some() {
- warn!("Config dimensions is deprecated; \
- please use window.dimensions instead");
+ warn!("Config dimensions is deprecated; please use window.dimensions instead");
}
if self.padding.is_some() {
- warn!("Config padding is deprecated; \
- please use window.padding instead");
+ warn!("Config padding is deprecated; please use window.padding instead");
}
if self.mouse.faux_scrollback_lines.is_some() {
- warn!("Config mouse.faux_scrollback_lines is deprecated; \
- please use mouse.faux_scrolling_lines instead");
+ warn!(
+ "Config mouse.faux_scrollback_lines is deprecated; please use \
+ mouse.faux_scrolling_lines instead"
+ );
}
if let Some(custom_cursor_colors) = self.custom_cursor_colors {
@@ -1957,18 +1974,21 @@ impl Config {
}
if self.cursor_style.is_some() {
- warn!("Config cursor_style is deprecated; \
- please use cursor.style instead");
+ warn!("Config cursor_style is deprecated; please use cursor.style instead");
}
if self.hide_cursor_when_typing.is_some() {
- warn!("Config hide_cursor_when_typing is deprecated; \
- please use mouse.hide_when_typing instead");
+ warn!(
+ "Config hide_cursor_when_typing is deprecated; please use mouse.hide_when_typing \
+ instead"
+ );
}
if self.unfocused_hollow_cursor.is_some() {
- warn!("Config unfocused_hollow_cursor is deprecated; \
- please use cursor.unfocused_hollow instead");
+ warn!(
+ "Config unfocused_hollow_cursor is deprecated; please use cursor.unfocused_hollow \
+ instead"
+ );
}
}
}
@@ -1990,10 +2010,7 @@ pub struct Dimensions {
impl Dimensions {
pub fn new(columns: Column, lines: Line) -> Self {
- Dimensions {
- columns,
- lines,
- }
+ Dimensions { columns, lines }
}
/// Get lines
@@ -2021,14 +2038,16 @@ pub struct Delta<T: Default + PartialEq + Eq> {
pub y: T,
}
-trait DeserializeSize : Sized {
+trait DeserializeSize: Sized {
fn deserialize<'a, D>(_: D) -> ::std::result::Result<Self, D::Error>
- where D: serde::de::Deserializer<'a>;
+ where
+ D: serde::de::Deserializer<'a>;
}
impl DeserializeSize for Size {
fn deserialize<'a, D>(deserializer: D) -> ::std::result::Result<Self, D::Error>
- where D: serde::de::Deserializer<'a>
+ where
+ D: serde::de::Deserializer<'a>,
{
use std::marker::PhantomData;
@@ -2037,7 +2056,8 @@ impl DeserializeSize for Size {
}
impl<'a, __D> Visitor<'a> for NumVisitor<__D>
- where __D: serde::de::Deserializer<'a>
+ where
+ __D: serde::de::Deserializer<'a>,
{
type Value = f64;
@@ -2046,20 +2066,22 @@ impl DeserializeSize for Size {
}
fn visit_f64<E>(self, value: f64) -> ::std::result::Result<Self::Value, E>
- where E: ::serde::de::Error
+ where
+ E: ::serde::de::Error,
{
Ok(value)
}
fn visit_u64<E>(self, value: u64) -> ::std::result::Result<Self::Value, E>
- where E: ::serde::de::Error
+ where
+ E: ::serde::de::Error,
{
Ok(value as f64)
}
}
let size = deserializer
- .deserialize_any(NumVisitor::<D>{ _marker: PhantomData })
+ .deserialize_any(NumVisitor::<D> { _marker: PhantomData })
.map(|v| Size::new(v as _));
// Use default font size as fallback
@@ -2153,10 +2175,7 @@ impl Font {
/// Get a font clone with a size modification
pub fn with_size(self, size: Size) -> Font {
- Font {
- size,
- .. self
- }
+ Font { size, ..self }
}
// Get normal font description
@@ -2185,8 +2204,10 @@ where
{
// This is necessary in order to get serde to complete deserialization of the configuration
let _ignored = bool::deserialize(deserializer);
- error!("The scale_with_dpi setting has been removed, \
- on X11 the WINIT_HIDPI_FACTOR environment variable can be used instead.");
+ error!(
+ "The scale_with_dpi setting has been removed, on X11 the WINIT_HIDPI_FACTOR environment \
+ variable can be used instead."
+ );
Ok(None)
}
@@ -2260,8 +2281,9 @@ impl Monitor {
}
pub fn new<H, P>(path: P, mut handler: H) -> Monitor
- where H: OnConfigReload + Send + 'static,
- P: Into<PathBuf>
+ where
+ H: OnConfigReload + Send + 'static,
+ P: Into<PathBuf>,
{
let path = path.into();
@@ -2271,34 +2293,33 @@ impl Monitor {
_thread: crate::util::thread::spawn_named("config watcher", move || {
let (tx, rx) = mpsc::channel();
// The Duration argument is a debouncing period.
- let mut watcher = watcher(tx, Duration::from_millis(10))
- .expect("Unable to spawn file watcher");
- let config_path = ::std::fs::canonicalize(path)
- .expect("canonicalize config path");
+ let mut watcher =
+ watcher(tx, Duration::from_millis(10)).expect("Unable to spawn file watcher");
+ let config_path = ::std::fs::canonicalize(path).expect("canonicalize config path");
// Get directory of config
let mut parent = config_path.clone();
parent.pop();
// Watch directory
- watcher.watch(&parent, RecursiveMode::NonRecursive)
+ watcher
+ .watch(&parent, RecursiveMode::NonRecursive)
.expect("watch alacritty.yml dir");
loop {
match rx.recv().expect("watcher event") {
- DebouncedEvent::Rename(_, _) => continue,
+ DebouncedEvent::Rename(..) => continue,
DebouncedEvent::Write(path)
- | DebouncedEvent::Create(path)
- | DebouncedEvent::Chmod(path) =>
- {
+ | DebouncedEvent::Create(path)
+ | DebouncedEvent::Chmod(path) => {
if path != config_path {
continue;
}
let _ = config_tx.send(path);
handler.on_config_reload();
- }
- _ => {}
+ },
+ _ => {},
}
}
}),
@@ -2645,13 +2666,13 @@ impl Key {
#[cfg(test)]
mod tests {
- use crate::cli::Options;
use super::{Config, DEFAULT_ALACRITTY_CONFIG};
+ use crate::cli::Options;
#[test]
fn parse_config() {
- let config: Config = ::serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG)
- .expect("deserialize config");
+ let config: Config =
+ ::serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG).expect("deserialize config");
// Sanity check that mouse bindings are being parsed
assert!(!config.mouse_bindings.is_empty());
@@ -2662,8 +2683,8 @@ mod tests {
#[test]
fn dynamic_title_ignoring_options_by_default() {
- let config: Config = ::serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG)
- .expect("deserialize config");
+ let config: Config =
+ ::serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG).expect("deserialize config");
let old_dynamic_title = config.dynamic_title;
let options = Options::default();
let config = config.update_dynamic_title(&options);
@@ -2672,8 +2693,8 @@ mod tests {
#[test]
fn dynamic_title_overridden_by_options() {
- let config: Config = ::serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG)
- .expect("deserialize config");
+ let config: Config =
+ ::serde_yaml::from_str(DEFAULT_ALACRITTY_CONFIG).expect("deserialize config");
let mut options = Options::default();
options.title = Some("foo".to_owned());
let config = config.update_dynamic_title(&options);
diff --git a/src/display.rs b/src/display.rs
index 8266e655..8dca2f64 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -14,24 +14,24 @@
//! The display subsystem including window management, font rasterization, and
//! GPU drawing.
-use std::sync::mpsc;
use std::f64;
+use std::sync::mpsc;
-use parking_lot::MutexGuard;
use glutin::dpi::{PhysicalPosition, PhysicalSize};
+use parking_lot::MutexGuard;
use crate::cli;
use crate::config::Config;
-use font::{self, Rasterize};
+use crate::index::Line;
+use crate::message_bar::Message;
use crate::meter::Meter;
+use crate::renderer::rects::{Rect, Rects};
use crate::renderer::{self, GlyphCache, QuadRenderer};
-use crate::renderer::rects::{Rects, Rect};
-use crate::term::{Term, SizeInfo, RenderableCell};
use crate::sync::FairMutex;
-use crate::window::{self, Window};
use crate::term::color::Rgb;
-use crate::index::Line;
-use crate::message_bar::Message;
+use crate::term::{RenderableCell, SizeInfo, Term};
+use crate::window::{self, Window};
+use font::{self, Rasterize};
#[derive(Debug)]
pub enum Error {
@@ -152,8 +152,8 @@ impl Display {
info!("Device pixel ratio: {}", dpr);
// get window properties for initializing the other subsystems
- let mut viewport_size = window.inner_size_pixels()
- .expect("glutin returns window size").to_physical(dpr);
+ let mut viewport_size =
+ window.inner_size_pixels().expect("glutin returns window size").to_physical(dpr);
// Create renderer
let mut renderer = QuadRenderer::new(viewport_size)?;
@@ -161,8 +161,7 @@ impl Display {
let (glyph_cache, cell_width, cell_height) =
Self::new_glyph_cache(dpr, &mut renderer, config)?;
- let dimensions = options.dimensions()
- .unwrap_or_else(|| config.dimensions());
+ let dimensions = options.dimensions().unwrap_or_else(|| config.dimensions());
let mut padding_x = f64::from(config.padding().x) * dpr;
let mut padding_y = f64::from(config.padding().y) * dpr;
@@ -216,13 +215,9 @@ impl Display {
// Clear screen
let background_color = config.colors().primary.background;
- renderer.with_api(
- config,
- &size_info,
- |api| {
- api.clear(background_color);
- },
- );
+ renderer.with_api(config, &size_info, |api| {
+ api.clear(background_color);
+ });
Ok(Display {
window,
@@ -238,9 +233,11 @@ impl Display {
})
}
- fn new_glyph_cache(dpr: f64, renderer: &mut QuadRenderer, config: &Config)
- -> Result<(GlyphCache, f32, f32), Error>
- {
+ fn new_glyph_cache(
+ dpr: f64,
+ renderer: &mut QuadRenderer,
+ config: &Config,
+ ) -> Result<(GlyphCache, f32, f32), Error> {
let font = config.font().clone();
let rasterizer = font::Rasterizer::new(dpr as f32, config.use_thin_strokes())?;
@@ -253,8 +250,7 @@ impl Display {
renderer.with_loader(|mut api| GlyphCache::new(rasterizer, &font, &mut api))?;
let stop = init_start.elapsed();
- let stop_f = stop.as_secs() as f64 +
- f64::from(stop.subsec_nanos()) / 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 {}s", stop_f);
cache
@@ -322,8 +318,8 @@ impl Display {
let dpr = self.window.hidpi_factor();
// Font size/DPI factor modification detected
- let font_changed = terminal.font_size != self.font_size
- || (dpr - self.size_info.dpr).abs() > f64::EPSILON;
+ let font_changed =
+ terminal.font_size != self.font_size || (dpr - self.size_info.dpr).abs() > f64::EPSILON;
if font_changed || self.last_message != terminal.message_buffer_mut().message() {
if new_size == None {
@@ -391,9 +387,8 @@ impl Display {
let background_color = terminal.background_color();
let window_focused = self.window.is_focused;
- let grid_cells: Vec<RenderableCell> = terminal
- .renderable_cells(config, window_focused)
- .collect();
+ let grid_cells: Vec<RenderableCell> =
+ terminal.renderable_cells(config, window_focused).collect();
// Get message from terminal to ignore modifications after lock is dropped
let message_buffer = terminal.message_buffer_mut().message();
@@ -486,20 +481,14 @@ impl Display {
// Draw render timer
if self.render_timer {
let timing = format!("{:.3} usec", self.meter.average());
- let color = Rgb {
- r: 0xd5,
- g: 0x4e,
- b: 0x53,
- };
+ let color = Rgb { r: 0xd5, g: 0x4e, b: 0x53 };
self.renderer.with_api(config, &size_info, |mut api| {
api.render_string(&timing[..], size_info.lines() - 2, glyph_cache, Some(color));
});
}
}
- self.window
- .swap_buffers()
- .expect("swap buffers");
+ self.window.swap_buffers().expect("swap buffers");
}
pub fn get_window_id(&self) -> Option<usize> {
@@ -509,13 +498,8 @@ impl Display {
/// Adjust the IME editor position according to the new location of the cursor
pub fn update_ime_position(&mut self, terminal: &Term) {
let point = terminal.cursor().point;
- let SizeInfo {
- cell_width: cw,
- cell_height: ch,
- padding_x: px,
- padding_y: py,
- ..
- } = *terminal.size_info();
+ let SizeInfo { cell_width: cw, cell_height: ch, padding_x: px, padding_y: py, .. } =
+ *terminal.size_info();
let dpr = self.window().hidpi_factor();
let nspot_x = f64::from(px + point.col.0 as f32 * cw);
diff --git a/src/event.rs b/src/event.rs
index f7d9f225..ffedce2d 100644
--- a/src/event.rs
+++ b/src/event.rs
@@ -1,33 +1,33 @@
//! Process window events
+use std::borrow::Cow;
+use std::env;
#[cfg(unix)]
use std::fs;
-use std::borrow::Cow;
use std::fs::File;
use std::io::Write;
use std::sync::mpsc;
-use std::time::{Instant};
-use std::env;
+use std::time::Instant;
-use serde_json as json;
-use parking_lot::MutexGuard;
-use glutin::{self, ModifiersState, Event, ElementState, MouseButton};
-use copypasta::{Clipboard, Load, Store, Buffer as ClipboardBuffer};
+use copypasta::{Buffer as ClipboardBuffer, Clipboard, Load, Store};
use glutin::dpi::PhysicalSize;
+use glutin::{self, ElementState, Event, ModifiersState, MouseButton};
+use parking_lot::MutexGuard;
+use serde_json as json;
-#[cfg(unix)]
-use crate::tty;
-use crate::grid::Scroll;
-use crate::config::{self, Config};
use crate::cli::Options;
+use crate::config::{self, Config};
use crate::display::OnResize;
-use crate::index::{Line, Column, Side, Point};
-use crate::input::{self, MouseBinding, KeyBinding};
+use crate::grid::Scroll;
+use crate::index::{Column, Line, Point, Side};
+use crate::input::{self, KeyBinding, MouseBinding};
use crate::selection::Selection;
use crate::sync::FairMutex;
-use crate::term::{Term, SizeInfo};
use crate::term::cell::Cell;
-use crate::util::{limit, start_daemon};
+use crate::term::{SizeInfo, Term};
+#[cfg(unix)]
+use crate::tty;
use crate::util::fmt::Red;
+use crate::util::{limit, start_daemon};
use crate::window::Window;
/// Byte sequences are sent to a `Notify` in response to some events
@@ -66,10 +66,7 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
let size_info = self.size_info();
let point = size_info.pixels_to_coords(x, y);
let cell_side = self.mouse().cell_side;
- self.update_selection(Point {
- line: point.line,
- col: point.col
- }, cell_side);
+ self.update_selection(Point { line: point.line, col: point.col }, cell_side);
}
}
@@ -209,9 +206,7 @@ impl WindowChanges {
impl Default for WindowChanges {
fn default() -> WindowChanges {
- WindowChanges {
- hide: false,
- }
+ WindowChanges { hide: false }
}
}
@@ -358,16 +353,14 @@ impl<N: Notify> Processor<N> {
grid.initialize_all(&Cell::default());
grid.truncate();
- let serialized_grid = json::to_string(&grid)
- .expect("serialize grid");
+ let serialized_grid = json::to_string(&grid).expect("serialize grid");
- let serialized_size = json::to_string(processor.ctx.terminal.size_info())
- .expect("serialize size");
+ let serialized_size =
+ json::to_string(processor.ctx.terminal.size_info())
+ .expect("serialize size");
- let serialized_config = format!(
- "{{\"history_size\":{}}}",
- grid.history_size()
- );
+ let serialized_config =
+ format!("{{\"history_size\":{}}}", grid.history_size());
File::create("./grid.json")
.and_then(|mut f| f.write_all(serialized_grid.as_bytes()))
@@ -453,7 +446,7 @@ impl<N: Notify> Processor<N> {
},
Event::Awakened => {
processor.ctx.terminal.dirty = true;
- }
+ },
}
}
@@ -462,7 +455,7 @@ impl<N: Notify> Processor<N> {
pub fn process_events<'a>(
&mut self,
term: &'a FairMutex<Term>,
- window: &mut Window
+ window: &mut Window,
) -> MutexGuard<'a, Term> {
// Terminal is lazily initialized the first time an event is returned
// from the blocking WaitEventsIterator. Otherwise, the pty reader would
diff --git a/src/event_loop.rs b/src/event_loop.rs
index 31e803de..4941b479 100644
--- a/src/event_loop.rs
+++ b/src/event_loop.rs
@@ -1,10 +1,10 @@
//! The main event loop which performs I/O on the pseudoterminal
use std::borrow::Cow;
use std::collections::VecDeque;
-use std::io::{self, ErrorKind, Read, Write};
use std::fs::File;
-use std::sync::Arc;
+use std::io::{self, ErrorKind, Read, Write};
use std::marker::Send;
+use std::sync::Arc;
use mio::{self, Events, PollOpt, Ready};
use mio_extras::channel::{self, Receiver, Sender};
@@ -15,10 +15,10 @@ use mio::unix::UnixReady;
use crate::ansi;
use crate::display;
use crate::event;
-use crate::tty;
+use crate::sync::FairMutex;
use crate::term::Term;
+use crate::tty;
use crate::util::thread;
-use crate::sync::FairMutex;
/// Messages that may be sent to the `EventLoop`
#[derive(Debug)]
@@ -58,14 +58,14 @@ enum DrainResult {
/// Nothing was available to receive
Empty,
/// A shutdown message was received
- Shutdown
+ Shutdown,
}
impl DrainResult {
pub fn is_shutdown(&self) -> bool {
match *self {
DrainResult::Shutdown => true,
- _ => false
+ _ => false,
}
}
}
@@ -84,12 +84,13 @@ pub struct Notifier(pub Sender<Msg>);
impl event::Notify for Notifier {
fn notify<B>(&mut self, bytes: B)
- where B: Into<Cow<'static, [u8]>>,
+ where
+ B: Into<Cow<'static, [u8]>>,
{
let bytes = bytes.into();
// terminal hangs if we send 0 bytes through.
if bytes.len() == 0 {
- return
+ return;
}
if self.0.send(Msg::Input(bytes)).is_err() {
panic!("expected send event loop msg");
@@ -99,11 +100,7 @@ impl event::Notify for Notifier {
impl Default for State {
fn default() -> State {
- State {
- write_list: VecDeque::new(),
- parser: ansi::Processor::new(),
- writing: None,
- }
+ State { write_list: VecDeque::new(), parser: ansi::Processor::new(), writing: None }
}
}
@@ -117,9 +114,7 @@ impl State {
#[inline]
fn goto_next(&mut self) {
- self.writing = self.write_list
- .pop_front()
- .map(Writing::new);
+ self.writing = self.write_list.pop_front().map(Writing::new);
}
#[inline]
@@ -161,8 +156,8 @@ impl Writing {
}
impl<T> EventLoop<T>
- where
- T: tty::EventedPty + Send + 'static,
+where
+ T: tty::EventedPty + Send + 'static,
{
/// Create a new event loop
pub fn new(
@@ -198,10 +193,10 @@ impl<T> EventLoop<T>
match msg {
Msg::Input(input) => {
state.write_list.push_back(input);
- }
+ },
Msg::Shutdown => {
return DrainResult::Shutdown;
- }
+ },
}
}
@@ -233,8 +228,8 @@ impl<T> EventLoop<T>
buf: &mut [u8],
mut writer: Option<&mut X>,
) -> io::Result<()>
- where
- X: Write,
+ where
+ X: Write,
{
const MAX_READ: usize = 0x1_0000;
let mut processed = 0;
@@ -271,20 +266,18 @@ impl<T> EventLoop<T>
// Run the parser
for byte in &buf[..got] {
- state
- .parser
- .advance(&mut **terminal, *byte, &mut self.pty.writer());
+ state.parser.advance(&mut **terminal, *byte, &mut self.pty.writer());
}
// Exit if we've processed enough bytes
if processed > MAX_READ {
break;
}
- }
+ },
Err(err) => match err.kind() {
ErrorKind::Interrupted | ErrorKind::WouldBlock => {
break;
- }
+ },
_ => return Err(err),
},
}
@@ -311,21 +304,21 @@ impl<T> EventLoop<T>
Ok(0) => {
state.set_current(Some(current));
break 'write_many;
- }
+ },
Ok(n) => {
current.advance(n);
if current.finished() {
state.goto_next();
break 'write_one;
}
- }
+ },
Err(err) => {
state.set_current(Some(current));
match err.kind() {
ErrorKind::Interrupted | ErrorKind::WouldBlock => break 'write_many,
_ => return Err(err),
}
- }
+ },
}
}
}
@@ -343,14 +336,10 @@ impl<T> EventLoop<T>
let poll_opts = PollOpt::edge() | PollOpt::oneshot();
let channel_token = tokens.next().unwrap();
- self.poll
- .register(&self.rx, channel_token, Ready::readable(), poll_opts)
- .unwrap();
+ self.poll.register(&self.rx, channel_token, Ready::readable(), poll_opts).unwrap();
// Register TTY through EventedRW interface
- self.pty
- .register(&self.poll, &mut tokens, Ready::readable(), poll_opts)
- .unwrap();
+ self.pty.register(&self.poll, &mut tokens, Ready::readable(), poll_opts).unwrap();
let mut events = Events::with_capacity(1024);
@@ -385,8 +374,12 @@ impl<T> EventLoop<T>
}
},
- token if token == self.pty.read_token() || token == self.pty.write_token() => {
- #[cfg(unix)] {
+ token
+ if token == self.pty.read_token()
+ || token == self.pty.write_token() =>
+ {
+ #[cfg(unix)]
+ {
if UnixReady::from(event.readiness()).is_hup() {
// don't try to do I/O on a dead PTY
continue;
@@ -395,7 +388,8 @@ impl<T> EventLoop<T>
if event.readiness().is_readable() {
if let Err(e) = self.pty_read(&mut state, &mut buf, pipe.as_mut()) {
- #[cfg(target_os = "linux")] {
+ #[cfg(target_os = "linux")]
+ {
// On Linux, a `read` on the master side of a PTY can fail
// with `EIO` if the client side hangs up. In that case,
// just loop back round for the inevitable `Exited` event.
diff --git a/src/grid/mod.rs b/src/grid/mod.rs
index a1903535..3a6bacf8 100644
--- a/src/grid/mod.rs
+++ b/src/grid/mod.rs
@@ -14,10 +14,10 @@
//! A specialized 2d grid implementation optimized for use in a terminal.
-use std::cmp::{min, max, Ordering};
-use std::ops::{Deref, Range, Index, IndexMut, RangeTo, RangeFrom, RangeFull, RangeInclusive};
+use std::cmp::{max, min, Ordering};
+use std::ops::{Deref, Index, IndexMut, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo};
-use crate::index::{self, Point, Line, Column, IndexRange};
+use crate::index::{self, Column, IndexRange, Line, Point};
use crate::selection::Selection;
mod row;
@@ -55,13 +55,13 @@ impl<T> Deref for Indexed<T> {
impl<T: PartialEq> ::std::cmp::PartialEq for Grid<T> {
fn eq(&self, other: &Self) -> bool {
// Compare struct fields and check result of grid comparison
- self.raw.eq(&other.raw) &&
- self.cols.eq(&other.cols) &&
- self.lines.eq(&other.lines) &&
- self.display_offset.eq(&other.display_offset) &&
- self.scroll_limit.eq(&other.scroll_limit) &&
- self.selection.eq(&other.selection) &&
- self.url_highlight.eq(&other.url_highlight)
+ self.raw.eq(&other.raw)
+ && self.cols.eq(&other.cols)
+ && self.lines.eq(&other.lines)
+ && self.display_offset.eq(&other.display_offset)
+ && self.scroll_limit.eq(&other.scroll_limit)
+ && self.selection.eq(&other.selection)
+ && self.url_highlight.eq(&other.url_highlight)
}
}
@@ -142,10 +142,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
}
pub fn visible_to_buffer(&self, point: Point) -> Point<usize> {
- Point {
- line: self.visible_line_to_buffer(point.line),
- col: point.col
- }
+ Point { line: self.visible_line_to_buffer(point.line), col: point.col }
}
pub fn buffer_line_to_visible(&self, line: usize) -> ViewportPosition {
@@ -164,8 +161,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
}
/// Update the size of the scrollback history
- pub fn update_history(&mut self, history_size: usize, template: &T)
- {
+ pub fn update_history(&mut self, history_size: usize, template: &T) {
self.raw.update_history(history_size, Row::new(self.cols, &template));
self.max_scroll_limit = history_size;
self.scroll_limit = min(self.scroll_limit, history_size);
@@ -177,20 +173,14 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
Scroll::Lines(count) => {
self.display_offset = min(
max((self.display_offset as isize) + count, 0isize) as usize,
- self.scroll_limit
+ self.scroll_limit,
);
},
Scroll::PageUp => {
- self.display_offset = min(
- self.display_offset + self.lines.0,
- self.scroll_limit
- );
+ self.display_offset = min(self.display_offset + self.lines.0, self.scroll_limit);
},
Scroll::PageDown => {
- self.display_offset -= min(
- self.display_offset,
- self.lines.0
- );
+ self.display_offset -= min(self.display_offset, self.lines.0);
},
Scroll::Top => self.display_offset = self.scroll_limit,
Scroll::Bottom => self.display_offset = 0,
@@ -222,8 +212,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
}
}
- fn increase_scroll_limit(&mut self, count: usize, template: &T)
- {
+ fn increase_scroll_limit(&mut self, count: usize, template: &T) {
self.scroll_limit = min(self.scroll_limit + count, self.max_scroll_limit);
// Initialize new lines when the history buffer is smaller than the scroll limit
@@ -246,11 +235,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
/// Alacritty keeps the cursor at the bottom of the terminal as long as there
/// is scrollback available. Once scrollback is exhausted, new lines are
/// simply added to the bottom of the screen.
- fn grow_lines(
- &mut self,
- new_line_count: index::Line,
- template: &T,
- ) {
+ fn grow_lines(&mut self, new_line_count: index::Line, template: &T) {
let lines_added = new_line_count - self.lines;
// Need to "resize" before updating buffer
@@ -435,7 +420,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
// Now, restore any scroll region lines
let lines = self.lines;
- for i in IndexRange(region.end .. lines) {
+ for i in IndexRange(region.end..lines) {
self.raw.swap_lines(i, i + positions);
}
@@ -449,7 +434,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
self.raw.swap_lines(line, line - positions);
}
- for line in IndexRange(region.start .. (region.start + positions)) {
+ for line in IndexRange(region.start..(region.start + positions)) {
self.raw[line].reset(&template);
}
}
@@ -458,19 +443,12 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
/// scroll_up moves lines at the bottom towards the top
///
/// This is the performance-sensitive part of scrolling.
- pub fn scroll_up(
- &mut self,
- region: &Range<index::Line>,
- positions: index::Line,
- template: &T
- ) {
+ pub fn scroll_up(&mut self, region: &Range<index::Line>, positions: index::Line, template: &T) {
if region.start == Line(0) {
// Update display offset when not pinned to active area
if self.display_offset != 0 {
- self.display_offset = min(
- self.display_offset + *positions,
- self.len() - self.num_lines().0,
- );
+ self.display_offset =
+ min(self.display_offset + *positions, self.len() - self.num_lines().0);
}
self.increase_scroll_limit(*positions, template);
@@ -506,7 +484,7 @@ impl<T: GridCell + Copy + Clone> Grid<T> {
}
// Clear reused lines
- for line in IndexRange((region.end - positions) .. region.end) {
+ for line in IndexRange((region.end - positions)..region.end) {
self.raw[line].reset(&template);
}
}
@@ -569,7 +547,7 @@ impl<T> Grid<T> {
/// This is used only for initializing after loading ref-tests
pub fn initialize_all(&mut self, template: &T)
where
- T: Copy
+ T: Copy,
{
let history_size = self.raw.len().saturating_sub(*self.lines);
self.raw.initialize(self.max_scroll_limit - history_size, Row::new(self.cols, template));
@@ -581,10 +559,7 @@ impl<T> Grid<T> {
}
pub fn iter_from(&self, point: Point<usize>) -> GridIterator<'_, T> {
- GridIterator {
- grid: self,
- cur: point,
- }
+ GridIterator { grid: self, cur: point }
}
#[inline]
@@ -613,8 +588,7 @@ impl<'a, T> Iterator for GridIterator<'a, T> {
let last_col = self.grid.num_cols() - Column(1);
match self.cur {
Point { line, col } if line == 0 && col == last_col => None,
- Point { col, .. } if
- (col == last_col) => {
+ Point { col, .. } if (col == last_col) => {
self.cur.line -= 1;
self.cur.col = Column(0);
Some(&self.grid[self.cur.line][self.cur.col])
@@ -622,7 +596,7 @@ impl<'a, T> Iterator for GridIterator<'a, T> {
_ => {
self.cur.col += Column(1);
Some(&self.grid[self.cur.line][self.cur.col])
- }
+ },
}
}
}
@@ -641,7 +615,7 @@ impl<'a, T> BidirectionalIterator for GridIterator<'a, T> {
_ => {
self.cur.col -= Column(1);
Some(&self.grid[self.cur.line][self.cur.col])
- }
+ },
}
}
}
@@ -742,77 +716,48 @@ impl<T> IndexRegion<Range<Line>, T> for Grid<T> {
assert!(index.start < self.num_lines());
assert!(index.end <= self.num_lines());
assert!(index.start <= index.end);
- Region {
- start: index.start,
- end: index.end,
- raw: &self.raw
- }
+ Region { start: index.start, end: index.end, raw: &self.raw }
}
+
fn region_mut(&mut self, index: Range<Line>) -> RegionMut<'_, T> {
assert!(index.start < self.num_lines());
assert!(index.end <= self.num_lines());
assert!(index.start <= index.end);
- RegionMut {
- start: index.start,
- end: index.end,
- raw: &mut self.raw
- }
+ RegionMut { start: index.start, end: index.end, raw: &mut self.raw }
}
}
impl<T> IndexRegion<RangeTo<Line>, T> for Grid<T> {
fn region(&self, index: RangeTo<Line>) -> Region<'_, T> {
assert!(index.end <= self.num_lines());
- Region {
- start: Line(0),
- end: index.end,
- raw: &self.raw
- }
+ Region { start: Line(0), end: index.end, raw: &self.raw }
}
+
fn region_mut(&mut self, index: RangeTo<Line>) -> RegionMut<'_, T> {
assert!(index.end <= self.num_lines());
- RegionMut {
- start: Line(0),
- end: index.end,
- raw: &mut self.raw
- }
+ RegionMut { start: Line(0), end: index.end, raw: &mut self.raw }
}
}
impl<T> IndexRegion<RangeFrom<Line>, T> for Grid<T> {
fn region(&self, index: RangeFrom<Line>) -> Region<'_, T> {
assert!(index.start < self.num_lines());
- Region {
- start: index.start,
- end: self.num_lines(),
- raw: &self.raw
- }
+ Region { start: index.start, end: self.num_lines(), raw: &self.raw }
}
+
fn region_mut(&mut self, index: RangeFrom<Line>) -> RegionMut<'_, T> {
assert!(index.start < self.num_lines());
- RegionMut {
- start: index.start,
- end: self.num_lines(),
- raw: &mut self.raw
- }
+ RegionMut { start: index.start, end: self.num_lines(), raw: &mut self.raw }
}
}
impl<T> IndexRegion<RangeFull, T> for Grid<T> {
fn region(&self, _: RangeFull) -> Region<'_, T> {
- Region {
- start: Line(0),
- end: self.num_lines(),
- raw: &self.raw
- }
+ Region { start: Line(0), end: self.num_lines(), raw: &self.raw }
}
fn region_mut(&mut self, _: RangeFull) -> RegionMut<'_, T> {
- RegionMut {
- start: Line(0),
- end: self.num_lines(),
- raw: &mut self.raw
- }
+ RegionMut { start: Line(0), end: self.num_lines(), raw: &mut self.raw }
}
}
@@ -829,33 +774,26 @@ pub struct RegionIterMut<'a, T> {
}
impl<'a, T> IntoIterator for Region<'a, T> {
- type Item = &'a Row<T>;
type IntoIter = RegionIter<'a, T>;
+ type Item = &'a Row<T>;
fn into_iter(self) -> Self::IntoIter {
- RegionIter {
- end: self.end,
- cur: self.start,
- raw: self.raw
- }
+ RegionIter { end: self.end, cur: self.start, raw: self.raw }
}
}
impl<'a, T> IntoIterator for RegionMut<'a, T> {
- type Item = &'a mut Row<T>;
type IntoIter = RegionIterMut<'a, T>;
+ type Item = &'a mut Row<T>;
fn into_iter(self) -> Self::IntoIter {
- RegionIterMut {
- end: self.end,
- cur: self.start,
- raw: self.raw
- }
+ RegionIterMut { end: self.end, cur: self.start, raw: self.raw }
}
}
impl<'a, T> Iterator for RegionIter<'a, T> {
type Item = &'a Row<T>;
+
fn next(&mut self) -> Option<Self::Item> {
if self.cur < self.end {
let index = self.cur;
@@ -869,13 +807,12 @@ impl<'a, T> Iterator for RegionIter<'a, T> {
impl<'a, T> Iterator for RegionIterMut<'a, T> {
type Item = &'a mut Row<T>;
+
fn next(&mut self) -> Option<Self::Item> {
if self.cur < self.end {
let index = self.cur;
self.cur += 1;
- unsafe {
- Some(&mut *(&mut self.raw[index] as *mut _))
- }
+ unsafe { Some(&mut *(&mut self.raw[index] as *mut _)) }
} else {
None
}
@@ -898,7 +835,7 @@ pub struct DisplayIter<'a, T> {
impl<'a, T: 'a> DisplayIter<'a, T> {
pub fn new(grid: &'a Grid<T>) -> DisplayIter<'a, T> {
let offset = grid.display_offset + *grid.num_lines() - 1;
- let limit = grid.display_offset;
+ let limit = grid.display_offset;
let col = Column(0);
let line = Line(0);
@@ -932,7 +869,7 @@ impl<'a, T: Copy + 'a> Iterator for DisplayIter<'a, T> {
let item = Some(Indexed {
inner: self.grid.raw[self.offset][self.col],
line: self.line,
- column: self.col
+ column: self.col,
});
// Update line/col to point to next item
diff --git a/src/grid/row.rs b/src/grid/row.rs
index ef27f040..0a58de97 100644
--- a/src/grid/row.rs
+++ b/src/grid/row.rs
@@ -14,9 +14,9 @@
//! Defines the Row type which makes up lines in the grid
+use std::cmp::{max, min};
use std::ops::{Index, IndexMut};
-use std::ops::{Range, RangeTo, RangeFrom, RangeFull, RangeToInclusive};
-use std::cmp::{min, max};
+use std::ops::{Range, RangeFrom, RangeFull, RangeTo, RangeToInclusive};
use std::slice;
use crate::grid::GridCell;
@@ -46,10 +46,7 @@ impl<T: PartialEq> PartialEq for Row<T> {
impl<T: Copy> Row<T> {
pub fn new(columns: Column, template: &T) -> Row<T> {
- Row {
- inner: vec![*template; *columns],
- occ: 0,
- }
+ Row { inner: vec![*template; *columns], occ: 0 }
}
pub fn grow(&mut self, cols: Column, template: &T) {
@@ -62,7 +59,7 @@ impl<T: Copy> Row<T> {
pub fn shrink(&mut self, cols: Column) -> Option<Vec<T>>
where
- T: GridCell
+ T: GridCell,
{
if self.inner.len() <= cols.0 {
return None;
@@ -96,10 +93,7 @@ impl<T: Copy> Row<T> {
impl<T> Row<T> {
#[inline]
pub fn from_vec(vec: Vec<T>, occ: usize) -> Row<T> {
- Row {
- inner: vec,
- occ,
- }
+ Row { inner: vec, occ }
}
#[inline]
@@ -121,7 +115,7 @@ impl<T> Row<T> {
#[inline]
pub fn append(&mut self, vec: &mut Vec<T>)
where
- T: GridCell
+ T: GridCell,
{
self.inner.append(vec);
self.occ = self.inner.iter().rposition(|c| !c.is_empty()).map(|i| i + 1).unwrap_or(0);
@@ -137,7 +131,7 @@ impl<T> Row<T> {
#[inline]
pub fn is_empty(&self) -> bool
where
- T: GridCell
+ T: GridCell,
{
self.inner.iter().all(|c| c.is_empty())
}
@@ -153,8 +147,8 @@ impl<T> Row<T> {
}
impl<'a, T> IntoIterator for &'a mut Row<T> {
- type Item = &'a mut T;
type IntoIter = slice::IterMut<'a, T>;
+ type Item = &'a mut T;
#[inline]
fn into_iter(self) -> slice::IterMut<'a, T> {
diff --git a/src/grid/storage.rs b/src/grid/storage.rs
index 6a119ead..32260426 100644
--- a/src/grid/storage.rs
+++ b/src/grid/storage.rs
@@ -15,9 +15,9 @@ use std::ops::{Index, IndexMut};
use static_assertions::assert_eq_size;
-use crate::index::{Column, Line};
-use crate::grid::GridCell;
use super::Row;
+use crate::grid::GridCell;
+use crate::index::{Column, Line};
/// Maximum number of invisible lines before buffer is resized
const TRUNCATE_STEP: usize = 100;
@@ -46,11 +46,8 @@ impl<T: PartialEq> ::std::cmp::PartialEq for Storage<T> {
}
// Check which vec has the bigger zero
- let (ref bigger, ref smaller) = if self.zero >= other.zero {
- (self, other)
- } else {
- (other, self)
- };
+ let (ref bigger, ref smaller) =
+ if self.zero >= other.zero { (self, other) } else { (other, self) };
// Calculate the actual zero offset
let len = self.inner.len();
@@ -88,12 +85,7 @@ impl<T> Storage<T> {
// Initialize visible lines, the scrollback buffer is initialized dynamically
let inner = vec![template; lines.0];
- Storage {
- inner,
- zero: 0,
- visible_lines: lines - 1,
- len: lines.0,
- }
+ Storage { inner, zero: 0, visible_lines: lines - 1, len: lines.0 }
}
/// Update the size of the scrollback history
@@ -179,7 +171,8 @@ impl<T> Storage<T> {
/// Dynamically grow the storage buffer at runtime
pub fn initialize(&mut self, num_rows: usize, template_row: Row<T>)
- where T: Clone
+ where
+ T: Clone,
{
let mut new = vec![template_row; num_rows];
@@ -297,7 +290,7 @@ impl<T> Storage<T> {
#[inline]
pub fn shrink_hidden(&mut self, cols: Column)
where
- T: GridCell + Copy
+ T: GridCell + Copy,
{
let start = self.zero + self.len;
let end = self.zero + self.inner.len();
@@ -317,7 +310,7 @@ impl<T> Storage<T> {
#[inline]
pub fn grow_hidden(&mut self, cols: Column, template: &T)
where
- T: Copy + Clone
+ T: Copy + Clone,
{
let start = self.zero + self.len;
let end = self.zero + self.inner.len();
@@ -333,6 +326,7 @@ impl<T> Storage<T> {
impl<T> Index<usize> for Storage<T> {
type Output = Row<T>;
+
#[inline]
fn index(&self, index: usize) -> &Self::Output {
&self.inner[self.compute_index(index)]
@@ -349,6 +343,7 @@ impl<T> IndexMut<usize> for Storage<T> {
impl<T> Index<Line> for Storage<T> {
type Output = Row<T>;
+
#[inline]
fn index(&self, index: Line) -> &Self::Output {
let index = self.visible_lines - index;
@@ -379,7 +374,11 @@ impl<T> IndexMut<Line> for Storage<T> {
fn grow_after_zero() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'-')],
+ inner: vec![
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'-'),
+ ],
zero: 0,
visible_lines: Line(2),
len: 3,
@@ -390,7 +389,12 @@ fn grow_after_zero() {
// Make sure the result is correct
let expected = Storage {
- inner: vec![Row::new(Column(1), &'-'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'-')],
+ inner: vec![
+ Row::new(Column(1), &'-'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'-'),
+ ],
zero: 1,
visible_lines: Line(0),
len: 4,
@@ -415,7 +419,11 @@ fn grow_after_zero() {
fn grow_before_zero() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'-'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1')],
+ inner: vec![
+ Row::new(Column(1), &'-'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ ],
zero: 1,
visible_lines: Line(2),
len: 3,
@@ -426,7 +434,12 @@ fn grow_before_zero() {
// Make sure the result is correct
let expected = Storage {
- inner: vec![Row::new(Column(1), &'-'), Row::new(Column(1), &'-'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1')],
+ inner: vec![
+ Row::new(Column(1), &'-'),
+ Row::new(Column(1), &'-'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ ],
zero: 2,
visible_lines: Line(0),
len: 4,
@@ -450,7 +463,11 @@ fn grow_before_zero() {
fn shrink_before_zero() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'2'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1')],
+ inner: vec![
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ ],
zero: 1,
visible_lines: Line(2),
len: 3,
@@ -461,7 +478,11 @@ fn shrink_before_zero() {
// Make sure the result is correct
let expected = Storage {
- inner: vec![Row::new(Column(1), &'2'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1')],
+ inner: vec![
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ ],
zero: 1,
visible_lines: Line(0),
len: 2,
@@ -485,7 +506,11 @@ fn shrink_before_zero() {
fn shrink_after_zero() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'2')],
+ inner: vec![
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ ],
zero: 0,
visible_lines: Line(2),
len: 3,
@@ -496,7 +521,11 @@ fn shrink_after_zero() {
// Make sure the result is correct
let expected = Storage {
- inner: vec![Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'2')],
+ inner: vec![
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ ],
zero: 0,
visible_lines: Line(0),
len: 2,
@@ -526,7 +555,14 @@ fn shrink_after_zero() {
fn shrink_before_and_after_zero() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'4'), Row::new(Column(1), &'5'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'2'), Row::new(Column(1), &'3')],
+ inner: vec![
+ Row::new(Column(1), &'4'),
+ Row::new(Column(1), &'5'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'3'),
+ ],
zero: 2,
visible_lines: Line(5),
len: 6,
@@ -537,7 +573,14 @@ fn shrink_before_and_after_zero() {
// Make sure the result is correct
let expected = Storage {
- inner: vec![Row::new(Column(1), &'4'), Row::new(Column(1), &'5'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'2'), Row::new(Column(1), &'3')],
+ inner: vec![
+ Row::new(Column(1), &'4'),
+ Row::new(Column(1), &'5'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'3'),
+ ],
zero: 2,
visible_lines: Line(0),
len: 2,
@@ -563,7 +606,14 @@ fn shrink_before_and_after_zero() {
fn truncate_invisible_lines() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'4'), Row::new(Column(1), &'5'), Row::new(Column(1), &'0'), Row::new(Column(1), &'1'), Row::new(Column(1), &'2'), Row::new(Column(1), &'3')],
+ inner: vec![
+ Row::new(Column(1), &'4'),
+ Row::new(Column(1), &'5'),
+ Row::new(Column(1), &'0'),
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'3'),
+ ],
zero: 2,
visible_lines: Line(1),
len: 2,
@@ -598,7 +648,11 @@ fn truncate_invisible_lines() {
fn truncate_invisible_lines_beginning() {
// Setup storage area
let mut storage = Storage {
- inner: vec![Row::new(Column(1), &'1'), Row::new(Column(1), &'2'), Row::new(Column(1), &'0')],
+ inner: vec![
+ Row::new(Column(1), &'1'),
+ Row::new(Column(1), &'2'),
+ Row::new(Column(1), &'0'),
+ ],
zero: 2,
visible_lines: Line(1),
len: 2,
diff --git a/src/grid/tests.rs b/src/grid/tests.rs
index 82edda69..fc41fdc6 100644
--- a/src/grid/tests.rs
+++ b/src/grid/tests.rs
@@ -14,10 +14,10 @@
//! Tests for the Gird
-use super::{Grid, BidirectionalIterator};
-use crate::index::{Point, Line, Column};
-use crate::term::cell::{Cell, Flags};
+use super::{BidirectionalIterator, Grid};
use crate::grid::GridCell;
+use crate::index::{Column, Line, Point};
+use crate::term::cell::{Cell, Flags};
impl GridCell for usize {
fn is_empty(&self) -> bool {
@@ -101,14 +101,11 @@ fn test_iter() {
let mut grid = Grid::new(Line(5), Column(5), 0, 0);
for i in 0..5 {
for j in 0..5 {
- grid[Line(i)][Column(j)] = i*5 + j;
+ grid[Line(i)][Column(j)] = i * 5 + j;
}
}
- let mut iter = grid.iter_from(Point {
- line: 4,
- col: Column(0),
- });
+ let mut iter = grid.iter_from(Point { line: 4, col: Column(0) });
assert_eq!(None, iter.prev());
assert_eq!(Some(&1), iter.next());
@@ -128,12 +125,8 @@ fn test_iter() {
assert_eq!(Column(4), iter.cur.col);
assert_eq!(4, iter.cur.line);
-
// test that iter ends at end of grid
- let mut final_iter = grid.iter_from(Point {
- line: 0,
- col: Column(4),
- });
+ let mut final_iter = grid.iter_from(Point { line: 0, col: Column(4) });
assert_eq!(None, final_iter.next());
assert_eq!(Some(&23), final_iter.prev());
}
diff --git a/src/index.rs b/src/index.rs
index 0004454e..0351c0ee 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -17,18 +17,18 @@
/// Indexing types and implementations for Grid and Line
use std::cmp::{Ord, Ordering};
use std::fmt;
-use std::ops::{self, Deref, Range, RangeInclusive, Add, Sub, AddAssign, SubAssign};
+use std::ops::{self, Add, AddAssign, Deref, Range, RangeInclusive, Sub, SubAssign};
/// The side of a cell
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum Side {
Left,
- Right
+ Right,
}
/// Index in the grid using row, column notation
#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Serialize, Deserialize, PartialOrd)]
-pub struct Point<L=Line> {
+pub struct Point<L = Line> {
pub line: L,
pub col: Column,
}
@@ -43,11 +43,10 @@ impl Ord for Point {
fn cmp(&self, other: &Point) -> Ordering {
use std::cmp::Ordering::*;
match (self.line.cmp(&other.line), self.col.cmp(&other.col)) {
- (Equal, Equal) => Equal,
- (Equal, ord) |
- (ord, Equal) => ord,
- (Less, _) => Less,
- (Greater, _) => Greater,
+ (Equal, Equal) => Equal,
+ (Equal, ord) | (ord, Equal) => ord,
+ (Less, _) => Less,
+ (Greater, _) => Greater,
}
}
}
@@ -156,7 +155,7 @@ macro_rules! forward_ref_binop {
$imp::$method(*self, *other)
}
}
- }
+ };
}
/// Macro for deriving deref
@@ -170,7 +169,7 @@ macro_rules! deref {
&self.0
}
}
- }
+ };
}
macro_rules! add {
@@ -183,7 +182,7 @@ macro_rules! add {
$construct(self.0 + rhs.0)
}
}
- }
+ };
}
macro_rules! sub {
@@ -223,7 +222,7 @@ macro_rules! sub {
$construct(self.0 - rhs.0)
}
}
- }
+ };
}
/// This exists because we can't implement Iterator on Range
@@ -246,6 +245,7 @@ pub trait Contains {
impl<T: PartialOrd<T>> Contains for Range<T> {
type Content = T;
+
fn contains_(&self, item: Self::Content) -> bool {
(self.start <= item) && (item < self.end)
}
@@ -253,6 +253,7 @@ impl<T: PartialOrd<T>> Contains for Range<T> {
impl<T: PartialOrd<T>> Contains for RangeInclusive<T> {
type Content = T;
+
fn contains_(&self, item: Self::Content) -> bool {
(self.start() <= &item) && (&item <= self.end())
}
@@ -383,7 +384,7 @@ ops!(Linear, Linear);
#[cfg(test)]
mod tests {
- use super::{Line, Column, Point};
+ use super::{Column, Line, Point};
#[test]
fn location_ordering() {
diff --git a/src/input.rs b/src/input.rs
index 51e4e712..8ce8f2cd 100644
--- a/src/input.rs
+++ b/src/input.rs
@@ -20,27 +20,27 @@
//! determine what to do when a non-modifier key is pressed.
use std::borrow::Cow;
use std::mem;
-use std::time::Instant;
use std::ops::RangeInclusive;
+use std::time::Instant;
-use copypasta::{Clipboard, Load, Buffer as ClipboardBuffer};
-use unicode_width::UnicodeWidthStr;
+use copypasta::{Buffer as ClipboardBuffer, Clipboard, Load};
use glutin::{
ElementState, KeyboardInput, ModifiersState, MouseButton, MouseCursor, MouseScrollDelta,
TouchPhase,
};
+use unicode_width::UnicodeWidthStr;
+use crate::ansi::{ClearMode, Handler};
use crate::config::{self, Key};
-use crate::grid::Scroll;
use crate::event::{ClickState, Mouse};
-use crate::index::{Line, Column, Side, Point, Linear};
-use crate::term::{Term, SizeInfo, Search};
+use crate::grid::Scroll;
+use crate::index::{Column, Line, Linear, Point, Side};
+use crate::message_bar::{self, Message};
use crate::term::mode::TermMode;
+use crate::term::{Search, SizeInfo, Term};
+use crate::url::Url;
use crate::util::fmt::Red;
use crate::util::start_daemon;
-use crate::message_bar::{self, Message};
-use crate::ansi::{Handler, ClearMode};
-use crate::url::Url;
pub const FONT_SIZE_STEP: f32 = 0.5;
@@ -148,10 +148,10 @@ impl<T: Eq> Binding<T> {
// Check input first since bindings are stored in one big list. This is
// the most likely item to fail so prioritizing it here allows more
// checks to be short circuited.
- self.trigger == *input &&
- self.mode_matches(mode) &&
- self.not_mode_matches(mode) &&
- self.mods_match(mods, relaxed)
+ self.trigger == *input
+ && self.mode_matches(mode)
+ && self.not_mode_matches(mode)
+ && self.mods_match(mods, relaxed)
}
#[inline]
@@ -267,8 +267,8 @@ impl Action {
},
Action::Paste => {
Clipboard::new()
- .and_then(|clipboard| clipboard.load_primary() )
- .map(|contents| { self.paste(ctx, &contents) })
+ .and_then(|clipboard| clipboard.load_primary())
+ .map(|contents| self.paste(ctx, &contents))
.unwrap_or_else(|err| {
error!("Error loading data from clipboard: {}", Red(err));
});
@@ -277,8 +277,8 @@ impl Action {
// Only paste if mouse events are not captured by an application
if !mouse_mode {
Clipboard::new()
- .and_then(|clipboard| clipboard.load_selection() )
- .map(|contents| { self.paste(ctx, &contents) })
+ .and_then(|clipboard| clipboard.load_selection())
+ .map(|contents| self.paste(ctx, &contents))
.unwrap_or_else(|err| {
error!("Error loading data from clipboard: {}", Red(err));
});
@@ -303,13 +303,13 @@ impl Action {
ctx.terminal_mut().exit();
},
Action::IncreaseFontSize => {
- ctx.terminal_mut().change_font_size(FONT_SIZE_STEP);
+ ctx.terminal_mut().change_font_size(FONT_SIZE_STEP);
},
Action::DecreaseFontSize => {
- ctx.terminal_mut().change_font_size(-FONT_SIZE_STEP);
- }
+ ctx.terminal_mut().change_font_size(-FONT_SIZE_STEP);
+ },
Action::ResetFontSize => {
- ctx.terminal_mut().reset_font_size();
+ ctx.terminal_mut().reset_font_size();
},
Action::ScrollPageUp => {
ctx.scroll(Scroll::PageUp);
@@ -339,7 +339,7 @@ impl Action {
fn paste<A: ActionContext>(&self, ctx: &mut A, contents: &str) {
if ctx.terminal().mode().contains(TermMode::BRACKETED_PASTE) {
ctx.write_to_pty(&b"\x1b[200~"[..]);
- ctx.write_to_pty(contents.replace("\x1b","").into_bytes());
+ ctx.write_to_pty(contents.replace("\x1b", "").into_bytes());
ctx.write_to_pty(&b"\x1b[201~"[..]);
} else {
// In non-bracketed (ie: normal) mode, terminal applications cannot distinguish
@@ -348,7 +348,7 @@ impl Action {
// pasting... since that's neither practical nor sensible (and probably an impossible
// task to solve in a general way), we'll just replace line breaks (windows and unix
// style) with a singe carriage return (\r, which is what the Enter key produces).
- ctx.write_to_pty(contents.replace("\r\n","\r").replace("\n","\r").into_bytes());
+ ctx.write_to_pty(contents.replace("\r\n", "\r").replace("\n", "\r").into_bytes());
}
}
}
@@ -411,13 +411,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
if self.ctx.mouse().left_button_state == ElementState::Pressed
&& (modifiers.shift || !self.ctx.terminal().mode().intersects(report_mode))
{
- self.ctx.update_selection(
- Point {
- line: point.line,
- col: point.col,
- },
- cell_side,
- );
+ self.ctx.update_selection(Point { line: point.line, col: point.col }, cell_side);
} else if self.ctx.terminal().mode().intersects(motion_mode)
&& size_info.contains_point(x, y, false)
{
@@ -443,7 +437,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
&& (!self.ctx.terminal().mode().intersects(mouse_mode) || modifiers.shift)
&& self.mouse_config.url.launcher.is_some()
{
- self.ctx.terminal().url_search(point.into())
+ self.ctx.terminal().url_search(point.into())
} else {
None
};
@@ -582,14 +576,14 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
self.ctx.mouse_mut().block_url_launcher = true;
self.on_mouse_double_click(button, point);
ClickState::DoubleClick
- },
+ }
ClickState::DoubleClick
if !button_changed && elapsed < self.mouse_config.triple_click.threshold =>
{
self.ctx.mouse_mut().block_url_launcher = true;
self.on_mouse_triple_click(button, point);
ClickState::TripleClick
- },
+ }
_ => {
// Don't launch URLs if this click cleared the selection
self.ctx.mouse_mut().block_url_launcher = !self.ctx.selection_is_empty();
@@ -617,7 +611,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
}
ClickState::Click
- }
+ },
};
}
@@ -690,7 +684,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
},
_ => (),
}
- }
+ },
}
}
@@ -744,11 +738,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
pub fn on_focus_change(&mut self, is_focused: bool) {
if self.ctx.terminal().mode().contains(TermMode::FOCUS_IN_OUT) {
- let chr = if is_focused {
- "I"
- } else {
- "O"
- };
+ let chr = if is_focused { "I" } else { "O" };
let msg = format!("\x1b[{}", chr);
self.ctx.write_to_pty(msg.into_bytes());
@@ -759,7 +749,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
&mut self,
state: ElementState,
button: MouseButton,
- modifiers: ModifiersState
+ modifiers: ModifiersState,
) {
match button {
MouseButton::Left => self.ctx.mouse_mut().left_button_state = state,
@@ -849,16 +839,18 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
&Key::Scancode(input.scancode),
false,
),
- _ => if let Some(key) = input.virtual_keycode {
- let key = Key::from_glutin_input(key);
- binding.is_triggered_by(
- *self.ctx.terminal().mode(),
- input.modifiers,
- &key,
+ _ => {
+ if let Some(key) = input.virtual_keycode {
+ let key = Key::from_glutin_input(key);
+ binding.is_triggered_by(
+ *self.ctx.terminal().mode(),
+ input.modifiers,
+ &key,
+ false,
+ )
+ } else {
false
- )
- } else {
- false
+ }
},
};
@@ -883,11 +875,12 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
for binding in self.mouse_bindings {
if binding.is_triggered_by(*self.ctx.terminal().mode(), mods, &button, true) {
// binding was triggered; run the action
- let mouse_mode = !mods.shift && self.ctx.terminal().mode().intersects(
- TermMode::MOUSE_REPORT_CLICK
- | TermMode::MOUSE_DRAG
- | TermMode::MOUSE_MOTION
- );
+ let mouse_mode = !mods.shift
+ && self.ctx.terminal().mode().intersects(
+ TermMode::MOUSE_REPORT_CLICK
+ | TermMode::MOUSE_DRAG
+ | TermMode::MOUSE_MOTION,
+ );
binding.execute(&mut self.ctx, mouse_mode);
has_binding = true;
}
@@ -898,10 +891,9 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
/// Return the message bar's message if there is some at the specified point
fn message_at_point(&mut self, point: Option<Point>) -> Option<Message> {
- if let (Some(point), Some(message)) = (
- point,
- self.ctx.terminal_mut().message_buffer_mut().message(),
- ) {
+ if let (Some(point), Some(message)) =
+ (point, self.ctx.terminal_mut().message_buffer_mut().message())
+ {
let size = self.ctx.size_info();
if point.line.0 >= size.lines().saturating_sub(message.text(&size).len()) {
return Some(message);
@@ -924,7 +916,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
}
self.ctx.clear_selection();
- }
+ },
}
}
@@ -942,15 +934,15 @@ mod tests {
use std::borrow::Cow;
use std::time::Duration;
- use glutin::{VirtualKeyCode, Event, WindowEvent, ElementState, MouseButton, ModifiersState};
+ use glutin::{ElementState, Event, ModifiersState, MouseButton, VirtualKeyCode, WindowEvent};
- use crate::term::{SizeInfo, Term, TermMode};
- use crate::event::{Mouse, ClickState, WindowChanges};
- use crate::config::{self, Config, ClickHandler};
- use crate::index::{Point, Side};
- use crate::selection::Selection;
+ use crate::config::{self, ClickHandler, Config};
+ use crate::event::{ClickState, Mouse, WindowChanges};
use crate::grid::Scroll;
+ use crate::index::{Point, Side};
use crate::message_bar::MessageBuffer;
+ use crate::selection::Selection;
+ use crate::term::{SizeInfo, Term, TermMode};
use super::{Action, Binding, Processor};
use copypasta::Buffer as ClipboardBuffer;
@@ -976,13 +968,19 @@ mod tests {
pub window_changes: &'a mut WindowChanges,
}
- impl <'a>super::ActionContext for ActionContext<'a> {
+ impl<'a> super::ActionContext for ActionContext<'a> {
fn write_to_pty<B: Into<Cow<'static, [u8]>>>(&mut self, _val: B) {}
+
fn update_selection(&mut self, _point: Point, _side: Side) {}
+
fn simple_selection(&mut self, _point: Point, _side: Side) {}
+
fn copy_selection(&self, _buffer: ClipboardBuffer) {}
+
fn clear_selection(&mut self) {}
+
fn hide_window(&mut self) {}
+
fn spawn_new_instance(&mut self) {}
fn terminal(&self) -> &Term {
diff --git a/src/lib.rs b/src/lib.rs
index 64d554ca..92ccb5a7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -17,8 +17,10 @@
#![cfg_attr(feature = "nightly", feature(core_intrinsics))]
#![cfg_attr(all(test, feature = "bench"), feature(test))]
-#[macro_use] extern crate log;
-#[macro_use] extern crate serde_derive;
+#[macro_use]
+extern crate log;
+#[macro_use]
+extern crate serde_derive;
#[cfg(target_os = "macos")]
#[macro_use]
@@ -37,6 +39,7 @@ pub mod index;
pub mod input;
pub mod locale;
pub mod logging;
+pub mod message_bar;
pub mod meter;
pub mod panic;
pub mod renderer;
@@ -44,10 +47,9 @@ pub mod selection;
pub mod sync;
pub mod term;
pub mod tty;
+mod url;
pub mod util;
pub mod window;
-pub mod message_bar;
-mod url;
pub use crate::grid::Grid;
pub use crate::term::Term;
diff --git a/src/locale.rs b/src/locale.rs
index 81904f79..40c915b5 100644
--- a/src/locale.rs
+++ b/src/locale.rs
@@ -13,13 +13,13 @@
// limitations under the License.
#![allow(clippy::let_unit_value)]
#![cfg(target_os = "macos")]
-use libc::{LC_CTYPE, setlocale};
-use std::ffi::{CString, CStr};
+use libc::{setlocale, LC_CTYPE};
+use std::env;
+use std::ffi::{CStr, CString};
use std::os::raw::c_char;
use std::ptr::null;
use std::slice;
use std::str;
-use std::env;
use objc::runtime::{Class, Object};
@@ -27,30 +27,32 @@ pub fn set_locale_environment() {
let locale_id = unsafe {
let locale_class = Class::get("NSLocale").unwrap();
let locale: *const Object = msg_send![locale_class, currentLocale];
- let _ : () = msg_send![locale_class, release];
+ let _: () = msg_send![locale_class, release];
// `localeIdentifier` returns extra metadata with the locale (including currency and
// collator) on newer versions of macOS. This is not a valid locale, so we use
// `languageCode` and `countryCode`, if they're available (macOS 10.12+):
// https://developer.apple.com/documentation/foundation/nslocale/1416263-localeidentifier?language=objc
// https://developer.apple.com/documentation/foundation/nslocale/1643060-countrycode?language=objc
// https://developer.apple.com/documentation/foundation/nslocale/1643026-languagecode?language=objc
- let is_language_code_supported: bool = msg_send![locale, respondsToSelector:sel!(languageCode)];
- let is_country_code_supported: bool = msg_send![locale, respondsToSelector:sel!(countryCode)];
+ let is_language_code_supported: bool =
+ msg_send![locale, respondsToSelector: sel!(languageCode)];
+ let is_country_code_supported: bool =
+ msg_send![locale, respondsToSelector: sel!(countryCode)];
let locale_id = if is_language_code_supported && is_country_code_supported {
let language_code: *const Object = msg_send![locale, languageCode];
let country_code: *const Object = msg_send![locale, countryCode];
let language_code_str = nsstring_as_str(language_code).to_owned();
- let _ : () = msg_send![language_code, release];
+ let _: () = msg_send![language_code, release];
let country_code_str = nsstring_as_str(country_code).to_owned();
- let _ : () = msg_send![country_code, release];
+ let _: () = msg_send![country_code, release];
format!("{}_{}.UTF-8", &language_code_str, &country_code_str)
} else {
let identifier: *const Object = msg_send![locale, localeIdentifier];
let identifier_str = nsstring_as_str(identifier).to_owned();
- let _ : () = msg_send![identifier, release];
+ let _: () = msg_send![identifier, release];
identifier_str + ".UTF-8"
};
- let _ : () = msg_send![locale, release];
+ let _: () = msg_send![locale, release];
locale_id
};
// check if locale_id is valid
@@ -66,11 +68,7 @@ pub fn set_locale_environment() {
};
// try setting `locale_id`
let modified = setlocale(LC_CTYPE, locale_ptr);
- let result = if modified.is_null() {
- String::new()
- } else {
- locale_id
- };
+ let result = if modified.is_null() { String::new() } else { locale_id };
// restore original setting
setlocale(LC_CTYPE, saved_original.as_ptr());
result
diff --git a/src/logging.rs b/src/logging.rs
index 0b1d25a4..c6ddd8e6 100644
--- a/src/logging.rs
+++ b/src/logging.rs
@@ -68,12 +68,7 @@ impl Logger {
let logfile = Mutex::new(OnDemandLogFile::new());
let stdout = Mutex::new(LineWriter::new(io::stdout()));
- Logger {
- level,
- logfile,
- stdout,
- message_tx,
- }
+ Logger { level, logfile, stdout, message_tx }
}
fn file_path(&self) -> Option<PathBuf> {
@@ -100,10 +95,7 @@ impl log::Log for Logger {
now,
record.level(),
record.file().unwrap_or("?"),
- record
- .line()
- .map(|l| l.to_string())
- .unwrap_or_else(|| "?".into()),
+ record.line().map(|l| l.to_string()).unwrap_or_else(|| "?".into()),
record.args()
)
} else {
@@ -161,11 +153,7 @@ impl OnDemandLogFile {
// Set log path as an environment variable
env::set_var(ALACRITTY_LOG_ENV, path.as_os_str());
- OnDemandLogFile {
- path,
- file: None,
- created: Arc::new(AtomicBool::new(false)),
- }
+ OnDemandLogFile { path, file: None, created: Arc::new(AtomicBool::new(false)) }
}
fn file(&mut self) -> Result<&mut LineWriter<File>, io::Error> {
@@ -176,21 +164,18 @@ impl OnDemandLogFile {
// Create the file if it doesn't exist yet
if self.file.is_none() {
- let file = OpenOptions::new()
- .append(true)
- .create(true)
- .open(&self.path);
+ let file = OpenOptions::new().append(true).create(true).open(&self.path);
match file {
Ok(file) => {
self.file = Some(io::LineWriter::new(file));
self.created.store(true, Ordering::Relaxed);
let _ = writeln!(io::stdout(), "Created log file at {:?}", self.path);
- }
+ },
Err(e) => {
let _ = writeln!(io::stdout(), "Unable to create log file: {}", e);
return Err(e);
- }
+ },
}
}
diff --git a/src/main.rs b/src/main.rs
index d5142dbe..d7e335e2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -16,7 +16,6 @@
#![deny(clippy::all, clippy::if_not_else, clippy::enum_glob_use, clippy::wrong_pub_self_convention)]
#![cfg_attr(feature = "nightly", feature(core_intrinsics))]
#![cfg_attr(all(test, feature = "bench"), feature(test))]
-
// With the default subsystem, 'console', windows creates an additional console
// window for the program.
// This is silently ignored on non-windows systems.
@@ -29,12 +28,12 @@ use dirs;
#[cfg(windows)]
use winapi::um::wincon::{AttachConsole, FreeConsole, ATTACH_PARENT_PROCESS};
-use log::{info, error};
+use log::{error, info};
use std::error::Error;
-use std::sync::Arc;
-use std::io::{self, Write};
use std::fs;
+use std::io::{self, Write};
+use std::sync::Arc;
#[cfg(target_os = "macos")]
use std::env;
@@ -42,19 +41,19 @@ use std::env;
#[cfg(not(windows))]
use std::os::unix::io::AsRawFd;
-#[cfg(target_os = "macos")]
-use alacritty::locale;
-use alacritty::{cli, event, die};
use alacritty::config::{self, Config, Monitor};
use alacritty::display::Display;
use alacritty::event_loop::{self, EventLoop, Msg};
+#[cfg(target_os = "macos")]
+use alacritty::locale;
use alacritty::logging;
+use alacritty::message_bar::MessageBuffer;
use alacritty::panic;
use alacritty::sync::FairMutex;
use alacritty::term::Term;
use alacritty::tty;
use alacritty::util::fmt::Red;
-use alacritty::message_bar::MessageBuffer;
+use alacritty::{cli, die, event};
fn main() {
panic::attach_handler();
@@ -63,7 +62,9 @@ fn main() {
// to the console of the parent process, so we do it explicitly. This fails
// silently if the parent has no console.
#[cfg(windows)]
- unsafe { AttachConsole(ATTACH_PARENT_PROCESS); }
+ unsafe {
+ AttachConsole(ATTACH_PARENT_PROCESS);
+ }
// Load command line options
let options = cli::Options::load();
@@ -77,7 +78,8 @@ fn main() {
// Load configuration file
// If the file is a command line argument, we won't write a generated default file
- let config_path = options.config_path()
+ let config_path = options
+ .config_path()
.or_else(Config::installed_config)
.or_else(|| Config::write_defaults().ok())
.map(|path| path.to_path_buf());
@@ -133,11 +135,7 @@ fn run(
// The display manages a window and can draw the terminal
let mut display = Display::new(&config, options)?;
- info!(
- "PTY Dimensions: {:?} x {:?}",
- display.size().lines(),
- display.size().cols()
- );
+ info!("PTY Dimensions: {:?} x {:?}", display.size().lines(), display.size().cols());
// Create the terminal
//
@@ -173,12 +171,8 @@ fn run(
// renderer and input processing. Note that access to the terminal state is
// synchronized since the I/O loop updates the state, and the display
// consumes it periodically.
- let event_loop = EventLoop::new(
- Arc::clone(&terminal),
- display.notifier(),
- pty,
- options.ref_test,
- );
+ let event_loop =
+ EventLoop::new(Arc::clone(&terminal), display.notifier(), pty, options.ref_test);
// The event loop channel allows write requests from the event processor
// to be sent to the loop and ultimately written to the pty.
@@ -259,16 +253,16 @@ fn run(
}
}
- loop_tx
- .send(Msg::Shutdown)
- .expect("Error sending shutdown to event loop");
+ loop_tx.send(Msg::Shutdown).expect("Error sending shutdown to event loop");
// FIXME patch notify library to have a shutdown method
// config_reloader.join().ok();
// Without explicitly detaching the console cmd won't redraw it's prompt
#[cfg(windows)]
- unsafe { FreeConsole(); }
+ unsafe {
+ FreeConsole();
+ }
info!("Goodbye");
diff --git a/src/message_bar.rs b/src/message_bar.rs
index d7f27e7e..8883dcb0 100644
--- a/src/message_bar.rs
+++ b/src/message_bar.rs
@@ -33,11 +33,7 @@ pub struct Message {
impl Message {
/// Create a new message
pub fn new(text: String, color: Rgb) -> Message {
- Message {
- text,
- color,
- topic: None,
- }
+ Message { text, color, topic: None }
}
/// Formatted message text lines
@@ -135,11 +131,7 @@ impl MessageBuffer {
/// Create new message buffer
pub fn new() -> MessageBuffer {
let (tx, messages) = crossbeam_channel::unbounded();
- MessageBuffer {
- current: None,
- messages,
- tx,
- }
+ MessageBuffer { current: None, messages, tx }
}
/// Check if there are any messages queued
@@ -215,10 +207,7 @@ mod test {
fn appends_close_button() {
let input = "a";
let mut message_buffer = MessageBuffer::new();
- message_buffer
- .tx()
- .send(Message::new(input.into(), color::RED))
- .unwrap();
+ message_buffer.tx().send(Message::new(input.into(), color::RED)).unwrap();
let size = SizeInfo {
width: 7.,
height: 10.,
@@ -238,10 +227,7 @@ mod test {
fn multiline_close_button_first_line() {
let input = "fo\nbar";
let mut message_buffer = MessageBuffer::new();
- message_buffer
- .tx()
- .send(Message::new(input.into(), color::RED))
- .unwrap();
+ message_buffer.tx().send(Message::new(input.into(), color::RED)).unwrap();
let size = SizeInfo {
width: 6.,
height: 10.,
@@ -261,10 +247,7 @@ mod test {
fn splits_on_newline() {
let input = "a\nb";
let mut message_buffer = MessageBuffer::new();
- message_buffer
- .tx()
- .send(Message::new(input.into(), color::RED))
- .unwrap();
+ message_buffer.tx().send(Message::new(input.into(), color::RED)).unwrap();
let size = SizeInfo {
width: 6.,
height: 10.,
@@ -284,10 +267,7 @@ mod test {
fn splits_on_length() {
let input = "foobar1";
let mut message_buffer = MessageBuffer::new();
- message_buffer
- .tx()
- .send(Message::new(input.into(), color::RED))
- .unwrap();
+ message_buffer.tx().send(Message::new(input.into(), color::RED)).unwrap();
let size = SizeInfo {
width: 6.,
height: 10.,
@@ -307,10 +287,7 @@ mod test {
fn empty_with_shortterm() {
let input = "foobar";
let mut message_buffer = MessageBuffer::new();
- message_buffer
- .tx()
- .send(Message::new(input.into(), color::RED))
- .unwrap();
+ message_buffer.tx().send(Message::new(input.into(), color::RED)).unwrap();
let size = SizeInfo {
width: 6.,
height: 0.,
@@ -330,10 +307,7 @@ mod test {
fn truncates_long_messages() {
let input = "hahahahahahahahahahaha truncate this because it's too long for the term";
let mut message_buffer = MessageBuffer::new();
- message_buffer
- .tx()
- .send(Message::new(input.into(), color::RED))
- .unwrap();
+ message_buffer.tx().send(Message::new(input.into(), color::RED)).unwrap();
let size = SizeInfo {
width: 22.,
height: (MIN_FREE_LINES + 2) as f32,
@@ -346,23 +320,17 @@ mod test {
let lines = message_buffer.message().unwrap().text(&size);
- assert_eq!(
- lines,
- vec![
- String::from("hahahahahahahahaha [X]"),
- String::from("[MESSAGE TRUNCATED] ")
- ]
- );
+ assert_eq!(lines, vec![
+ String::from("hahahahahahahahaha [X]"),
+ String::from("[MESSAGE TRUNCATED] ")
+ ]);
}
#[test]
fn hide_button_when_too_narrow() {
let input = "ha";
let mut message_buffer = MessageBuffer::new();
- message_buffer
- .tx()
- .send(Message::new(input.into(), color::RED))
- .unwrap();
+ message_buffer.tx().send(Message::new(input.into(), color::RED)).unwrap();
let size = SizeInfo {
width: 2.,
height: 10.,
@@ -382,10 +350,7 @@ mod test {
fn hide_truncated_when_too_narrow() {
let input = "hahahahahahahahaha";
let mut message_buffer = MessageBuffer::new();
- message_buffer
- .tx()
- .send(Message::new(input.into(), color::RED))
- .unwrap();
+ message_buffer.tx().send(Message::new(input.into(), color::RED)).unwrap();
let size = SizeInfo {
width: 2.,
height: (MIN_FREE_LINES + 2) as f32,
@@ -405,10 +370,7 @@ mod test {
fn add_newline_for_button() {
let input = "test";
let mut message_buffer = MessageBuffer::new();
- message_buffer
- .tx()
- .send(Message::new(input.into(), color::RED))
- .unwrap();
+ message_buffer.tx().send(Message::new(input.into(), color::RED)).unwrap();
let size = SizeInfo {
width: 5.,
height: 10.,
@@ -466,10 +428,7 @@ mod test {
fn wrap_on_words() {
let input = "a\nbc defg";
let mut message_buffer = MessageBuffer::new();
- message_buffer
- .tx()
- .send(Message::new(input.into(), color::RED))
- .unwrap();
+ message_buffer.tx().send(Message::new(input.into(), color::RED)).unwrap();
let size = SizeInfo {
width: 5.,
height: 10.,
@@ -482,14 +441,11 @@ mod test {
let lines = message_buffer.message().unwrap().text(&size);
- assert_eq!(
- lines,
- vec![
- String::from("a [X]"),
- String::from("bc "),
- String::from("defg ")
- ]
- );
+ assert_eq!(lines, vec![
+ String::from("a [X]"),
+ String::from("bc "),
+ String::from("defg ")
+ ]);
}
#[test]
diff --git a/src/meter.rs b/src/meter.rs
index 32650e4d..81da4442 100644
--- a/src/meter.rs
+++ b/src/meter.rs
@@ -31,7 +31,7 @@
//! // the average won't mean much until it's filled up at least once.
//! println!("Average time: {}", meter.average());
-use std::time::{Instant, Duration};
+use std::time::{Duration, Instant};
const NUM_SAMPLES: usize = 10;
@@ -61,10 +61,7 @@ pub struct Sampler<'a> {
impl<'a> Sampler<'a> {
fn new(meter: &'a mut Meter) -> Sampler<'a> {
- Sampler {
- meter,
- created_at: Instant::now(),
- }
+ Sampler { meter, created_at: Instant::now() }
}
#[inline]
diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs
index 6258ba60..b7b4f21a 100644
--- a/src/renderer/mod.rs
+++ b/src/renderer/mod.rs
@@ -22,17 +22,17 @@ use std::sync::mpsc;
use std::time::Duration;
use fnv::FnvHasher;
-use glutin::dpi::PhysicalSize;
use font::{self, FontDesc, FontKey, GlyphKey, Rasterize, RasterizedGlyph, Rasterizer};
+use glutin::dpi::PhysicalSize;
use notify::{watcher, DebouncedEvent, RecursiveMode, Watcher};
-use crate::gl::types::*;
+use crate::config::{self, Config, Delta};
use crate::gl;
+use crate::gl::types::*;
use crate::index::{Column, Line};
+use crate::renderer::rects::{Rect, Rects};
use crate::term::color::Rgb;
-use crate::config::{self, Config, Delta};
use crate::term::{self, cell, RenderableCell};
-use crate::renderer::rects::{Rect, Rects};
pub mod rects;
@@ -91,7 +91,7 @@ impl ::std::fmt::Display for Error {
match *self {
Error::ShaderCreation(ref err) => {
write!(f, "There was an error initializing the shaders: {}", err)
- }
+ },
}
}
}
@@ -214,11 +214,7 @@ impl GlyphCache {
fn load_glyphs_for_font<L: LoadGlyph>(&mut self, font: FontKey, loader: &mut L) {
let size = self.font_size;
for i in 32u8..=128u8 {
- self.get(GlyphKey {
- font_key: font,
- c: i as char,
- size,
- }, loader);
+ self.get(GlyphKey { font_key: font, c: i as char, size }, loader);
}
}
@@ -230,7 +226,8 @@ impl GlyphCache {
let size = font.size();
// Load regular font
- let regular_desc = Self::make_desc(&font.normal(), font::Slant::Normal, font::Weight::Normal);
+ let regular_desc =
+ Self::make_desc(&font.normal(), font::Slant::Normal, font::Weight::Normal);
let regular = rasterizer.load_font(&regular_desc, size)?;
@@ -239,9 +236,7 @@ impl GlyphCache {
if desc == regular_desc {
regular
} else {
- rasterizer
- .load_font(&desc, size)
- .unwrap_or_else(|_| regular)
+ rasterizer.load_font(&desc, size).unwrap_or_else(|_| regular)
}
};
@@ -251,7 +246,8 @@ impl GlyphCache {
let bold = load_or_regular(bold_desc);
// Load italic font
- let italic_desc = Self::make_desc(&font.italic(), font::Slant::Italic, font::Weight::Normal);
+ let italic_desc =
+ Self::make_desc(&font.italic(), font::Slant::Italic, font::Weight::Normal);
let italic = load_or_regular(italic_desc);
@@ -278,30 +274,30 @@ impl GlyphCache {
}
pub fn get<'a, L>(&'a mut self, glyph_key: GlyphKey, loader: &mut L) -> &'a Glyph
- where L: LoadGlyph
+ where
+ L: LoadGlyph,
{
let glyph_offset = self.glyph_offset;
let rasterizer = &mut self.rasterizer;
let metrics = &self.metrics;
- self.cache
- .entry(glyph_key)
- .or_insert_with(|| {
- let mut rasterized = rasterizer.get_glyph(glyph_key)
- .unwrap_or_else(|_| Default::default());
+ self.cache.entry(glyph_key).or_insert_with(|| {
+ let mut rasterized =
+ rasterizer.get_glyph(glyph_key).unwrap_or_else(|_| Default::default());
- rasterized.left += i32::from(glyph_offset.x);
- rasterized.top += i32::from(glyph_offset.y);
- rasterized.top -= metrics.descent as i32;
+ rasterized.left += i32::from(glyph_offset.x);
+ rasterized.top += i32::from(glyph_offset.y);
+ rasterized.top -= metrics.descent as i32;
- loader.load_glyph(&rasterized)
+ loader.load_glyph(&rasterized)
})
}
+
pub fn update_font_size<L: LoadGlyph>(
&mut self,
font: &config::Font,
size: font::Size,
dpr: f64,
- loader: &mut L
+ loader: &mut L,
) -> Result<(), font::Error> {
// Clear currently cached data in both GL and the registry
loader.clear();
@@ -410,10 +406,7 @@ pub struct Batch {
impl Batch {
#[inline]
pub fn new() -> Batch {
- Batch {
- tex: 0,
- instances: Vec::with_capacity(BATCH_MAX),
- }
+ Batch { tex: 0, instances: Vec::with_capacity(BATCH_MAX) }
}
pub fn add_item(&mut self, cell: &RenderableCell, glyph: &Glyph) {
@@ -592,16 +585,13 @@ impl QuadRenderer {
gl::GenBuffers(1, &mut rect_vbo);
gl::GenBuffers(1, &mut rect_ebo);
gl::BindVertexArray(rect_vao);
- let indices: [i32; 6] = [
- 0, 1, 3,
- 1, 2, 3,
- ];
+ let indices: [i32; 6] = [0, 1, 3, 1, 2, 3];
gl::BindBuffer(gl::ELEMENT_ARRAY_BUFFER, rect_ebo);
gl::BufferData(
gl::ELEMENT_ARRAY_BUFFER,
(size_of::<i32>() * indices.len()) as _,
indices.as_ptr() as *const _,
- gl::STATIC_DRAW
+ gl::STATIC_DRAW,
);
// Cleanup
@@ -629,13 +619,13 @@ impl QuadRenderer {
let event = rx.recv().expect("watcher event");
match event {
- DebouncedEvent::Rename(_, _) => continue,
+ DebouncedEvent::Rename(..) => continue,
DebouncedEvent::Create(_)
| DebouncedEvent::Write(_)
| DebouncedEvent::Chmod(_) => {
msg_tx.send(Msg::ShaderReload).expect("msg send ok");
- }
- _ => {}
+ },
+ _ => {},
}
}
});
@@ -686,7 +676,14 @@ impl QuadRenderer {
gl::BindBuffer(gl::ARRAY_BUFFER, self.rect_vbo);
// Position
- gl::VertexAttribPointer(0, 2, gl::FLOAT, gl::FALSE, (size_of::<f32>() * 2) as _, ptr::null());
+ gl::VertexAttribPointer(
+ 0,
+ 2,
+ gl::FLOAT,
+ gl::FALSE,
+ (size_of::<f32>() * 2) as _,
+ ptr::null(),
+ );
gl::EnableVertexAttribArray(0);
}
@@ -720,12 +717,7 @@ impl QuadRenderer {
}
}
- pub fn with_api<F, T>(
- &mut self,
- config: &Config,
- props: &term::SizeInfo,
- func: F,
- ) -> T
+ pub fn with_api<F, T>(&mut self, config: &Config, props: &term::SizeInfo, func: F) -> T
where
F: FnOnce(RenderApi<'_>) -> T,
{
@@ -788,11 +780,11 @@ impl QuadRenderer {
(Ok(program), Ok(rect_program)) => {
info!("... successfully reloaded shaders");
(program, rect_program)
- }
+ },
(Err(err), _) | (_, Err(err)) => {
error!("{}", err);
return;
- }
+ },
};
self.active_tex = 0;
@@ -842,19 +834,14 @@ impl QuadRenderer {
unsafe {
// Setup vertices
- let vertices: [f32; 8] = [
- x + width, y ,
- x + width, y - height,
- x , y - height,
- x , y ,
- ];
+ let vertices: [f32; 8] = [x + width, y, x + width, y - height, x, y - height, x, y];
// Load vertex data into array buffer
gl::BufferData(
gl::ARRAY_BUFFER,
(size_of::<f32>() * vertices.len()) as _,
vertices.as_ptr() as *const _,
- gl::STATIC_DRAW
+ gl::STATIC_DRAW,
);
// Color
@@ -927,7 +914,7 @@ impl<'a> RenderApi<'a> {
string: &str,
line: Line,
glyph_cache: &mut GlyphCache,
- color: Option<Rgb>
+ color: Option<Rgb>,
) {
let bg_alpha = color.map(|_| 1.0).unwrap_or(0.0);
let col = Column(0);
@@ -943,7 +930,7 @@ impl<'a> RenderApi<'a> {
chars[0] = c;
chars
},
- bg: color.unwrap_or(Rgb { r: 0, g: 0, b: 0}),
+ bg: color.unwrap_or(Rgb { r: 0, g: 0, b: 0 }),
fg: Rgb { r: 0, g: 0, b: 0 },
flags: cell::Flags::empty(),
bg_alpha,
@@ -993,11 +980,7 @@ impl<'a> RenderApi<'a> {
chars[0] = ' ';
}
- let mut glyph_key = GlyphKey {
- font_key,
- size: glyph_cache.font_size,
- c: chars[0],
- };
+ let mut glyph_key = GlyphKey { font_key, size: glyph_cache.font_size, c: chars[0] };
// Add cell to batch
let glyph = glyph_cache.get(glyph_key, self);
@@ -1028,7 +1011,7 @@ fn load_glyph(
active_tex: &mut GLuint,
atlas: &mut Vec<Atlas>,
current_atlas: &mut usize,
- rasterized: &RasterizedGlyph
+ rasterized: &RasterizedGlyph,
) -> Glyph {
// At least one atlas is guaranteed to be in the `self.atlas` list; thus
// the unwrap.
@@ -1042,20 +1025,18 @@ fn load_glyph(
atlas.push(new);
}
load_glyph(active_tex, atlas, current_atlas, rasterized)
- }
- Err(AtlasInsertError::GlyphTooLarge) => {
- Glyph {
- tex_id: atlas[*current_atlas].id,
- top: 0.0,
- left: 0.0,
- width: 0.0,
- height: 0.0,
- uv_bot: 0.0,
- uv_left: 0.0,
- uv_width: 0.0,
- uv_height: 0.0,
- }
- }
+ },
+ Err(AtlasInsertError::GlyphTooLarge) => Glyph {
+ tex_id: atlas[*current_atlas].id,
+ top: 0.0,
+ left: 0.0,
+ width: 0.0,
+ height: 0.0,
+ uv_bot: 0.0,
+ uv_left: 0.0,
+ uv_width: 0.0,
+ uv_height: 0.0,
+ },
}
}
@@ -1113,7 +1094,9 @@ impl TextShaderProgram {
}
macro_rules! cptr {
- ($thing:expr) => { $thing.as_ptr() as *const _ }
+ ($thing:expr) => {
+ $thing.as_ptr() as *const _
+ };
}
macro_rules! assert_uniform_valid {
@@ -1146,16 +1129,16 @@ impl TextShaderProgram {
shader.update_projection(size.width as f32, size.height as f32, 0., 0.);
- unsafe { gl::UseProgram(0); }
+ unsafe {
+ gl::UseProgram(0);
+ }
Ok(shader)
}
fn update_projection(&self, width: f32, height: f32, padding_x: f32, padding_y: f32) {
// Bounds check
- if (width as u32) < (2 * padding_x as u32) ||
- (height as u32) < (2 * padding_y as u32)
- {
+ if (width as u32) < (2 * padding_x as u32) || (height as u32) < (2 * padding_y as u32) {
return;
}
@@ -1204,16 +1187,8 @@ impl RectShaderProgram {
} else {
(Some(RECT_SHADER_V), Some(RECT_SHADER_F))
};
- let vertex_shader = create_shader(
- RECT_SHADER_V_PATH,
- gl::VERTEX_SHADER,
- vertex_src
- )?;
- let fragment_shader = create_shader(
- RECT_SHADER_F_PATH,
- gl::FRAGMENT_SHADER,
- fragment_src
- )?;
+ let vertex_shader = create_shader(RECT_SHADER_V_PATH, gl::VERTEX_SHADER, vertex_src)?;
+ let fragment_shader = create_shader(RECT_SHADER_F_PATH, gl::FRAGMENT_SHADER, fragment_src)?;
let program = create_program(vertex_shader, fragment_shader)?;
unsafe {
@@ -1223,14 +1198,9 @@ impl RectShaderProgram {
}
// get uniform locations
- let u_color = unsafe {
- gl::GetUniformLocation(program, b"color\0".as_ptr() as *const _)
- };
+ let u_color = unsafe { gl::GetUniformLocation(program, b"color\0".as_ptr() as *const _) };
- let shader = RectShaderProgram {
- id: program,
- u_color,
- };
+ let shader = RectShaderProgram { id: program, u_color };
unsafe { gl::UseProgram(0) }
@@ -1276,9 +1246,11 @@ fn create_program(vertex: GLuint, fragment: GLuint) -> Result<GLuint, ShaderCrea
}
}
-fn create_shader(path: &str, kind: GLenum, source: Option<&'static str>)
- -> Result<GLuint, ShaderCreationError>
-{
+fn create_shader(
+ path: &str,
+ kind: GLenum,
+ source: Option<&'static str>,
+) -> Result<GLuint, ShaderCreationError> {
let from_disk;
let source = if let Some(src) = source {
src
@@ -1308,7 +1280,9 @@ fn create_shader(path: &str, kind: GLenum, source: Option<&'static str>)
let log = get_shader_info_log(shader);
// Cleanup
- unsafe { gl::DeleteShader(shader); }
+ unsafe {
+ gl::DeleteShader(shader);
+ }
Err(ShaderCreationError::Compile(PathBuf::from(path), log))
}
@@ -1325,12 +1299,7 @@ fn get_program_info_log(program: GLuint) -> String {
let mut actual_length: GLint = 0;
let mut buf: Vec<u8> = Vec::with_capacity(max_length as usize);
unsafe {
- gl::GetProgramInfoLog(
- program,
- max_length,
- &mut actual_length,
- buf.as_mut_ptr() as *mut _,
- );
+ gl::GetProgramInfoLog(program, max_length, &mut actual_length, buf.as_mut_ptr() as *mut _);
}
// Build a string
@@ -1353,12 +1322,7 @@ fn get_shader_info_log(shader: GLuint) -> String {
let mut actual_length: GLint = 0;
let mut buf: Vec<u8> = Vec::with_capacity(max_length as usize);
unsafe {
- gl::GetShaderInfoLog(
- shader,
- max_length,
- &mut actual_length,
- buf.as_mut_ptr() as *mut _,
- );
+ gl::GetShaderInfoLog(shader, max_length, &mut actual_length, buf.as_mut_ptr() as *mut _);
}
// Build a string
@@ -1410,15 +1374,11 @@ impl ::std::error::Error for ShaderCreationError {
impl ::std::fmt::Display for ShaderCreationError {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
match *self {
- ShaderCreationError::Io(ref err) => {
- write!(f, "Couldn't read shader: {}", err)
- },
+ ShaderCreationError::Io(ref err) => write!(f, "Couldn't read shader: {}", err),
ShaderCreationError::Compile(ref path, ref log) => {
write!(f, "Failed compiling shader at {}: {}", path.display(), log)
},
- ShaderCreationError::Link(ref log) => {
- write!(f, "Failed linking shader: {}", log)
- },
+ ShaderCreationError::Link(ref log) => write!(f, "Failed linking shader: {}", log),
}
}
}
@@ -1509,14 +1469,7 @@ impl Atlas {
gl::BindTexture(gl::TEXTURE_2D, 0);
}
- Atlas {
- id,
- width: size,
- height: size,
- row_extent: 0,
- row_baseline: 0,
- row_tallest: 0,
- }
+ Atlas { id, width: size, height: size, row_extent: 0, row_baseline: 0, row_tallest: 0 }
}
pub fn clear(&mut self) {
@@ -1529,7 +1482,7 @@ impl Atlas {
pub fn insert(
&mut self,
glyph: &RasterizedGlyph,
- active_tex: &mut u32
+ active_tex: &mut u32,
) -> Result<Glyph, AtlasInsertError> {
if glyph.width > self.width || glyph.height > self.height {
return Err(AtlasInsertError::GlyphTooLarge);
diff --git a/src/renderer/rects.rs b/src/renderer/rects.rs
index e066c365..e6a45639 100644
--- a/src/renderer/rects.rs
+++ b/src/renderer/rects.rs
@@ -14,8 +14,8 @@
use std::collections::HashMap;
use crate::term::cell::Flags;
-use crate::term::{RenderableCell, SizeInfo};
use crate::term::color::Rgb;
+use crate::term::{RenderableCell, SizeInfo};
use font::Metrics;
#[derive(Debug, Copy, Clone)]
@@ -47,13 +47,7 @@ impl<'a> Rects<'a> {
last_starts.insert(Flags::UNDERLINE, None);
last_starts.insert(Flags::STRIKEOUT, None);
- Self {
- inner: Vec::new(),
- last_cell: None,
- last_starts,
- metrics,
- size,
- }
+ Self { inner: Vec::new(), last_cell: None, last_starts, metrics, size }
}
/// Convert the stored rects to rectangles for the renderer.
@@ -61,15 +55,13 @@ impl<'a> Rects<'a> {
// If there's still a line pending, draw it until the last cell
for (flag, start_cell) in self.last_starts.iter_mut() {
if let Some(start) = start_cell {
- self.inner.push(
- create_rect(
- &start,
- &self.last_cell.unwrap(),
- *flag,
- &self.metrics,
- &self.size,
- )
- );
+ self.inner.push(create_rect(
+ &start,
+ &self.last_cell.unwrap(),
+ *flag,
+ &self.metrics,
+ &self.size,
+ ));
}
}
@@ -108,12 +100,14 @@ impl<'a> Rects<'a> {
} else {
None
}
- }
+ },
// Check for new start of line
- None => if cell.flags.contains(flag) {
- Some(*cell)
- } else {
- None
+ None => {
+ if cell.flags.contains(flag) {
+ Some(*cell)
+ } else {
+ None
+ }
},
};
}
@@ -158,12 +152,8 @@ fn create_rect(
y = max_y;
}
- let rect = Rect::new(
- start_x + size.padding_x,
- y.round() + size.padding_y,
- width,
- height.round(),
- );
+ let rect =
+ Rect::new(start_x + size.padding_x, y.round() + size.padding_y, width, height.round());
(rect, start.fg)
}
diff --git a/src/selection.rs b/src/selection.rs
index 8009b805..d2009586 100644
--- a/src/selection.rs
+++ b/src/selection.rs
@@ -18,10 +18,10 @@
//! finalized when the button is released. The selection should be cleared
//! when text is added/removed/scrolled on the screen. The selection should
//! also be cleared if the user clicks off of the selection.
-use std::cmp::{min, max};
+use std::cmp::{max, min};
use std::ops::Range;
-use crate::index::{Point, Column, Side};
+use crate::index::{Column, Point, Side};
use crate::term::Search;
/// Describes a region of a 2-dimensional area
@@ -55,8 +55,8 @@ pub enum Selection {
/// The line under the initial point. This is always selected regardless
/// of which way the cursor is moved.
- initial_line: isize
- }
+ initial_line: isize,
+ },
}
/// A Point and side within that point.
@@ -83,8 +83,8 @@ impl Selection {
Selection::Simple {
region: Range {
start: Anchor::new(location.into(), side),
- end: Anchor::new(location.into(), side)
- }
+ end: Anchor::new(location.into(), side),
+ },
}
}
@@ -102,25 +102,17 @@ impl Selection {
region.start.line += offset;
region.end.line += offset;
*initial_line += offset;
- }
+ },
}
}
pub fn semantic(point: Point<usize>) -> Selection {
- Selection::Semantic {
- region: Range {
- start: point.into(),
- end: point.into(),
- }
- }
+ Selection::Semantic { region: Range { start: point.into(), end: point.into() } }
}
pub fn lines(point: Point<usize>) -> Selection {
Selection::Lines {
- region: Range {
- start: point.into(),
- end: point.into(),
- },
+ region: Range { start: point.into(), end: point.into() },
initial_line: point.line as isize,
}
}
@@ -131,9 +123,7 @@ impl Selection {
Selection::Simple { ref mut region } => {
region.end = Anchor::new(location.into(), side);
},
- Selection::Semantic { ref mut region } |
- Selection::Lines { ref mut region, .. } =>
- {
+ Selection::Semantic { ref mut region } | Selection::Lines { ref mut region, .. } => {
region.end = location.into();
},
}
@@ -144,36 +134,28 @@ impl Selection {
G: Search + Dimensions,
{
match *self {
- Selection::Simple { ref region } => {
- Selection::span_simple(grid, region, alt_screen)
- },
+ Selection::Simple { ref region } => Selection::span_simple(grid, region, alt_screen),
Selection::Semantic { ref region } => {
Selection::span_semantic(grid, region, alt_screen)
},
Selection::Lines { ref region, initial_line } => {
Selection::span_lines(grid, region, initial_line, alt_screen)
- }
+ },
}
}
- pub fn is_empty(&self) -> bool
- {
+ pub fn is_empty(&self) -> bool {
match *self {
Selection::Simple { ref region } => {
region.start == region.end && region.start.side == region.end.side
},
- Selection::Semantic { .. } | Selection::Lines { .. } => {
- false
- },
+ Selection::Semantic { .. } | Selection::Lines { .. } => false,
}
}
- fn span_semantic<G>(
- grid: &G,
- region: &Range<Point<isize>>,
- alt_screen: bool,
- ) -> Option<Span>
- where G: Search + Dimensions
+ fn span_semantic<G>(grid: &G, region: &Range<Point<isize>>, alt_screen: bool) -> Option<Span>
+ where
+ G: Search + Dimensions,
{
let cols = grid.dimensions().col;
let lines = grid.dimensions().line.0 as isize;
@@ -199,12 +181,7 @@ impl Selection {
::std::mem::swap(&mut start, &mut end);
}
- Some(Span {
- cols,
- front: start,
- tail: end,
- ty: SpanType::Inclusive,
- })
+ Some(Span { cols, front: start, tail: end, ty: SpanType::Inclusive })
}
fn span_lines<G>(
@@ -214,21 +191,15 @@ impl Selection {
alt_screen: bool,
) -> Option<Span>
where
- G: Dimensions
+ G: Dimensions,
{
let cols = grid.dimensions().col;
let lines = grid.dimensions().line.0 as isize;
// First, create start and end points based on initial line and the grid
// dimensions.
- let mut start = Point {
- col: cols - 1,
- line: initial_line
- };
- let mut end = Point {
- col: Column(0),
- line: initial_line
- };
+ let mut start = Point { col: cols - 1, line: initial_line };
+ let mut end = Point { col: Column(0), line: initial_line };
// Now, expand lines based on where cursor started and ended.
if region.start.line < region.end.line {
@@ -245,17 +216,12 @@ impl Selection {
Selection::alt_screen_clamp(&mut start, &mut end, lines, cols)?;
}
- Some(Span {
- cols,
- front: start.into(),
- tail: end.into(),
- ty: SpanType::Inclusive
- })
+ Some(Span { cols, front: start.into(), tail: end.into(), ty: SpanType::Inclusive })
}
fn span_simple<G>(grid: &G, region: &Range<Anchor>, alt_screen: bool) -> Option<Span>
where
- G: Dimensions
+ G: Dimensions,
{
let start = region.start.point;
let start_side = region.start.side;
@@ -276,7 +242,9 @@ impl Selection {
// No selection for single cell with identical sides or two cell with right+left sides
if (front == tail && front_side == tail_side)
- || (tail_side == Side::Right && front_side == Side::Left && front.line == tail.line
+ || (tail_side == Side::Right
+ && front_side == Side::Left
+ && front.line == tail.line
&& front.col == tail.col + 1)
{
return None;
@@ -303,12 +271,7 @@ impl Selection {
}
// Return the selection with all cells inclusive
- Some(Span {
- cols,
- front: front.into(),
- tail: tail.into(),
- ty: SpanType::Inclusive,
- })
+ Some(Span { cols, front: front.into(), tail: tail.into(), ty: SpanType::Inclusive })
}
// Clamp selection in the alternate screen to the visible region
@@ -387,7 +350,7 @@ impl Span {
(Span::wrap_start(self.front, self.cols), Span::wrap_end(self.tail, self.cols))
},
SpanType::ExcludeFront => (Span::wrap_start(self.front, self.cols), self.tail),
- SpanType::ExcludeTail => (self.front, Span::wrap_end(self.tail, self.cols))
+ SpanType::ExcludeTail => (self.front, Span::wrap_end(self.tail, self.cols)),
};
Locations { start, end }
@@ -395,10 +358,7 @@ impl Span {
fn wrap_start(mut start: Point<usize>, cols: Column) -> Point<usize> {
if start.col == cols - 1 {
- Point {
- line: start.line + 1,
- col: Column(0),
- }
+ Point { line: start.line + 1, col: Column(0) }
} else {
start.col += 1;
start
@@ -407,15 +367,9 @@ impl Span {
fn wrap_end(end: Point<usize>, cols: Column) -> Point<usize> {
if end.col == Column(0) && end.line != 0 {
- Point {
- line: end.line - 1,
- col: cols
- }
+ Point { line: end.line - 1, col: cols }
} else {
- Point {
- line: end.line,
- col: end.col - 1
- }
+ Point { line: end.line, col: end.col - 1 }
}
}
}
@@ -431,8 +385,8 @@ impl Span {
/// look like [ B] and [E ].
#[cfg(test)]
mod test {
- use crate::index::{Line, Column, Side, Point};
use super::{Selection, Span, SpanType};
+ use crate::index::{Column, Line, Point, Side};
use crate::url::Url;
struct Dimensions(Point);
@@ -444,17 +398,22 @@ mod test {
impl Dimensions {
pub fn new(line: usize, col: usize) -> Self {
- Dimensions(Point {
- line: Line(line),
- col: Column(col)
- })
+ Dimensions(Point { line: Line(line), col: Column(col) })
}
}
impl super::Search for Dimensions {
- fn semantic_search_left(&self, point: Point<usize>) -> Point<usize> { point }
- fn semantic_search_right(&self, point: Point<usize>) -> Point<usize> { point }
- fn url_search(&self, _: Point<usize>) -> Option<Url> { None }
+ fn semantic_search_left(&self, point: Point<usize>) -> Point<usize> {
+ point
+ }
+
+ fn semantic_search_right(&self, point: Point<usize>) -> Point<usize> {
+ point
+ }
+
+ fn url_search(&self, _: Point<usize>) -> Option<Url> {
+ None
+ }
}
/// Test case of single cell selection
diff --git a/src/sync.rs b/src/sync.rs
index 06d6cea4..0fcd0862 100644
--- a/src/sync.rs
+++ b/src/sync.rs
@@ -31,10 +31,7 @@ pub struct FairMutex<T> {
impl<T> FairMutex<T> {
/// Create a new fair mutex
pub fn new(data: T) -> FairMutex<T> {
- FairMutex {
- data: Mutex::new(data),
- next: Mutex::new(()),
- }
+ FairMutex { data: Mutex::new(data), next: Mutex::new(()) }
}
/// Lock the mutex
diff --git a/src/term/cell.rs b/src/term/cell.rs
index 88f9d7a1..4d2f4c1c 100644
--- a/src/term/cell.rs
+++ b/src/term/cell.rs
@@ -13,7 +13,7 @@
// limitations under the License.
use bitflags::bitflags;
-use crate::ansi::{NamedColor, Color};
+use crate::ansi::{Color, NamedColor};
use crate::grid::{self, GridCell};
use crate::index::Column;
@@ -47,19 +47,14 @@ pub struct Cell {
pub fg: Color,
pub bg: Color,
pub flags: Flags,
- #[serde(default="default_extra")]
+ #[serde(default = "default_extra")]
pub extra: [char; MAX_ZEROWIDTH_CHARS],
}
impl Default for Cell {
fn default() -> Cell {
- Cell::new(
- ' ',
- Color::Named(NamedColor::Foreground),
- Color::Named(NamedColor::Background)
- )
+ Cell::new(' ', Color::Named(NamedColor::Foreground), Color::Named(NamedColor::Background))
}
-
}
impl GridCell for Cell {
@@ -130,13 +125,7 @@ impl Cell {
}
pub fn new(c: char, fg: Color, bg: Color) -> Cell {
- Cell {
- extra: [' '; MAX_ZEROWIDTH_CHARS],
- c,
- bg,
- fg,
- flags: Flags::empty(),
- }
+ Cell { extra: [' '; MAX_ZEROWIDTH_CHARS], c, bg, fg, flags: Flags::empty() }
}
#[inline]
diff --git a/src/term/color.rs b/src/term/color.rs
index abd7527a..39def612 100644
--- a/src/term/color.rs
+++ b/src/term/color.rs
@@ -1,5 +1,5 @@
-use std::ops::{Index, IndexMut, Mul};
use std::fmt;
+use std::ops::{Index, IndexMut, Mul};
use crate::ansi;
use crate::config::Colors;
@@ -24,7 +24,7 @@ impl Mul<f32> for Rgb {
let result = Rgb {
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
+ b: (f32::from(self.b) * rhs).max(0.0).min(255.0) as u8,
};
trace!("Scaling RGB by {} from {:?} to {:?}", rhs, self, result);
@@ -60,28 +60,26 @@ impl<'a> From<&'a Colors> for List {
impl List {
pub fn fill_named(&mut self, colors: &Colors) {
// Normals
- self[ansi::NamedColor::Black] = colors.normal.black;
- self[ansi::NamedColor::Red] = colors.normal.red;
- self[ansi::NamedColor::Green] = colors.normal.green;
- self[ansi::NamedColor::Yellow] = colors.normal.yellow;
- self[ansi::NamedColor::Blue] = colors.normal.blue;
+ self[ansi::NamedColor::Black] = colors.normal.black;
+ self[ansi::NamedColor::Red] = colors.normal.red;
+ self[ansi::NamedColor::Green] = colors.normal.green;
+ self[ansi::NamedColor::Yellow] = colors.normal.yellow;
+ self[ansi::NamedColor::Blue] = colors.normal.blue;
self[ansi::NamedColor::Magenta] = colors.normal.magenta;
- self[ansi::NamedColor::Cyan] = colors.normal.cyan;
- self[ansi::NamedColor::White] = colors.normal.white;
+ self[ansi::NamedColor::Cyan] = colors.normal.cyan;
+ self[ansi::NamedColor::White] = colors.normal.white;
// Brights
- self[ansi::NamedColor::BrightBlack] = colors.bright.black;
- self[ansi::NamedColor::BrightRed] = colors.bright.red;
- self[ansi::NamedColor::BrightGreen] = colors.bright.green;
- self[ansi::NamedColor::BrightYellow] = colors.bright.yellow;
- self[ansi::NamedColor::BrightBlue] = colors.bright.blue;
+ self[ansi::NamedColor::BrightBlack] = colors.bright.black;
+ self[ansi::NamedColor::BrightRed] = colors.bright.red;
+ self[ansi::NamedColor::BrightGreen] = colors.bright.green;
+ self[ansi::NamedColor::BrightYellow] = colors.bright.yellow;
+ self[ansi::NamedColor::BrightBlue] = colors.bright.blue;
self[ansi::NamedColor::BrightMagenta] = colors.bright.magenta;
- self[ansi::NamedColor::BrightCyan] = colors.bright.cyan;
- self[ansi::NamedColor::BrightWhite] = colors.bright.white;
- self[ansi::NamedColor::BrightForeground] = colors
- .primary
- .bright_foreground
- .unwrap_or(colors.primary.foreground);
+ self[ansi::NamedColor::BrightCyan] = colors.bright.cyan;
+ self[ansi::NamedColor::BrightWhite] = colors.bright.white;
+ self[ansi::NamedColor::BrightForeground] =
+ colors.primary.bright_foreground.unwrap_or(colors.primary.foreground);
// Foreground and background
self[ansi::NamedColor::Foreground] = colors.primary.foreground;
@@ -89,36 +87,34 @@ impl List {
// Foreground and background for custom cursor colors
self[ansi::NamedColor::CursorText] = colors.cursor.text.unwrap_or_else(Rgb::default);
- self[ansi::NamedColor::Cursor] = colors.cursor.cursor.unwrap_or_else(Rgb::default);
+ self[ansi::NamedColor::Cursor] = colors.cursor.cursor.unwrap_or_else(Rgb::default);
// Dims
- self[ansi::NamedColor::DimForeground] = colors
- .primary
- .dim_foreground
- .unwrap_or(colors.primary.foreground * 0.66);
+ self[ansi::NamedColor::DimForeground] =
+ colors.primary.dim_foreground.unwrap_or(colors.primary.foreground * 0.66);
match colors.dim {
Some(ref dim) => {
trace!("Using config-provided dim colors");
- self[ansi::NamedColor::DimBlack] = dim.black;
- self[ansi::NamedColor::DimRed] = dim.red;
- self[ansi::NamedColor::DimGreen] = dim.green;
- self[ansi::NamedColor::DimYellow] = dim.yellow;
- self[ansi::NamedColor::DimBlue] = dim.blue;
+ self[ansi::NamedColor::DimBlack] = dim.black;
+ self[ansi::NamedColor::DimRed] = dim.red;
+ self[ansi::NamedColor::DimGreen] = dim.green;
+ self[ansi::NamedColor::DimYellow] = dim.yellow;
+ self[ansi::NamedColor::DimBlue] = dim.blue;
self[ansi::NamedColor::DimMagenta] = dim.magenta;
- self[ansi::NamedColor::DimCyan] = dim.cyan;
- self[ansi::NamedColor::DimWhite] = dim.white;
- }
+ self[ansi::NamedColor::DimCyan] = dim.cyan;
+ self[ansi::NamedColor::DimWhite] = dim.white;
+ },
None => {
trace!("Deriving dim colors from normal colors");
- self[ansi::NamedColor::DimBlack] = colors.normal.black * 0.66;
- self[ansi::NamedColor::DimRed] = colors.normal.red * 0.66;
- self[ansi::NamedColor::DimGreen] = colors.normal.green * 0.66;
- self[ansi::NamedColor::DimYellow] = colors.normal.yellow * 0.66;
- self[ansi::NamedColor::DimBlue] = colors.normal.blue * 0.66;
+ self[ansi::NamedColor::DimBlack] = colors.normal.black * 0.66;
+ self[ansi::NamedColor::DimRed] = colors.normal.red * 0.66;
+ self[ansi::NamedColor::DimGreen] = colors.normal.green * 0.66;
+ self[ansi::NamedColor::DimYellow] = colors.normal.yellow * 0.66;
+ self[ansi::NamedColor::DimBlue] = colors.normal.blue * 0.66;
self[ansi::NamedColor::DimMagenta] = colors.normal.magenta * 0.66;
- self[ansi::NamedColor::DimCyan] = colors.normal.cyan * 0.66;
- self[ansi::NamedColor::DimWhite] = colors.normal.white * 0.66;
- }
+ self[ansi::NamedColor::DimCyan] = colors.normal.cyan * 0.66;
+ self[ansi::NamedColor::DimWhite] = colors.normal.white * 0.66;
+ },
}
}
@@ -129,14 +125,13 @@ impl List {
for g in 0..6 {
for b in 0..6 {
// Override colors 16..232 with the config (if present)
- if let Some(indexed_color) = colors
- .indexed_colors
- .iter()
- .find(|ic| ic.index == index as u8)
+ if let Some(indexed_color) =
+ colors.indexed_colors.iter().find(|ic| ic.index == index as u8)
{
self[index] = indexed_color.color;
} else {
- self[index] = Rgb { r: if r == 0 { 0 } else { r * 40 + 55 },
+ self[index] = Rgb {
+ r: if r == 0 { 0 } else { r * 40 + 55 },
b: if b == 0 { 0 } else { b * 40 + 55 },
g: if g == 0 { 0 } else { g * 40 + 55 },
};
@@ -157,10 +152,8 @@ impl List {
let color_index = 16 + 216 + i;
// Override colors 232..256 with the config (if present)
- if let Some(indexed_color) = colors
- .indexed_colors
- .iter()
- .find(|ic| ic.index == color_index)
+ if let Some(indexed_color) =
+ colors.indexed_colors.iter().find(|ic| ic.index == color_index)
{
self[index] = indexed_color.color;
index += 1;
@@ -168,11 +161,7 @@ impl List {
}
let value = i * 10 + 8;
- self[index] = Rgb {
- r: value,
- g: value,
- b: value
- };
+ self[index] = Rgb { r: value, g: value, b: value };
index += 1;
}
diff --git a/src/term/mod.rs b/src/term/mod.rs
index 89105041..5edef44f 100644
--- a/src/term/mod.rs
+++ b/src/term/mod.rs
@@ -13,30 +13,32 @@
// limitations under the License.
//
//! Exports the `Term` type which is a high-level API for the Grid
-use std::ops::{Range, Index, IndexMut, RangeInclusive};
-use std::{ptr, io, mem};
-use std::cmp::{min, max};
+use std::cmp::{max, min};
+use std::ops::{Index, IndexMut, Range, RangeInclusive};
use std::time::{Duration, Instant};
+use std::{io, mem, ptr};
use arraydeque::ArrayDeque;
-use unicode_width::UnicodeWidthChar;
use glutin::MouseCursor;
+use unicode_width::UnicodeWidthChar;
-use font::{self, Size};
-use crate::ansi::{self, Color, NamedColor, Attr, Handler, CharsetIndex, StandardCharset, CursorStyle};
+use crate::ansi::{
+ self, Attr, CharsetIndex, Color, CursorStyle, Handler, NamedColor, StandardCharset,
+};
+use crate::config::{Config, VisualBellAnimation};
use crate::grid::{
BidirectionalIterator, DisplayIter, Grid, GridCell, IndexRegion, Indexed, Scroll,
- ViewportPosition
+ ViewportPosition,
};
-use crate::index::{self, Point, Column, Line, IndexRange, Contains, Linear};
-use crate::selection::{self, Selection, Locations};
-use crate::config::{Config, VisualBellAnimation};
-use copypasta::{Clipboard, Load, Store};
+use crate::index::{self, Column, Contains, IndexRange, Line, Linear, Point};
use crate::input::FONT_SIZE_STEP;
-use crate::url::{Url, UrlParser};
use crate::message_bar::MessageBuffer;
+use crate::selection::{self, Locations, Selection};
+use crate::term::cell::{Cell, Flags, LineLength};
use crate::term::color::Rgb;
-use crate::term::cell::{LineLength, Cell, Flags};
+use crate::url::{Url, UrlParser};
+use copypasta::{Clipboard, Load, Store};
+use font::{self, Size};
#[cfg(windows)]
use crate::tty;
@@ -139,10 +141,7 @@ impl Search for Term {
impl selection::Dimensions for Term {
fn dimensions(&self) -> Point {
- Point {
- col: self.grid.num_cols(),
- line: self.grid.num_lines()
- }
+ Point { col: self.grid.num_cols(), line: self.grid.num_lines() }
}
}
@@ -200,7 +199,7 @@ impl<'a> RenderableCellsIter<'a> {
(ViewportPosition::Below, ViewportPosition::Visible(end_line)) => {
Some((grid.num_lines(), Column(0), end_line, loc.end.col))
},
- (ViewportPosition::Below, ViewportPosition::Above) => {
+ (ViewportPosition::Below, ViewportPosition::Above) => {
Some((grid.num_lines(), Column(0), Line(0), Column(0)))
},
_ => None,
@@ -209,14 +208,8 @@ impl<'a> RenderableCellsIter<'a> {
if let Some((start_line, start_col, end_line, end_col)) = locations {
// start and end *lines* are swapped as we switch from buffer to
// Line coordinates.
- let mut end = Point {
- line: start_line,
- col: start_col,
- };
- let mut start = Point {
- line: end_line,
- col: end_col,
- };
+ let mut end = Point { line: start_line, col: start_col };
+ let mut start = Point { line: end_line, col: end_col };
if start > end {
::std::mem::swap(&mut start, &mut end);
@@ -242,32 +235,31 @@ impl<'a> RenderableCellsIter<'a> {
config,
colors: &term.colors,
cursor_cells: ArrayDeque::new(),
- }.initialize(cursor_style)
+ }
+ .initialize(cursor_style)
}
fn push_cursor_cells(&mut self, original: Cell, cursor: Cell, wide: Cell) {
// Prints the char under the cell if cursor is situated on a non-empty cell
- self.cursor_cells.push_back(Indexed {
- line: self.cursor.line,
- column: self.cursor.col,
- inner: original,
- }).expect("won't exceed capacity");
+ self.cursor_cells
+ .push_back(Indexed { line: self.cursor.line, column: self.cursor.col, inner: original })
+ .expect("won't exceed capacity");
// Prints the cursor
- self.cursor_cells.push_back(Indexed {
- line: self.cursor.line,
- column: self.cursor.col,
- inner: cursor,
- }).expect("won't exceed capacity");
+ self.cursor_cells
+ .push_back(Indexed { line: self.cursor.line, column: self.cursor.col, inner: cursor })
+ .expect("won't exceed capacity");
// If cursor is over a wide (2 cell size) character,
// print the second cursor cell
if self.is_wide_cursor(&cursor) {
- self.cursor_cells.push_back(Indexed {
- line: self.cursor.line,
- column: self.cursor.col + 1,
- inner: wide,
- }).expect("won't exceed capacity");
+ self.cursor_cells
+ .push_back(Indexed {
+ line: self.cursor.line,
+ column: self.cursor.col + 1,
+ inner: wide,
+ })
+ .expect("won't exceed capacity");
}
}
@@ -321,11 +313,13 @@ impl<'a> RenderableCellsIter<'a> {
/// Populates list of cursor cells with the original cell
fn populate_no_cursor(&mut self) {
- self.cursor_cells.push_back(Indexed {
- line: self.cursor.line,
- column: self.cursor.col,
- inner: self.grid[self.cursor],
- }).expect("won't exceed capacity");
+ self.cursor_cells
+ .push_back(Indexed {
+ line: self.cursor.line,
+ column: self.cursor.col,
+ inner: self.grid[self.cursor],
+ })
+ .expect("won't exceed capacity");
}
fn initialize(mut self, cursor_style: CursorStyle) -> Self {
@@ -342,7 +336,7 @@ impl<'a> RenderableCellsIter<'a> {
},
CursorStyle::Underline => {
self.populate_underline_cursor();
- }
+ },
}
} else {
self.populate_no_cursor();
@@ -361,37 +355,41 @@ impl<'a> RenderableCellsIter<'a> {
match fg {
Color::Spec(rgb) => rgb,
Color::Named(ansi) => {
- match (self.config.draw_bold_text_with_bright_colors(), cell.flags & Flags::DIM_BOLD) {
+ match (
+ self.config.draw_bold_text_with_bright_colors(),
+ cell.flags & Flags::DIM_BOLD,
+ ) {
// If no bright foreground is set, treat it like the BOLD flag doesn't exist
(_, self::cell::Flags::DIM_BOLD)
if ansi == NamedColor::Foreground
&& self.config.colors().primary.bright_foreground.is_none() =>
{
self.colors[NamedColor::DimForeground]
- }
+ },
// Draw bold text in bright colors *and* contains bold flag.
- (true, self::cell::Flags::BOLD) => self.colors[ansi.to_bright()],
+ (true, self::cell::Flags::BOLD) => self.colors[ansi.to_bright()],
// Cell is marked as dim and not bold
- (_, self::cell::Flags::DIM) |
- (false, self::cell::Flags::DIM_BOLD) => self.colors[ansi.to_dim()],
+ (_, self::cell::Flags::DIM) | (false, self::cell::Flags::DIM_BOLD) => {
+ self.colors[ansi.to_dim()]
+ },
// None of the above, keep original color.
- _ => self.colors[ansi]
+ _ => self.colors[ansi],
}
},
Color::Indexed(idx) => {
let idx = match (
self.config.draw_bold_text_with_bright_colors(),
cell.flags & Flags::DIM_BOLD,
- idx
+ idx,
) {
- (true, self::cell::Flags::BOLD, 0..=7) => idx as usize + 8,
- (false, self::cell::Flags::DIM, 8..=15) => idx as usize - 8,
- (false, self::cell::Flags::DIM, 0..=7) => idx as usize + 260,
+ (true, self::cell::Flags::BOLD, 0..=7) => idx as usize + 8,
+ (false, self::cell::Flags::DIM, 8..=15) => idx as usize - 8,
+ (false, self::cell::Flags::DIM, 0..=7) => idx as usize + 260,
_ => idx as usize,
};
self.colors[idx]
- }
+ },
}
}
@@ -399,7 +397,7 @@ impl<'a> RenderableCellsIter<'a> {
fn compute_bg_alpha(&self, bg: Color) -> f32 {
match bg {
Color::Named(NamedColor::Background) => 0.0,
- _ => 1.0
+ _ => 1.0,
}
}
@@ -435,8 +433,8 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
fn next(&mut self) -> Option<Self::Item> {
loop {
// Handle cursor
- let (cell, selected, highlighted) = if self.cursor_offset == self.inner.offset() &&
- self.inner.column() == self.cursor.col
+ let (cell, selected, highlighted) = if self.cursor_offset == self.inner.offset()
+ && self.inner.column() == self.cursor.col
{
// Cursor cell
let mut cell = self.cursor_cells.pop_front().unwrap();
@@ -454,9 +452,8 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
let index = Linear::new(self.grid.num_cols(), cell.column, cell.line);
- let selected = self.selection.as_ref()
- .map(|range| range.contains_(index))
- .unwrap_or(false);
+ let selected =
+ self.selection.as_ref().map(|range| range.contains_(index)).unwrap_or(false);
// Skip empty cells
if cell.is_empty() && !selected {
@@ -464,7 +461,9 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
}
// Underline URL highlights
- let highlighted = self.url_highlight.as_ref()
+ let highlighted = self
+ .url_highlight
+ .as_ref()
.map(|range| range.contains_(index))
.unwrap_or(false);
@@ -506,10 +505,9 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
bg: bg_rgb,
bg_alpha,
flags,
- })
+ });
}
}
-
}
pub mod mode {
@@ -558,41 +556,40 @@ impl CharsetMapping for StandardCharset {
fn map(&self, c: char) -> char {
match *self {
StandardCharset::Ascii => c,
- StandardCharset::SpecialCharacterAndLineDrawing =>
- match c {
- '`' => '◆',
- 'a' => '▒',
- 'b' => '\t',
- 'c' => '\u{000c}',
- 'd' => '\r',
- 'e' => '\n',
- 'f' => '°',
- 'g' => '±',
- 'h' => '\u{2424}',
- 'i' => '\u{000b}',
- 'j' => '┘',
- 'k' => '┐',
- 'l' => '┌',
- 'm' => '└',
- 'n' => '┼',
- 'o' => '⎺',
- 'p' => '⎻',
- 'q' => '─',
- 'r' => '⎼',
- 's' => '⎽',
- 't' => '├',
- 'u' => '┤',
- 'v' => '┴',
- 'w' => '┬',
- 'x' => '│',
- 'y' => '≤',
- 'z' => '≥',
- '{' => 'π',
- '|' => '≠',
- '}' => '£',
- '~' => '·',
- _ => c
- },
+ StandardCharset::SpecialCharacterAndLineDrawing => match c {
+ '`' => '◆',
+ 'a' => '▒',
+ 'b' => '\t',
+ 'c' => '\u{000c}',
+ 'd' => '\r',
+ 'e' => '\n',
+ 'f' => '°',
+ 'g' => '±',
+ 'h' => '\u{2424}',
+ 'i' => '\u{000b}',
+ 'j' => '┘',
+ 'k' => '┐',
+ 'l' => '┌',
+ 'm' => '└',
+ 'n' => '┼',
+ 'o' => '⎺',
+ 'p' => '⎻',
+ 'q' => '─',
+ 'r' => '⎼',
+ 's' => '⎽',
+ 't' => '├',
+ 'u' => '┤',
+ 'v' => '┴',
+ 'w' => '┬',
+ 'x' => '│',
+ 'y' => '≤',
+ 'z' => '≥',
+ '{' => 'π',
+ '|' => '≠',
+ '}' => '£',
+ '~' => '·',
+ _ => c,
+ },
}
}
}
@@ -602,6 +599,7 @@ struct Charsets([StandardCharset; 4]);
impl Index<CharsetIndex> for Charsets {
type Output = StandardCharset;
+
fn index(&self, index: CharsetIndex) -> &StandardCharset {
&self.0[index as usize]
}
@@ -637,10 +635,10 @@ pub struct VisualBell {
}
fn cubic_bezier(p0: f64, p1: f64, p2: f64, p3: f64, x: f64) -> f64 {
- (1.0 - x).powi(3) * p0 +
- 3.0 * (1.0 - x).powi(2) * x * p1 +
- 3.0 * (1.0 - x) * x.powi(2) * p2 +
- x.powi(3) * p3
+ (1.0 - x).powi(3) * p0
+ + 3.0 * (1.0 - x).powi(2) * x * p1
+ + 3.0 * (1.0 - x) * x.powi(2) * p2
+ + x.powi(3) * p3
}
impl VisualBell {
@@ -675,7 +673,7 @@ impl VisualBell {
}
false
},
- None => true
+ None => true,
}
}
@@ -703,10 +701,10 @@ impl VisualBell {
}
let elapsed = instant.duration_since(earlier);
- let elapsed_f = elapsed.as_secs() as f64 +
- f64::from(elapsed.subsec_nanos()) / 1e9f64;
- let duration_f = self.duration.as_secs() as f64 +
- f64::from(self.duration.subsec_nanos()) / 1e9f64;
+ let elapsed_f =
+ elapsed.as_secs() as f64 + f64::from(elapsed.subsec_nanos()) / 1e9f64;
+ let duration_f = self.duration.as_secs() as f64
+ + 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
@@ -722,7 +720,9 @@ impl VisualBell {
},
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),
+ VisualBellAnimation::EaseOutCubic => {
+ cubic_bezier(0.215, 0.61, 0.355, 1.0, time)
+ },
VisualBellAnimation::EaseOutQuart => cubic_bezier(0.165, 0.84, 0.44, 1.0, time),
VisualBellAnimation::EaseOutQuint => cubic_bezier(0.23, 1.0, 0.32, 1.0, time),
VisualBellAnimation::EaseOutExpo => cubic_bezier(0.19, 1.0, 0.22, 1.0, time),
@@ -733,7 +733,7 @@ impl VisualBell {
// Since we want the `intensity` of the VisualBell to decay over
// `time`, we subtract the `inverse_intensity` from 1.0.
1.0 - inverse_intensity
- }
+ },
}
}
@@ -890,12 +890,11 @@ impl SizeInfo {
Point {
line: min(line, Line(self.lines().saturating_sub(1))),
- col: min(col, Column(self.cols().saturating_sub(1)))
+ col: min(col, Column(self.cols().saturating_sub(1))),
}
}
}
-
impl Term {
pub fn selection(&self) -> &Option<Selection> {
&self.grid.selection
@@ -997,8 +996,7 @@ impl Term {
self.default_cursor_style = config.cursor_style();
self.dynamic_title = config.dynamic_title();
self.auto_scroll = config.scrolling().auto_scroll;
- self.grid
- .update_history(config.scrolling().history as usize, &self.cursor.template);
+ self.grid.update_history(config.scrolling().history as usize, &self.cursor.template);
}
#[inline]
@@ -1011,7 +1009,9 @@ impl Term {
trait PushChar {
fn push_char(&mut self, c: char);
fn maybe_newline(&mut self, grid: &Grid<Cell>, line: usize, ending: Column) {
- if ending != Column(0) && !grid[line][ending - 1].flags.contains(cell::Flags::WRAPLINE) {
+ if ending != Column(0)
+ && !grid[line][ending - 1].flags.contains(cell::Flags::WRAPLINE)
+ {
self.push_char('\n');
}
}
@@ -1026,7 +1026,7 @@ impl Term {
use std::ops::Range;
- trait Append : PushChar {
+ trait Append: PushChar {
fn append(
&mut self,
grid: &Grid<Cell>,
@@ -1042,7 +1042,7 @@ impl Term {
grid: &Grid<Cell>,
tabs: &TabStops,
mut line: usize,
- cols: Range<Column>
+ cols: Range<Column>,
) {
// Select until last line still within the buffer
line = min(line, grid.len() - 1);
@@ -1115,7 +1115,6 @@ impl Term {
// Starting line
res.append(&self.grid, &self.tabs, start.line, Column(0)..start.col);
-
},
// Multi line selection
@@ -1130,7 +1129,7 @@ impl Term {
// Starting line
res.append(&self.grid, &self.tabs, start.line, Column(0)..start.col);
- }
+ },
}
Some(res)
@@ -1180,11 +1179,12 @@ impl Term {
window_focused: bool,
) -> RenderableCellsIter<'_> {
let alt_screen = self.mode.contains(TermMode::ALT_SCREEN);
- let selection = self.grid.selection.as_ref()
+ let selection = self
+ .grid
+ .selection
+ .as_ref()
.and_then(|s| s.to_span(self, alt_screen))
- .map(|span| {
- span.to_locations()
- });
+ .map(|span| span.to_locations());
let cursor = if window_focused || !config.unfocused_hollow_cursor() {
self.cursor_style.unwrap_or(self.default_cursor_style)
@@ -1192,12 +1192,7 @@ impl Term {
CursorStyle::HollowBlock
};
- RenderableCellsIter::new(
- &self,
- config,
- selection,
- cursor,
- )
+ RenderableCellsIter::new(&self, config, selection, cursor)
}
/// Resize terminal to new dimensions
@@ -1205,8 +1200,8 @@ impl Term {
debug!("Resizing terminal");
// Bounds check; lots of math assumes width and height are > 0
- if size.width as usize <= 2 * self.size_info.padding_x as usize ||
- size.height as usize <= 2 * self.size_info.padding_y as usize
+ if size.width as usize <= 2 * self.size_info.padding_x as usize
+ || size.height as usize <= 2 * self.size_info.padding_y as usize
{
return;
}
@@ -1455,10 +1450,7 @@ impl ansi::Handler for Term {
trace!("Wrapping input");
{
- let location = Point {
- line: self.cursor.point.line,
- col: self.cursor.point.col
- };
+ let location = Point { line: self.cursor.point.line, col: self.cursor.point.col };
let cell = &mut self.grid[&location];
cell.flags.insert(cell::Flags::WRAPLINE);
@@ -1498,8 +1490,7 @@ impl ansi::Handler for Term {
if width == 0 {
let col = self.cursor.point.col.0.saturating_sub(1);
let line = self.cursor.point.line;
- if self.grid[line][Column(col)].flags.contains(cell::Flags::WIDE_CHAR_SPACER)
- {
+ if self.grid[line][Column(col)].flags.contains(cell::Flags::WIDE_CHAR_SPACER) {
col.saturating_sub(1);
}
self.grid[line][Column(col)].push_extra(c);
@@ -1536,8 +1527,7 @@ impl ansi::Handler for Term {
let mut template = self.cursor.template;
template.c = 'E';
- self.grid.region_mut(..)
- .each(|c| c.reset(&template));
+ self.grid.region_mut(..).each(|c| c.reset(&template));
}
#[inline]
@@ -1858,11 +1848,7 @@ impl ansi::Handler for Term {
#[inline]
fn save_cursor_position(&mut self) {
trace!("Saving cursor position");
- let cursor = if self.alt {
- &mut self.cursor_save_alt
- } else {
- &mut self.cursor_save
- };
+ let cursor = if self.alt { &mut self.cursor_save_alt } else { &mut self.cursor_save };
*cursor = self.cursor;
}
@@ -1870,11 +1856,7 @@ impl ansi::Handler for Term {
#[inline]
fn restore_cursor_position(&mut self) {
trace!("Restoring cursor position");
- let source = if self.alt {
- &self.cursor_save_alt
- } else {
- &self.cursor_save
- };
+ let source = if self.alt { &self.cursor_save_alt } else { &self.cursor_save };
self.cursor = *source;
self.cursor.point.line = min(self.cursor.point.line, self.grid.num_lines() - 1);
@@ -1887,7 +1869,7 @@ impl ansi::Handler for Term {
let mut template = self.cursor.template;
template.flags ^= template.flags;
- let col = self.cursor.point.col;
+ let col = self.cursor.point.col;
match mode {
ansi::LineClearMode::Right => {
@@ -1929,13 +1911,12 @@ impl ansi::Handler for Term {
/// Set the clipboard
#[inline]
- fn set_clipboard(&mut self, string: &str)
- {
- Clipboard::new()
- .and_then(|mut clipboard| clipboard.store_primary(string))
- .unwrap_or_else(|err| {
+ fn set_clipboard(&mut self, string: &str) {
+ Clipboard::new().and_then(|mut clipboard| clipboard.store_primary(string)).unwrap_or_else(
+ |err| {
warn!("Error storing selection to clipboard: {}", err);
- });
+ },
+ );
}
#[inline]
@@ -1954,7 +1935,8 @@ impl ansi::Handler for Term {
cell.reset(&template);
}
if self.cursor.point.line < self.grid.num_lines() - 1 {
- self.grid.region_mut((self.cursor.point.line + 1)..)
+ self.grid
+ .region_mut((self.cursor.point.line + 1)..)
.each(|cell| cell.reset(&template));
}
},
@@ -1963,7 +1945,8 @@ impl ansi::Handler for Term {
// If clearing more than one line
if self.cursor.point.line > Line(1) {
// Fully clear all lines before the current line
- self.grid.region_mut(..self.cursor.point.line)
+ self.grid
+ .region_mut(..self.cursor.point.line)
.each(|cell| cell.reset(&template));
}
// Clear up to the current column in the current line
@@ -1987,7 +1970,7 @@ impl ansi::Handler for Term {
},
ansi::TabulationClearMode::All => {
self.tabs.clear_all();
- }
+ },
}
}
@@ -2042,7 +2025,9 @@ impl ansi::Handler for Term {
Attr::Bold => self.cursor.template.flags.insert(cell::Flags::BOLD),
Attr::CancelBold => self.cursor.template.flags.remove(cell::Flags::BOLD),
Attr::Dim => self.cursor.template.flags.insert(cell::Flags::DIM),
- Attr::CancelBoldDim => self.cursor.template.flags.remove(cell::Flags::BOLD | cell::Flags::DIM),
+ Attr::CancelBoldDim => {
+ self.cursor.template.flags.remove(cell::Flags::BOLD | cell::Flags::DIM)
+ },
Attr::Italic => self.cursor.template.flags.insert(cell::Flags::ITALIC),
Attr::CancelItalic => self.cursor.template.flags.remove(cell::Flags::ITALIC),
Attr::Underscore => self.cursor.template.flags.insert(cell::Flags::UNDERLINE),
@@ -2053,7 +2038,7 @@ impl ansi::Handler for Term {
Attr::CancelStrike => self.cursor.template.flags.remove(cell::Flags::STRIKEOUT),
_ => {
debug!("Term got unhandled attr: {:?}", attr);
- }
+ },
}
}
@@ -2093,12 +2078,12 @@ impl ansi::Handler for Term {
ansi::Mode::Insert => self.mode.insert(mode::TermMode::INSERT), // heh
ansi::Mode::BlinkingCursor => {
trace!("... unimplemented mode");
- }
+ },
}
}
#[inline]
- fn unset_mode(&mut self,mode: ansi::Mode) {
+ fn unset_mode(&mut self, mode: ansi::Mode) {
trace!("Unsetting mode: {:?}", mode);
match mode {
ansi::Mode::SwapScreenAndSetRestoreCursor => {
@@ -2133,7 +2118,7 @@ impl ansi::Handler for Term {
ansi::Mode::Insert => self.mode.remove(mode::TermMode::INSERT),
ansi::Mode::BlinkingCursor => {
trace!("... unimplemented mode");
- }
+ },
}
}
@@ -2177,7 +2162,7 @@ impl ansi::Handler for Term {
}
struct TabStops {
- tabs: Vec<bool>
+ tabs: Vec<bool>,
}
impl TabStops {
@@ -2185,7 +2170,7 @@ impl TabStops {
TabStops {
tabs: IndexRange::from(Column(0)..num_cols)
.map(|i| (*i as usize) % tabspaces == 0)
- .collect::<Vec<bool>>()
+ .collect::<Vec<bool>>(),
}
}
@@ -2214,18 +2199,18 @@ impl IndexMut<Column> for TabStops {
mod tests {
use serde_json;
- use super::{Cell, Term, SizeInfo};
+ use super::{Cell, SizeInfo, Term};
use crate::term::cell;
+ use crate::ansi::{self, CharsetIndex, Handler, StandardCharset};
+ use crate::config::Config;
use crate::grid::{Grid, Scroll};
- use crate::index::{Point, Line, Column, Side};
- use crate::ansi::{self, Handler, CharsetIndex, StandardCharset};
- use crate::selection::Selection;
- use std::mem;
+ use crate::index::{Column, Line, Point, Side};
use crate::input::FONT_SIZE_STEP;
- use font::Size;
- use crate::config::Config;
use crate::message_bar::MessageBuffer;
+ use crate::selection::Selection;
+ use font::Size;
+ use std::mem;
#[test]
fn semantic_selection_works() {
@@ -2290,7 +2275,6 @@ mod tests {
grid[Line(0)][Column(0)].c = '"';
grid[Line(0)][Column(3)].c = '"';
-
mem::swap(&mut term.grid, &mut grid);
*term.selection_mut() = Some(Selection::lines(Point { line: 0, col: Column(3) }));
@@ -2336,8 +2320,7 @@ mod tests {
let grid: Grid<Cell> = Grid::new(Line(24), Column(80), 0, template);
let serialized = serde_json::to_string(&grid).expect("ser");
- let deserialized = serde_json::from_str::<Grid<Cell>>(&serialized)
- .expect("de");
+ let deserialized = serde_json::from_str::<Grid<Cell>>(&serialized).expect("de");
assert_eq!(deserialized, grid);
}
@@ -2355,8 +2338,7 @@ mod tests {
};
let mut term = Term::new(&Default::default(), size, MessageBuffer::new());
let cursor = Point::new(Line(0), Column(0));
- term.configure_charset(CharsetIndex::G0,
- StandardCharset::SpecialCharacterAndLineDrawing);
+ term.configure_charset(CharsetIndex::G0, StandardCharset::SpecialCharacterAndLineDrawing);
term.input('a');
assert_eq!(term.grid()[&cursor].c, '▒');
@@ -2440,7 +2422,7 @@ mod tests {
cell_height: 3.0,
padding_x: 0.0,
padding_y: 0.0,
- dpr: 1.0
+ dpr: 1.0,
};
let config: Config = Default::default();
let mut term: Term = Term::new(&config, size, MessageBuffer::new());
@@ -2460,27 +2442,27 @@ mod tests {
#[cfg(all(test, feature = "bench"))]
mod benches {
- extern crate test;
extern crate serde_json as json;
+ extern crate test;
- use std::io::Read;
use std::fs::File;
+ use std::io::Read;
use std::mem;
use std::path::Path;
- use crate::grid::Grid;
use crate::config::Config;
+ use crate::grid::Grid;
use crate::message_bar::MessageBuffer;
- use super::{SizeInfo, Term};
use super::cell::Cell;
+ use super::{SizeInfo, Term};
fn read_string<P>(path: P) -> String
- where P: AsRef<Path>
+ where
+ P: AsRef<Path>,
{
let mut res = String::new();
- File::open(path.as_ref()).unwrap()
- .read_to_string(&mut res).unwrap();
+ File::open(path.as_ref()).unwrap().read_to_string(&mut res).unwrap();
res
}
@@ -2497,12 +2479,14 @@ mod benches {
#[bench]
fn render_iter(b: &mut test::Bencher) {
// Need some realistic grid state; using one of the ref files.
- let serialized_grid = read_string(
- concat!(env!("CARGO_MANIFEST_DIR"), "/tests/ref/vim_large_window_scroll/grid.json")
- );
- let serialized_size = read_string(
- concat!(env!("CARGO_MANIFEST_DIR"), "/tests/ref/vim_large_window_scroll/size.json")
- );
+ let serialized_grid = read_string(concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/tests/ref/vim_large_window_scroll/grid.json"
+ ));
+ let serialized_size = read_string(concat!(
+ env!("CARGO_MANIFEST_DIR"),
+ "/tests/ref/vim_large_window_scroll/size.json"
+ ));
let mut grid: Grid<Cell> = json::from_str(&serialized_grid).unwrap();
let size: SizeInfo = json::from_str(&serialized_size).unwrap();
diff --git a/src/tty/mod.rs b/src/tty/mod.rs
index ea2dd0c4..ec175ee6 100644
--- a/src/tty/mod.rs
+++ b/src/tty/mod.rs
@@ -57,7 +57,7 @@ pub trait EventedReadWrite {
#[derive(PartialEq)]
pub enum ChildEvent {
/// Indicates the child has exited
- Exited
+ Exited,
}
/// A pseudoterminal (or PTY)
@@ -65,7 +65,7 @@ pub enum ChildEvent {
/// This is a refinement of EventedReadWrite that also provides a channel through which we can be
/// notified if the PTY child process does something we care about (other than writing to the TTY).
/// In particular, this allows for race-free child exit notification on UNIX (cf. `SIGCHLD`).
-pub trait EventedPty : EventedReadWrite {
+pub trait EventedPty: EventedReadWrite {
#[cfg(unix)]
fn child_event_token(&self) -> mio::Token;
@@ -83,11 +83,7 @@ pub fn setup_env(config: &Config) {
// below.
env::set_var(
"TERM",
- if Database::from_name("alacritty").is_ok() {
- "alacritty"
- } else {
- "xterm-256color"
- },
+ if Database::from_name("alacritty").is_ok() { "alacritty" } else { "xterm-256color" },
);
// Advertise 24-bit color support
diff --git a/src/tty/unix.rs b/src/tty/unix.rs
index d8392dcd..0e3dc2fd 100644
--- a/src/tty/unix.rs
+++ b/src/tty/unix.rs
@@ -15,24 +15,27 @@
//! tty related functionality
//!
-use crate::tty::{EventedReadWrite, EventedPty, ChildEvent};
-use crate::term::SizeInfo;
-use crate::display::OnResize;
-use crate::config::{Config, Shell};
use crate::cli::Options;
+use crate::config::{Config, Shell};
+use crate::display::OnResize;
+use crate::term::SizeInfo;
+use crate::tty::{ChildEvent, EventedPty, EventedReadWrite};
use mio;
use libc::{self, c_int, pid_t, winsize, TIOCSCTTY};
use nix::pty::openpty;
use signal_hook::{self as sighook, iterator::Signals};
-use std::os::unix::{process::CommandExt, io::{FromRawFd, AsRawFd, RawFd}};
-use std::fs::File;
-use std::process::{Command, Stdio, Child};
-use std::ffi::CStr;
-use std::ptr;
use mio::unix::EventedFd;
+use std::ffi::CStr;
+use std::fs::File;
use std::io;
+use std::os::unix::{
+ io::{AsRawFd, FromRawFd, RawFd},
+ process::CommandExt,
+};
+use std::process::{Child, Command, Stdio};
+use std::ptr;
use std::sync::atomic::{AtomicUsize, Ordering};
/// Process ID of child process
@@ -55,8 +58,7 @@ fn make_pty(size: winsize) -> (RawFd, RawFd) {
win_size.ws_xpixel = 0;
win_size.ws_ypixel = 0;
- let ends = openpty(Some(&win_size), None)
- .expect("openpty failed");
+ let ends = openpty(Some(&win_size), None).expect("openpty failed");
(ends.master, ends.slave)
}
@@ -134,7 +136,6 @@ pub struct Pty {
token: mio::Token,
signals: Signals,
signals_token: mio::Token,
-
}
impl Pty {
@@ -145,9 +146,7 @@ impl Pty {
pub fn resize<T: ToWinsize>(&self, size: &T) {
let win = size.to_winsize();
- let res = unsafe {
- libc::ioctl(self.fd.as_raw_fd(), libc::TIOCSWINSZ, &win as *const _)
- };
+ let res = unsafe { libc::ioctl(self.fd.as_raw_fd(), libc::TIOCSWINSZ, &win as *const _) };
if res < 0 {
die!("ioctl TIOCSWINSZ failed: {}", errno());
@@ -170,10 +169,7 @@ pub fn new<T: ToWinsize>(
let default_shell = if cfg!(target_os = "macos") {
let shell_name = pw.shell.rsplit('/').next().unwrap();
- let argv = vec![
- String::from("-c"),
- format!("exec -a -{} {}", shell_name, pw.shell),
- ];
+ let argv = vec![String::from("-c"), format!("exec -a -{} {}", shell_name, pw.shell)];
Shell::new_with_args("/bin/bash", argv)
} else {
@@ -265,7 +261,7 @@ pub fn new<T: ToWinsize>(
},
Err(err) => {
die!("Failed to spawn command: {}", err);
- }
+ },
}
}
@@ -282,19 +278,14 @@ impl EventedReadWrite for Pty {
poll_opts: mio::PollOpt,
) -> io::Result<()> {
self.token = token.next().unwrap();
- poll.register(
- &EventedFd(&self.fd.as_raw_fd()),
- self.token,
- interest,
- poll_opts
- )?;
+ poll.register(&EventedFd(&self.fd.as_raw_fd()), self.token, interest, poll_opts)?;
self.signals_token = token.next().unwrap();
poll.register(
&self.signals,
self.signals_token,
mio::Ready::readable(),
- mio::PollOpt::level()
+ mio::PollOpt::level(),
)
}
@@ -303,20 +294,15 @@ impl EventedReadWrite for Pty {
&mut self,
poll: &mio::Poll,
interest: mio::Ready,
- poll_opts: mio::PollOpt
+ poll_opts: mio::PollOpt,
) -> io::Result<()> {
- poll.reregister(
- &EventedFd(&self.fd.as_raw_fd()),
- self.token,
- interest,
- poll_opts
- )?;
+ poll.reregister(&EventedFd(&self.fd.as_raw_fd()), self.token, interest, poll_opts)?;
poll.reregister(
&self.signals,
self.signals_token,
mio::Ready::readable(),
- mio::PollOpt::level()
+ mio::PollOpt::level(),
)
}
@@ -350,23 +336,20 @@ impl EventedReadWrite for Pty {
impl EventedPty for Pty {
#[inline]
fn next_child_event(&mut self) -> Option<ChildEvent> {
- self.signals
- .pending()
- .next()
- .and_then(|signal| {
- if signal != sighook::SIGCHLD {
- return None;
- }
-
- match self.child.try_wait() {
- Err(e) => {
- error!("Error checking child process termination: {}", e);
- None
- },
- Ok(None) => None,
- Ok(_) => Some(ChildEvent::Exited),
- }
- })
+ self.signals.pending().next().and_then(|signal| {
+ if signal != sighook::SIGCHLD {
+ return None;
+ }
+
+ match self.child.try_wait() {
+ Err(e) => {
+ error!("Error checking child process termination: {}", e);
+ None
+ },
+ Ok(None) => None,
+ Ok(_) => Some(ChildEvent::Exited),
+ }
+ })
}
#[inline]
@@ -400,9 +383,7 @@ impl OnResize for i32 {
fn on_resize(&mut self, size: &SizeInfo) {
let win = size.to_winsize();
- let res = unsafe {
- libc::ioctl(*self, libc::TIOCSWINSZ, &win as *const _)
- };
+ let res = unsafe { libc::ioctl(*self, libc::TIOCSWINSZ, &win as *const _) };
if res < 0 {
die!("ioctl TIOCSWINSZ failed: {}", errno());
diff --git a/src/tty/windows/conpty.rs b/src/tty/windows/conpty.rs
index 6c74df7f..7383118f 100644
--- a/src/tty/windows/conpty.rs
+++ b/src/tty/windows/conpty.rs
@@ -214,10 +214,7 @@ pub fn new<'a>(
cmdline.insert(0, initial_command.program().into());
// Warning, here be borrow hell
- let cwd = options
- .working_dir
- .as_ref()
- .map(|dir| canonicalize(dir).unwrap());
+ let cwd = options.working_dir.as_ref().map(|dir| canonicalize(dir).unwrap());
let cwd = cwd.as_ref().map(|dir| dir.to_str().unwrap());
// Create the client application, using startup info containing ConPTY info
@@ -250,10 +247,7 @@ pub fn new<'a>(
let conin = EventedAnonWrite::new(conin);
let conout = EventedAnonRead::new(conout);
- let agent = Conpty {
- handle: pty_handle,
- api,
- };
+ let agent = Conpty { handle: pty_handle, api };
Some(Pty {
handle: super::PtyHandle::Conpty(ConptyHandle::new(agent)),
@@ -279,10 +273,7 @@ fn coord_from_sizeinfo(sizeinfo: &SizeInfo) -> Option<COORD> {
let lines = sizeinfo.lines().0;
if cols <= i16::MAX as usize && lines <= i16::MAX as usize {
- Some(COORD {
- X: sizeinfo.cols().0 as i16,
- Y: sizeinfo.lines().0 as i16,
- })
+ Some(COORD { X: sizeinfo.cols().0 as i16, Y: sizeinfo.lines().0 as i16 })
} else {
None
}
diff --git a/src/tty/windows/mod.rs b/src/tty/windows/mod.rs
index 2f5caa93..c87c5257 100644
--- a/src/tty/windows/mod.rs
+++ b/src/tty/windows/mod.rs
@@ -28,7 +28,7 @@ use crate::cli::Options;
use crate::config::Config;
use crate::display::OnResize;
use crate::term::SizeInfo;
-use crate::tty::{EventedReadWrite, EventedPty};
+use crate::tty::{EventedPty, EventedReadWrite};
mod conpty;
mod winpty;
@@ -44,14 +44,14 @@ pub fn process_should_exit() -> bool {
WAIT_OBJECT_0 => {
info!("wait_object_0");
true
- }
+ },
// Reached timeout of 0, process has not exited
WAIT_TIMEOUT => false,
// Error checking process, winpty gave us a bad agent handle?
_ => {
info!("Bad exit: {}", ::std::io::Error::last_os_error());
true
- }
+ },
}
}
}
@@ -219,7 +219,7 @@ impl<'a> OnResize for PtyHandle<'a> {
PtyHandle::Conpty(c) => {
let mut handle = c.clone();
handle.on_resize(sizeinfo)
- }
+ },
}
}
}
@@ -240,34 +240,14 @@ impl<'a> EventedReadWrite for Pty<'a> {
self.write_token = token.next().unwrap();
if interest.is_readable() {
- poll.register(
- &self.conout,
- self.read_token,
- mio::Ready::readable(),
- poll_opts,
- )?
+ poll.register(&self.conout, self.read_token, mio::Ready::readable(), poll_opts)?
} else {
- poll.register(
- &self.conout,
- self.read_token,
- mio::Ready::empty(),
- poll_opts,
- )?
+ poll.register(&self.conout, self.read_token, mio::Ready::empty(), poll_opts)?
}
if interest.is_writable() {
- poll.register(
- &self.conin,
- self.write_token,
- mio::Ready::writable(),
- poll_opts,
- )?
+ poll.register(&self.conin, self.write_token, mio::Ready::writable(), poll_opts)?
} else {
- poll.register(
- &self.conin,
- self.write_token,
- mio::Ready::empty(),
- poll_opts,
- )?
+ poll.register(&self.conin, self.write_token, mio::Ready::empty(), poll_opts)?
}
Ok(())
}
@@ -280,34 +260,14 @@ impl<'a> EventedReadWrite for Pty<'a> {
poll_opts: mio::PollOpt,
) -> io::Result<()> {
if interest.is_readable() {
- poll.reregister(
- &self.conout,
- self.read_token,
- mio::Ready::readable(),
- poll_opts,
- )?;
+ poll.reregister(&self.conout, self.read_token, mio::Ready::readable(), poll_opts)?;
} else {
- poll.reregister(
- &self.conout,
- self.read_token,
- mio::Ready::empty(),
- poll_opts,
- )?;
+ poll.reregister(&self.conout, self.read_token, mio::Ready::empty(), poll_opts)?;
}
if interest.is_writable() {
- poll.reregister(
- &self.conin,
- self.write_token,
- mio::Ready::writable(),
- poll_opts,
- )?;
+ poll.reregister(&self.conin, self.write_token, mio::Ready::writable(), poll_opts)?;
} else {
- poll.reregister(
- &self.conin,
- self.write_token,
- mio::Ready::empty(),
- poll_opts,
- )?;
+ poll.reregister(&self.conin, self.write_token, mio::Ready::empty(), poll_opts)?;
}
Ok(())
}
@@ -340,4 +300,4 @@ impl<'a> EventedReadWrite for Pty<'a> {
}
}
-impl<'a> EventedPty for Pty<'a> { }
+impl<'a> EventedPty for Pty<'a> {}
diff --git a/src/tty/windows/winpty.rs b/src/tty/windows/winpty.rs
index 26536eee..10bd9d01 100644
--- a/src/tty/windows/winpty.rs
+++ b/src/tty/windows/winpty.rs
@@ -14,29 +14,29 @@
use super::{Pty, HANDLE};
-use std::io;
use std::fs::OpenOptions;
-use std::os::windows::io::{FromRawHandle, IntoRawHandle};
+use std::io;
use std::os::windows::fs::OpenOptionsExt;
+use std::os::windows::io::{FromRawHandle, IntoRawHandle};
use std::sync::Arc;
use std::u16;
use dunce::canonicalize;
use mio_named_pipes::NamedPipe;
use winapi::um::winbase::FILE_FLAG_OVERLAPPED;
-use winpty::{ConfigFlags, MouseMode, SpawnConfig, SpawnFlags, Winpty};
use winpty::Config as WinptyConfig;
+use winpty::{ConfigFlags, MouseMode, SpawnConfig, SpawnFlags, Winpty};
+use crate::cli::Options;
use crate::config::{Config, Shell};
use crate::display::OnResize;
-use crate::cli::Options;
use crate::term::SizeInfo;
// We store a raw pointer because we need mutable access to call
// on_resize from a separate thread. Winpty internally uses a mutex
// so this is safe, despite outwards appearance.
pub struct Agent<'a> {
- winpty: *mut Winpty<'a>
+ winpty: *mut Winpty<'a>,
}
/// Handle can be cloned freely and moved between threads.
@@ -48,9 +48,7 @@ unsafe impl<'a> Sync for Agent<'a> {}
impl<'a> Agent<'a> {
pub fn new(winpty: Winpty<'a>) -> Self {
- Self {
- winpty: Box::into_raw(Box::new(winpty))
- }
+ Self { winpty: Box::into_raw(Box::new(winpty)) }
}
/// Get immutable access to Winpty.
@@ -68,11 +66,12 @@ impl<'a> Agent<'a> {
impl<'a> Drop for Agent<'a> {
fn drop(&mut self) {
- unsafe { Box::from_raw(self.winpty); }
+ unsafe {
+ Box::from_raw(self.winpty);
+ }
}
}
-
/// How long the winpty agent should wait for any RPC request
/// This is a placeholder value until we see how often long responses happen
const AGENT_TIMEOUT: u32 = 10000;
@@ -112,30 +111,19 @@ pub fn new<'a>(
Some(&cmdline.join(" ")),
cwd,
None, // Env
- ).unwrap();
+ )
+ .unwrap();
let default_opts = &mut OpenOptions::new();
- default_opts
- .share_mode(0)
- .custom_flags(FILE_FLAG_OVERLAPPED);
+ default_opts.share_mode(0).custom_flags(FILE_FLAG_OVERLAPPED);
let (conout_pipe, conin_pipe);
unsafe {
conout_pipe = NamedPipe::from_raw_handle(
- default_opts
- .clone()
- .read(true)
- .open(conout)
- .unwrap()
- .into_raw_handle(),
+ default_opts.clone().read(true).open(conout).unwrap().into_raw_handle(),
);
conin_pipe = NamedPipe::from_raw_handle(
- default_opts
- .clone()
- .write(true)
- .open(conin)
- .unwrap()
- .into_raw_handle(),
+ default_opts.clone().write(true).open(conin).unwrap().into_raw_handle(),
);
};
@@ -166,7 +154,7 @@ pub fn new<'a>(
conout: super::EventedReadablePipe::Named(conout_pipe),
conin: super::EventedWritablePipe::Named(conin_pipe),
read_token: 0.into(),
- write_token: 0.into()
+ write_token: 0.into(),
}
}
diff --git a/src/url.rs b/src/url.rs
index 33665197..d3caf9fc 100644
--- a/src/url.rs
+++ b/src/url.rs
@@ -12,17 +12,15 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use url;
use unicode_width::UnicodeWidthChar;
+use url;
use crate::term::cell::{Cell, Flags};
// See https://tools.ietf.org/html/rfc3987#page-13
const URL_SEPARATOR_CHARS: [char; 10] = ['<', '>', '"', ' ', '{', '}', '|', '\\', '^', '`'];
const URL_DENY_END_CHARS: [char; 8] = ['.', ',', ';', ':', '?', '!', '/', '('];
-const URL_SCHEMES: [&str; 8] = [
- "http", "https", "mailto", "news", "file", "git", "ssh", "ftp",
-];
+const URL_SCHEMES: [&str; 8] = ["http", "https", "mailto", "news", "file", "git", "ssh", "ftp"];
/// URL text and origin of the original click position.
#[derive(Debug, PartialEq)]
@@ -39,10 +37,7 @@ pub struct UrlParser {
impl UrlParser {
pub fn new() -> Self {
- UrlParser {
- state: String::new(),
- origin: 0,
- }
+ UrlParser { state: String::new(), origin: 0 }
}
/// Advance the parser one character to the left.
@@ -74,19 +69,17 @@ impl UrlParser {
// Remove non-alphabetical characters before the scheme
// https://tools.ietf.org/html/rfc3986#section-3.1
if let Some(index) = self.state.find("://") {
- let iter = self
- .state
- .char_indices()
- .rev()
- .skip_while(|(byte_index, _)| *byte_index >= index);
+ let iter =
+ self.state.char_indices().rev().skip_while(|(byte_index, _)| *byte_index >= index);
for (byte_index, c) in iter {
match c {
'a'...'z' | 'A'...'Z' => (),
_ => {
- self.origin = self.origin.saturating_sub(byte_index + c.width().unwrap_or(1));
+ self.origin =
+ self.origin.saturating_sub(byte_index + c.width().unwrap_or(1));
self.state = self.state.split_off(byte_index + c.len_utf8());
break;
- }
+ },
}
}
}
@@ -103,7 +96,7 @@ impl UrlParser {
')' | ']' => {
self.state.truncate(i);
break;
- }
+ },
_ => (),
}
}
@@ -127,14 +120,11 @@ impl UrlParser {
match url::Url::parse(&self.state) {
Ok(url) => {
if URL_SCHEMES.contains(&url.scheme()) && self.origin > 0 {
- Some(Url {
- origin: self.origin - 1,
- text: self.state,
- })
+ Some(Url { origin: self.origin - 1, text: self.state })
} else {
None
}
- }
+ },
Err(_) => None,
}
}
@@ -160,9 +150,9 @@ mod tests {
use crate::grid::Grid;
use crate::index::{Column, Line, Point};
- use crate::term::{Search, SizeInfo, Term};
- use crate::term::cell::{Cell, Flags};
use crate::message_bar::MessageBuffer;
+ use crate::term::cell::{Cell, Flags};
+ use crate::term::{Search, SizeInfo, Term};
fn url_create_term(input: &str) -> Term {
let size = SizeInfo {
diff --git a/src/util.rs b/src/util.rs
index 4532d2e4..06e8436d 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -12,10 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
-use std::{cmp, io};
use std::ffi::OsStr;
use std::process::Command;
use std::process::Stdio;
+use std::{cmp, io};
#[cfg(not(windows))]
use std::os::unix::process::CommandExt;
@@ -35,10 +35,7 @@ pub mod thread {
T: Send + 'static,
S: Into<String>,
{
- ::std::thread::Builder::new()
- .name(name.into())
- .spawn(f)
- .expect("thread spawn works")
+ ::std::thread::Builder::new().name(name.into()).spawn(f).expect("thread spawn works")
}
pub use std::thread::*;
@@ -87,9 +84,9 @@ pub mod fmt {
#[cfg(not(windows))]
pub fn start_daemon<I, S>(program: &str, args: I) -> io::Result<()>
- where
- I: IntoIterator<Item = S>,
- S: AsRef<OsStr>,
+where
+ I: IntoIterator<Item = S>,
+ S: AsRef<OsStr>,
{
Command::new(program)
.args(args)
@@ -109,9 +106,9 @@ pub fn start_daemon<I, S>(program: &str, args: I) -> io::Result<()>
#[cfg(windows)]
pub fn start_daemon<I, S>(program: &str, args: I) -> io::Result<()>
- where
- I: IntoIterator<Item = S>,
- S: AsRef<OsStr>,
+where
+ I: IntoIterator<Item = S>,
+ S: AsRef<OsStr>,
{
// Setting all the I/O handles to null and setting the
// CREATE_NEW_PROCESS_GROUP and CREATE_NO_WINDOW has the effect
diff --git a/src/window.rs b/src/window.rs
index 96b62cd3..c0231970 100644
--- a/src/window.rs
+++ b/src/window.rs
@@ -15,17 +15,16 @@ use std::convert::From;
use std::fmt::Display;
use crate::gl;
+use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize};
+#[cfg(not(any(target_os = "macos", windows)))]
+use glutin::os::unix::EventsLoopExt;
#[cfg(windows)]
use glutin::Icon;
-#[cfg(windows)]
-use image::ImageFormat;
use glutin::{
- self, ContextBuilder, ControlFlow, Event, EventsLoop,
- MouseCursor, WindowBuilder, ContextTrait
+ self, ContextBuilder, ContextTrait, ControlFlow, Event, EventsLoop, MouseCursor, WindowBuilder,
};
-use glutin::dpi::{LogicalPosition, LogicalSize, PhysicalPosition, PhysicalSize};
-#[cfg(not(any(target_os = "macos", windows)))]
-use glutin::os::unix::EventsLoopExt;
+#[cfg(windows)]
+use image::ImageFormat;
use crate::cli::Options;
use crate::config::{Decorations, WindowConfig};
@@ -160,12 +159,7 @@ impl Window {
// Set OpenGL symbol loader. This call MUST be after window.make_current on windows.
gl::load_with(|symbol| window.get_proc_address(symbol) as *const _);
- let window = Window {
- event_loop,
- window,
- mouse_visible: true,
- is_focused: false,
- };
+ let window = Window { event_loop, window, mouse_visible: true, is_focused: false };
window.run_os_extensions();
@@ -177,9 +171,7 @@ impl Window {
/// Some window properties are provided since subsystems like font
/// rasterization depend on DPI and scale factor.
pub fn device_properties(&self) -> DeviceProperties {
- DeviceProperties {
- scale_factor: self.window.get_hidpi_factor(),
- }
+ DeviceProperties { scale_factor: self.window.get_hidpi_factor() }
}
pub fn inner_size_pixels(&self) -> Option<LogicalSize> {
@@ -204,9 +196,7 @@ impl Window {
#[inline]
pub fn create_window_proxy(&self) -> Proxy {
- Proxy {
- inner: self.event_loop.create_proxy(),
- }
+ Proxy { inner: self.event_loop.create_proxy() }
}
#[inline]
@@ -260,7 +250,7 @@ impl Window {
pub fn get_platform_window(
title: &str,
class: &str,
- window_config: &WindowConfig
+ window_config: &WindowConfig,
) -> WindowBuilder {
use glutin::os::unix::WindowBuilderExt;
@@ -285,7 +275,7 @@ impl Window {
pub fn get_platform_window(
title: &str,
_class: &str,
- window_config: &WindowConfig
+ window_config: &WindowConfig,
) -> WindowBuilder {
let icon = Icon::from_bytes_with_format(WINDOW_ICON, ImageFormat::ICO).unwrap();
@@ -307,7 +297,7 @@ impl Window {
pub fn get_platform_window(
title: &str,
_class: &str,
- window_config: &WindowConfig
+ window_config: &WindowConfig,
) -> WindowBuilder {
use glutin::os::macos::WindowBuilderExt;
@@ -328,19 +318,16 @@ impl Window {
.with_titlebar_buttons_hidden(true)
.with_titlebar_transparent(true)
.with_fullsize_content_view(true),
- Decorations::None => window
- .with_titlebar_hidden(true),
+ Decorations::None => window.with_titlebar_hidden(true),
}
}
- #[cfg(
- any(
- target_os = "linux",
- target_os = "freebsd",
- target_os = "dragonfly",
- target_os = "openbsd"
- )
- )]
+ #[cfg(any(
+ target_os = "linux",
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "openbsd"
+ ))]
pub fn set_urgent(&self, is_urgent: bool) {
use glutin::os::unix::WindowExt;
self.window.set_urgent(is_urgent);
@@ -384,21 +371,20 @@ pub trait OsExtensions {
fn run_os_extensions(&self) {}
}
-#[cfg(
- not(
- any(
- target_os = "linux",
- target_os = "freebsd",
- target_os = "dragonfly",
- target_os = "openbsd"
- )
- )
-)]
+#[cfg(not(any(
+ target_os = "linux",
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "openbsd"
+)))]
impl OsExtensions for Window {}
-#[cfg(
- any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd")
-)]
+#[cfg(any(
+ target_os = "linux",
+ target_os = "freebsd",
+ target_os = "dragonfly",
+ target_os = "openbsd"
+))]
impl OsExtensions for Window {
fn run_os_extensions(&self) {
use glutin::os::unix::WindowExt;