mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 08:58:21 +00:00
error if file to be opened in external editor will not be found (#184)
This commit is contained in:
parent
abe3b48d47
commit
540997c177
4 changed files with 9 additions and 10 deletions
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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>),
|
||||
}
|
||||
|
||||
///
|
||||
|
|
|
|||
|
|
@ -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),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue