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

Move config directory #126

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions THEMES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ default on light terminal:
![](assets/light-theme.png)

to change the colors of the program you have to modify `theme.ron` file
[Ron format](https://github.com/ron-rs/ron) located at config path (same as [log path](README.md#diagnostics)).
[Ron format](https://github.com/ron-rs/ron) located at config path. The path differs depending on the operating system:

* `$HOME/Library/Preferences/gitui/theme.ron` (mac)
* `$XDG_CONFIG_HOME/gitui/theme.ron` (linux using XDG)
* `$HOME/.config/gitui/theme.ron` (linux)

Valid colors can be found in [ColorDef](./src/ui/style.rs#ColorDef) struct. note that rgb colors might not be supported
in every terminal.
in every terminal.
35 changes: 33 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ fn main() -> Result<()> {
return Ok(());
}

// TODO: To be removed in a future version, when upgrading from 0.6.x or earlier is unlikely
migrate_config()?;

setup_terminal()?;
defer! {
shutdown_terminal().expect("shutdown failed");
Expand Down Expand Up @@ -202,7 +205,26 @@ fn start_terminal<W: Write>(
Ok(terminal)
}

fn get_app_config_path() -> Result<PathBuf> {
fn migrate_config() -> Result<()> {
let cache_path: PathBuf = get_app_cache_path()?;

let entries = cache_path
.read_dir()?
.flat_map(|dir_entry| dir_entry)
.filter(|entry| {
!entry.file_name().to_string_lossy().ends_with(".log")
});

for entry in entries {
let mut config_path: PathBuf = get_app_config_path()?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

one minor thing: we can move out the call to get_app_config_path outside the loop and keep using a clone of it. just pushed that: c6eb066

config_path.push(entry.file_name());
fs::rename(entry.path(), config_path)?;
}

Ok(())
}

fn get_app_cache_path() -> Result<PathBuf> {
let mut path = dirs::cache_dir()
.ok_or_else(|| anyhow!("failed to find os cache dir."))?;

Expand All @@ -211,8 +233,17 @@ fn get_app_config_path() -> Result<PathBuf> {
Ok(path)
}

fn get_app_config_path() -> Result<PathBuf> {
let mut path = dirs::config_dir()
.ok_or_else(|| anyhow!("failed to find os config dir."))?;

path.push("gitui");
fs::create_dir_all(&path)?;
Ok(path)
}

fn setup_logging() -> Result<()> {
let mut path = get_app_config_path()?;
let mut path = get_app_cache_path()?;
path.push("gitui.log");

let _ = WriteLogger::init(
Expand Down