summaryrefslogtreecommitdiffstats
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
parent91aa683bcd060b2ac2f621a388a6448f564d0537 (diff)
Add rustfmt style guidev0.3.0-rc1
-rw-r--r--.travis.yml4
-rw-r--r--CONTRIBUTING.md2
-rw-r--r--build.rs25
-rwxr-xr-xci/install.sh7
-rwxr-xr-xci/script.sh6
-rw-r--r--copypasta/src/macos.rs46
-rw-r--r--copypasta/src/windows.rs12
-rw-r--r--copypasta/src/x11.rs48
-rw-r--r--font/src/darwin/byte_order.rs11
-rw-r--r--font/src/darwin/mod.rs195
-rw-r--r--font/src/ft/fc/char_set.rs14
-rw-r--r--font/src/ft/fc/config.rs11
-rw-r--r--font/src/ft/fc/font_set.rs34
-rw-r--r--font/src/ft/fc/mod.rs53
-rw-r--r--font/src/ft/fc/object_set.rs6
-rw-r--r--font/src/ft/fc/pattern.rs254
-rw-r--r--font/src/ft/mod.rs175
-rw-r--r--font/src/lib.rs46
-rw-r--r--font/src/rusttype/mod.rs70
-rw-r--r--rustfmt.toml13
-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
-rw-r--r--tests/ref.rs28
-rw-r--r--winpty/build.rs6
-rw-r--r--winpty/src/windows.rs161
57 files changed, 1878 insertions, 2395 deletions
diff --git a/.travis.yml b/.travis.yml
index e1c9ce53..6749cfe0 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -35,6 +35,10 @@ matrix:
os: windows
env: CLIPPY=true
rust: stable
+ - name: "Rustfmt"
+ os: linux
+ env: RUSTFMT=true
+ rust: nightly
allow_failures:
- rust: nightly
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 8818e383..bb5010a4 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -89,7 +89,7 @@ Changes compared to the latest Alacritty release which have a direct effect on t
### Style
-Alacritty currently does not have any automatically enforced style guidelines. As a result of that, it is not possible to run `rustfmt` on existing files. New code should however follow the default ruleset of `rustfmt` and for newly created files it is possible to run the `rustfmt` tool directly.
+All Alacritty changes are automatically verified by CI to conform to its rustfmt guidelines. If a CI build is failing because of formatting issues, you can install rustfmt using `rustup component add rustfmt` and then format all code using `cargo fmt`.
# Contact
diff --git a/build.rs b/build.rs
index 4036dad2..1a12a670 100644
--- a/build.rs
+++ b/build.rs
@@ -14,10 +14,10 @@
#[cfg(windows)]
use embed_resource;
#[cfg(windows)]
-use tempfile;
-#[cfg(windows)]
use reqwest;
#[cfg(windows)]
+use tempfile;
+#[cfg(windows)]
use zip;
use gl_generator::{Api, Fallbacks, GlobalGenerator, Profile, Registry};
@@ -27,24 +27,20 @@ use std::fs::File;
use std::path::Path;
#[cfg(windows)]
-use std::io;
-#[cfg(windows)]
use std::fs::OpenOptions;
+#[cfg(windows)]
+use std::io;
#[cfg(windows)]
-const WINPTY_PACKAGE_URL: &str = "https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-msvc2015.zip";
+const WINPTY_PACKAGE_URL: &str =
+ "https://github.com/rprichard/winpty/releases/download/0.4.3/winpty-0.4.3-msvc2015.zip";
fn main() {
let dest = env::var("OUT_DIR").unwrap();
let mut file = File::create(&Path::new(&dest).join("gl_bindings.rs")).unwrap();
- Registry::new(
- Api::Gl,
- (4, 5),
- Profile::Core,
- Fallbacks::All,
- ["GL_ARB_blend_func_extended"],
- ).write_bindings(GlobalGenerator, &mut file)
+ Registry::new(Api::Gl, (4, 5), Profile::Core, Fallbacks::All, ["GL_ARB_blend_func_extended"])
+ .write_bindings(GlobalGenerator, &mut file)
.unwrap();
#[cfg(windows)]
@@ -68,7 +64,8 @@ fn aquire_winpty_agent(out_path: &Path) {
.read(true)
.write(true)
.create(true)
- .open(tmp_dir.path().join("winpty_package.zip")).unwrap();
+ .open(tmp_dir.path().join("winpty_package.zip"))
+ .unwrap();
io::copy(&mut response, &mut file).unwrap();
@@ -77,7 +74,7 @@ fn aquire_winpty_agent(out_path: &Path) {
let target = match env::var("TARGET").unwrap().split("-").next().unwrap() {
"x86_64" => "x64",
"i386" => "ia32",
- _ => panic!("architecture has no winpty binary")
+ _ => panic!("architecture has no winpty binary"),
};
let mut winpty_agent = archive.by_name(&format!("{}/bin/winpty-agent.exe", target)).unwrap();
diff --git a/ci/install.sh b/ci/install.sh
index af4bb776..ccbe3728 100755
--- a/ci/install.sh
+++ b/ci/install.sh
@@ -1,6 +1,11 @@
#!/bin/bash
-# Add clippy for linting with nightly builds
+# Add clippy for lint validation
if [ "$CLIPPY" == "true" ]; then
rustup component add clippy
fi
+
+# Add rustfmt for format validation
+if [ "$RUSTFMT" == "true" ]; then
+ rustup component add rustfmt
+fi
diff --git a/ci/script.sh b/ci/script.sh
index c17bbbd2..21991415 100755
--- a/ci/script.sh
+++ b/ci/script.sh
@@ -9,6 +9,12 @@ if [ "$CLIPPY" == "true" ]; then
exit
fi
+# Run clippy rustfmt
+if [ "$RUSTFMT" == "true" ]; then
+ cargo fmt -- --check
+ exit
+fi
+
# Run test in release mode if a tag is present, to produce an optimized binary
if [ -n "$TRAVIS_TAG" ]; then
cargo test --release || error=true
diff --git a/copypasta/src/macos.rs b/copypasta/src/macos.rs
index 1942ac43..d0ccaec4 100644
--- a/copypasta/src/macos.rs
+++ b/copypasta/src/macos.rs
@@ -4,18 +4,18 @@
//! https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/PasteboardGuide106/Articles/pbReading.html#//apple_ref/doc/uid/TP40008123-SW1
mod ns {
- extern crate objc_id;
extern crate objc_foundation;
+ extern crate objc_id;
#[link(name = "AppKit", kind = "framework")]
- extern {}
+ extern "C" {}
use std::mem;
- use objc::runtime::{Class, Object};
+ use self::objc_foundation::{INSArray, INSObject, INSString};
+ use self::objc_foundation::{NSArray, NSDictionary, NSObject, NSString};
use self::objc_id::{Id, Owned};
- use self::objc_foundation::{NSArray, NSObject, NSDictionary, NSString};
- use self::objc_foundation::{INSString, INSArray, INSObject};
+ use objc::runtime::{Class, Object};
/// Rust API for NSPasteboard
pub struct Pasteboard(Id<Object>);
@@ -55,6 +55,7 @@ mod ns {
impl PasteboardReadObject<String> for Pasteboard {
type Err = ReadStringError;
+
fn read_object(&self) -> Result<String, ReadStringError> {
// Get string class; need this for passing to readObjectsForClasses
let ns_string_class = match Class::get("NSString") {
@@ -133,9 +134,7 @@ mod ns {
// The writeObjects method returns true in case of success, and
// false otherwise.
- let ok: bool = unsafe {
- msg_send![self.0, writeObjects:objects]
- };
+ let ok: bool = unsafe { msg_send![self.0, writeObjects: objects] };
if ok {
Ok(())
@@ -175,9 +174,7 @@ mod ns {
impl ::std::error::Error for NewPasteboardError {
fn description(&self) -> &str {
match *self {
- NewPasteboardError::GetPasteboardClass => {
- "NSPasteboard class not found"
- },
+ NewPasteboardError::GetPasteboardClass => "NSPasteboard class not found",
NewPasteboardError::LoadGeneralPasteboard => {
"[NSPasteboard generalPasteboard] failed"
},
@@ -209,9 +206,7 @@ mod ns {
}
};
- let id = unsafe {
- Id::from_ptr(ptr)
- };
+ let id = unsafe { Id::from_ptr(ptr) };
Ok(Pasteboard(id))
}
@@ -222,9 +217,7 @@ mod ns {
/// This is the first step in providing data on the pasteboard. The
/// return value is the change count of the pasteboard
pub fn clear_contents(&mut self) -> usize {
- unsafe {
- msg_send![self.0, clearContents]
- }
+ unsafe { msg_send![self.0, clearContents] }
}
}
}
@@ -236,7 +229,6 @@ pub enum Error {
WriteString(ns::WriteStringError),
}
-
impl ::std::error::Error for Error {
fn cause(&self) -> Option<&::std::error::Error> {
match *self {
@@ -258,9 +250,7 @@ impl ::std::error::Error for Error {
impl ::std::fmt::Display for Error {
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
match *self {
- Error::CreatePasteboard(ref err) => {
- write!(f, "Failed to create pasteboard: {}", err)
- },
+ Error::CreatePasteboard(ref err) => write!(f, "Failed to create pasteboard: {}", err),
Error::ReadString(ref err) => {
write!(f, "Failed to read string from pasteboard: {}", err)
},
@@ -301,23 +291,23 @@ impl super::Load for Clipboard {
fn load_primary(&self) -> Result<String, Self::Err> {
use self::ns::PasteboardReadObject;
- self.0.read_object()
- .map_err(::std::convert::From::from)
+ self.0.read_object().map_err(::std::convert::From::from)
}
}
impl super::Store for Clipboard {
fn store_primary<S>(&mut self, contents: S) -> Result<(), Self::Err>
- where S: Into<String>
+ where
+ S: Into<String>,
{
use self::ns::PasteboardWriteObject;
- self.0.write_object(contents.into())
- .map_err(::std::convert::From::from)
+ self.0.write_object(contents.into()).map_err(::std::convert::From::from)
}
fn store_selection<S>(&mut self, _contents: S) -> Result<(), Self::Err>
- where S: Into<String>
+ where
+ S: Into<String>,
{
// No such thing on macOS
Ok(())
@@ -327,7 +317,7 @@ impl super::Store for Clipboard {
#[cfg(test)]
mod tests {
use super::Clipboard;
- use ::{Load, Store};
+ use {Load, Store};
#[test]
fn create_clipboard_save_load_contents() {
diff --git a/copypasta/src/windows.rs b/copypasta/src/windows.rs
index 95e3db55..48b033cc 100644
--- a/copypasta/src/windows.rs
+++ b/copypasta/src/windows.rs
@@ -33,9 +33,7 @@ impl Load for Clipboard {
type Err = Error;
fn new() -> Result<Self, Error> {
- ClipboardContext::new()
- .map(Clipboard)
- .map_err(Error::Clipboard)
+ ClipboardContext::new().map(Clipboard).map_err(Error::Clipboard)
}
fn load_primary(&self) -> Result<String, Self::Err> {
@@ -56,9 +54,7 @@ impl Store for Clipboard {
where
S: Into<String>,
{
- self.0
- .set_contents(contents.into())
- .map_err(Error::Clipboard)
+ self.0.set_contents(contents.into()).map_err(Error::Clipboard)
}
/// Sets the secondary clipboard contents
@@ -67,8 +63,6 @@ impl Store for Clipboard {
where
S: Into<String>,
{
- self.0
- .set_contents(contents.into())
- .map_err(Error::Clipboard)
+ self.0.set_contents(contents.into()).map_err(Error::Clipboard)
}
}
diff --git a/copypasta/src/x11.rs b/copypasta/src/x11.rs
index c7d9c696..3e0d7913 100644
--- a/copypasta/src/x11.rs
+++ b/copypasta/src/x11.rs
@@ -7,10 +7,10 @@
//!
//! FIXME: Implement actual X11 clipboard API using the ICCCM reference
//! https://tronche.com/gui/x/icccm/
+use std::ffi::OsStr;
use std::io;
-use std::process::{Output, Command};
+use std::process::{Command, Output};
use std::string::FromUtf8Error;
-use std::ffi::OsStr;
use super::{Load, Store};
@@ -45,13 +45,11 @@ 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::Io(ref err) => {
- match err.kind() {
- io::ErrorKind::NotFound => {
- write!(f, "Please install `xclip` to enable clipboard support")
- },
- _ => write!(f, "Error calling xclip: {}", err),
- }
+ Error::Io(ref err) => match err.kind() {
+ io::ErrorKind::NotFound => {
+ write!(f, "Please install `xclip` to enable clipboard support")
+ },
+ _ => write!(f, "Error calling xclip: {}", err),
},
Error::Xclip(ref s) => write!(f, "Error from xclip: {}", s),
Error::Utf8(ref err) => write!(f, "Error parsing xclip output: {}", err),
@@ -79,17 +77,13 @@ impl Load for Clipboard {
}
fn load_primary(&self) -> Result<String, Self::Err> {
- let output = Command::new("xclip")
- .args(&["-o", "-selection", "clipboard"])
- .output()?;
+ let output = Command::new("xclip").args(&["-o", "-selection", "clipboard"]).output()?;
Clipboard::process_xclip_output(output)
}
fn load_selection(&self) -> Result<String, Self::Err> {
- let output = Command::new("xclip")
- .args(&["-o"])
- .output()?;
+ let output = Command::new("xclip").args(&["-o"]).output()?;
Clipboard::process_xclip_output(output)
}
@@ -99,7 +93,8 @@ impl Store for Clipboard {
/// Sets the primary clipboard contents
#[inline]
fn store_primary<S>(&mut self, contents: S) -> Result<(), Self::Err>
- where S: Into<String>
+ where
+ S: Into<String>,
{
self.store(contents, &["-i", "-selection", "clipboard"])
}
@@ -107,7 +102,8 @@ impl Store for Clipboard {
/// Sets the secondary clipboard contents
#[inline]
fn store_selection<S>(&mut self, contents: S) -> Result<(), Self::Err>
- where S: Into<String>
+ where
+ S: Into<String>,
{
self.store(contents, &["-i"])
}
@@ -116,26 +112,22 @@ impl Store for Clipboard {
impl Clipboard {
fn process_xclip_output(output: Output) -> Result<String, Error> {
if output.status.success() {
- String::from_utf8(output.stdout)
- .map_err(::std::convert::From::from)
+ String::from_utf8(output.stdout).map_err(::std::convert::From::from)
} else {
- String::from_utf8(output.stderr)
- .map_err(::std::convert::From::from)
+ String::from_utf8(output.stderr).map_err(::std::convert::From::from)
}
}
fn store<C, S>(&mut self, contents: C, args: &[S]) -> Result<(), Error>
- where C: Into<String>,
- S: AsRef<OsStr>,
+ where
+ C: Into<String>,
+ S: AsRef<OsStr>,
{
use std::io::Write;
use std::process::{Command, Stdio};
let contents = contents.into();
- let mut child = Command::new("xclip")
- .args(args)
- .stdin(Stdio::piped())
- .spawn()?;
+ let mut child = Command::new("xclip").args(args).stdin(Stdio::piped()).spawn()?;
if let Some(stdin) = child.stdin.as_mut() {
stdin.write_all(contents.as_bytes())?;
@@ -154,7 +146,7 @@ impl Clipboard {
#[cfg(test)]
mod tests {
use super::Clipboard;
- use ::{Load, Store};
+ use {Load, Store};
#[test]
fn clipboard_works() {
diff --git a/font/src/darwin/byte_order.rs b/font/src/darwin/byte_order.rs
index 2ea46fcb..382caa31 100644
--- a/font/src/darwin/byte_order.rs
+++ b/font/src/darwin/byte_order.rs
@@ -40,9 +40,10 @@ pub fn extract_rgb(bytes: &[u8]) -> Vec<u8> {
#[cfg(target_endian = "big")]
pub fn extract_rgb(bytes: Vec<u8>) -> Vec<u8> {
- bytes.into_iter()
- .enumerate()
- .filter(|&(index, _)| ((index) % 4) != 0)
- .map(|(_, val)| val)
- .collect::<Vec<_>>()
+ bytes
+ .into_iter()
+ .enumerate()
+ .filter(|&(index, _)| ((index) % 4) != 0)
+ .map(|(_, val)| val)
+ .collect::<Vec<_>>()
}
diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs
index 60b1a3e7..15a97e24 100644
--- a/font/src/darwin/mod.rs
+++ b/font/src/darwin/mod.rs
@@ -17,34 +17,37 @@
//! TODO error handling... just search for unwrap.
#![allow(improper_ctypes)]
use std::collections::HashMap;
-use std::ptr;
use std::path::PathBuf;
+use std::ptr;
-use ::{Slant, Weight, Style};
+use {Slant, Style, Weight};
-use core_foundation::string::{CFString};
-use core_foundation::array::{CFIndex, CFArray};
+use core_foundation::array::{CFArray, CFIndex};
+use core_foundation::string::CFString;
use core_graphics::base::kCGImageAlphaPremultipliedFirst;
use core_graphics::color_space::CGColorSpace;
-use core_graphics::context::{CGContext};
+use core_graphics::context::CGContext;
use core_graphics::font::{CGFont, CGGlyph};
use core_graphics::geometry::{CGPoint, CGRect, CGSize};
-use core_text::font::{CTFont, new_from_descriptor as ct_new_from_descriptor, cascade_list_for_languages as ct_cascade_list_for_languages};
+use core_text::font::{
+ cascade_list_for_languages as ct_cascade_list_for_languages,
+ new_from_descriptor as ct_new_from_descriptor, CTFont,
+};
use core_text::font_collection::create_for_family;
use core_text::font_collection::get_family_names as ct_get_family_names;
use core_text::font_descriptor::kCTFontDefaultOrientation;
use core_text::font_descriptor::kCTFontHorizontalOrientation;
use core_text::font_descriptor::kCTFontVerticalOrientation;
-use core_text::font_descriptor::{CTFontDescriptor, CTFontOrientation};
use core_text::font_descriptor::SymbolicTraitAccessors;
+use core_text::font_descriptor::{CTFontDescriptor, CTFontOrientation};
use euclid::{Point2D, Rect, Size2D};
-use super::{FontDesc, RasterizedGlyph, Metrics, FontKey, GlyphKey};
+use super::{FontDesc, FontKey, GlyphKey, Metrics, RasterizedGlyph};
pub mod byte_order;
-use self::byte_order::kCGBitmapByteOrder32Host;
use self::byte_order::extract_rgb;
+use self::byte_order::kCGBitmapByteOrder32Host;
use super::Size;
@@ -59,11 +62,11 @@ pub struct Descriptor {
display_name: String,
font_path: PathBuf,
- ct_descriptor: CTFontDescriptor
+ ct_descriptor: CTFontDescriptor,
}
impl Descriptor {
- fn new(desc:CTFontDescriptor) -> Descriptor {
+ fn new(desc: CTFontDescriptor) -> Descriptor {
Descriptor {
family_name: desc.family_name(),
font_name: desc.font_name(),
@@ -111,16 +114,14 @@ 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::MissingGlyph(ref c) => {
- write!(f, "Glyph not found for char {:?}", c)
- },
- Error::MissingFont(ref desc) => {
- write!(f, "Couldn't find a font with {}\
- \n\tPlease check the font config in your alacritty.yml.", desc)
- },
- Error::FontNotLoaded => {
- f.write_str("Tried to use a font that hasn't been loaded")
- }
+ Error::MissingGlyph(ref c) => write!(f, "Glyph not found for char {:?}", c),
+ Error::MissingFont(ref desc) => write!(
+ f,
+ "Couldn't find a font with {}\n\tPlease check the font config in your \
+ alacritty.yml.",
+ desc
+ ),
+ Error::FontNotLoaded => f.write_str("Tried to use a font that hasn't been loaded"),
}
}
}
@@ -139,50 +140,41 @@ impl ::Rasterize for Rasterizer {