From bde4dacc791501440515c1a51ad2fcb0256cf04c Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Fri, 16 Dec 2016 22:48:04 -0800 Subject: [PATCH] Misc formatting fixes --- copypasta/src/macos.rs | 32 +++++++++++++---------- font/src/darwin/mod.rs | 54 ++++++++++++++++++++++++++------------- font/src/ft/list_fonts.rs | 20 ++++++++++++--- font/src/ft/mod.rs | 5 +++- font/src/lib.rs | 4 +-- src/ansi.rs | 49 +++++++++++++++++++++-------------- src/config.rs | 8 ++++-- src/display.rs | 6 ++++- src/event_loop.rs | 14 ++++++++-- src/grid.rs | 8 +++--- src/meter.rs | 4 +-- src/renderer/mod.rs | 9 ++++--- src/term/mod.rs | 24 +++++++++-------- src/util.rs | 5 +++- 14 files changed, 159 insertions(+), 83 deletions(-) diff --git a/copypasta/src/macos.rs b/copypasta/src/macos.rs index dfbf5a87..1b133b92 100644 --- a/copypasta/src/macos.rs +++ b/copypasta/src/macos.rs @@ -1,6 +1,7 @@ //! Clipboard access on macOS //! -//! Implemented according to https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/PasteboardGuide106/Articles/pbReading.html#//apple_ref/doc/uid/TP40008123-SW1 +//! Implemented according to +//! 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; @@ -62,22 +63,25 @@ mod ns { }; let classes: Id> = unsafe { - // I think this transmute is valid. It's going from an Id to an - // Id. From transmute's perspective, the only thing that matters is that - // they both have the same size (they do for now since the generic is phantom data). - // In both cases, the underlying pointer is an id (from `[NSString class]`), so - // again, this should be valid. There's just nothing implemented in objc_id or - // objc_foundation to do this "safely". By the way, the only reason this is - // necessary is because INSObject isn't implemented for Id. + // I think this transmute is valid. It's going from an + // Id to an Id. From transmute's perspective, + // the only thing that matters is that they both have the same + // size (they do for now since the generic is phantom data). In + // both cases, the underlying pointer is an id (from `[NSString + // class]`), so again, this should be valid. There's just + // nothing implemented in objc_id or objc_foundation to do this + // "safely". By the way, the only reason this is necessary is + // because INSObject isn't implemented for Id. // - // And if that argument isn't convincing, my final reasoning is that "it seems to - // work". + // And if that argument isn't convincing, my final reasoning is + // that "it seems to work". NSArray::from_vec(vec![mem::transmute(ns_string)]) }; // No options // - // Apparently this doesn't compile without a type hint, so it maps objects to objects! + // Apparently this doesn't compile without a type hint, so it maps + // objects to objects! let options: Id> = NSDictionary::new(); // call [pasteboard readObjectsForClasses:options:] @@ -95,8 +99,10 @@ mod ns { } }; - // Ok, this is great. We have an NSArray, and these have decent bindings. Use - // the first item returned (if an item was returned) or just return an empty string + // Ok, this is great. We have an NSArray, and these have + // decent bindings. Use the first item returned (if an item was + // returned) or just return an empty string + // // XXX Should this return an error if no items were returned? let contents = copied_items .first_object() diff --git a/font/src/darwin/mod.rs b/font/src/darwin/mod.rs index 1b295801..c445996d 100644 --- a/font/src/darwin/mod.rs +++ b/font/src/darwin/mod.rs @@ -226,9 +226,15 @@ impl Descriptor { impl Font { /// The the bounding rect of a glyph - pub fn bounding_rect_for_glyph(&self, orientation: FontOrientation, index: u32) -> Rect { - let cg_rect = self.ct_font.get_bounding_rects_for_glyphs(orientation as CTFontOrientation, - &[index as CGGlyph]); + pub fn bounding_rect_for_glyph( + &self, + orientation: FontOrientation, + index: u32 + ) -> Rect { + let cg_rect = self.ct_font.get_bounding_rects_for_glyphs( + orientation as CTFontOrientation, + &[index as CGGlyph] + ); Rect::new( Point2D::new(cg_rect.origin.x, cg_rect.origin.y), @@ -255,10 +261,12 @@ impl Font { let indices = [index as CGGlyph]; - self.ct_font.get_advances_for_glyphs(FontOrientation::Default as _, - &indices[0], - ptr::null_mut(), - 1) + self.ct_font.get_advances_for_glyphs( + FontOrientation::Default as _, + &indices[0], + ptr::null_mut(), + 1 + ) } pub fn get_glyph(&self, character: char, _size: f64) -> RasterizedGlyph { @@ -297,19 +305,25 @@ impl Font { }; } - let mut cg_context = CGContext::create_bitmap_context(rasterized_width as usize, - rasterized_height as usize, - 8, // bits per component - rasterized_width as usize * 4, - &CGColorSpace::create_device_rgb(), - kCGImageAlphaPremultipliedFirst | - kCGBitmapByteOrder32Host); + let mut cg_context = CGContext::create_bitmap_context( + rasterized_width as usize, + rasterized_height as usize, + 8, // bits per component + rasterized_width as usize * 4, + &CGColorSpace::create_device_rgb(), + kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host + ); // Give the context an opaque, black background cg_context.set_rgb_fill_color(0.0, 0.0, 0.0, 1.0); - let context_rect = CGRect::new(&CGPoint::new(0.0, 0.0), - &CGSize::new(rasterized_width as f64, - rasterized_height as f64)); + let context_rect = CGRect::new( + &CGPoint::new(0.0, 0.0), + &CGSize::new( + rasterized_width as f64, + rasterized_height as f64 + ) + ); + cg_context.fill_rect(context_rect); // Uses thin strokes @@ -354,7 +368,11 @@ impl Font { let chars = [character as UniChar]; let mut glyphs = [0 as CGGlyph]; - let res = self.ct_font.get_glyphs_for_characters(&chars[0], &mut glyphs[0], 1 as CFIndex); + let res = self.ct_font.get_glyphs_for_characters( + &chars[0], + &mut glyphs[0], + 1 as CFIndex + ); if res { Some(glyphs[0] as u32) diff --git a/font/src/ft/list_fonts.rs b/font/src/ft/list_fonts.rs index 1dc716d5..44794501 100644 --- a/font/src/ft/list_fonts.rs +++ b/font/src/ft/list_fonts.rs @@ -65,7 +65,11 @@ fn list_families() -> Vec { } let mut id = 0; - while FcPatternGetString(*font, b"family\0".as_ptr() as *mut c_char, id, &mut family) == FcResultMatch { + while FcPatternGetString( + *font, + b"family\0".as_ptr() as *mut c_char, + id, &mut family + ) == FcResultMatch { let safe_family = fc_char8_to_string(family); id += 1; families.push(safe_family); @@ -139,7 +143,11 @@ pub fn get_family_info(family: String) -> Family { let family_name = family_name.as_ptr(); // Add family name to pattern. Use this for searching. - FcPatternAddString(pattern, FAMILY.as_ptr() as *mut c_char, family_name as *mut FcChar8); + FcPatternAddString( + pattern, + FAMILY.as_ptr() as *mut c_char, + family_name as *mut FcChar8 + ); // Request filename, style, and index for each variant in family let object_set = FcObjectSetCreate(); // *mut FcObjectSet @@ -147,7 +155,13 @@ pub fn get_family_info(family: String) -> Family { FcObjectSetAdd(object_set, INDEX.as_ptr() as *mut c_char); FcObjectSetAdd(object_set, STYLE.as_ptr() as *mut c_char); - let variants = FcFontSetList(config, &mut font_set, 1 /* nsets */, pattern, object_set); + let variants = FcFontSetList( + config, + &mut font_set, + 1 /* nsets */, + pattern, object_set + ); + let num_variant = (*variants).nfont as isize; for i in 0..num_variant { diff --git a/font/src/ft/mod.rs b/font/src/ft/mod.rs index fa4325a0..c9abd693 100644 --- a/font/src/ft/mod.rs +++ b/font/src/ft/mod.rs @@ -117,7 +117,10 @@ impl Rasterizer { unsafe { let ft_lib = self.library.raw(); - freetype::ffi::FT_Library_SetLcdFilter(ft_lib, freetype::ffi::FT_LCD_FILTER_DEFAULT); + freetype::ffi::FT_Library_SetLcdFilter( + ft_lib, + freetype::ffi::FT_LCD_FILTER_DEFAULT + ); } let bitmap = glyph.bitmap(); diff --git a/font/src/lib.rs b/font/src/lib.rs index 74563b1a..ca8de0a2 100644 --- a/font/src/lib.rs +++ b/font/src/lib.rs @@ -14,11 +14,9 @@ // //! Compatibility layer for different font engines //! -//! This module is developed as part of Alacritty; Alacritty does not include Windows support -//! as a goal at this time, and neither does this module. -//! //! CoreText is used on Mac OS. //! FreeType is used on everything that's not Mac OS. +//! Eventually, ClearType support will be available for windows #![feature(integer_atomics)] #[cfg(not(target_os = "macos"))] diff --git a/src/ansi.rs b/src/ansi.rs index 1848b9ca..633a7e54 100644 --- a/src/ansi.rs +++ b/src/ansi.rs @@ -176,13 +176,14 @@ pub trait Handler { /// Erase `count` chars in current line following cursor /// - /// Erase means resetting to the default state (default colors, no content, no mode flags) + /// Erase means resetting to the default state (default colors, no content, + /// no mode flags) fn erase_chars(&mut self, Column) {} /// Delete `count` chars /// - /// Deleting a character is like the delete key on the keyboard - everything to the right of the - /// deleted things is shifted left. + /// Deleting a character is like the delete key on the keyboard - everything + /// to the right of the deleted things is shifted left. fn delete_chars(&mut self, Column) {} /// Move backward `count` tabs @@ -211,8 +212,9 @@ pub trait Handler { /// Reverse Index /// - /// Move the active position to the same horizontal position on the preceding line. If the - /// active position is at the top margin, a scroll down is performed + /// Move the active position to the same horizontal position on the + /// preceding line. If the active position is at the top margin, a scroll + /// down is performed fn reverse_index(&mut self) {} /// set a terminal attribute @@ -690,7 +692,13 @@ impl<'a, H, W> vte::Perform for Performer<'a, H, W> } #[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 + ) { match byte { b'D' => self.handler.linefeed(), b'E' => self.handler.newline(), @@ -998,19 +1006,22 @@ 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(); diff --git a/src/config.rs b/src/config.rs index a6d8150e..aca16a1d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -459,7 +459,10 @@ impl de::Deserialize for RawBinding { impl Visitor for RawBindingVisitor { type Value = RawBinding; - fn visit_map(&mut self, mut visitor: V) -> ::std::result::Result + fn visit_map( + &mut self, + mut visitor: V + ) -> ::std::result::Result where V: MapVisitor, { let mut mods: Option<::glutin::Mods> = None; @@ -1129,7 +1132,8 @@ impl Monitor { if op.contains(op::IGNORED) { if let Some(path) = path.as_ref() { if let Err(err) = watcher.watch(&path) { - err_println!("failed to establish watch on {:?}: {:?}", path, err); + err_println!("failed to establish watch on {:?}: {:?}", + path, err); } } } diff --git a/src/display.rs b/src/display.rs index b6c5f401..a6b6528d 100644 --- a/src/display.rs +++ b/src/display.rs @@ -176,7 +176,11 @@ impl Display { } /// Process pending resize events - pub fn handle_resize(&mut self, terminal: &mut MutexGuard, items: &mut [&mut OnResize]) { + pub fn handle_resize( + &mut self, + terminal: &mut MutexGuard, + items: &mut [&mut OnResize] + ) { // Resize events new_size and are handled outside the poll_events // iterator. This has the effect of coalescing multiple resize // events into one. diff --git a/src/event_loop.rs b/src/event_loop.rs index e8e323e4..44d71f94 100644 --- a/src/event_loop.rs +++ b/src/event_loop.rs @@ -174,7 +174,14 @@ impl EventLoop } #[inline] - fn pty_read(&mut self, state: &mut State, buf: &mut [u8], mut writer: Option<&mut W>) { + fn pty_read( + &mut self, + state: &mut State, + buf: &mut [u8], + mut writer: Option<&mut W> + ) + where W: Write + { loop { match self.pty.read(&mut buf[..]) { Ok(0) => break, @@ -234,7 +241,10 @@ impl EventLoop } } - pub fn spawn(mut self, state: Option) -> thread::JoinHandle<(EventLoop, State)> { + pub fn spawn( + mut self, + state: Option + ) -> thread::JoinHandle<(EventLoop, State)> { thread::spawn_named("pty reader", move || { let mut state = state.unwrap_or_else(Default::default); let mut buf = [0u8; 4096]; diff --git a/src/grid.rs b/src/grid.rs index 7192b996..d8b701b9 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -331,9 +331,9 @@ row_index_range!(RangeTo); row_index_range!(RangeFrom); row_index_range!(RangeFull); -// ------------------------------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // Row ranges for Grid -// ------------------------------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- impl Index> for Grid { type Output = [Row]; @@ -383,9 +383,9 @@ impl IndexMut> for Grid { } } -// ------------------------------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- // Column ranges for Row -// ------------------------------------------------------------------------------------------------- +// ----------------------------------------------------------------------------- impl Index> for Row { type Output = [T]; diff --git a/src/meter.rs b/src/meter.rs index 2dc2ed21..58c92145 100644 --- a/src/meter.rs +++ b/src/meter.rs @@ -27,8 +27,8 @@ //! let _sampler = meter.sampler(); //! } //! -//! // Get the moving average. The meter tracks a fixed number of samles, and the average won't mean -//! // much until it's filled up at least once. +//! // Get the moving average. The meter tracks a fixed number of samles, and +//! // the average won't mean much until it's filled up at least once. //! println!("Average time: {}", meter.average()); use std::time::{Instant, Duration}; diff --git a/src/renderer/mod.rs b/src/renderer/mod.rs index d771b6dc..79cfd665 100644 --- a/src/renderer/mod.rs +++ b/src/renderer/mod.rs @@ -127,7 +127,9 @@ impl GlyphCache { // Load regular font let regular_desc = FontDesc::new(font.family(), font.style()); - let regular = rasterizer.load_font(®ular_desc, size).expect("regular font load ok"); + let regular = rasterizer + .load_font(®ular_desc, size) + .expect("regular font load ok"); // Load bold font let bold_style = font.bold_style().unwrap_or("Bold"); @@ -1192,8 +1194,9 @@ impl Atlas { /// Insert the glyph without checking for room /// - /// Internal function for use once atlas has been checked for space. GL errors could still occur - /// at this point if we were checking for them; hence, the Result. + /// Internal function for use once atlas has been checked for space. GL + /// errors could still occur at this point if we were checking for them; + /// hence, the Result. fn insert_inner(&mut self, glyph: &RasterizedGlyph, active_tex: &mut u32) diff --git a/src/term/mod.rs b/src/term/mod.rs index 1bed8134..777c3bce 100644 --- a/src/term/mod.rs +++ b/src/term/mod.rs @@ -343,8 +343,8 @@ impl Term { return; } - // Scroll up to keep cursor and as much context as possible in grid. This only runs when the - // lines decreases. + // Scroll up to keep cursor and as much context as possible in grid. + // This only runs when the lines decreases. self.scroll_region = Line(0)..self.grid.num_lines(); // Scroll up to keep cursor in terminal @@ -366,8 +366,9 @@ impl Term { self.cursor.col = limit(self.cursor.col, Column(0), num_cols); // Recreate tabs list - self.tabs = (Column(0)..self.grid.num_cols()).map(|i| (*i as usize) % TAB_SPACES == 0) - .collect::>(); + self.tabs = (Column(0)..self.grid.num_cols()) + .map(|i| (*i as usize) % TAB_SPACES == 0) + .collect::>(); self.tabs[0] = false; @@ -707,7 +708,8 @@ impl ansi::Handler for Term { ptr::copy(src, dst, n); } - // Clear last `count` cells in line. If deleting 1 char, need to delete 1 cell. + // Clear last `count` cells in line. If deleting 1 char, need to delete + // 1 cell. let template = self.empty_cell.clone(); let end = self.size_info.cols() - count; for c in &mut line[end..] { @@ -946,13 +948,13 @@ mod bench { /// Benchmark for the renderable cells iterator /// - /// The renderable cells iterator yields cells that require work to be displayed (that is, not a - /// an empty background cell). This benchmark measures how long it takes to process the whole - /// iterator. + /// The renderable cells iterator yields cells that require work to be + /// displayed (that is, not a an empty background cell). This benchmark + /// measures how long it takes to process the whole iterator. /// - /// When this benchmark was first added, it averaged ~78usec on my macbook pro. The total - /// render time for this grid is anywhere between ~1500 and ~2000usec (measured imprecisely with - /// the visual meter). + /// When this benchmark was first added, it averaged ~78usec on my macbook + /// pro. The total render time for this grid is anywhere between ~1500 and + /// ~2000usec (measured imprecisely with the visual meter). #[bench] fn render_iter(b: &mut test::Bencher) { // Need some realistic grid state; using one of the ref files. diff --git a/src/util.rs b/src/util.rs index eddb2a5a..0607ff61 100644 --- a/src/util.rs +++ b/src/util.rs @@ -21,7 +21,10 @@ pub mod thread { T: Send + 'static, S: Into { - ::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::*;