forked from mirrors/rmenu
Compare commits
7 Commits
feat/v1.1.
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
5fb9aa6863 | ||
|
64fdbaafc4 | ||
018a98d7bc | |||
2c71f4ad2b | |||
|
aed276b104 | ||
|
ecacad55bc | ||
|
9e736ccd07 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -3138,7 +3138,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rmenu"
|
name = "rmenu"
|
||||||
version = "1.1.0"
|
version = "1.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cached 0.44.0",
|
"cached 0.44.0",
|
||||||
"clap",
|
"clap",
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
body {
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
.navbar {
|
.navbar {
|
||||||
width: 0;
|
width: 0;
|
||||||
@ -9,6 +12,10 @@
|
|||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|
||||||
|
height: 100vh;
|
||||||
|
min-height: 100vh;
|
||||||
|
overflow-y: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.result {
|
.result {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "rmenu"
|
name = "rmenu"
|
||||||
version = "1.1.0"
|
version = "1.1.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
@ -1,19 +1,19 @@
|
|||||||
|
|
||||||
body {
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
body > div {
|
|
||||||
height: -webkit-fill-available;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
html,
|
html,
|
||||||
body,
|
body,
|
||||||
.content {
|
.content {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
body {
|
||||||
|
overflow: hidden;
|
||||||
|
padding-top: 60px;
|
||||||
|
}
|
||||||
|
|
||||||
|
body>div {
|
||||||
|
height: -webkit-fill-available;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
.navbar {
|
.navbar {
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
@ -23,9 +23,10 @@ body,
|
|||||||
}
|
}
|
||||||
|
|
||||||
.results {
|
.results {
|
||||||
height: 100vh;
|
|
||||||
margin-top: 50px;
|
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
height: calc(100vh - 60px);
|
||||||
|
min-height: calc(100vh - 60px);
|
||||||
|
scroll-margin-top: 60px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.selected {
|
.selected {
|
||||||
@ -43,19 +44,21 @@ input {
|
|||||||
height: 5vw;
|
height: 5vw;
|
||||||
border: none;
|
border: none;
|
||||||
outline: none;
|
outline: none;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
font-size: large;
|
font-size: large;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Result CSS */
|
/* Result CSS */
|
||||||
|
|
||||||
.result, .action {
|
.result,
|
||||||
|
.action {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: left;
|
justify-content: left;
|
||||||
}
|
}
|
||||||
|
|
||||||
.result > div, .action > div {
|
.result>div,
|
||||||
|
.action>div {
|
||||||
margin: 2px 5px;
|
margin: 2px 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,15 +3,11 @@ use std::fs;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use rmenu_plugin::Entry;
|
use rmenu_plugin::Entry;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::config::{CacheSetting, PluginConfig};
|
use crate::config::{CacheSetting, PluginConfig};
|
||||||
use crate::CONFIG_DIR;
|
use crate::XDG_PREFIX;
|
||||||
|
|
||||||
static CONFIG_PATH: Lazy<PathBuf> =
|
|
||||||
Lazy::new(|| PathBuf::from(shellexpand::tilde(CONFIG_DIR).to_string()));
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum CacheError {
|
pub enum CacheError {
|
||||||
@ -29,7 +25,10 @@ pub enum CacheError {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cache_file(name: &str) -> PathBuf {
|
fn cache_file(name: &str) -> PathBuf {
|
||||||
CONFIG_PATH.join(format!("{name}.cache"))
|
xdg::BaseDirectories::with_prefix(XDG_PREFIX)
|
||||||
|
.expect("Failed to read xdg base dirs")
|
||||||
|
.place_cache_file(format!("{name}.cache"))
|
||||||
|
.expect("Failed to write xdg cache dirs")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read Entries from Cache (if Valid and Available)
|
/// Read Entries from Cache (if Valid and Available)
|
||||||
|
@ -10,7 +10,7 @@ use rmenu_plugin::{Entry, Message};
|
|||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
use crate::config::{cfg_replace, Config, Keybind};
|
use crate::config::{cfg_replace, Config, Keybind};
|
||||||
use crate::{DEFAULT_CONFIG, DEFAULT_THEME};
|
use crate::{DEFAULT_CONFIG, DEFAULT_THEME, XDG_PREFIX};
|
||||||
|
|
||||||
/// Allowed Formats for Entry Ingestion
|
/// Allowed Formats for Entry Ingestion
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
@ -179,28 +179,37 @@ pub enum RMenuError {
|
|||||||
pub type Result<T> = std::result::Result<T, RMenuError>;
|
pub type Result<T> = std::result::Result<T, RMenuError>;
|
||||||
|
|
||||||
impl Args {
|
impl Args {
|
||||||
/// Find Configuration Path
|
/// Find a specifically named file across xdg config paths
|
||||||
pub fn find_config(&self) -> PathBuf {
|
fn find_xdg_file(&self, name: &str, base: &Option<PathBuf>) -> Option<String> {
|
||||||
self.config.clone().unwrap_or_else(|| {
|
return base
|
||||||
xdg::BaseDirectories::with_prefix("rmenu")
|
.clone()
|
||||||
.expect("Failed to read xdg base dirs")
|
.or_else(|| {
|
||||||
.find_config_file(DEFAULT_CONFIG)
|
xdg::BaseDirectories::with_prefix(XDG_PREFIX)
|
||||||
.unwrap_or_else(PathBuf::new)
|
.expect("Failed to read xdg base dirs")
|
||||||
})
|
.find_config_file(name)
|
||||||
|
})
|
||||||
|
.map(|f| {
|
||||||
|
let f = f.to_string_lossy().to_string();
|
||||||
|
shellexpand::tilde(&f).to_string()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load Configuration File
|
/// Load Configuration File
|
||||||
pub fn get_config(&self, path: &PathBuf) -> Result<Config> {
|
pub fn get_config(&self) -> Result<Config> {
|
||||||
let path = path.to_string_lossy().to_string();
|
let config = self.find_xdg_file(DEFAULT_CONFIG, &self.config);
|
||||||
let path = shellexpand::tilde(&path).to_string();
|
|
||||||
let config: Config = match read_to_string(path) {
|
if let Some(path) = config {
|
||||||
Ok(content) => serde_yaml::from_str(&content),
|
let config: Config = match read_to_string(path) {
|
||||||
Err(err) => {
|
Ok(content) => serde_yaml::from_str(&content),
|
||||||
log::error!("Failed to Load Config: {err:?}");
|
Err(err) => {
|
||||||
Ok(Config::default())
|
log::error!("Failed to Load Config: {err:?}");
|
||||||
}
|
Ok(Config::default())
|
||||||
}?;
|
}
|
||||||
Ok(config)
|
}?;
|
||||||
|
return Ok(config);
|
||||||
|
}
|
||||||
|
log::error!("Failed to Load Config: no file found in xdg config paths");
|
||||||
|
Ok(Config::default())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Update Configuration w/ CLI Specified Settings
|
/// Update Configuration w/ CLI Specified Settings
|
||||||
@ -242,17 +251,16 @@ impl Args {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Load CSS Theme or Default
|
/// Load CSS Theme or Default
|
||||||
pub fn get_theme(&self, cfgdir: &PathBuf) -> String {
|
pub fn get_theme(&self) -> String {
|
||||||
let theme = self.theme.clone().or(Some(cfgdir.join(DEFAULT_THEME)));
|
self.find_xdg_file(DEFAULT_THEME, &self.theme)
|
||||||
if let Some(theme) = theme {
|
.map(read_to_string)
|
||||||
let path = theme.to_string_lossy().to_string();
|
.map(|f| {
|
||||||
let path = shellexpand::tilde(&path).to_string();
|
f.unwrap_or_else(|err| {
|
||||||
match read_to_string(&path) {
|
log::error!("Failed to load CSS: {err:?}");
|
||||||
Ok(css) => return css,
|
String::new()
|
||||||
Err(err) => log::error!("Failed to load CSS: {err:?}"),
|
})
|
||||||
}
|
})
|
||||||
}
|
.unwrap_or_else(String::new)
|
||||||
String::new()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Load Additional CSS or Default
|
/// Load Additional CSS or Default
|
||||||
@ -260,9 +268,9 @@ impl Args {
|
|||||||
let css = self
|
let css = self
|
||||||
.css
|
.css
|
||||||
.clone()
|
.clone()
|
||||||
.or(c.css.as_ref().map(|s| PathBuf::from(s)));
|
.map(|s| s.to_string_lossy().to_string())
|
||||||
if let Some(css) = css {
|
.or(c.css.clone());
|
||||||
let path = css.to_string_lossy().to_string();
|
if let Some(path) = css {
|
||||||
let path = shellexpand::tilde(&path).to_string();
|
let path = shellexpand::tilde(&path).to_string();
|
||||||
match read_to_string(&path) {
|
match read_to_string(&path) {
|
||||||
Ok(css) => return css,
|
Ok(css) => return css,
|
||||||
|
@ -10,9 +10,9 @@ mod state;
|
|||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use rmenu_plugin::{self_exe, Entry};
|
use rmenu_plugin::{self_exe, Entry};
|
||||||
|
|
||||||
static CONFIG_DIR: &'static str = "~/.config/rmenu/";
|
|
||||||
static DEFAULT_THEME: &'static str = "style.css";
|
static DEFAULT_THEME: &'static str = "style.css";
|
||||||
static DEFAULT_CONFIG: &'static str = "config.yaml";
|
static DEFAULT_CONFIG: &'static str = "config.yaml";
|
||||||
|
static XDG_PREFIX: &'static str = "rmenu";
|
||||||
static DEFAULT_CSS_CONTENT: &'static str = include_str!("../public/default.css");
|
static DEFAULT_CSS_CONTENT: &'static str = include_str!("../public/default.css");
|
||||||
|
|
||||||
/// Application State for GUI
|
/// Application State for GUI
|
||||||
@ -43,8 +43,7 @@ fn main() -> cli::Result<()> {
|
|||||||
|
|
||||||
// parse cli and retrieve values for app
|
// parse cli and retrieve values for app
|
||||||
let mut cli = cli::Args::parse();
|
let mut cli = cli::Args::parse();
|
||||||
let mut cfgpath = cli.find_config();
|
let mut config = cli.get_config()?;
|
||||||
let mut config = cli.get_config(&cfgpath)?;
|
|
||||||
let entries = cli.get_entries(&mut config)?;
|
let entries = cli.get_entries(&mut config)?;
|
||||||
|
|
||||||
// update config based on cli-settings and entries
|
// update config based on cli-settings and entries
|
||||||
@ -55,10 +54,7 @@ fn main() -> cli::Result<()> {
|
|||||||
.any(|e| e.icon.is_some() || e.icon_alt.is_some());
|
.any(|e| e.icon.is_some() || e.icon_alt.is_some());
|
||||||
config.use_comments = config.use_comments && entries.iter().any(|e| e.comment.is_some());
|
config.use_comments = config.use_comments && entries.iter().any(|e| e.comment.is_some());
|
||||||
|
|
||||||
// retrieve cfgdir and get theme/css
|
let theme = cli.get_theme();
|
||||||
cfgpath.pop();
|
|
||||||
let cfgdir = cfgpath;
|
|
||||||
let theme = cli.get_theme(&cfgdir);
|
|
||||||
let css = cli.get_css(&config);
|
let css = cli.get_css(&config);
|
||||||
|
|
||||||
// genrate app context and run gui
|
// genrate app context and run gui
|
||||||
|
Loading…
Reference in New Issue
Block a user