mirror of https://github.com/helix-editor/helix
Merge remote-tracking branch 'origin/master' into debug
commit
c7759a5aa0
@ -0,0 +1,92 @@
|
|||||||
|
use std::path::{Component, Path, PathBuf};
|
||||||
|
|
||||||
|
/// Replaces users home directory from `path` with tilde `~` if the directory
|
||||||
|
/// is available, otherwise returns the path unchanged.
|
||||||
|
pub fn fold_home_dir(path: &Path) -> PathBuf {
|
||||||
|
if let Ok(home) = super::home_dir() {
|
||||||
|
if path.starts_with(&home) {
|
||||||
|
// it's ok to unwrap, the path starts with home dir
|
||||||
|
return PathBuf::from("~").join(path.strip_prefix(&home).unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
path.to_path_buf()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Expands tilde `~` into users home directory if avilable, otherwise returns the path
|
||||||
|
/// unchanged. The tilde will only be expanded when present as the first component of the path
|
||||||
|
/// and only slash follows it.
|
||||||
|
pub fn expand_tilde(path: &Path) -> PathBuf {
|
||||||
|
let mut components = path.components().peekable();
|
||||||
|
if let Some(Component::Normal(c)) = components.peek() {
|
||||||
|
if c == &"~" {
|
||||||
|
if let Ok(home) = super::home_dir() {
|
||||||
|
// it's ok to unwrap, the path starts with `~`
|
||||||
|
return home.join(path.strip_prefix("~").unwrap());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
path.to_path_buf()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Normalize a path, removing things like `.` and `..`.
|
||||||
|
///
|
||||||
|
/// CAUTION: This does not resolve symlinks (unlike
|
||||||
|
/// [`std::fs::canonicalize`]). This may cause incorrect or surprising
|
||||||
|
/// behavior at times. This should be used carefully. Unfortunately,
|
||||||
|
/// [`std::fs::canonicalize`] can be hard to use correctly, since it can often
|
||||||
|
/// fail, or on Windows returns annoying device paths. This is a problem Cargo
|
||||||
|
/// needs to improve on.
|
||||||
|
/// Copied from cargo: <https://github.com/rust-lang/cargo/blob/070e459c2d8b79c5b2ac5218064e7603329c92ae/crates/cargo-util/src/paths.rs#L81>
|
||||||
|
pub fn get_normalized_path(path: &Path) -> PathBuf {
|
||||||
|
let path = expand_tilde(path);
|
||||||
|
let mut components = path.components().peekable();
|
||||||
|
let mut ret = if let Some(c @ Component::Prefix(..)) = components.peek().cloned() {
|
||||||
|
components.next();
|
||||||
|
PathBuf::from(c.as_os_str())
|
||||||
|
} else {
|
||||||
|
PathBuf::new()
|
||||||
|
};
|
||||||
|
|
||||||
|
for component in components {
|
||||||
|
match component {
|
||||||
|
Component::Prefix(..) => unreachable!(),
|
||||||
|
Component::RootDir => {
|
||||||
|
ret.push(component.as_os_str());
|
||||||
|
}
|
||||||
|
Component::CurDir => {}
|
||||||
|
Component::ParentDir => {
|
||||||
|
ret.pop();
|
||||||
|
}
|
||||||
|
Component::Normal(c) => {
|
||||||
|
ret.push(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the canonical, absolute form of a path with all intermediate components normalized.
|
||||||
|
///
|
||||||
|
/// This function is used instead of `std::fs::canonicalize` because we don't want to verify
|
||||||
|
/// here if the path exists, just normalize it's components.
|
||||||
|
pub fn get_canonicalized_path(path: &Path) -> std::io::Result<PathBuf> {
|
||||||
|
let path = if path.is_relative() {
|
||||||
|
std::env::current_dir().map(|current_dir| current_dir.join(path))?
|
||||||
|
} else {
|
||||||
|
path.to_path_buf()
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(get_normalized_path(path.as_path()))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_relative_path(path: &Path) -> PathBuf {
|
||||||
|
let path = if path.is_absolute() {
|
||||||
|
let cwdir = std::env::current_dir().expect("couldn't determine current directory");
|
||||||
|
path.strip_prefix(cwdir).unwrap_or(path)
|
||||||
|
} else {
|
||||||
|
path
|
||||||
|
};
|
||||||
|
fold_home_dir(path)
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
# Author: Shafkath Shuhan <shafkathshuhannyc@gmail.com>
|
||||||
|
|
||||||
|
"namespace" = { fg = "type" }
|
||||||
|
"module" = { fg = "type" }
|
||||||
|
|
||||||
|
"type" = { fg = "type" }
|
||||||
|
"type.builtin" = { fg = "#66D9EF" }
|
||||||
|
"type.enum.variant" = { fg = "text" }
|
||||||
|
"constructor" = { fg = "text" }
|
||||||
|
"property" = { fg = "variable" }
|
||||||
|
|
||||||
|
"keyword" = { fg = "keyword" }
|
||||||
|
"keyword.directive" = { fg = "keyword" }
|
||||||
|
"keyword.control" = { fg = "keyword" }
|
||||||
|
"label" = { fg = "keyword" }
|
||||||
|
|
||||||
|
"special" = { fg = "keyword" }
|
||||||
|
"operator" = { fg = "text" }
|
||||||
|
|
||||||
|
"punctuation" = { fg = "text" }
|
||||||
|
"punctuation.delimiter" = { fg = "text" }
|
||||||
|
|
||||||
|
"variable" = { fg = "variable" }
|
||||||
|
"variable.parameter" = { fg = "#fd971f" }
|
||||||
|
"variable.builtin" = { fg = "keyword" }
|
||||||
|
"constant" = { fg = "variable" }
|
||||||
|
"constant.builtin" = { fg = "#ae81ff" }
|
||||||
|
|
||||||
|
"function" = { fg = "fn_declaration" }
|
||||||
|
"function.builtin" = { fg = "fn_declaration" }
|
||||||
|
"function.macro" = { fg = "keyword" }
|
||||||
|
"attribute" = { fg = "fn_declaration" }
|
||||||
|
|
||||||
|
"comment" = { fg = "#88846F" }
|
||||||
|
|
||||||
|
"string" = { fg = "#e6db74" }
|
||||||
|
"number" = { fg = "#ae81ff" }
|
||||||
|
"escape" = { fg = "#ae81ff" }
|
||||||
|
|
||||||
|
"ui.background" = { fg = "text", bg = "background" }
|
||||||
|
|
||||||
|
"ui.window" = { bg = "widget" }
|
||||||
|
"ui.popup" = { bg = "widget" }
|
||||||
|
"ui.help" = { bg = "widget" }
|
||||||
|
"ui.menu.selected" = { bg = "widget" }
|
||||||
|
|
||||||
|
"ui.cursor" = { fg = "cursor", modifiers = ["reversed"] }
|
||||||
|
"ui.cursor.primary" = { fg = "cursor", modifiers = ["reversed"] }
|
||||||
|
"ui.cursor.match" = { fg = "#888888", modifiers = ["reversed"] }
|
||||||
|
|
||||||
|
"ui.selection" = { bg = "#878b91" }
|
||||||
|
"ui.selection.primary" = { bg = "#575b61" }
|
||||||
|
|
||||||
|
"ui.linenr" = { fg = "#90908a" }
|
||||||
|
"ui.linenr.selected" = { fg = "#c2c2bf" }
|
||||||
|
|
||||||
|
"ui.statusline" = { fg = "active_text", bg = "#75715e" }
|
||||||
|
"ui.statusline.inactive" = { fg = "active_text", bg = "#75715e" }
|
||||||
|
|
||||||
|
"ui.text" = { fg = "text", bg = "background" }
|
||||||
|
"ui.text.focus" = { fg = "active_text" }
|
||||||
|
|
||||||
|
"warning" = { fg = "#cca700" }
|
||||||
|
"error" = { fg = "#f48771" }
|
||||||
|
"info" = { fg = "#75beff" }
|
||||||
|
"hint" = { fg = "#eeeeeeb3" }
|
||||||
|
|
||||||
|
diagnostic = { modifiers = ["underlined"] }
|
||||||
|
|
||||||
|
[palette]
|
||||||
|
type = "#A6E22E"
|
||||||
|
keyword = "#F92672"
|
||||||
|
regex = "#CE9178"
|
||||||
|
special = "#C586C0"
|
||||||
|
variable = "#F8F8F2"
|
||||||
|
fn_declaration = "#A6E22E"
|
||||||
|
|
||||||
|
background = "#272822"
|
||||||
|
text = "#f8f8f2"
|
||||||
|
active_text = "#ffffff"
|
||||||
|
cursor = "#a6a6a6"
|
||||||
|
inactive_cursor = "#878b91"
|
||||||
|
widget = "#1e1f1c"
|
Loading…
Reference in New Issue