Skip to content

Commit

Permalink
Added more various editor/viewer configurability
Browse files Browse the repository at this point in the history
  • Loading branch information
Linus-Mussmaecher committed Jun 16, 2024
1 parent fb0d1c0 commit 04004a6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 10 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,12 @@ Here is a list of all possible configuration settings:
Otherwise, local stats are shown.
This setting therefore avoids showing duplicating stats at all times.
- `editor` configures the command to edit your notes.
This can be a terminal application or an external application.
- `viewer` configures the command for your HTML viewing application (I use `google-chrome-stable`). If unconfigured, tries to use your systems default application for HTML files.
This is a list of string, containg the programm in the first position and all arguments in the further entries, wherby `%p` will be replaced by the path of the note to be openend.
For example, if you want to run `my_editor --theme <cool-theme> --path <note_path>`, put `["my_editor", "--theme", "<cool-theme>", "--path", "%p"]`.
If unconfigured, tries to use your `EDITOR` environment variable or system default application.
- `viewer` configures the command for your HTML viewing application, see `editor` for details.
I use `["firefox", "-P", "<my note profile>", "%p"].
If unconfigured, tries to use your systems default application for HTML files.
The following configuration options manage the HTML files created by rucola:
- `enable_html` is set to `true` by default, causing all your notes to be converted to HTML files on program start and for those HTMLs to be continuously kept up-to-date in case of file changes.
Set to `false` to never create HTMLs in the background.
Expand Down
4 changes: 2 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ pub struct Config {
/// When to show the global stats area
pub(crate) stats_show: ui::screen::StatsShow,
/// The editor to use for notes
pub(crate) editor: Option<String>,
pub(crate) editor: Option<Vec<String>>,
/// Viewer to open html files with
pub(crate) viewer: Option<String>,
pub(crate) viewer: Option<Vec<String>>,
/// When set to true, HTML files are mass-created on start and continuously kept up to date with file changes instead of being created on-demand.
pub(crate) enable_html: bool,
/// Path to .css file to style htmls with.
Expand Down
23 changes: 20 additions & 3 deletions src/io/file_manager.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{data, error};
use std::{fs, io::Write, path};
use std::{fs, io::Write, path, process};

/// Saves configurations to manipulate the file system the notes are stored in.
#[derive(Debug, Clone)]
Expand All @@ -9,7 +9,7 @@ pub struct FileManager {
/// Default file ending for newly created notes
default_extension: String,
/// The editor to use for notes
editor: Option<String>,
editor: Option<Vec<String>>,
}
impl Default for FileManager {
fn default() -> Self {
Expand Down Expand Up @@ -228,7 +228,24 @@ impl FileManager {
self.editor
.as_ref()
// create a command from it
.map(|editor_string| open::with_command(path, editor_string))
.and_then(|editor_arg_list| {
let mut iter = editor_arg_list.iter();
if let Some(programm) = iter.next() {
let mut cmd = process::Command::new(programm);
for arg in iter {
if arg == "%p" {
// special argument for the user to indicate where to put the path
cmd.arg(&path);
} else {
// all other arguments are appended in order
cmd.arg(arg);
}
}
Some(cmd)
} else {
None
}
})
// Try the $EDITOR variable
.or_else(|| {
std::env::var("EDITOR")
Expand Down
23 changes: 20 additions & 3 deletions src/io/html_builder.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{fs, io::Write, path};
use std::{fs, io::Write, path, process};

use crate::{data, error};

Expand All @@ -18,7 +18,7 @@ pub struct HtmlBuilder {
/// A list of strings to replace in math mode to mimic latex commands
math_replacements: Vec<(String, String)>,
/// Viewer to open html files with
viewer: Option<String>,
viewer: Option<Vec<String>>,
}

impl Default for HtmlBuilder {
Expand Down Expand Up @@ -199,7 +199,24 @@ impl HtmlBuilder {
self.viewer
.as_ref()
// create a command from it
.map(|viewer_string| open::with_command(&path, viewer_string))
.and_then(|viewer_arg_list| {
let mut iter = viewer_arg_list.iter();
if let Some(programm) = iter.next() {
let mut cmd = process::Command::new(programm);
for arg in iter {
if arg == "%p" {
// special argument for the user to indicate where to put the path
cmd.arg(&path);
} else {
// all other arguments are appended in order
cmd.arg(arg);
}
}
Some(cmd)
} else {
None
}
})
// if it was not there, take the default command
.or_else(|| open::commands(&path).pop())
// if it was also not there, throw an error
Expand Down

0 comments on commit 04004a6

Please sign in to comment.