aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorJoe Wilm <joe@jwilm.com>2016-06-28 09:18:54 -0700
committerJoe Wilm <joe@jwilm.com>2016-06-28 09:18:54 -0700
commit69ed81d2495c6eb548c44e73c0e9ed359d3820f0 (patch)
treec12611c50799452ee99ca03b7097dab1780dd27e /src/main.rs
parent8454bbe18340208286572a01e32f2d1a84440308 (diff)
downloadalacritty-69ed81d2495c6eb548c44e73c0e9ed359d3820f0.tar.gz
alacritty-69ed81d2495c6eb548c44e73c0e9ed359d3820f0.zip
Refactor Tty and Grid creation into Term::new
This moves more logic out of main() and prepares the Term type to handle resizing. By providing all size data to Term, it is now possible to implement a resize function there which handles all resizing logic save for the rendering subsystem.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs82
1 files changed, 35 insertions, 47 deletions
diff --git a/src/main.rs b/src/main.rs
index 714831da..49f2655e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -35,7 +35,6 @@ use std::sync::{mpsc, Arc};
use parking_lot::Mutex;
use font::FontDesc;
-use grid::Grid;
use meter::Meter;
use renderer::{QuadRenderer, GlyphCache};
use term::Term;
@@ -100,14 +99,6 @@ mod gl {
include!(concat!(env!("OUT_DIR"), "/gl_bindings.rs"));
}
-#[derive(Debug)]
-pub struct TermProps {
- width: f32,
- height: f32,
- cell_width: f32,
- cell_height: f32,
-}
-
#[cfg(target_os = "linux")]
static FONT: &'static str = "DejaVu Sans Mono";
#[cfg(target_os = "linux")]
@@ -147,24 +138,10 @@ fn main() {
println!("Cell Size: ({} x {})", cell_width, cell_height);
- let num_cols = grid::num_cells_axis(cell_width, width);
- let num_rows = grid::num_cells_axis(cell_height, height);
-
- let tty = tty::new(num_rows as u8, num_cols as u8);
- tty.resize(num_rows as usize, num_cols as usize, width as usize, height as usize);
- let reader = tty.reader();
- let writer = tty.writer();
+ let terminal = Term::new(width as f32, height as f32, cell_width as f32, cell_height as f32);
- println!("num_cols, num_rows = {}, {}", num_cols, num_rows);
-
- let grid = Grid::new(num_rows as usize, num_cols as usize);
-
- let props = TermProps {
- cell_width: cell_width as f32,
- cell_height: cell_height as f32,
- height: height as f32,
- width: width as f32,
- };
+ let reader = terminal.tty().reader();
+ let writer = terminal.tty().writer();
let mut glyph_cache = GlyphCache::new(rasterizer, desc, font_size);
let needs_render = Arc::new(AtomicBool::new(true));
@@ -179,7 +156,7 @@ fn main() {
}
});
- let terminal = Arc::new(Mutex::new(Term::new(tty, grid)));
+ let terminal = Arc::new(Mutex::new(terminal));
let term_ref = terminal.clone();
let mut meter = Meter::new();
@@ -255,10 +232,16 @@ fn main() {
gl::Enable(gl::MULTISAMPLE);
}
+ // Create renderer
let mut renderer = QuadRenderer::new(width, height);
- renderer.with_api(&props, |mut api| {
- glyph_cache.init(&mut api);
- });
+
+ // Initialize glyph cache
+ {
+ let terminal = term_ref.lock();
+ renderer.with_api(terminal.size_info(), |mut api| {
+ glyph_cache.init(&mut api);
+ });
+ }
loop {
unsafe {
@@ -266,32 +249,37 @@ fn main() {
gl::Clear(gl::COLOR_BUFFER_BIT);
}
+ // Need scope so lock is released when swap_buffers is called
{
// Flag that it's time for render
needs_render2.store(true, Ordering::Release);
// Acquire term lock
- let mut terminal = term_ref.lock();
+ let terminal = term_ref.lock();
// Have the lock, ok to lower flag
needs_render2.store(false, Ordering::Relaxed);
- let _sampler = meter.sampler();
- renderer.with_api(&props, |mut api| {
- // Draw the grid
- api.render_grid(terminal.grid(), &mut glyph_cache);
+ // Draw grid + cursor
+ {
+ let _sampler = meter.sampler();
- // Also draw the cursor
- if terminal.mode().contains(term::mode::SHOW_CURSOR) {
- api.render_cursor(terminal.cursor(), &mut glyph_cache);
- }
- })
- }
+ renderer.with_api(terminal.size_info(), |mut api| {
+ // Draw the grid
+ api.render_grid(terminal.grid(), &mut glyph_cache);
- // Draw render timer
- let timing = format!("{:.3} usec", meter.average());
- let color = Rgb { r: 0xd5, g: 0x4e, b: 0x53 };
- renderer.with_api(&props, |mut api| {
- api.render_string(&timing[..], &mut glyph_cache, &color);
- });
+ // Also draw the cursor
+ if terminal.mode().contains(term::mode::SHOW_CURSOR) {
+ api.render_cursor(terminal.cursor(), &mut glyph_cache);
+ }
+ })
+ }
+
+ // Draw render timer
+ let timing = format!("{:.3} usec", meter.average());
+ let color = Rgb { r: 0xd5, g: 0x4e, b: 0x53 };
+ renderer.with_api(terminal.size_info(), |mut api| {
+ api.render_string(&timing[..], &mut glyph_cache, &color);
+ });
+ }
window.swap_buffers().unwrap();