Fix StartFifo and ToggleFifo

Also add `xplr.config.general.start_fifo`.

Closes: https://github.com/sayanarijit/xplr/issues/280
pull/282/head
Arijit Basu 3 years ago committed by Arijit Basu
parent 2df8d47b0f
commit d29f6aed6d

@ -483,6 +483,9 @@ pub struct GeneralConfig {
#[serde(default)]
pub initial_layout: Option<String>,
#[serde(default)]
pub start_fifo: Option<String>,
}
impl GeneralConfig {
@ -570,6 +573,11 @@ impl GeneralConfig {
pub fn set_read_only(&mut self, read_only: bool) {
self.read_only = read_only;
}
/// Get a reference to the general config's start fifo.
pub fn start_fifo(&self) -> Option<&String> {
self.start_fifo.as_ref()
}
}
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]

@ -14,6 +14,9 @@ xplr.config.general.read_only = false
------ Recover mode
xplr.config.general.disable_recover_mode = false
------ Start FIFO
xplr.config.general.start_fifo = nil
------ Prompt
xplr.config.general.prompt.format = " "
xplr.config.general.prompt.style.add_modifiers = nil

@ -86,6 +86,16 @@ fn call(app: &app::App, cmd: app::Command, silent: bool) -> io::Result<ExitStatu
.status()
}
fn start_fifo(path: &str, focus_path: &str) -> Result<fs::File> {
match fs::OpenOptions::new().write(true).open(path) {
Ok(mut file) => {
writeln!(file, "{}", focus_path)?;
Ok(file)
}
Err(e) => Err(e.into()),
}
}
pub struct Runner {
pwd: PathBuf,
focused_path: Option<PathBuf>,
@ -171,7 +181,18 @@ impl Runner {
// let mut stdout = stdout.lock();
execute!(stdout, term::EnterAlternateScreen)?;
let mut fifo: Option<fs::File> = None;
let mut fifo: Option<fs::File> = if let Some(path) = app.config().general().start_fifo() {
match start_fifo(&path, &app.focused_node_str()) {
Ok(file) => Some(file),
Err(e) => {
app = app.log_error(e.to_string())?;
None
}
}
} else {
None
};
let mut last_focus: Option<app::Node> = None;
let mut mouse_enabled = app.config().general().enable_mouse();
@ -327,15 +348,11 @@ impl Runner {
}
app::MsgOut::StartFifo(path) => {
if let Some(file) = fifo {
fifo = None;
std::mem::drop(file);
}
match fs::OpenOptions::new().write(true).open(path) {
Ok(file) => fifo = Some(file),
fifo = match start_fifo(&path, &app.focused_node_str()) {
Ok(file) => Some(file),
Err(e) => {
app = app.log_error(e.to_string())?;
None
}
}
}
@ -352,10 +369,11 @@ impl Runner {
fifo = None;
std::mem::drop(file);
} else {
match fs::OpenOptions::new().write(true).open(path) {
Ok(file) => fifo = Some(file),
fifo = match start_fifo(&path, &app.focused_node_str()) {
Ok(file) => Some(file),
Err(e) => {
app = app.log_error(e.to_string())?;
None
}
}
}

Loading…
Cancel
Save