1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-18 13:55:23 -05:00

Misc formatting fixes

This commit is contained in:
Joe Wilm 2016-12-16 22:48:04 -08:00
parent 781572096e
commit bde4dacc79
14 changed files with 159 additions and 83 deletions

View file

@ -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<NSArray<NSObject, Owned>> = unsafe {
// I think this transmute is valid. It's going from an Id<Object> to an
// Id<NSObject>. 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<Object>.
// I think this transmute is valid. It's going from an
// Id<Object> to an Id<NSObject>. 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<Object>.
//
// 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<NSObject, NSObject>> = NSDictionary::new();
// call [pasteboard readObjectsForClasses:options:]
@ -95,8 +99,10 @@ mod ns {
}
};
// Ok, this is great. We have an NSArray<NSString>, 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<NSString>, 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()

View file

@ -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<f64> {
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<f64> {
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)

View file

@ -65,7 +65,11 @@ fn list_families() -> Vec<String> {
}
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 {

View file

@ -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();

View file

@ -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"))]

View file

@ -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();

View file

@ -459,7 +459,10 @@ impl de::Deserialize for RawBinding {
impl Visitor for RawBindingVisitor {
type Value = RawBinding;
fn visit_map<V>(&mut self, mut visitor: V) -> ::std::result::Result<RawBinding, V::Error>
fn visit_map<V>(
&mut self,
mut visitor: V
) -> ::std::result::Result<RawBinding, V::Error>
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);
}
}
}

View file

@ -176,7 +176,11 @@ impl Display {
}
/// Process pending resize events
pub fn handle_resize(&mut self, terminal: &mut MutexGuard<Term>, items: &mut [&mut OnResize]) {
pub fn handle_resize(
&mut self,
terminal: &mut MutexGuard<Term>,
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.

View file

@ -174,7 +174,14 @@ impl<Io> EventLoop<Io>
}
#[inline]
fn pty_read<W: Write>(&mut self, state: &mut State, buf: &mut [u8], mut writer: Option<&mut W>) {
fn pty_read<W>(
&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<Io> EventLoop<Io>
}
}
pub fn spawn(mut self, state: Option<State>) -> thread::JoinHandle<(EventLoop<Io>, State)> {
pub fn spawn(
mut self,
state: Option<State>
) -> thread::JoinHandle<(EventLoop<Io>, State)> {
thread::spawn_named("pty reader", move || {
let mut state = state.unwrap_or_else(Default::default);
let mut buf = [0u8; 4096];

View file

@ -331,9 +331,9 @@ row_index_range!(RangeTo<usize>);
row_index_range!(RangeFrom<usize>);
row_index_range!(RangeFull);
// -------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Row ranges for Grid
// -------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------
impl<T> Index<Range<index::Line>> for Grid<T> {
type Output = [Row<T>];
@ -383,9 +383,9 @@ impl<T> IndexMut<RangeFrom<index::Line>> for Grid<T> {
}
}
// -------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Column ranges for Row
// -------------------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------
impl<T> Index<Range<index::Column>> for Row<T> {
type Output = [T];

View file

@ -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};

View file

@ -127,7 +127,9 @@ impl GlyphCache {
// Load regular font
let regular_desc = FontDesc::new(font.family(), font.style());
let regular = rasterizer.load_font(&regular_desc, size).expect("regular font load ok");
let regular = rasterizer
.load_font(&regular_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)

View file

@ -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::<Vec<bool>>();
self.tabs = (Column(0)..self.grid.num_cols())
.map(|i| (*i as usize) % TAB_SPACES == 0)
.collect::<Vec<bool>>();
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.

View file

@ -21,7 +21,10 @@ 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::*;