Scrollback cleanup

There were some unneeded codeblocks and TODO/XXX comments in the code
that have been removed. All issues marked with TODO/XXX have either been
already resolved or tracking issues exist.
This commit is contained in:
Christian Duerr 2018-07-21 17:17:41 +00:00 committed by GitHub
parent b05ad74fe6
commit f50ca1a54c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 853 additions and 672 deletions

View File

@ -12,18 +12,22 @@ rust:
- nightly
env:
- FEATURES="clippy"
- FEATURES=""
- CLIPPY="true"
- CLIPPY=""
install:
- if [ -n "$CLIPPY" ]; then cargo install -f clippy; fi
matrix:
fast_finish: true
exclude:
- rust: stable
env: FEATURES="clippy"
env: CLIPPY="true"
- rust: nightly
env: FEATURES=""
env: CLIPPY=""
allow_failures:
- rust: nightly
script:
- cargo test --no-default-features --features "$FEATURES"
- if [ -n "$CLIPPY" ]; then cargo clippy --all-features --all-targets; fi
- if [ -z "$CLIPPY" ]; then cargo test; fi

547
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -34,9 +34,9 @@ fnv = "1"
unicode-width = "0.1"
arraydeque = "0.4"
glutin = "0.16"
clippy = { version = "*", optional = true }
env_logger = "0.5"
base64 = "0.9.0"
static_assertions = "0.2.5"
[target.'cfg(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="openbsd"))'.dependencies]
x11-dl = "2"

View File

@ -44,7 +44,7 @@ $(DMG_NAME): $(APP_NAME)
install: $(DMG_NAME) ## Mount disk image
@open $(DMG_DIR)/$(DMG_NAME)
.PHONY: app binary clean dmg install
.PHONY: app binary clean dmg install $(TARGET)
clean: ## Remove all artifacts
-rm -rf $(APP_DIR)

View File

@ -37,8 +37,7 @@ built from source.
Instructions are provided for macOS and many Linux variants to compile Alacritty
from source. With the exception of Arch (which has a package in the AUR), Void Linux (in main repository) and
[NixOS](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/alacritty/default.nix)
(at the moment in unstable, will be part of 17.09), please first read the
[NixOS](https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/misc/alacritty/default.nix), please first read the
[prerequisites](#prerequisites) section, then find the section for your OS, and
finally go to [building](#building) and [configuration](#configuration).
@ -50,6 +49,12 @@ cd alacritty-git
makepkg -isr
```
### openSUSE Tumbleweed Linux
```sh
zypper in alacritty
```
### Void Linux
```sh

View File

@ -36,6 +36,9 @@ Increases the level of verbosity (the max level is \fB\-vvv\fR)
Prints version information
.SH "OPTIONS"
.TP
\fB\-\-class\fR <class>
Defines the window class on X11 [default: Alacritty]
.TP
\fB\-e\fR, \fB\-\-command\fR <command>...
Command and args to execute (must be last argument)
.HP

View File

@ -116,6 +116,12 @@ font:
x: 0
y: 0
# Scale the font size based on the monitor's DPI. This will lead to bigger text on HiDPI
# screens and make reading text a little easier.
# On X11 it is possible to change the DPI for each instance of alacritty by using
# `WINIT_HIDPI_FACTOR=1.0 alacritty` to scale the font.
scale_with_dpi: true
# OS X only: use thin stroke font rendering. Thin strokes are suitable
# for retina displays, but for non-retina you probably want this set to
# false.
@ -310,6 +316,8 @@ live_config_reload: true
key_bindings:
- { key: V, mods: Control|Shift, action: Paste }
- { key: C, mods: Control|Shift, action: Copy }
- { key: Paste, action: Paste }
- { key: Copy, action: Copy }
- { key: Q, mods: Command, action: Quit }
- { key: W, mods: Command, action: Quit }
- { key: Insert, mods: Shift, action: PasteSelection }

View File

@ -96,6 +96,10 @@ font:
x: 0
y: 0
# Scale the font size based on the monitor's DPI. This will lead to bigger text on HiDPI
# screens and make reading text a little easier.
scale_with_dpi: true
# OS X only: use thin stroke font rendering. Thin strokes are suitable
# for retina displays, but for non-retina you probably want this set to
# false.
@ -287,6 +291,8 @@ live_config_reload: true
key_bindings:
- { key: V, mods: Command, action: Paste }
- { key: C, mods: Command, action: Copy }
- { key: Paste, action: Paste }
- { key: Copy, action: Copy }
- { key: Q, mods: Command, action: Quit }
- { key: W, mods: Command, action: Quit }
- { key: Home, chars: "\x1bOH", mode: AppCursor }

View File

@ -1,5 +1,7 @@
//! A cross-platform clipboard library
#![cfg_attr(feature = "cargo-clippy", deny(clippy, if_not_else, enum_glob_use, wrong_pub_self_convention))]
// This has to be here due to macro_use
#[cfg(target_os = "macos")]
#[macro_use] extern crate objc;

224
font/Cargo.lock generated Normal file
View File

@ -0,0 +1,224 @@
[[package]]
name = "bitflags"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cc"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cmake"
version = "0.1.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "core-foundation"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "core-foundation-sys"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "core-graphics"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "core-text"
version = "9.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "euclid"
version = "0.17.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "expat-sys"
version = "2.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cmake 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "font"
version = "0.1.0"
dependencies = [
"core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"core-text 9.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"euclid 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)",
"foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype-rs 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-fontconfig 0.4.0 (git+https://github.com/jwilm/rust-fontconfig?branch=updated-2017-10-8)",
]
[[package]]
name = "foreign-types"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "foreign-types-shared"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "freetype-rs"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "freetype-sys"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"libz-sys 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libz-sys"
version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
"vcpkg 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "log"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.1.43"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "pkg-config"
version = "0.3.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "servo-fontconfig"
version = "0.4.0"
source = "git+https://github.com/jwilm/rust-fontconfig?branch=updated-2017-10-8#be2b94de833ec69cf767186262a5fb8360fa5b45"
dependencies = [
"libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)",
"servo-fontconfig-sys 4.0.3 (git+https://github.com/jwilm/libfontconfig?branch=updated-2017-10-8)",
]
[[package]]
name = "servo-fontconfig-sys"
version = "4.0.3"
source = "git+https://github.com/jwilm/libfontconfig?branch=updated-2017-10-8#5c1845e1bffa11cf4d3e6fb27f456bf5c814ce1b"
dependencies = [
"expat-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"freetype-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "vcpkg"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum bitflags 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1370e9fc2a6ae53aea8b7a5110edbd08836ed87c88736dfabccade1c2b44bff4"
"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789"
"checksum cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "49ec142f5768efb5b7622aebc3fdbdbb8950a4b9ba996393cb76ef7466e8747d"
"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18"
"checksum cmake 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "95470235c31c726d72bf2e1f421adc1e65b9d561bf5529612cbe1a72da1467b3"
"checksum core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980"
"checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa"
"checksum core-graphics 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fb0ed45fdc32f9ab426238fba9407dfead7bacd7900c9b4dd3f396f46eafdae3"
"checksum core-text 9.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bd581c37283d0c23311d179aefbb891f2324ee0405da58a26e8594ab76e5748"
"checksum euclid 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c95fd0d455f114291a3109286bd387bd423770058474a2d3f38b712cd661df60"
"checksum expat-sys 2.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c470ccb972f2088549b023db8029ed9da9426f5affbf9b62efff7009ab8ed5b1"
"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1"
"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b"
"checksum freetype-rs 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a1418e2a055fec8efe18c1a90a54b2cf5e649e583830dd4c71226c4e3bc920c6"
"checksum freetype-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eccfb6d96cac99921f0c2142a91765f6c219868a2c45bdfe7d65a08775f18127"
"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1"
"checksum libz-sys 1.0.18 (registry+https://github.com/rust-lang/crates.io-index)" = "87f737ad6cc6fd6eefe3d9dc5412f1573865bded441300904d2f42269e140f16"
"checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac"
"checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31"
"checksum num-traits 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "775393e285254d2f5004596d69bb8bc1149754570dcc08cf30cabeba67955e28"
"checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f"
"checksum servo-fontconfig 0.4.0 (git+https://github.com/jwilm/rust-fontconfig?branch=updated-2017-10-8)" = "<none>"
"checksum servo-fontconfig-sys 4.0.3 (git+https://github.com/jwilm/libfontconfig?branch=updated-2017-10-8)" = "<none>"
"checksum vcpkg 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7ed0f6789c8a85ca41bbc1c9d175422116a9869bd1cf31bb08e1493ecce60380"

View File

@ -24,7 +24,7 @@ pub const kCGBitmapByteOrder32Host: u32 = kCGBitmapByteOrder32Little;
pub const kCGBitmapByteOrder32Host: u32 = kCGBitmapByteOrder32Big;
#[cfg(target_endian = "little")]
pub fn extract_rgb(bytes: Vec<u8>) -> Vec<u8> {
pub fn extract_rgb(bytes: &[u8]) -> Vec<u8> {
let pixels = bytes.len() / 4;
let mut rgb = Vec::with_capacity(pixels * 3);
@ -32,7 +32,7 @@ pub fn extract_rgb(bytes: Vec<u8>) -> Vec<u8> {
let offset = i * 4;
rgb.push(bytes[offset + 2]);
rgb.push(bytes[offset + 1]);
rgb.push(bytes[offset + 0]);
rgb.push(bytes[offset]);
}
rgb

View File

@ -132,8 +132,8 @@ impl ::Rasterize for Rasterizer {
Ok(Rasterizer {
fonts: HashMap::new(),
keys: HashMap::new(),
device_pixel_ratio: device_pixel_ratio,
use_thin_strokes: use_thin_strokes,
device_pixel_ratio,
use_thin_strokes,
})
}
@ -162,7 +162,7 @@ impl ::Rasterize for Rasterizer {
}
/// Get rasterized glyph for given glyph key
fn get_glyph(&mut self, glyph: &GlyphKey) -> Result<RasterizedGlyph, Error> {
fn get_glyph(&mut self, glyph: GlyphKey) -> Result<RasterizedGlyph, Error> {
// get loaded font
let font = self.fonts
@ -196,7 +196,7 @@ impl Rasterizer {
for descriptor in descriptors {
if descriptor.style_name == style {
// Found the font we want
let scaled_size = size.as_f32_pts() as f64 * self.device_pixel_ratio as f64;
let scaled_size = f64::from(size.as_f32_pts()) * f64::from(self.device_pixel_ratio);
let font = descriptor.to_font(scaled_size, true);
return Ok(font);
}
@ -220,7 +220,7 @@ impl Rasterizer {
Slant::Normal => false,
_ => true,
};
let scaled_size = size.as_f32_pts() as f64 * self.device_pixel_ratio as f64;
let scaled_size = f64::from(size.as_f32_pts()) * f64::from(self.device_pixel_ratio);
let descriptors = descriptors_for_family(&desc.name[..]);
for descriptor in descriptors {
@ -246,11 +246,11 @@ impl Rasterizer {
// Helper to try and get a glyph for a given font. Used for font fallback.
fn maybe_get_glyph(
&self,
glyph: &GlyphKey,
glyph: GlyphKey,
font: &Font,
) -> Option<Result<RasterizedGlyph, Error>> {
let scaled_size = self.device_pixel_ratio * glyph.size.as_f32_pts();
font.get_glyph(glyph.c, scaled_size as _, self.use_thin_strokes)
font.get_glyph(glyph.c, f64::from(scaled_size), self.use_thin_strokes)
.map(|r| Some(Ok(r)))
.unwrap_or_else(|e| match e {
Error::MissingGlyph(_) => None,
@ -301,7 +301,7 @@ pub fn get_family_names() -> Vec<String> {
/// Return fallback descriptors for font/language list
fn cascade_list_for_languages(
ct_font: &CTFont,
languages: &Vec<String>
languages: &[String]
) -> Vec<Descriptor> {
// convert language type &Vec<String> -> CFArray
@ -356,7 +356,7 @@ impl Descriptor {
let menlo = ct_new_from_descriptor(&descriptor.ct_descriptor, size);
// TODO fixme, hardcoded en for english
let mut fallbacks = cascade_list_for_languages(&menlo, &vec!["en".to_owned()])
let mut fallbacks = cascade_list_for_languages(&menlo, &["en".to_owned()])
.into_iter()
.filter(|desc| desc.font_path != "")
.map(|desc| desc.to_font(size, false))
@ -368,12 +368,11 @@ impl Descriptor {
// many chars. We add the symbols back in.
// Investigate if we can actually use the .-prefixed
// fallbacks somehow.
descriptors_for_family("Apple Symbols")
.into_iter()
.next() // should only have one element; use it
.map(|descriptor| {
fallbacks.push(descriptor.to_font(size, false))
});
if let Some(descriptor) =
descriptors_for_family("Apple Symbols").into_iter().next()
{
fallbacks.push(descriptor.to_font(size, false))
};
// Include Menlo in the fallback list as well
fallbacks.insert(0, Font {
@ -390,9 +389,9 @@ impl Descriptor {
};
Font {
ct_font: ct_font,
cg_font: cg_font,
fallbacks: fallbacks,
ct_font,
cg_font,
fallbacks,
}
}
}
@ -424,8 +423,8 @@ impl Font {
let line_height = (ascent + descent + leading + 0.5).floor();
Metrics {
average_advance: average_advance,
line_height: line_height,
average_advance,
line_height,
descent: -(self.ct_font.descent() as f32),
}
}
@ -482,13 +481,13 @@ impl Font {
}
let glyph_index = self.glyph_index(character)
.ok_or(Error::MissingGlyph(character))?;
.ok_or_else(|| Error::MissingGlyph(character))?;
let bounds = self.bounding_rect_for_glyph(Default::default(), glyph_index);
let rasterized_left = bounds.origin.x.floor() as i32;
let rasterized_width =
(bounds.origin.x - (rasterized_left as f64) + bounds.size.width).ceil() as u32;
(bounds.origin.x - f64::from(rasterized_left) + bounds.size.width).ceil() as u32;
let rasterized_descent = (-bounds.origin.y).ceil() as i32;
let rasterized_ascent = (bounds.size.height + bounds.origin.y).ceil() as i32;
let rasterized_height = (rasterized_descent + rasterized_ascent) as u32;
@ -519,8 +518,8 @@ impl Font {
let context_rect = CGRect::new(
&CGPoint::new(0.0, 0.0),
&CGSize::new(
rasterized_width as f64,
rasterized_height as f64
f64::from(rasterized_width),
f64::from(rasterized_height)
)
);
@ -542,8 +541,8 @@ impl Font {
// Set fill color to white for drawing the glyph
cg_context.set_rgb_fill_color(1.0, 1.0, 1.0, 1.0);
let rasterization_origin = CGPoint {
x: -rasterized_left as f64,
y: rasterized_descent as f64,
x: f64::from(-rasterized_left),
y: f64::from(rasterized_descent),
};
self.ct_font.draw_glyphs(&[glyph_index as CGGlyph],
@ -552,7 +551,7 @@ impl Font {
let rasterized_pixels = cg_context.data().to_vec();
let buf = extract_rgb(rasterized_pixels);
let buf = extract_rgb(&rasterized_pixels);
Ok(RasterizedGlyph {
c: character,
@ -560,7 +559,7 @@ impl Font {
top: (bounds.size.height + bounds.origin.y).ceil() as i32,
width: rasterized_width as i32,
height: rasterized_height as i32,
buf: buf,
buf,
})
}
@ -585,7 +584,7 @@ impl Font {
);
if res {
Some(glyphs[0] as u32)
Some(u32::from(glyphs[0]))
} else {
None
}

View File

@ -24,7 +24,13 @@ foreign_type! {
}
impl CharSet {
pub fn new() -> CharSet {
pub fn new() -> Self {
Self::default()
}
}
impl Default for CharSet {
fn default() -> Self {
CharSet(unsafe { FcCharSetCreate() })
}
}

View File

@ -38,7 +38,7 @@ impl Config {
impl ConfigRef {
/// Returns one of the two sets of fonts from the configuration as
/// specified by `set`.
pub fn get_fonts<'a>(&'a self, set: SetName) -> &'a FontSetRef {
pub fn get_fonts(&self, set: SetName) -> &FontSetRef {
unsafe {
let ptr = FcConfigGetFonts(self.as_ptr(), set as u32);
FontSetRef::from_ptr(ptr)

View File

@ -180,9 +180,9 @@ pub enum Width {
}
impl Width {
fn to_isize(&self) -> isize {
fn to_isize(self) -> isize {
use self::Width::*;
match *self {
match self {
Ultracondensed => 50,
Extracondensed => 63,
Condensed => 75,

View File

@ -24,8 +24,13 @@ foreign_type! {
}
impl ObjectSet {
#[allow(dead_code)]
pub fn new() -> ObjectSet {
pub fn new() -> Self {
Self::default()
}
}
impl Default for ObjectSet {
fn default() -> Self {
ObjectSet(unsafe {
FcObjectSetCreate()
})

View File

@ -39,8 +39,8 @@ pub struct StringPropertyIter<'a> {
impl<'a> StringPropertyIter<'a> {
fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> StringPropertyIter<'b> {
StringPropertyIter {
pattern: pattern,
object: object,
pattern,
object,
index: 0
}
}
@ -82,8 +82,8 @@ pub struct BooleanPropertyIter<'a> {
impl<'a> BooleanPropertyIter<'a> {
fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> BooleanPropertyIter<'b> {
BooleanPropertyIter {
pattern: pattern,
object: object,
pattern,
object,
index: 0
}
}
@ -101,7 +101,7 @@ impl<'a> BooleanPropertyIter<'a> {
};
if result == FcResultMatch {
Some(!(value == 0))
Some(value != 0)
} else {
None
}
@ -118,8 +118,8 @@ pub struct IntPropertyIter<'a> {
impl<'a> IntPropertyIter<'a> {
fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> IntPropertyIter<'b> {
IntPropertyIter {
pattern: pattern,
object: object,
pattern,
object,
index: 0
}
}
@ -171,7 +171,7 @@ pub struct HintStylePropertyIter<'a> {
}
impl<'a> HintStylePropertyIter<'a> {
fn new<'b>(pattern: &'b PatternRef) -> HintStylePropertyIter<'b> {
fn new(pattern: &PatternRef) -> HintStylePropertyIter {
HintStylePropertyIter {
inner: IntPropertyIter::new(pattern, b"hintstyle\0")
}
@ -201,7 +201,7 @@ pub struct LcdFilterPropertyIter<'a> {
}
impl<'a> LcdFilterPropertyIter<'a> {
fn new<'b>(pattern: &'b PatternRef) -> LcdFilterPropertyIter<'b> {
fn new(pattern: &PatternRef) -> LcdFilterPropertyIter {
LcdFilterPropertyIter {
inner: IntPropertyIter::new(pattern, b"lcdfilter\0")
}
@ -236,14 +236,14 @@ pub struct DoublePropertyIter<'a> {
impl<'a> DoublePropertyIter<'a> {
fn new<'b>(pattern: &'b PatternRef, object: &'b [u8]) -> DoublePropertyIter<'b> {
DoublePropertyIter {
pattern: pattern,
object: object,
pattern,
object,
index: 0
}
}
fn get_value(&self, index: usize) -> Option<f64> {
let mut value = 0 as c_double;
let mut value = f64::from(0);
let result = unsafe {
FcPatternGetDouble(
@ -379,7 +379,13 @@ macro_rules! string_accessor {
}
impl Pattern {
pub fn new() -> Pattern {
pub fn new() -> Self {
Self::default()
}
}
impl Default for Pattern {
fn default() -> Self {
Pattern(unsafe { FcPatternCreate() })
}
}
@ -483,11 +489,11 @@ impl PatternRef {
BooleanPropertyIter::new(self, object)
}
pub fn hintstyle<'a>(&'a self) -> HintStylePropertyIter<'a> {
pub fn hintstyle(&self) -> HintStylePropertyIter {
HintStylePropertyIter::new(self)
}
pub fn lcdfilter<'a>(&'a self) -> LcdFilterPropertyIter<'a> {
pub fn lcdfilter(&self) -> LcdFilterPropertyIter {
LcdFilterPropertyIter::new(self)
}
@ -565,7 +571,7 @@ impl PatternRef {
RgbaPropertyIter::new(self, b"rgba\0")
}
pub fn set_rgba(&self, rgba: Rgba) -> bool {
pub fn set_rgba(&self, rgba: &Rgba) -> bool {
unsafe {
self.add_integer(b"rgba\0", rgba.to_isize())
}

View File

@ -80,8 +80,8 @@ impl ::Rasterize for FreeTypeRasterizer {
Ok(FreeTypeRasterizer {
faces: HashMap::new(),
keys: HashMap::new(),
library: library,
device_pixel_ratio: device_pixel_ratio,
library,
device_pixel_ratio,
})
}
@ -94,7 +94,7 @@ impl ::Rasterize for FreeTypeRasterizer {
Ok(Metrics {
average_advance: full.cell_width,
line_height: height,
descent: descent,
descent,
})
}
@ -102,7 +102,7 @@ impl ::Rasterize for FreeTypeRasterizer {
self.get_face(desc, size)
}
fn get_glyph(&mut self, glyph_key: &GlyphKey) -> Result<RasterizedGlyph, Error> {
fn get_glyph(&mut self, glyph_key: GlyphKey) -> Result<RasterizedGlyph, Error> {
self.get_rendered_glyph(glyph_key)
}
@ -172,7 +172,7 @@ impl FreeTypeRasterizer {
} as f64;
Ok(FullMetrics {
size_metrics: size_metrics,
size_metrics,
cell_width: width
})
}
@ -188,7 +188,7 @@ impl FreeTypeRasterizer {
pattern.add_family(&desc.name);
pattern.set_weight(weight.into_fontconfig_type());
pattern.set_slant(slant.into_fontconfig_type());
pattern.add_pixelsize(size.as_f32_pts() as _);
pattern.add_pixelsize(f64::from(size.as_f32_pts()));
let font = fc::font_match(fc::Config::get_current(), &mut pattern)
.ok_or_else(|| Error::MissingFont(desc.to_owned()))?;
@ -210,7 +210,7 @@ impl FreeTypeRasterizer {
let mut pattern = fc::Pattern::new();
pattern.add_family(&desc.name);
pattern.add_style(style);
pattern.add_pixelsize(size.as_f32_pts() as _);
pattern.add_pixelsize(f64::from(size.as_f32_pts()));
let font = fc::font_match(fc::Config::get_current(), &mut pattern)
.ok_or_else(|| Error::MissingFont(desc.to_owned()))?;
@ -232,24 +232,24 @@ impl FreeTypeRasterizer {
let ft_face = self.library.new_face(&path, index)?;
// Get available pixel sizes if font isn't scalable.
let non_scalable = if !pattern.scalable().next().unwrap_or(true) {
let non_scalable = if pattern.scalable().next().unwrap_or(true) {
None
} else {
let mut pixelsize = pattern.pixelsize();
debug!("pixelsizes: {:?}", pixelsize);
Some(FixedSize {
pixelsize: pixelsize.next().expect("has 1+ pixelsize"),
})
} else {
None
};
let face = Face {
ft_face: ft_face,
ft_face,
key: FontKey::next(),
load_flags: Self::ft_load_flags(pattern),
render_mode: Self::ft_render_mode(pattern),
lcd_filter: Self::ft_lcd_filter(pattern),
non_scalable: non_scalable,
non_scalable,
};
debug!("Loaded Face {:?}", face);
@ -264,19 +264,15 @@ impl FreeTypeRasterizer {
}
}
fn face_for_glyph(&mut self, glyph_key: &GlyphKey, have_recursed: bool) -> Result<FontKey, Error> {
fn face_for_glyph(&mut self, glyph_key: GlyphKey, have_recursed: bool) -> Result<FontKey, Error> {
let c = glyph_key.c;
let use_initial_face = if self.faces.contains_key(&glyph_key.font_key) {
// Get face and unwrap since we just checked for presence.
let face = self.faces.get(&glyph_key.font_key).unwrap();
let face = &self.faces[&glyph_key.font_key];
let index = face.ft_face.get_char_index(c as usize);
if index != 0 || have_recursed {
true
} else {
false
}
index != 0 || have_recursed
} else {
false
};
@ -289,7 +285,7 @@ impl FreeTypeRasterizer {
}
}
fn get_rendered_glyph(&mut self, glyph_key: &GlyphKey)
fn get_rendered_glyph(&mut self, glyph_key: GlyphKey)
-> Result<RasterizedGlyph, Error> {
// Render a custom symbol for the underline and beam cursor
match glyph_key.c {
@ -334,7 +330,7 @@ impl FreeTypeRasterizer {
// Render a normal character if it's not a cursor
let font_key = self.face_for_glyph(glyph_key, false)?;
let face = self.faces.get(&font_key).unwrap();
let face = &self.faces[&font_key];
let index = face.ft_face.get_char_index(glyph_key.c as usize);
let size = face.non_scalable.as_ref()
@ -360,7 +356,7 @@ impl FreeTypeRasterizer {
left: glyph.bitmap_left(),
width: pixel_width,
height: glyph.bitmap().rows(),
buf: buf,
buf,
})
}
@ -490,7 +486,7 @@ impl FreeTypeRasterizer {
}
Ok((bitmap.width(), packed))
},
mode @ _ => panic!("unhandled pixel mode: {:?}", mode)
mode => panic!("unhandled pixel mode: {:?}", mode)
}
}

View File

@ -17,6 +17,9 @@
//! CoreText is used on Mac OS.
//! FreeType is used on everything that's not Mac OS.
//! Eventually, ClearType support will be available for windows
#![cfg_attr(feature = "cargo-clippy", deny(clippy, if_not_else, enum_glob_use, wrong_pub_self_convention))]
#[cfg(not(target_os = "macos"))]
extern crate fontconfig;
#[cfg(not(target_os = "macos"))]
@ -116,7 +119,7 @@ impl FontDesc {
{
FontDesc {
name: name.into(),
style: style
style,
}
}
}
@ -146,7 +149,7 @@ impl FontKey {
}
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Debug, Copy, Clone, Eq)]
pub struct GlyphKey {
pub c: char,
pub font_key: FontKey,
@ -165,6 +168,19 @@ impl Hash for GlyphKey {
}
}
impl PartialEq for GlyphKey {
fn eq(&self, other: &Self) -> bool {
unsafe {
// This transmute is fine:
//
// - If GlyphKey ever becomes a different size, this will fail to compile
// - Result is being used for equality checking and has no fields (it's a u64)
let other = ::std::mem::transmute::<GlyphKey, u64>(*other);
::std::mem::transmute::<GlyphKey, u64>(*self).eq(&other)
}
}
}
/// Font size stored as integer
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
pub struct Size(i16);
@ -183,7 +199,7 @@ impl Size {
/// Get the f32 size in points
pub fn as_f32_pts(self) -> f32 {
self.0 as f32 / Size::factor()
f32::from(self.0) / Size::factor()
}
}
@ -224,14 +240,14 @@ pub fn get_underline_cursor_glyph(descent: i32, width: i32) -> Result<Rasterized
let buf = vec![255u8; (width * height * 3) as usize];
// Create a custom glyph with the rectangle data attached to it
return Ok(RasterizedGlyph {
Ok(RasterizedGlyph {
c: UNDERLINE_CURSOR_CHAR,
top: descent + height,
left: 0,
height,
width,
buf: buf,
});
buf,
})
}
// Returns a custom beam cursor character
@ -245,14 +261,14 @@ pub fn get_beam_cursor_glyph(
let buf = vec![255u8; (beam_width * height * 3) as usize];
// Create a custom glyph with the rectangle data attached to it
return Ok(RasterizedGlyph {
Ok(RasterizedGlyph {
c: BEAM_CURSOR_CHAR,
top: ascent,
left: 0,
height,
width: beam_width,
buf: buf,
});
buf,
})
}
// Returns a custom box cursor character
@ -276,14 +292,14 @@ pub fn get_box_cursor_glyph(
}
// Create a custom glyph with the rectangle data attached to it
return Ok(RasterizedGlyph {
Ok(RasterizedGlyph {
c: BOX_CURSOR_CHAR,
top: ascent,
left: 0,
height,
width,
buf: buf,
});
buf,
})
}
struct BufDebugger<'a>(&'a [u8]);
@ -331,5 +347,5 @@ pub trait Rasterize {
fn load_font(&mut self, &FontDesc, Size) -> Result<FontKey, Self::Err>;
/// Rasterize the glyph described by `GlyphKey`.
fn get_glyph(&mut self, &GlyphKey) -> Result<RasterizedGlyph, Self::Err>;
fn get_glyph(&mut self, GlyphKey) -> Result<RasterizedGlyph, Self::Err>;
}

View File

@ -561,8 +561,8 @@ pub enum NamedColor {
}
impl NamedColor {
pub fn to_bright(&self) -> Self {
match *self {
pub fn to_bright(self) -> Self {
match self {
NamedColor::Black => NamedColor::BrightBlack,
NamedColor::Red => NamedColor::BrightRed,
NamedColor::Green => NamedColor::BrightGreen,
@ -583,8 +583,8 @@ impl NamedColor {
}
}
pub fn to_dim(&self) -> Self {
match *self {
pub fn to_dim(self) -> Self {
match self {
NamedColor::Black => NamedColor::DimBlack,
NamedColor::Red => NamedColor::DimRed,
NamedColor::Green => NamedColor::DimGreen,

View File

@ -15,18 +15,18 @@ extern crate log;
use clap::{Arg, App};
use index::{Line, Column};
use config::{Dimensions, Shell};
use window::{DEFAULT_TITLE, DEFAULT_CLASS};
use std::path::{Path, PathBuf};
use std::borrow::Cow;
const DEFAULT_TITLE: &str = "Alacritty";
/// Options specified on the command line
pub struct Options {
pub live_config_reload: Option<bool>,
pub print_events: bool,
pub ref_test: bool,
pub dimensions: Option<Dimensions>,
pub title: String,
pub title: Option<String>,
pub class: Option<String>,
pub log_level: log::LevelFilter,
pub command: Option<Shell<'static>>,
pub working_dir: Option<PathBuf>,
@ -40,7 +40,8 @@ impl Default for Options {
print_events: false,
ref_test: false,
dimensions: None,
title: DEFAULT_TITLE.to_owned(),
title: None,
class: None,
log_level: log::LevelFilter::Warn,
command: None,
working_dir: None,
@ -79,8 +80,12 @@ impl Options {
.arg(Arg::with_name("title")
.long("title")
.short("t")
.default_value(DEFAULT_TITLE)
.help("Defines the window title"))
.takes_value(true)
.help(&format!("Defines the window title [default: {}]", DEFAULT_TITLE)))
.arg(Arg::with_name("class")
.long("class")
.takes_value(true)
.help(&format!("Defines window class on X11 [default: {}]", DEFAULT_CLASS)))
.arg(Arg::with_name("q")
.short("q")
.multiple(true)
@ -132,9 +137,8 @@ impl Options {
}
}
if let Some(title) = matches.value_of("title") {
options.title = title.to_owned();
}
options.class = matches.value_of("class").map(|c| c.to_owned());
options.title = matches.value_of("title").map(|t| t.to_owned());
match matches.occurrences_of("q") {
0 => {},

View File

@ -23,6 +23,7 @@ use notify::{Watcher, watcher, DebouncedEvent, RecursiveMode};
use glutin::ModifiersState;
use cli::Options;
use input::{Action, Binding, MouseBinding, KeyBinding};
use index::{Line, Column};
use ansi::CursorStyle;
@ -224,7 +225,7 @@ impl Alpha {
}
#[inline]
pub fn get(&self) -> f32 {
pub fn get(self) -> f32 {
self.0
}
@ -1446,6 +1447,14 @@ impl Config {
Ok(config)
}
/// Overrides the `dynamic_title` configuration based on `--title`.
pub fn update_dynamic_title(mut self, options: &Options) -> Self {
if options.title.is_some() {
self.dynamic_title = false;
}
self
}
fn read_file<P: AsRef<Path>>(path: P) -> Result<String> {
let mut f = fs::File::open(path)?;
let mut contents = String::new();
@ -1609,7 +1618,10 @@ pub struct Font {
glyph_offset: Delta<i8>,
#[serde(default="true_bool", deserialize_with = "default_true_bool")]
use_thin_strokes: bool
use_thin_strokes: bool,
#[serde(default="true_bool", deserialize_with = "default_true_bool")]
scale_with_dpi: bool,
}
fn default_bold_desc() -> FontDescription {
@ -1662,6 +1674,11 @@ impl Font {
.. self
}
}
/// Check whether dpi should be applied
pub fn scale_with_dpi(&self) -> bool {
self.scale_with_dpi
}
}
#[cfg(target_os = "macos")]
@ -1673,8 +1690,9 @@ impl Default for Font {
italic: FontDescription::new_with_family("Menlo"),
size: Size::new(11.0),
use_thin_strokes: true,
scale_with_dpi: true,
glyph_offset: Default::default(),
offset: Default::default(),
glyph_offset: Default::default()
}
}
}
@ -1688,8 +1706,9 @@ impl Default for Font {
italic: FontDescription::new_with_family("monospace"),
size: Size::new(11.0),
use_thin_strokes: false,
scale_with_dpi: true,
glyph_offset: Default::default(),
offset: Default::default(),
glyph_offset: Default::default()
}
}
}
@ -1771,6 +1790,7 @@ impl Monitor {
#[cfg(test)]
mod tests {
use cli::Options;
use super::Config;
#[cfg(target_os="macos")]
@ -1791,9 +1811,29 @@ mod tests {
// Sanity check that key bindings are being parsed
assert!(!config.key_bindings.is_empty());
}
#[test]
fn dynamic_title_ignoring_options_by_default() {
let config: Config = ::serde_yaml::from_str(ALACRITTY_YML)
.expect("deserialize config");
let old_dynamic_title = config.dynamic_title;
let options = Options::default();
let config = config.update_dynamic_title(&options);
assert_eq!(old_dynamic_title, config.dynamic_title);
}
#[test]
fn dynamic_title_overridden_by_options() {
let config: Config = ::serde_yaml::from_str(ALACRITTY_YML)
.expect("deserialize config");
let mut options = Options::default();
options.title = Some("foo".to_owned());
let config = config.update_dynamic_title(&options);
assert!(!config.dynamic_title);
}
}
#[cfg_attr(feature = "clippy", allow(enum_variant_names))]
#[cfg_attr(feature = "cargo-clippy", allow(enum_variant_names))]
#[derive(Deserialize, Copy, Clone)]
enum Key {
Key1,
@ -1947,13 +1987,16 @@ enum Key {
WebStop,
Yen,
Caret,
Copy,
Paste,
Cut,
}
impl Key {
fn to_glutin_key(&self) -> ::glutin::VirtualKeyCode {
fn to_glutin_key(self) -> ::glutin::VirtualKeyCode {
use ::glutin::VirtualKeyCode::*;
// Thank you, vim macros!
match *self {
match self {
Key::Key1 => Key1,
Key::Key2 => Key2,
Key::Key3 => Key3,
@ -2105,6 +2148,9 @@ impl Key {
Key::WebStop => WebStop,
Key::Yen => Yen,
Key::Caret => Caret,
Key::Copy => Copy,
Key::Paste => Paste,
Key::Cut => Cut,
}
}
}

View File

@ -136,12 +136,16 @@ impl Display {
let render_timer = config.render_timer();
// Create the window where Alacritty will be displayed
let mut window = Window::new(&options.title, config.window())?;
let mut window = Window::new(&options, config.window())?;
// get window properties for initializing the other subsystems
let mut viewport_size = window.inner_size_pixels()
.expect("glutin returns window size");
let dpr = window.hidpi_factor();
let dpr = if config.font().scale_with_dpi() {
window.hidpi_factor()
} else {
1.0
};
info!("device_pixel_ratio: {}", dpr);
@ -149,7 +153,7 @@ impl Display {
let mut renderer = QuadRenderer::new(config, viewport_size)?;
let (glyph_cache, cell_width, cell_height) =
Self::new_glyph_cache(&window, &mut renderer, config)?;
Self::new_glyph_cache(dpr, &mut renderer, config)?;
let dimensions = options.dimensions()
@ -210,11 +214,10 @@ impl Display {
})
}
fn new_glyph_cache(window : &Window, renderer : &mut QuadRenderer, config: &Config)
fn new_glyph_cache(dpr: f32, renderer: &mut QuadRenderer, config: &Config)
-> Result<(GlyphCache, f32, f32), Error>
{
let font = config.font().clone();
let dpr = window.hidpi_factor();
let rasterizer = font::Rasterizer::new(dpr, config.use_thin_strokes())?;
// Initialize glyph cache

View File

@ -59,17 +59,15 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
}
fn copy_selection(&self, buffer: ::copypasta::Buffer) {
self.terminal
.selection_to_string()
.map(|selected| {
if !selected.is_empty() {
Clipboard::new()
.and_then(|mut clipboard| clipboard.store(selected, buffer))
.unwrap_or_else(|err| {
warn!("Error storing selection to clipboard. {}", Red(err));
});
}
});
if let Some(selected) = self.terminal.selection_to_string() {
if !selected.is_empty() {
Clipboard::new()
.and_then(|mut clipboard| clipboard.store(selected, buffer))
.unwrap_or_else(|err| {
warn!("Error storing selection to clipboard. {}", Red(err));
});
}
}
}
fn clear_selection(&mut self) {
@ -113,7 +111,7 @@ impl<'a, N: Notify + 'a> input::ActionContext for ActionContext<'a, N> {
self.terminal.pixels_to_coords(self.mouse.x as usize, self.mouse.y as usize)
}
fn change_font_size(&mut self, delta: i8) {
fn change_font_size(&mut self, delta: f32) {
self.terminal.change_font_size(delta);
}
@ -241,7 +239,7 @@ impl<N: Notify> Processor<N> {
resize_tx,
ref_test,
mouse: Default::default(),
size_info: size_info,
size_info,
hide_cursor_when_typing: config.hide_cursor_when_typing(),
hide_cursor: false,
received_count: 0,
@ -298,7 +296,7 @@ impl<N: Notify> Processor<N> {
},
KeyboardInput { input, .. } => {
let glutin::KeyboardInput { state, virtual_keycode, modifiers, .. } = input;
processor.process_key(state, virtual_keycode, &modifiers);
processor.process_key(state, virtual_keycode, modifiers);
if state == ElementState::Pressed {
// Hide cursor while typing
*hide_cursor = true;
@ -308,9 +306,11 @@ impl<N: Notify> Processor<N> {
processor.received_char(c);
},
MouseInput { state, button, modifiers, .. } => {
*hide_cursor = false;
processor.mouse_input(state, button, modifiers);
processor.ctx.terminal.dirty = true;
if *window_is_focused {
*hide_cursor = false;
processor.mouse_input(state, button, modifiers);
processor.ctx.terminal.dirty = true;
}
},
CursorMoved { position: (x, y), modifiers, .. } => {
let x = limit(x as i32, 0, processor.ctx.size_info.width as i32);

View File

@ -102,6 +102,7 @@ pub struct GridIterator<'a, T: 'a> {
pub cur: Point<usize>,
}
#[derive(Copy, Clone)]
pub enum Scroll {
Lines(isize),
PageUp,
@ -396,6 +397,7 @@ impl<T: Copy + Clone> Grid<T> {
}
}
#[cfg_attr(feature = "cargo-clippy", allow(len_without_is_empty))]
impl<T> Grid<T> {
#[inline]
pub fn num_lines(&self) -> index::Line {
@ -437,15 +439,6 @@ impl<T> Grid<T> {
pub fn contains(&self, point: &Point) -> bool {
self.lines > point.line && self.cols > point.col
}
// /// Swap two lines in the grid
// ///
// /// This could have used slice::swap internally, but we are able to have
// /// better error messages by doing the bounds checking ourselves.
// #[inline]
// pub fn swap_lines(&mut self, src: index::Line, dst: index::Line) {
// self.raw.swap(*src, *dst);
// }
}
impl<'a, T> Iterator for GridIterator<'a, T> {
@ -566,10 +559,10 @@ impl<'a, T> RegionMut<'a, T> {
pub trait IndexRegion<I, T> {
/// Get an immutable region of Self
fn region<'a>(&'a self, _: I) -> Region<'a, T>;
fn region(&self, _: I) -> Region<T>;
/// Get a mutable region of Self
fn region_mut<'a>(&'a mut self, _: I) -> RegionMut<'a, T>;
fn region_mut(&mut self, _: I) -> RegionMut<T>;
}
impl<T> IndexRegion<Range<Line>, T> for Grid<T> {
@ -772,13 +765,11 @@ impl<'a, T: Copy + 'a> Iterator for DisplayIter<'a, T> {
// Update line/col to point to next item
self.col += 1;
if self.col == self.grid.num_cols() {
if self.offset != self.limit {
self.offset -= 1;
if self.col == self.grid.num_cols() && self.offset != self.limit {
self.offset -= 1;
self.col = Column(0);
self.line = Line(*self.grid.lines - 1 - (self.offset - self.limit));
}
self.col = Column(0);
self.line = Line(*self.grid.lines - 1 - (self.offset - self.limit));
}
item

View File

@ -71,6 +71,7 @@ impl<T: Copy + Clone> Row<T> {
}
}
#[cfg_attr(feature = "cargo-clippy", allow(len_without_is_empty))]
impl<T> Row<T> {
pub fn shrink(&mut self, cols: Column) {
while self.len() != *cols {
@ -84,7 +85,7 @@ impl<T> Row<T> {
self.inner.len()
}
pub fn iter<'a>(&'a self) -> slice::Iter<'a, T> {
pub fn iter(&self) -> slice::Iter<T> {
self.inner.iter()
}
}

View File

@ -68,12 +68,12 @@ impl<T: PartialEq> ::std::cmp::PartialEq for Storage<T> {
// Smaller Zero (3):
// 7 8 9 | 0 1 2 3 | 4 5 6
// C3 C3 C3 | C1 C1 C1 C1 | C2 C2 C2
&bigger.inner[bigger_zero..]
== &smaller.inner[smaller_zero..smaller_zero + (len - bigger_zero)]
&& &bigger.inner[..bigger_zero - smaller_zero]
== &smaller.inner[smaller_zero + (len - bigger_zero)..]
&& &bigger.inner[bigger_zero - smaller_zero..bigger_zero]
== &smaller.inner[..smaller_zero]
bigger.inner[bigger_zero..]
== smaller.inner[smaller_zero..smaller_zero + (len - bigger_zero)]
&& bigger.inner[..bigger_zero - smaller_zero]
== smaller.inner[smaller_zero + (len - bigger_zero)..]
&& bigger.inner[bigger_zero - smaller_zero..bigger_zero]
== smaller.inner[..smaller_zero]
}
}
@ -84,11 +84,8 @@ impl<T> Storage<T> {
T: Clone,
{
// Allocate all lines in the buffer, including scrollback history
//
// TODO (jwilm) Allocating each line at this point is expensive and
// delays startup. A nice solution might be having `Row` delay
// allocation until it's actually used.
let inner = vec![template; cap];
Storage {
inner,
zero: 0,
@ -124,7 +121,7 @@ impl<T> Storage<T> {
}
/// Grow the number of lines in the buffer, filling new lines with the template
pub fn grow_lines(&mut self, growage: usize, template_row: Row<T>)
fn grow_lines(&mut self, growage: usize, template_row: Row<T>)
where
T: Clone,
{
@ -225,9 +222,6 @@ impl<T> Storage<T> {
/// The default implementation from swap generates 8 movups and 4 movaps
/// instructions. This implementation achieves the swap in only 8 movups
/// instructions.
///
// TODO Once specialization is available, Storage<T> can be fully generic
// again instead of enforcing inner: Vec<Row<T>>.
pub fn swap(&mut self, a: usize, b: usize) {
debug_assert!(::std::mem::size_of::<Row<T>>() == 32);

View File

@ -20,7 +20,7 @@ use index::{Point, Line, Column};
// Scroll up moves lines upwards
#[test]
fn scroll_up() {
println!("");
println!();
let mut grid = Grid::new(Line(10), Column(1), 0, 0);
for i in 0..10 {
@ -58,7 +58,7 @@ fn scroll_up() {
// Scroll down moves lines downwards
#[test]
fn scroll_down() {
println!("");
println!();
let mut grid = Grid::new(Line(10), Column(1), 0, 0);
for i in 0..10 {

View File

@ -270,7 +270,7 @@ macro_rules! inclusive {
match *self {
Empty { .. } => (0, Some(0)),
NonEmpty { ref start, ref end } => {
NonEmpty { start, end } => {
let added = $steps_add_one(start, end);
match added {
Some(hint) => (hint.saturating_add(1), hint.checked_add(1)),
@ -283,9 +283,9 @@ macro_rules! inclusive {
}
}
fn steps_add_one_u8(start: &u8, end: &u8) -> Option<usize> {
if *start < *end {
Some((*end - *start) as usize)
fn steps_add_one_u8(start: u8, end: u8) -> Option<usize> {
if start < end {
Some((end - start) as usize)
} else {
None
}
@ -330,11 +330,11 @@ macro_rules! ops {
impl $ty {
#[inline]
#[allow(trivial_numeric_casts)]
fn steps_between(start: &$ty, end: &$ty, by: &$ty) -> Option<usize> {
if *by == $construct(0) { return None; }
if *start < *end {
fn steps_between(start: $ty, end: $ty, by: $ty) -> Option<usize> {
if by == $construct(0) { return None; }
if start < end {
// Note: We assume $t <= usize here
let diff = (*end - *start).0;
let diff = (end - start).0;
let by = by.0;
if diff % by > 0 {
Some(diff / by + 1)
@ -347,8 +347,8 @@ macro_rules! ops {
}
#[inline]
fn steps_between_by_one(start: &$ty, end: &$ty) -> Option<usize> {
Self::steps_between(start, end, &$construct(1))
fn steps_between_by_one(start: $ty, end: $ty) -> Option<usize> {
Self::steps_between(start, end, $construct(1))
}
}
@ -366,7 +366,7 @@ macro_rules! ops {
}
#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
match Self::Item::steps_between_by_one(&self.0.start, &self.0.end) {
match Self::Item::steps_between_by_one(self.0.start, self.0.end) {
Some(hint) => (hint, Some(hint)),
None => (0, None)
}

View File

@ -35,6 +35,8 @@ use term::SizeInfo;
use term::mode::TermMode;
use util::fmt::Red;
pub const FONT_SIZE_STEP: f32 = 0.5;
/// Processes input from glutin.
///
/// An escape sequence may be emitted in case specific keys or key combinations
@ -64,7 +66,7 @@ pub trait ActionContext {
fn received_count(&mut self) -> &mut usize;
fn suppress_chars(&mut self) -> &mut bool;
fn last_modifiers(&mut self) -> &mut ModifiersState;
fn change_font_size(&mut self, delta: i8);
fn change_font_size(&mut self, delta: f32);
fn reset_font_size(&mut self);
fn scroll(&mut self, scroll: Scroll);
}
@ -103,15 +105,15 @@ impl<T: Eq> Binding<T> {
fn is_triggered_by(
&self,
mode: TermMode,
mods: &ModifiersState,
mods: ModifiersState,
input: &T
) -> bool {
// 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.mode_matches(mode) &&
self.not_mode_matches(mode) &&
self.mods_match(mods)
}
}
@ -124,12 +126,12 @@ impl<T> Binding<T> {
}
#[inline]
fn mode_matches(&self, mode: &TermMode) -> bool {
fn mode_matches(&self, mode: TermMode) -> bool {
self.mode.is_empty() || mode.intersects(self.mode)
}
#[inline]
fn not_mode_matches(&self, mode: &TermMode) -> bool {
fn not_mode_matches(&self, mode: TermMode) -> bool {
self.notmode.is_empty() || !mode.intersects(self.notmode)
}
@ -137,10 +139,10 @@ impl<T> Binding<T> {
///
/// Optimized to use single check instead of four (one per modifier)
#[inline]
fn mods_match(&self, mods: &ModifiersState) -> bool {
debug_assert!(4 == mem::size_of::<ModifiersState>());
fn mods_match(&self, mods: ModifiersState) -> bool {
assert_eq_size!(ModifiersState, u32);
unsafe {
mem::transmute_copy::<_, u32>(&self.mods) == mem::transmute_copy::<_, u32>(mods)
mem::transmute_copy::<_, u32>(&self.mods) == mem::transmute_copy::<_, u32>(&mods)
}
}
}
@ -243,10 +245,10 @@ impl Action {
::std::process::exit(0);
},
Action::IncreaseFontSize => {
ctx.change_font_size(1);
ctx.change_font_size(FONT_SIZE_STEP);
},
Action::DecreaseFontSize => {
ctx.change_font_size(-1);
ctx.change_font_size(-FONT_SIZE_STEP);
}
Action::ResetFontSize => {
ctx.reset_font_size();
@ -507,19 +509,19 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
let mouse_modes = TermMode::MOUSE_REPORT_CLICK | TermMode::MOUSE_DRAG | TermMode::MOUSE_MOTION;
// Make sure the new and deprecated setting are both allowed
let faux_scrollback_lines = self.mouse_config
let faux_scrolling_lines = self.mouse_config
.faux_scrollback_lines
.unwrap_or(self.scrolling_config.faux_multiplier as usize);
if self.ctx.terminal_mode().intersects(mouse_modes) {
self.mouse_report(code, ElementState::Pressed, modifiers);
} else if self.ctx.terminal_mode().contains(TermMode::ALT_SCREEN)
&& faux_scrollback_lines > 0 && !modifiers.shift
&& faux_scrolling_lines > 0 && !modifiers.shift
{
// Faux scrolling
let cmd = code + 1; // 64 + 1 = A, 65 + 1 = B
let mut content = Vec::with_capacity(faux_scrollback_lines as usize * 3);
for _ in 0..faux_scrollback_lines {
let mut content = Vec::with_capacity(faux_scrolling_lines as usize * 3);
for _ in 0..faux_scrolling_lines {
content.push(0x1b);
content.push(b'O');
content.push(cmd);
@ -527,7 +529,8 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
self.ctx.write_to_pty(content);
} else {
for _ in 0..scroll_multiplier {
self.ctx.scroll(Scroll::Lines(-((code as isize) * 2 - 129)));
// Transform the reported button codes 64 and 65 into 1 and -1 lines to scroll
self.ctx.scroll(Scroll::Lines(-(code as isize * 2 - 129)));
}
}
}
@ -567,7 +570,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
return;
}
self.process_mouse_bindings(&ModifiersState::default(), button);
self.process_mouse_bindings(ModifiersState::default(), button);
}
/// Process key input
@ -577,11 +580,11 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
&mut self,
state: ElementState,
key: Option<VirtualKeyCode>,
mods: &ModifiersState,
mods: ModifiersState,
) {
match (key, state) {
(Some(key), ElementState::Pressed) => {
*self.ctx.last_modifiers() = *mods;
*self.ctx.last_modifiers() = mods;
*self.ctx.received_count() = 0;
*self.ctx.suppress_chars() = false;
@ -623,7 +626,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
/// for its action to be executed.
///
/// Returns true if an action is executed.
fn process_key_bindings(&mut self, mods: &ModifiersState, key: VirtualKeyCode) -> bool {
fn process_key_bindings(&mut self, mods: ModifiersState, key: VirtualKeyCode) -> bool {
for binding in self.key_bindings {
if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &key) {
// binding was triggered; run the action
@ -641,7 +644,7 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
/// for its action to be executed.
///
/// Returns true if an action is executed.
fn process_mouse_bindings(&mut self, mods: &ModifiersState, button: MouseButton) -> bool {
fn process_mouse_bindings(&mut self, mods: ModifiersState, button: MouseButton) -> bool {
for binding in self.mouse_bindings {
if binding.is_triggered_by(self.ctx.terminal_mode(), mods, &button) {
// binding was triggered; run the action
@ -741,7 +744,7 @@ mod tests {
fn last_modifiers(&mut self) -> &mut ModifiersState {
&mut self.last_modifiers
}
fn change_font_size(&mut self, _delta: i8) {
fn change_font_size(&mut self, _delta: f32) {
}
fn reset_font_size(&mut self) {
}
@ -824,9 +827,9 @@ mod tests {
#[test]
fn $name() {
if $triggers {
assert!($binding.is_triggered_by($mode, &$mods, &KEY));
assert!($binding.is_triggered_by($mode, $mods, &KEY));
} else {
assert!(!$binding.is_triggered_by($mode, &$mods, &KEY));
assert!(!$binding.is_triggered_by($mode, $mods, &KEY));
}
}
}

View File

@ -13,12 +13,7 @@
// limitations under the License.
//
//! Alacritty - The GPU Enhanced Terminal
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
#![cfg_attr(feature = "clippy", deny(clippy))]
#![cfg_attr(feature = "clippy", deny(enum_glob_use))]
#![cfg_attr(feature = "clippy", deny(if_not_else))]
#![cfg_attr(feature = "clippy", deny(wrong_pub_self_convention))]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, if_not_else, enum_glob_use, wrong_pub_self_convention))]
#![cfg_attr(feature = "nightly", feature(core_intrinsics))]
#![cfg_attr(all(test, feature = "bench"), feature(test))]
@ -26,6 +21,7 @@
#[macro_use] extern crate clap;
#[macro_use] extern crate log;
#[macro_use] extern crate serde_derive;
#[macro_use] extern crate static_assertions;
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os="dragonfly", target_os="openbsd"))]
extern crate x11_dl;
@ -115,11 +111,9 @@ impl Mul<f32> for Rgb {
}
#[cfg_attr(feature = "clippy", allow(too_many_arguments))]
#[cfg_attr(feature = "clippy", allow(doc_markdown))]
#[cfg_attr(feature = "clippy", allow(unreadable_literal))]
#[allow(unused_mut)]
pub mod gl {
#![allow(non_upper_case_globals)]
#![cfg_attr(feature = "cargo-clippy", allow(clippy))]
include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs"));
}

View File

@ -11,6 +11,7 @@
// 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.
#![cfg_attr(feature = "cargo-clippy", allow(let_unit_value))]
#![cfg(target_os = "macos")]
use libc::{LC_CTYPE, setlocale};
use std::ffi::{CString, CStr};

View File

@ -29,7 +29,7 @@ pub struct Logger<T> {
impl<T: Send + io::Write> Logger<T> {
// False positive, see: https://github.com/rust-lang-nursery/rust-clippy/issues/734
#[cfg_attr(feature = "clippy", allow(new_ret_no_self))]
#[cfg_attr(feature = "cargo-clippy", allow(new_ret_no_self))]
pub fn new(output: T, level: log::LevelFilter) -> Logger<io::LineWriter<T>> {
log::set_max_level(level);
Logger {

View File

@ -13,12 +13,7 @@
// limitations under the License.
//
//! Alacritty - The GPU Enhanced Terminal
#![cfg_attr(feature = "clippy", feature(plugin))]
#![cfg_attr(feature = "clippy", plugin(clippy))]
#![cfg_attr(feature = "clippy", deny(clippy))]
#![cfg_attr(feature = "clippy", deny(enum_glob_use))]
#![cfg_attr(feature = "clippy", deny(if_not_else))]
#![cfg_attr(feature = "clippy", deny(wrong_pub_self_convention))]
#![cfg_attr(feature = "cargo-clippy", deny(clippy, if_not_else, enum_glob_use, wrong_pub_self_convention))]
#![cfg_attr(feature = "nightly", feature(core_intrinsics))]
#![cfg_attr(all(test, feature = "bench"), feature(test))]
@ -49,7 +44,7 @@ use alacritty::util::fmt::Red;
fn main() {
// Load command line options and config
let options = cli::Options::load();
let config = load_config(&options);
let config = load_config(&options).update_dynamic_title(&options);
// Switch to home directory
#[cfg(target_os = "macos")]
@ -183,7 +178,7 @@ fn run(mut config: Config, options: &cli::Options) -> Result<(), Box<Error>> {
.as_ref()
.and_then(|monitor| monitor.pending_config())
{
config = new_config;
config = new_config.update_dynamic_title(&options);
display.update_config(&config);
processor.update_config(&config);
terminal.update_config(&config);

View File

@ -183,7 +183,7 @@ impl GlyphCache {
// Need to load at least one glyph for the face before calling metrics.
// The glyph requested here ('m' at the time of writing) has no special
// meaning.
rasterizer.get_glyph(&GlyphKey { font_key: regular, c: 'm', size: font.size() })?;
rasterizer.get_glyph(GlyphKey { font_key: regular, c: 'm', size: font.size() })?;
let metrics = rasterizer.metrics(regular)?;
let mut cache = GlyphCache {
@ -211,7 +211,7 @@ impl GlyphCache {
) {
let size = self.font_size;
for i in RangeInclusive::new(32u8, 128u8) {
self.get(&GlyphKey {
self.get(GlyphKey {
font_key: font,
c: i as char,
size,
@ -273,14 +273,14 @@ impl GlyphCache {
.expect("metrics load since font is loaded at glyph cache creation")
}
pub fn get<'a, L>(&'a mut self, glyph_key: &GlyphKey, loader: &mut L) -> &'a Glyph
pub fn get<'a, L>(&'a mut self, glyph_key: GlyphKey, loader: &mut L) -> &'a Glyph
where L: LoadGlyph
{
let glyph_offset = self.glyph_offset;
let rasterizer = &mut self.rasterizer;
let metrics = &self.metrics;
self.cache
.entry(*glyph_key)
.entry(glyph_key)
.or_insert_with(|| {
let mut rasterized = rasterizer.get_glyph(glyph_key)
.unwrap_or_else(|_| Default::default());
@ -306,7 +306,7 @@ impl GlyphCache {
let font = font.to_owned().with_size(size);
info!("Font size changed: {:?}", font.size);
let (regular, bold, italic) = Self::compute_font_keys(&font, &mut self.rasterizer)?;
self.rasterizer.get_glyph(&GlyphKey { font_key: regular, c: 'm', size: font.size() })?;
self.rasterizer.get_glyph(GlyphKey { font_key: regular, c: 'm', size: font.size() })?;
let metrics = self.rasterizer.metrics(regular)?;
self.font_size = font.size;
@ -842,7 +842,7 @@ impl<'a> RenderApi<'a> {
// Add cell to batch
{
let glyph = glyph_cache.get(&glyph_key, self);
let glyph = glyph_cache.get(glyph_key, self);
self.add_render_item(&cell, glyph);
}
@ -856,7 +856,7 @@ impl<'a> RenderApi<'a> {
c: '_'
};
let underscore = glyph_cache.get(&glyph_key, self);
let underscore = glyph_cache.get(glyph_key, self);
self.add_render_item(&cell, underscore);
}
}

View File

@ -157,8 +157,8 @@ impl Selection {
Selection::Semantic { ref region } => {
Selection::span_semantic(grid, region)
},
Selection::Lines { ref region, ref initial_line } => {
Selection::span_lines(grid, region, *initial_line)
Selection::Lines { ref region, initial_line } => {
Selection::span_lines(grid, region, initial_line)
}
}
}
@ -253,13 +253,12 @@ impl Selection {
// Remove last cell if selection ends to the left of a cell
if front_side == Side::Left && start != end {
if front.col != Column(0) {
front.col -= 1;
}
// Special case when selection starts to left of first cell
else {
if front.col == Column(0) {
front.col = cols - 1;
front.line += 1;
} else {
front.col -= 1;
}
}

View File

@ -30,6 +30,7 @@ use selection::{self, Selection, Locations};
use config::{Config, VisualBellAnimation};
use {MouseCursor, Rgb};
use copypasta::{Clipboard, Load, Store};
use input::FONT_SIZE_STEP;
pub mod cell;
pub mod color;
@ -129,7 +130,7 @@ impl<'a> RenderableCellsIter<'a> {
let inner = grid.display_iter();
let mut selection_range = None;
selection.map(|loc| {
if let Some(loc) = selection {
// Get on-screen lines of the selection's locations
let start_line = grid.buffer_line_to_visible(loc.start.line);
let end_line = grid.buffer_line_to_visible(loc.end.line);
@ -171,17 +172,17 @@ impl<'a> RenderableCellsIter<'a> {
// Update the selection
selection_range = Some(RangeInclusive::new(start, end));
}
});
}
RenderableCellsIter {
cursor: cursor,
cursor_offset: cursor_offset,
grid: grid,
inner: inner,
mode: mode,
cursor,
cursor_offset,
grid,
inner,
mode,
selection: selection_range,
config: config,
colors: colors,
config,
colors,
cursor_cells: ArrayDeque::new(),
}.initialize(cursor_style)
}
@ -313,9 +314,9 @@ impl<'a> RenderableCellsIter<'a> {
self.mode.contains(mode::TermMode::SHOW_CURSOR) && self.grid.contains(self.cursor)
}
fn compute_fg_rgb(&self, fg: &Color, cell: &Cell) -> Rgb {
fn compute_fg_rgb(&self, fg: Color, cell: &Cell) -> Rgb {
use self::cell::Flags;
match *fg {
match fg {
Color::Spec(rgb) => rgb,
Color::Named(ansi) => {
match (self.config.draw_bold_text_with_bright_colors(), cell.flags & Flags::DIM_BOLD) {
@ -346,15 +347,15 @@ impl<'a> RenderableCellsIter<'a> {
}
#[inline]
fn compute_bg_alpha(&self, bg: &Color) -> f32 {
match *bg {
fn compute_bg_alpha(&self, bg: Color) -> f32 {
match bg {
Color::Named(NamedColor::Background) => 0.0,
_ => 1.0
}
}
fn compute_bg_rgb(&self, bg: &Color) -> Rgb {
match *bg {
fn compute_bg_rgb(&self, bg: Color) -> Rgb {
match bg {
Color::Spec(rgb) => rgb,
Color::Named(ansi) => self.colors[ansi],
Color::Indexed(idx) => self.colors[idx],
@ -403,8 +404,6 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
let index = Linear(cell.line.0 * self.grid.num_cols().0 + cell.column.0);
// XXX (jwilm) selection temp disabled
//
let selected = self.selection.as_ref()
.map(|range| range.contains_(index))
.unwrap_or(false);
@ -429,13 +428,13 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
fg_rgb = self.colors[NamedColor::Background];
bg_alpha = 1.0
} else {
bg_rgb = self.compute_fg_rgb(&cell.fg, &cell);
fg_rgb = self.compute_bg_rgb(&cell.bg);
bg_rgb = self.compute_fg_rgb(cell.fg, &cell);
fg_rgb = self.compute_bg_rgb(cell.bg);
}
} else {
fg_rgb = self.compute_fg_rgb(&cell.fg, &cell);
bg_rgb = self.compute_bg_rgb(&cell.bg);
bg_alpha = self.compute_bg_alpha(&cell.bg);
fg_rgb = self.compute_fg_rgb(cell.fg, &cell);
bg_rgb = self.compute_bg_rgb(cell.bg);
bg_alpha = self.compute_bg_alpha(cell.bg);
}
return Some(RenderableCell {
@ -445,7 +444,7 @@ impl<'a> Iterator for RenderableCellsIter<'a> {
c: cell.c,
fg: fg_rgb,
bg: bg_rgb,
bg_alpha: bg_alpha,
bg_alpha,
})
}
}
@ -890,10 +889,10 @@ impl Term {
}
}
pub fn change_font_size(&mut self, delta: i8) {
// Saturating addition with minimum font size 1
let new_size = self.font_size + Size::new(f32::from(delta));
self.font_size = max(new_size, Size::new(1.));
pub fn change_font_size(&mut self, delta: f32) {
// Saturating addition with minimum font size FONT_SIZE_STEP
let new_size = self.font_size + Size::new(delta);
self.font_size = max(new_size, Size::new(FONT_SIZE_STEP));
self.dirty = true;
}
@ -1157,18 +1156,6 @@ impl Term {
self.tabs = IndexRange::from(Column(0)..self.grid.num_cols())
.map(|i| (*i as usize) % self.tabspaces == 0)
.collect::<Vec<bool>>();
// if num_lines > old_lines {
// // Make sure bottom of terminal is clear
// let template = self.cursor.template;
// self.grid
// .region_mut((self.cursor.point.line + 1)..)
// .each(|c| c.reset(&template));
// self.alt_grid
// .region_mut((self.cursor_save_alt.point.line + 1)..)
// .each(|c| c.reset(&template));
// }
}
#[inline]
@ -2002,6 +1989,9 @@ mod tests {
use ansi::{Handler, CharsetIndex, StandardCharset};
use selection::Selection;
use std::mem;
use input::FONT_SIZE_STEP;
use font::Size;
use config::Config;
#[test]
fn semantic_selection_works() {
@ -2105,6 +2095,72 @@ mod tests {
assert_eq!(term.grid()[&cursor].c, '▒');
}
fn change_font_size_works(font_size: f32) {
let size = SizeInfo {
width: 21.0,
height: 51.0,
cell_width: 3.0,
cell_height: 3.0,
padding_x: 0.0,
padding_y: 0.0,
};
let config: Config = Default::default();
let mut term: Term = Term::new(&config, size);
term.change_font_size(font_size);
let expected_font_size: Size = config.font().size() + Size::new(font_size);
assert_eq!(term.font_size, expected_font_size);
}
#[test]
fn increase_font_size_works() {
change_font_size_works(10.0);
}
#[test]
fn decrease_font_size_works() {
change_font_size_works(-10.0);
}
#[test]
fn prevent_font_below_threshold_works() {
let size = SizeInfo {
width: 21.0,
height: 51.0,
cell_width: 3.0,
cell_height: 3.0,
padding_x: 0.0,
padding_y: 0.0,
};
let config: Config = Default::default();
let mut term: Term = Term::new(&config, size);
term.change_font_size(-100.0);
let expected_font_size: Size = Size::new(FONT_SIZE_STEP);
assert_eq!(term.font_size, expected_font_size);
}
#[test]
fn reset_font_size_works() {
let size = SizeInfo {
width: 21.0,
height: 51.0,
cell_width: 3.0,
cell_height: 3.0,
padding_x: 0.0,
padding_y: 0.0,
};
let config: Config = Default::default();
let mut term: Term = Term::new(&config, size);
term.change_font_size(10.0);
term.reset_font_size();
let expected_font_size: Size = config.font().size();
assert_eq!(term.font_size, expected_font_size);
}
}
#[cfg(all(test, feature = "bench"))]
@ -2161,7 +2217,7 @@ mod benches {
mem::swap(&mut terminal.grid, &mut grid);
b.iter(|| {
let iter = terminal.renderable_cells(&config, None, false);
let iter = terminal.renderable_cells(&config, false);
for cell in iter {
test::black_box(cell);
}

View File

@ -117,7 +117,7 @@ fn set_controlling_terminal(fd: c_int) {
// based on architecture (32/64). So a generic cast is used to make sure
// there are no issues. To allow such a generic cast the clippy warning
// is disabled.
#[cfg_attr(feature = "clippy", allow(cast_lossless))]
#[cfg_attr(feature = "cargo-clippy", allow(cast_lossless))]
libc::ioctl(fd, TIOCSCTTY as _, 0)
};

View File

@ -15,7 +15,6 @@ use std::cmp;
#[cfg(not(feature = "nightly"))]
#[inline(always)]
#[cfg_attr(feature = "clippy", allow(inline_always))]
pub unsafe fn unlikely(x: bool) -> bool {
x
}
@ -74,24 +73,12 @@ pub mod fmt {
/// Write a `Display` or `Debug` escaped with Red
pub struct Red => "31";
/// Write a `Display` or `Debug` escaped with Green
pub struct Green => "32";
/// Write a `Display` or `Debug` escaped with Yellow
pub struct Yellow => "33";
}
/// Write a `Display` or `Debug` escaped with Red
pub struct Green<T>(pub T);
impl<T: fmt::Display> fmt::Display for Green<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "\x1b[32m{}\x1b[0m", self.0)
}
}
impl<T: fmt::Debug> fmt::Debug for Green<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "\x1b[32m{:?}\x1b[0m", self.0)
}
}
}
#[cfg(test)]

View File

@ -22,8 +22,26 @@ use glutin::GlContext;
use MouseCursor;
use cli::Options;
use config::WindowConfig;
/// Default text for the window's title bar, if not overriden.
///
/// In X11, this the default value for the `WM_NAME` property.
pub const DEFAULT_TITLE: &str = "Alacritty";
/// Default text for general window class, X11 specific.
///
/// In X11, this is the default value for the `WM_CLASS` property. The
/// second value of `WM_CLASS` is **never** changed to anything but
/// the default value.
///
/// ```ignore
/// $ xprop | grep WM_CLASS
/// WM_CLASS(STRING) = "Alacritty", "Alacritty"
/// ```
pub const DEFAULT_CLASS: &str = "Alacritty";
/// Window errors
#[derive(Debug)]
pub enum Error {
@ -199,17 +217,19 @@ impl Window {
///
/// This creates a window and fully initializes a window.
pub fn new(
title: &str,
options: &Options,
window_config: &WindowConfig,
) -> Result<Window> {
let event_loop = EventsLoop::new();
let title = options.title.as_ref().map_or(DEFAULT_TITLE, |t| t);
let class = options.class.as_ref().map_or(DEFAULT_CLASS, |c| c);
let window_builder = WindowBuilder::new()
.with_title(title)
.with_visibility(false)
.with_transparency(true)
.with_decorations(window_config.decorations());
let window_builder = Window::platform_builder_ext(window_builder);
let window_builder = Window::platform_builder_ext(window_builder, &class);
let window = create_gl_window(window_builder.clone(), &event_loop, false)
.or_else(|_| create_gl_window(window_builder, &event_loop, true))?;
window.show();
@ -322,13 +342,13 @@ impl Window {
}
#[cfg(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd"))]
fn platform_builder_ext(window_builder: WindowBuilder) -> WindowBuilder {
fn platform_builder_ext(window_builder: WindowBuilder, wm_class: &str) -> WindowBuilder {
use glutin::os::unix::WindowBuilderExt;
window_builder.with_class("alacritty".to_owned(), "Alacritty".to_owned())
window_builder.with_class(wm_class.to_owned(), "Alacritty".to_owned())
}
#[cfg(not(any(target_os = "linux", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd")))]
fn platform_builder_ext(window_builder: WindowBuilder) -> WindowBuilder {
fn platform_builder_ext(window_builder: WindowBuilder, _: &str) -> WindowBuilder {
window_builder
}