error if file to be opened in external editor will not be found (#184)

This commit is contained in:
Stephan Dilly 2020-07-08 19:47:25 +02:00
parent abe3b48d47
commit 540997c177
4 changed files with 9 additions and 10 deletions

View file

@ -18,8 +18,7 @@ use anyhow::{anyhow, Result};
use asyncgit::{sync, AsyncNotification, CWD};
use crossbeam_channel::Sender;
use crossterm::event::{Event, KeyEvent};
use std::path::PathBuf;
use std::{cell::Cell, cell::RefCell, rc::Rc};
use std::{cell::Cell, cell::RefCell, path::Path, rc::Rc};
use tui::{
backend::Backend,
layout::{Constraint, Direction, Layout, Margin, Rect},
@ -49,7 +48,7 @@ pub struct App {
// "Flags"
requires_redraw: Cell<bool>,
file_to_open: Option<Box<PathBuf>>,
file_to_open: Option<String>,
}
// public interface
@ -202,7 +201,7 @@ impl App {
let result = match self.file_to_open.take() {
Some(path) => {
ExternalEditorComponent::open_file_in_editor(
&path,
Path::new(&path),
)
}
None => self.commit.show_editor(),

View file

@ -38,6 +38,10 @@ impl ExternalEditorComponent {
/// opens file at given `path` in an available editor
pub fn open_file_in_editor(path: &Path) -> Result<()> {
if !path.exists() {
return Err(anyhow!("file not found: {:?}", path));
}
io::stdout().execute(LeaveAlternateScreen)?;
defer! {
io::stdout().execute(EnterAlternateScreen).expect("reset terminal");

View file

@ -1,7 +1,6 @@
use crate::tabs::StashingOptions;
use asyncgit::sync::CommitId;
use bitflags::bitflags;
use std::path::PathBuf;
use std::{cell::RefCell, collections::VecDeque, rc::Rc};
bitflags! {
@ -50,7 +49,7 @@ pub enum InternalEvent {
///
InspectCommit(CommitId),
///
OpenExternalEditor(Option<Box<PathBuf>>),
OpenExternalEditor(Option<String>),
}
///

View file

@ -18,7 +18,6 @@ use asyncgit::{
};
use crossbeam_channel::Sender;
use crossterm::event::Event;
use std::path::PathBuf;
use tui::layout::{Constraint, Direction, Layout};
///
@ -389,9 +388,7 @@ impl Component for Status {
{
self.queue.borrow_mut().push_back(
InternalEvent::OpenExternalEditor(
Some(Box::new(PathBuf::from(
path,
))),
Some(path),
),
);
}