From a387dc0e49018c1e087fb654ffee94faeb15c123 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 3 Mar 2018 17:10:47 -0800 Subject: [PATCH] factor out window spawning --- src/gliumwindows.rs | 2 +- src/main.rs | 103 +++++++++++++++++++++---------------------- src/opengl/render.rs | 6 +-- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/src/gliumwindows.rs b/src/gliumwindows.rs index af4c39dd1..a5961ec5f 100644 --- a/src/gliumwindows.rs +++ b/src/gliumwindows.rs @@ -90,7 +90,7 @@ impl TerminalWindow { terminal: Terminal, pty: MasterPty, process: Child, - fonts: FontConfiguration, + fonts: &Rc, palette: term::color::ColorPalette, ) -> Result { let (cell_height, cell_width) = { diff --git a/src/main.rs b/src/main.rs index 5c4cb696d..77bb47061 100644 --- a/src/main.rs +++ b/src/main.rs @@ -370,40 +370,6 @@ impl GuiEventLoop { } } -fn run_glium( - master: pty::MasterPty, - child: std::process::Child, - config: &Rc, - fontconfig: FontConfiguration, - terminal: term::Terminal, - initial_pixel_width: u16, - initial_pixel_height: u16, -) -> Result<(), Error> { - let event_loop = GuiEventLoop::new()?; - - let window = gliumwindows::TerminalWindow::new( - &*event_loop.event_loop.borrow_mut(), - event_loop.paster.clone(), - initial_pixel_width, - initial_pixel_height, - terminal, - master, - child, - fontconfig, - config - .colors - .as_ref() - .map(|p| p.clone().into()) - .unwrap_or_else(term::color::ColorPalette::default), - )?; - - event_loop.add_window(window)?; - - event_loop.run()?; - - Ok(()) -} - // let message = "; ❤ 😍🤢\n\x1b[91;mw00t\n\x1b[37;104;m bleet\x1b[0;m."; // terminal.advance_bytes(message); // != @@ -425,10 +391,44 @@ fn run() -> Result<(), Error> { let config = Rc::new(config::Config::load()?); println!("Using configuration: {:#?}", config); + let fontconfig = Rc::new(FontConfiguration::new(Rc::clone(&config))); + + let cmd = if args.is_present("PROG") { + Some( + args.values_of_os("PROG") + .expect("PROG wasn't present after all!?") + .collect(), + ) + } else { + None + }; + + let event_loop = GuiEventLoop::new()?; + + spawn_window(&event_loop, cmd, &config, &fontconfig)?; + + event_loop.run()?; + Ok(()) +} + +fn spawn_window( + event_loop: &GuiEventLoop, + cmd: Option>, + config: &Rc, + fontconfig: &Rc, +) -> Result<(), Error> { + let cmd = match cmd { + Some(args) => { + let mut args = args.iter(); + let mut cmd = Command::new(args.next().expect("executable name")); + cmd.args(args); + cmd + } + None => Command::new(get_shell()?), + }; + // First step is to figure out the font metrics so that we know how // big things are going to be. - - let fontconfig = FontConfiguration::new(Rc::clone(&config)); let font = fontconfig.default_font()?; // we always load the cell_height for font 0, @@ -448,15 +448,6 @@ fn run() -> Result<(), Error> { initial_pixel_height, )?; - let cmd = if args.is_present("PROG") { - let mut args = args.values_of_os("PROG") - .expect("PROG wasn't present after all!?"); - let mut cmd = Command::new(args.next().expect("executable name")); - cmd.args(args); - cmd - } else { - Command::new(get_shell()?) - }; let child = slave.spawn_command(cmd)?; eprintln!("spawned: {:?}", child); @@ -467,15 +458,23 @@ fn run() -> Result<(), Error> { config.hyperlink_rules.clone(), ); - run_glium( - master, - child, - &config, - fontconfig, - terminal, + let window = gliumwindows::TerminalWindow::new( + &*event_loop.event_loop.borrow_mut(), + event_loop.paster.clone(), initial_pixel_width, initial_pixel_height, - ) + terminal, + master, + child, + fontconfig, + config + .colors + .as_ref() + .map(|p| p.clone().into()) + .unwrap_or_else(term::color::ColorPalette::default), + )?; + + event_loop.add_window(window) } fn main() { diff --git a/src/opengl/render.rs b/src/opengl/render.rs index 0ed8b519a..a5052f6cc 100644 --- a/src/opengl/render.rs +++ b/src/opengl/render.rs @@ -248,7 +248,7 @@ void main() { pub struct Renderer { width: u16, height: u16, - fonts: FontConfiguration, + fonts: Rc, cell_height: usize, cell_width: usize, descender: isize, @@ -267,7 +267,7 @@ impl Renderer { facade: &F, width: u16, height: u16, - fonts: FontConfiguration, + fonts: &Rc, palette: term::color::ColorPalette, ) -> Result { let (cell_height, cell_width, descender) = { @@ -382,7 +382,7 @@ impl Renderer { glyph_index_buffer, width, height, - fonts, + fonts: Rc::clone(fonts), cell_height, cell_width, descender,