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

feat: add configuration file support #70

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open

feat: add configuration file support #70

wants to merge 18 commits into from

Conversation

lanej
Copy link

@lanej lanej commented Jan 9, 2025

Introduces a configuration file support for the project, following the XDG Base Directory Specification. The configuration file allows users to customize various settings, including keybindings and color schemes. This update enhances the flexibility and user experience of the application by allowing greater customization
according to individual preferences.

Key Features 🔑

  • Configuration File Support: A new configuration file is introduced, following the XDG standard, typically found at ~/.config/jnv/config.toml. This allows users to define custom configurations outside of the codebase.
  • Customizable Keybindings:: Users can now specify custom keybindings for different actions within the application. This is particularly useful for users who prefer alternative shortcuts to enhance their workflow efficiency.
  • Customizable Style: The configuration also supports customization of color schemes and styles for different components of the interface, providing a more tailored user experience.

Changes Summary 📋

• Added a new module config.rs to handle loading and parsing of the configuration file.
• Refactored the main.rs to incorporate configuration loading logic and adjusted the initialization of various components to use the loaded configurations.
• Expanded editor.rs to utilize keybindings from the configuration file.
• Adjusted prompt.rs to align with the changes in the configuration handling structure.
• Added default configuration logic to ensure application functionality in the absence of a custom configuration file.

References 📖

Closes #23 by implementing a system for customizable configurations as discussed.

Thoughts 🧠

  • It would be slick to parse the JQ_COLORS environment variable for color customization if not specified in the configuration file.
  • Support for non-named colors by hex and/or decimal would be nice.

TODO 🗒️

@lanej lanej marked this pull request as draft January 9, 2025 04:25
lanej added 3 commits January 9, 2025 09:57
- Updated test assertions to reflect the changes in active_item_style
- Added `env_logger` for enhanced logging capabilities.
- Integrated `shellexpand` to handle tilde expansion in config paths.
- Updated `ConfigContentStyle` to use simplified field names.
- Ensured unknown fields in config files are denied.
- Modified tests to reflect changes in `ConfigContentStyle`.
src/config.rs Outdated Show resolved Hide resolved
lanej added 2 commits January 9, 2025 14:17
Added support for custom key events and focus prefixes in the
configuration. This includes new fields in the Config and
ConfigFile structs, as well as updates to the merge function
and related tests. The changes enhance the flexibility and
customizability of the editor.
@lanej lanej marked this pull request as ready for review January 9, 2025 22:23
@lanej
Copy link
Author

lanej commented Jan 9, 2025

I'd like to get a general temperature check on pursuing this path @ynqa

lanej added 9 commits January 9, 2025 15:32
Added spin_duration field to Config and ConfigFile structs. Updated
merge function to handle spin_duration. Set default spin_duration to
300ms. Removed redundant spin_duration initialization in main.
Added new style options to Config and ConfigFile structs, including
prefix_style, active_char_style, inactive_char_style, curly_brackets_style,
square_brackets_style, key_style, string_value_style, number_value_style,
boolean_value_style, and null_value_style. Updated merge function and
default implementation to handle these new styles.
Removed unused dependencies `env_logger`, `log`, and `humantime` from
Cargo.toml and Cargo.lock. Cleaned up related imports and initialization
code in main.rs.
@ynqa ynqa self-requested a review January 22, 2025 01:40
long = "write-default-config",
help = "Writes the default configuration to the specified file and exits."
)]
pub write_default_config: bool,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to create the config file at the time of the first execution.

src/main.rs Outdated
long_help = "
Specifies the path to the configuration file.
",
default_value = "~/.config/jnv/config.toml",
Copy link
Owner

@ynqa ynqa Jan 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about using directories-rs for default? I want to manage the optimal directory for each platform.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easy enough

@ynqa
Copy link
Owner

ynqa commented Jan 25, 2025

@lanej Thank you for your contribution. I’m sorry for the delayed review, and I’ve left a few comments.

default_value = "~/.config/jnv/config.toml",
value_parser = |x: &str| Ok::<String, std::convert::Infallible>(shellexpand::tilde(x).into_owned()),
)]
pub config_file: String,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’d like to place an example of the actual configuration file somewhere (in examples/?).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea

- Bump versions for various dependencies in Cargo.lock
- Add `dirs` crate to Cargo.toml
- Remove `shellexpand` crate from Cargo.toml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: configure keymap/colors
2 participants