start factoring out some common TerminalWindow code
This commit is contained in:
1 parent
46c0c7753f
commit
315ff45880
4 files changed
+62
-57
No files matched your search
+12
-27
@@ -4,6 +4,7 @@ use crate::config::Config;
|
||||
use crate::failure::Error;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::guicommon::tabs::{Tab, TabId, Tabs};
|
||||
use crate::guicommon::window::TerminalWindow;
|
||||
use crate::guiloop::glutinloop::GuiEventLoop;
|
||||
use crate::guiloop::SessionTerminated;
|
||||
use crate::opengl::render::Renderer;
|
||||
@@ -210,6 +211,17 @@ pub struct GliumTerminalWindow {
|
||||
tabs: Tabs,
|
||||
}
|
||||
|
||||
impl TerminalWindow for GliumTerminalWindow {
|
||||
fn get_tabs(&mut self) -> &mut Tabs {
|
||||
&mut self.tabs
|
||||
}
|
||||
|
||||
fn set_window_title(&mut self, title: &str) -> Result<(), Error> {
|
||||
self.host.display.gl_window().set_title(title);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl GliumTerminalWindow {
|
||||
pub fn new(
|
||||
event_loop: &Rc<GuiEventLoop>,
|
||||
@@ -321,14 +333,6 @@ impl GliumTerminalWindow {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn activate_tab(&mut self, tab: usize) -> Result<(), Error> {
|
||||
let max = self.tabs.len();
|
||||
if tab < max {
|
||||
self.tabs.set_active(tab);
|
||||
self.update_title();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub fn activate_tab_relative(&mut self, delta: isize) -> Result<(), Error> {
|
||||
let max = self.tabs.len();
|
||||
let active = self.tabs.get_active_idx() as isize;
|
||||
@@ -337,25 +341,6 @@ impl GliumTerminalWindow {
|
||||
self.activate_tab(tab as usize % max)
|
||||
}
|
||||
|
||||
fn update_title(&mut self) {
|
||||
let num_tabs = self.tabs.len();
|
||||
|
||||
if num_tabs == 0 {
|
||||
return;
|
||||
}
|
||||
let tab_no = self.tabs.get_active_idx();
|
||||
|
||||
let terminal = self.tabs.get_active().unwrap().terminal();
|
||||
let title = terminal.get_title();
|
||||
let window = self.host.display.gl_window();
|
||||
|
||||
if num_tabs == 1 {
|
||||
window.set_title(title)
|
||||
} else {
|
||||
window.set_title(&format!("[{}/{}] {}", tab_no + 1, num_tabs, title));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn window_id(&self) -> glutin::WindowId {
|
||||
self.host.display.gl_window().id()
|
||||
}
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
pub mod tabs;
|
||||
pub mod window;
|
||||
@@ -0,0 +1,37 @@
|
||||
use crate::guicommon::tabs::Tabs;
|
||||
use failure::Error;
|
||||
|
||||
pub trait TerminalWindow {
|
||||
fn get_tabs(&mut self) -> &mut Tabs;
|
||||
fn set_window_title(&mut self, title: &str) -> Result<(), Error>;
|
||||
|
||||
fn activate_tab(&mut self, tab_idx: usize) -> Result<(), Error> {
|
||||
let max = self.get_tabs().len();
|
||||
if tab_idx < max {
|
||||
self.get_tabs().set_active(tab_idx);
|
||||
self.update_title();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn update_title(&mut self) {
|
||||
let num_tabs = self.get_tabs().len();
|
||||
|
||||
if num_tabs == 0 {
|
||||
return;
|
||||
}
|
||||
let tab_no = self.get_tabs().get_active_idx();
|
||||
|
||||
let title = {
|
||||
let terminal = self.get_tabs().get_active().unwrap().terminal();
|
||||
terminal.get_title().to_owned()
|
||||
};
|
||||
|
||||
if num_tabs == 1 {
|
||||
self.set_window_title(&title).ok();
|
||||
} else {
|
||||
self.set_window_title(&format!("[{}/{}] {}", tab_no + 1, num_tabs, title))
|
||||
.ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
-30
@@ -5,6 +5,7 @@ use super::{Connection, Window};
|
||||
use crate::config::Config;
|
||||
use crate::font::FontConfiguration;
|
||||
use crate::guicommon::tabs::{Tab, TabId, Tabs};
|
||||
use crate::guicommon::window::TerminalWindow;
|
||||
use crate::guiloop::x11::{GuiEventLoop, WindowId};
|
||||
use crate::guiloop::SessionTerminated;
|
||||
use crate::opengl::textureatlas::OutOfTextureSpace;
|
||||
@@ -160,6 +161,17 @@ impl<'a> term::TerminalHost for TabHost<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl TerminalWindow for X11TerminalWindow {
|
||||
fn get_tabs(&mut self) -> &mut Tabs {
|
||||
&mut self.tabs
|
||||
}
|
||||
|
||||
fn set_window_title(&mut self, title: &str) -> Result<(), Error> {
|
||||
self.host.window.set_title(title);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl X11TerminalWindow {
|
||||
pub fn new(
|
||||
event_loop: &Rc<GuiEventLoop>,
|
||||
@@ -525,36 +537,6 @@ impl X11TerminalWindow {
|
||||
Ok(tab_id)
|
||||
}
|
||||
|
||||
fn update_title(&mut self) {
|
||||
let num_tabs = self.tabs.len();
|
||||
if num_tabs == 0 {
|
||||
return;
|
||||
}
|
||||
let tab_no = self.tabs.get_active_idx();
|
||||
|
||||
let terminal = self.tabs.get_active().unwrap().terminal();
|
||||
|
||||
if num_tabs == 1 {
|
||||
self.host.window.set_title(terminal.get_title());
|
||||
} else {
|
||||
self.host.window.set_title(&format!(
|
||||
"[{}/{}] {}",
|
||||
tab_no + 1,
|
||||
num_tabs,
|
||||
terminal.get_title()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn activate_tab(&mut self, tab: usize) -> Result<(), Error> {
|
||||
let max = self.tabs.len();
|
||||
if tab < max {
|
||||
self.tabs.set_active(tab);
|
||||
self.update_title();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn activate_tab_relative(&mut self, delta: isize) -> Result<(), Error> {
|
||||
let max = self.tabs.len();
|
||||
let active = self.tabs.get_active_idx() as isize;
|
||||
|
||||
Reference in new issue
Block a user