Skip to content

Commit

Permalink
error if file to be opened in external editor will not be found (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Dilly committed Jul 8, 2020
1 parent abe3b48 commit 540997c
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(),
Expand Down
4 changes: 4 additions & 0 deletions src/components/externaleditor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions src/queue.rs
Original file line number Diff line number Diff line change
@@ -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! {
Expand Down Expand Up @@ -50,7 +49,7 @@ pub enum InternalEvent {
///
InspectCommit(CommitId),
///
OpenExternalEditor(Option<Box<PathBuf>>),
OpenExternalEditor(Option<String>),
}

///
Expand Down
5 changes: 1 addition & 4 deletions src/tabs/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use asyncgit::{
};
use crossbeam_channel::Sender;
use crossterm::event::Event;
use std::path::PathBuf;
use tui::layout::{Constraint, Direction, Layout};

///
Expand Down Expand Up @@ -389,9 +388,7 @@ impl Component for Status {
{
self.queue.borrow_mut().push_back(
InternalEvent::OpenExternalEditor(
Some(Box::new(PathBuf::from(
path,
))),
Some(path),
),
);
}
Expand Down

0 comments on commit 540997c

Please sign in to comment.