Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config file #1119

Merged
merged 25 commits into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
cab267b
[WIP] Config file
LoipesMas Jan 3, 2022
1de837b
rename NEOVIDE_NO_VSYNC to NEOVIDE_VSYNC
LoipesMas Apr 9, 2023
9c93fd6
Remove font aliasing setting, write settings from config file to env
LoipesMas Apr 9, 2023
85dbcfd
update dirs, use dirs::config_dir for config file
LoipesMas Apr 9, 2023
ab6e940
add geometry setting, remove unused code
LoipesMas Apr 9, 2023
43bf51a
rename `neovide_config_path` to `neovide_config_dir`
LoipesMas Apr 9, 2023
9cd1d92
Add srgb to config
LoipesMas Apr 10, 2023
3437cba
rename `multi_grid` to `multigrid` in config
LoipesMas Apr 10, 2023
dc4195d
add `no_idle` setting to config
LoipesMas Apr 10, 2023
a704ef2
Add `neovim_bin` option to config.
LoipesMas Apr 10, 2023
2b9329c
Remove redundant brackets
LoipesMas Apr 10, 2023
eabf6d3
Add `frame` option
LoipesMas Apr 10, 2023
8a624b2
Update docs for changed options
LoipesMas Apr 10, 2023
124a83f
Add documentation for the config file.
LoipesMas Apr 10, 2023
f3346de
Use `xdg` instead of `dirs` for unix
LoipesMas May 1, 2023
35f75cf
Merge branch 'main' into config_file
LoipesMas May 1, 2023
523b697
Merge branch 'main' into config_file
LoipesMas Jun 5, 2023
291e9e6
Update website
LoipesMas Jun 5, 2023
aa136b7
Remove useless `error!`
LoipesMas Jun 6, 2023
a01069e
Remove geometry option from config
LoipesMas Jun 6, 2023
0bd3f9f
Merge branch 'main' into config_file
LoipesMas Jun 7, 2023
6634591
`cargo fix`
LoipesMas Jun 7, 2023
d7ca99f
Update `no_idle` option
LoipesMas Jun 7, 2023
738ee88
Move config initialization to a function
LoipesMas Jun 7, 2023
9a168db
Update config-file.md
last-partizan Jun 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 53 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ cfg-if = "1.0.0"
clap = { version = "4.0.8", features = ["cargo", "derive", "env"] }
csscolorparser = "0.6.2"
derive-new = "0.5.9"
dirs = "4.0.0"
dirs = "5.0.0"
LoipesMas marked this conversation as resolved.
Show resolved Hide resolved
euclid = "0.22.7"
flexi_logger = { version = "0.22.3", default-features = false }
futures = "0.3.21"
Expand All @@ -45,6 +45,7 @@ swash = "0.1.4"
time = "0.3.9"
tokio = { version = "1.25.0", features = ["full"] }
tokio-util = { version = "0.7.4", features = ["compat"] }
toml = "0.7.3"
unicode-segmentation = "1.9.0"
which = "4.2.5"
winit = { git = "https://github.com/neovide/winit", branch = "new-keyboard-all" }
Expand Down
6 changes: 3 additions & 3 deletions src/cmd_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct CmdLineSettings {
pub neovim_args: Vec<String>,

/// The geometry of the window
#[arg(long, default_value_t = last_window_geometry())]
#[arg(long, default_value_t = last_window_geometry(), env = "NEOVIDE_GEOMETRY")]
pub geometry: Dimensions,

/// If to enable logging to a file in the current directory
Expand Down Expand Up @@ -68,11 +68,11 @@ pub struct CmdLineSettings {

/// Do not request sRGB when initializing the window, may help with GPUs with weird pixel
/// formats
#[arg(long = "nosrgb", env = "NEOVIDE_NO_SRGB", action = ArgAction::SetFalse, value_parser = FalseyValueParser::new())]
#[arg(long = "nosrgb", env = "NEOVIDE_SRGB", action = ArgAction::SetFalse, value_parser = FalseyValueParser::new())]
pub srgb: bool,

/// Do not try to request VSync on the window
#[arg(long = "novsync", env = "NEOVIDE_NO_VSYNC", action = ArgAction::SetFalse, value_parser = FalseyValueParser::new())]
#[arg(long = "novsync", env = "NEOVIDE_VSYNC", action = ArgAction::SetFalse, value_parser = FalseyValueParser::new())]
pub vsync: bool,

/// Which NeoVim binary to invoke headlessly instead of `nvim` found on $PATH
Expand Down
4 changes: 3 additions & 1 deletion src/frame.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use core::fmt;

use serde::Deserialize;

use clap::{builder::PossibleValue, ValueEnum};

// Options for the frame decorations
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default, Deserialize)]
pub enum Frame {
#[default]
Full,
Expand Down
11 changes: 11 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use std::env::{self, args};

#[cfg(not(test))]
use flexi_logger::{Cleanup, Criterion, Duplicate, FileSpec, Logger, Naming};
use log::error;
use log::trace;

use backtrace::Backtrace;
Expand All @@ -57,6 +58,8 @@ pub use running_tracker::*;
#[cfg(target_os = "windows")]
pub use windows_utils::*;

use crate::settings::{config_path, Config};

const BACKTRACES_FILE: &str = "neovide_backtraces.log";
const REQUEST_MESSAGE: &str = "This is a bug and we would love for it to be reported to https://github.com/neovide/neovide/issues";

Expand Down Expand Up @@ -142,6 +145,14 @@ fn protected_main() {
#[cfg(target_os = "windows")]
windows_attach_to_console();

match Config::load_from_path(&config_path()) {
LoipesMas marked this conversation as resolved.
Show resolved Hide resolved
Ok(config) => config.write_to_env(),
Err(err) => {
eprintln!("{err}");
error!("{err}");
LoipesMas marked this conversation as resolved.
Show resolved Hide resolved
}
};

//Will exit if -h or -v
if let Err(err) = cmd_line::handle_command_line_arguments(args().collect()) {
eprintln!("{err}");
Expand Down
82 changes: 82 additions & 0 deletions src/settings/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Config file handling

use std::env;

use serde::Deserialize;

use crate::{dimensions::Dimensions, frame::Frame};

use std::path::{Path, PathBuf};

const CONFIG_FILE: &str = "config.toml";

fn neovide_config_dir() -> PathBuf {
let mut path = dirs::config_dir().unwrap();
path.push("neovide");
path
}

pub fn config_path() -> PathBuf {
let mut config_path = neovide_config_dir();
config_path.push(CONFIG_FILE);
config_path
}
last-partizan marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Debug, Deserialize, Default)]
pub struct Config {
pub multigrid: Option<bool>,
pub maximized: Option<bool>,
pub vsync: Option<bool>,
pub srgb: Option<bool>,
pub no_idle: Option<bool>,
pub neovim_bin: Option<PathBuf>,
pub frame: Option<Frame>,
pub geometry: Option<Dimensions>,
LoipesMas marked this conversation as resolved.
Show resolved Hide resolved
}

impl Config {
pub fn write_to_env(&self) {
last-partizan marked this conversation as resolved.
Show resolved Hide resolved
if let Some(multigrid) = self.multigrid {
env::set_var("NEOVIDE_MULTIGRID", multigrid.to_string());
}
if let Some(maximized) = self.maximized {
env::set_var("NEOVIDE_MAXIMIZED", maximized.to_string());
}
if let Some(vsync) = self.vsync {
env::set_var("NEOVIDE_VSYNC", vsync.to_string());
}
if let Some(srgb) = self.srgb {
env::set_var("NEOVIDE_SRGB", srgb.to_string());
}
if let Some(no_idle) = self.no_idle {
env::set_var("NEOVIDE_NO_IDLE", no_idle.to_string());
LoipesMas marked this conversation as resolved.
Show resolved Hide resolved
}
if let Some(frame) = self.frame {
env::set_var("NEOVIDE_FRAME", frame.to_string());
}
if let Some(neovim_bin) = &self.neovim_bin {
env::set_var("NEOVIM_BIN", neovim_bin.to_string_lossy().to_string());
}
if let Some(geometry) = self.geometry {
env::set_var("NEOVIDE_GEOMETRY", geometry.to_string());
}
}

pub fn load_from_path(path: &Path) -> Result<Self, String> {
let toml = std::fs::read_to_string(path).map_err(|e| {
format!(
"Error while trying to open config file {}:\n{}\nContinuing with default config.",
path.to_string_lossy(),
e
)
})?;
let config = toml::from_str(&toml).map_err(|e| {
format!(
last-partizan marked this conversation as resolved.
Show resolved Hide resolved
"Error while parsing config file {}:\n{}\nContinuing with default config.",
path.to_string_lossy(),
e
)
})?;
Ok(config)
}
}
3 changes: 3 additions & 0 deletions src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub use window_geometry::{
PersistentWindowSettings, DEFAULT_WINDOW_GEOMETRY,
};

mod config;
pub use config::{config_path, Config};

lazy_static! {
pub static ref SETTINGS: Settings = Settings::new();
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ______________________________________________________________________
- [Installation](installation.md)
- [Configuration](configuration.md)
- [Command Line Reference](command-line-reference.md)
- [Config File](config-file.md)
- [Editing w/ External Tools](editing-with-external-tools.md)
- [Troubleshooting](troubleshooting.md)
- [FAQ](faq.md)
Expand Down
8 changes: 4 additions & 4 deletions website/docs/command-line-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Can be set to:
### Geometry

```sh
--geometry=<width>x<height>
--geometry=<width>x<height> or $NEOVIDE_GEOMETRY=<width>x<height>
```

Sets the initial neovide window size in characters.
Expand Down Expand Up @@ -101,7 +101,7 @@ one.
### No sRGB

```sh
--nosrgb or $NEOVIDE_NO_SRGB
--nosrgb or $NEOVIDE_SRGB=false
```

Don't request sRGB on the window. Swapping sometimes fixes startup issues.
Expand All @@ -119,10 +119,10 @@ buffers.
Note: Even if files are opened in tabs, they're buffers anyways. It's just about them being visible
or not.

## No VSync
### No VSync

```sh
--novsync
--novsync or $NEOVIDE_VSYNC=false
```

**Available since 0.10.2.**
Expand Down