2020-10-16 05:29:22 +02:00
|
|
|
use crate::View;
|
|
|
|
|
|
|
|
use std::path::PathBuf;
|
|
|
|
|
|
|
|
use anyhow::Error;
|
|
|
|
|
|
|
|
pub struct Editor {
|
2020-10-19 09:20:59 +02:00
|
|
|
pub views: Vec<View>,
|
|
|
|
pub focus: usize,
|
2020-10-16 07:37:12 +02:00
|
|
|
pub should_close: bool,
|
2020-10-16 05:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Editor {
|
|
|
|
pub fn new() -> Self {
|
2020-10-16 07:37:12 +02:00
|
|
|
Self {
|
2020-10-19 09:20:59 +02:00
|
|
|
views: Vec::new(),
|
|
|
|
focus: 0,
|
2020-10-16 07:37:12 +02:00
|
|
|
should_close: false,
|
|
|
|
}
|
2020-10-16 05:29:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn open(&mut self, path: PathBuf, size: (u16, u16)) -> Result<(), Error> {
|
2020-10-19 09:20:59 +02:00
|
|
|
let pos = self.views.len();
|
|
|
|
self.views.push(View::open(path, size)?);
|
|
|
|
self.focus = pos;
|
2020-10-16 05:29:22 +02:00
|
|
|
Ok(())
|
|
|
|
}
|
2020-10-19 09:20:59 +02:00
|
|
|
|
|
|
|
pub fn view(&self) -> Option<&View> {
|
|
|
|
self.views.get(self.focus)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn view_mut(&mut self) -> Option<&mut View> {
|
|
|
|
self.views.get_mut(self.focus)
|
|
|
|
}
|
2020-10-16 05:29:22 +02:00
|
|
|
}
|