Skip to content

Commit

Permalink
Merge pull request #31 from Shizcow/develop
Browse files Browse the repository at this point in the history
Release 5.4.0
  • Loading branch information
Shizcow authored Jul 26, 2020
2 parents 869e400 + 33290a6 commit 28e523c
Show file tree
Hide file tree
Showing 34 changed files with 565 additions and 166 deletions.
2 changes: 1 addition & 1 deletion config.mk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = 5.3.1
VERSION = 5.4.0

# paths
PREFIX = /usr/local
Expand Down
2 changes: 1 addition & 1 deletion makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ stest:
scaffold:
mkdir -p target
mkdir -p target/build
> target/build/deps.toml
touch target/build/deps.toml
$(MAKE) m4 # second round will finish deps

m4:
Expand Down
7 changes: 5 additions & 2 deletions src/build/CargoSource.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,21 @@ clipboard = "0.5"
itertools = "0.9"
lazy_static = "1.4.0"
libc = "0.2.69"
overrider = "0.6.1"
overrider = "^0.7.0"
pledge = "0.4.0"
regex = "1.3.7"
rustc_version_runtime = "0.2.0"
servo-fontconfig = "0.5.0"
unicode-segmentation = "1.6.0"
yaml-rust = "^0.3" # clap uses yaml-rust too, so Cargo will figure out the proper version
x11 = "2.18.2"
include(target/build/deps.toml) #m4

[build-dependencies]
overrider_build = "0.5.1"
overrider_build = "^0.7.0"
proc_use = "^0.2.1"
yaml-rust = "^0.3"
termcolor = "1.1"

[features]
Xinerama = []
Expand Down
14 changes: 14 additions & 0 deletions src/build/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ use std::fs::File;
use std::io::Read;
use proc_use::UseBuilder;

#[path = "../config/src/util.rs"]
mod util;

fn main() {
let build_path_str = "../../target/build";

let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let build_path = PathBuf::from(build_path_str);
println!("cargo:rustc-env=BUILD_DIR={}", build_path_str);

println!("cargo:rerun-if-changed={}", build_path.join("watch_files").canonicalize().unwrap().display().to_string());
println!("cargo:rerun-if-env-changed=PLUGINS");

// grab the list of plugins and aliases
let mut plugin_file = File::open(build_path.join("watch_files")).unwrap();
Expand Down Expand Up @@ -38,6 +44,14 @@ fn main() {
usebuilder
.write_to_file_all(out_path.join("proc_mod_plugin.rs"));

// if plugin files are changed without modifying anything else,
// sometimes overrider needs to be ran again
let plugins = util::get_selected_plugin_list();
for plugin in plugins{
let mut plugin_yaml = util::get_yaml(&format!("../plugins/{}/plugin.yml", plugin), Some(&plugin));
println!("cargo:rerun-if-changed=../plugins/{}/{}", plugin, util::get_yaml_top_level(&mut plugin_yaml, "entry").unwrap());
}

// link libs
if cfg!(feature = "Xinerama") {
println!("cargo:rustc-link-lib=Xinerama");
Expand Down
12 changes: 6 additions & 6 deletions src/config/src/checkdeps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,33 @@ else
fi

printf "Checking for X11 headers... "
if test -f "/usr/include/X11/Xlib.h";
if $CC -c ../../headers/src/xlib.h -o /dev/null;
then
echo "yes"
else
echo "no"
>&2 echo "Build-time dependency /usr/include/X11/Xlib.h is not present. Install the xorg development packages"
>&2 echo "Build-time dependency <X11/Xlib.h> is not present. Install the xorg development packages"
FAILED=1
fi

printf "Checking for fontconfig headers... "
if test -f "/usr/include/fontconfig/fontconfig.h";
if $CC -c ../../headers/src/fontconfig.h -o /dev/null;
then
echo "yes"
else
echo "no"
>&2 echo "Build-time dependency /usr/include/fontconfig/fontconfig.h is not present. Install fontconfig packages"
>&2 echo "Build-time dependency <fontconfig/fontconfig.h> is not present. Install fontconfig packages"
FAILED=1
fi

if [ "$XINERAMA" = "true" ]; then
printf "Checking for xinerama headers... "
if test -f "/usr/include/X11/extensions/Xinerama.h";
if $CC -c ../../headers/src/xinerama.h -o /dev/null;
then
echo "yes"
else
echo "no"
>&2 echo "Build-time dependency /usr/include/X11/extensions/Xinerama.h is not present. Install xinerama package(s) or disable the feature in config.mk"
>&2 echo "Build-time dependency <extensions/Xinerama.h> is not present. Install xinerama package(s) or disable the feature in config.mk"
FAILED=1
fi
fi
Expand Down
16 changes: 12 additions & 4 deletions src/config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,19 @@ fn main() {
// 2) proc_use import files
// 3) overrider watch files
// 4) Cargo.toml<dmenu-build> plugin dependencies
// 5) manpage (used later)
let mut watch_globs = Vec::new();
let mut deps_vec = Vec::new();
let mut manpage = Manpage::new("dmenu", &env::var("VERSION").unwrap(), 1);

// prepare to edit cli_base args
let mut yaml = get_yaml("dmenu/cli_base.yml");
let mut yaml = get_yaml("dmenu/cli_base.yml", None);
let yaml_args: &mut Vec<yaml::Yaml> = get_yaml_args(&mut yaml).unwrap();

// For every plugin, check if it has arguements. If so, add them to clap and overrider
// While we're here, set proc_use to watch the plugin entry points
for plugin in plugins {
let mut plugin_yaml = get_yaml(&format!("plugins/{}/plugin.yml", plugin));
let mut plugin_yaml = get_yaml(&format!("plugins/{}/plugin.yml", plugin), Some(&plugin));

if let Some(plugin_yaml_args) = get_yaml_args(&mut plugin_yaml) {
yaml_args.append(plugin_yaml_args);
Expand Down Expand Up @@ -67,6 +69,10 @@ fn main() {
build_failed = true;
}
}

if let Some(desc) = get_yaml_top_level(&mut plugin_yaml, "about") {
manpage.plugin(plugin, desc.to_string());
}
}
if build_failed {
std::process::exit(1);
Expand All @@ -79,7 +85,6 @@ fn main() {
}

// Now that cli is built, generate manpage
let mut manpage = Manpage::new("dmenu", &env::var("CARGO_PKG_VERSION").unwrap(), 1);
manpage.desc_short("dynamic menu")
.description("dmenu",
"is a dynamic menu for X, which reads a list of newline\\-separated \
Expand All @@ -91,7 +96,10 @@ fn main() {
"is a script used by\n\
.IR dwm (1)\n\
which lists programs in the user's $PATH and runs the result in \
their $SHELL.");
their $SHELL. It is kept here for compatibility; j4-dmenu-desktop \
is the recommended alternative."
).build("This dmenu is dmenu-rs, a rewrite of dmenu in rust. It's faster and more \
flexible.");

for arg in yaml_args {
let hash = match arg {
Expand Down
2 changes: 1 addition & 1 deletion src/config/src/list_plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ fn main() {
.file_name().unwrap()
.to_str() .unwrap()
.to_string();
let mut plugin_yaml = get_yaml(&path.display().to_string());
let mut plugin_yaml = get_yaml(&path.display().to_string(), None);
let about = get_yaml_top_level(&mut plugin_yaml, "about").unwrap();

table.add_row(Row::new(vec![
Expand Down
35 changes: 27 additions & 8 deletions src/config/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,40 @@ pub fn get_selected_plugin_list() -> Vec<String> {
└─────────────────────────────────┘\
\n\n");
if plugins_str.len() > 0 {
plugins_str
plugins_str.trim()
.split(" ").map(|s| s.to_string()).collect()
} else {
Vec::new()
}
}

pub fn get_yaml(file: &str) -> Yaml {
let mut base = File::open(file).expect(file);
let mut yaml_str = String::new();
if let Err(err) = base.read_to_string(&mut yaml_str) {
panic!("Could not read yaml base file {}", err);
pub fn get_yaml(file: &str, plugin: Option<&str>) -> Yaml {
match File::open(file) {
Ok(mut base) => {
let mut yaml_str = String::new();
if let Err(err) = base.read_to_string(&mut yaml_str) {
panic!("Could not read yaml base file {}", err);
}
yaml_str = yaml_str.replace("$VERSION", &env!("VERSION"));
YamlLoader::load_from_str(&yaml_str).unwrap().swap_remove(0)
},
Err(err) => {
if let Some(plugin_name) = plugin {
let mut stdout = StandardStream::stdout(ColorChoice::Always);
stdout.set_color(ColorSpec::new().set_fg(Some(Color::Red)))
.expect("Could not get stdout");
println!("Could not find plugin '{}'. Perhaps it's invalid? \
Double check config.mk"
, plugin_name);
stdout.set_color(&ColorSpec::new())
.expect("Could not get stdout");
println!(""); // make sure colors are flushed
std::process::exit(1);
} else {
panic!("{}", err);
}
},
}
yaml_str = yaml_str.replace("$VERSION", &env!("VERSION"));
YamlLoader::load_from_str(&yaml_str).unwrap().swap_remove(0)
}


Expand Down
75 changes: 60 additions & 15 deletions src/dmenu/clapflags.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use clap::{ArgMatches, App};
use itertools::Itertools;
use yaml_rust::yaml::Yaml;
use regex::RegexBuilder;

use crate::config::{Clrs::*, Schemes::*, Config, DefaultWidth};

use crate::result::*;

lazy_static::lazy_static! {
static ref YAML: Yaml = {
Expand All @@ -15,11 +16,41 @@ lazy_static::lazy_static! {
pub static ref CLAP_FLAGS: ArgMatches<'static> = App::from_yaml(&YAML).get_matches();
}

pub fn validate(config: &mut Config) -> Result<(), String> {
pub fn validate(config: &mut Config) -> CompResult<()> {

if CLAP_FLAGS.occurrences_of("version") > 2 {
eprintln!("More than 2 version flags do nothing special");
}
if CLAP_FLAGS.occurrences_of("version") == 1 {
return Die::stdout(format!("dmenu-rs {}", env!("VERSION")));
}
if CLAP_FLAGS.occurrences_of("version") >= 2 {
let plugins = env!("PLUGINS");
if plugins.len() == 0 {
return Die::stdout(format!("dmenu-rs {}\n\
Compiled with rustc {}\n\
Compiled without plugins",
env!("VERSION"),
rustc_version_runtime::version(),
));
} else {
return Die::stdout(format!("dmenu-rs {}\n\
Compiled with rustc {}\n\
Compiled with plugins:\n\
{}",
env!("VERSION"),
rustc_version_runtime::version(),
plugins.split(" ")
.map(|p| format!("- {}", p))
.join("\n"),
));
}
}

let color_regex = RegexBuilder::new("^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})\0$")
.case_insensitive(true)
.build().map_err(|_| format!("Could not build regex"))?;
.build().map_err(|_| Die::Stderr("Could not build regex"
.to_owned()))?;

// bottom
if CLAP_FLAGS.occurrences_of("bottom") == 1 {
Expand All @@ -39,13 +70,15 @@ pub fn validate(config: &mut Config) -> Result<(), String> {
// lines
if let Some(lines) = CLAP_FLAGS.value_of("lines") {
config.lines = lines.parse::<u32>()
.map_err(|_| format!("-l: Lines must be a non-negaitve integer"))?;
.map_err(|_| Die::Stderr("-l: Lines must be a non-negaitve integer"
.to_owned()))?;
}

// monitor
if let Some(monitor) = CLAP_FLAGS.value_of("monitor") {
config.mon = monitor.parse::<i32>()
.map_err(|_| format!("-m: Monitor must be a non-negaitve integer"))?;
.map_err(|_| Die::Stderr("-m: Monitor must be a non-negaitve integer"
.to_owned()))?;
}

// prompt
Expand All @@ -65,7 +98,8 @@ pub fn validate(config: &mut Config) -> Result<(), String> {
let mut color = color.to_string();
color.push('\0');
color_regex.find_iter(&color).nth(0)
.ok_or(format!("--nb: Color must be in hex format (#123456 or #123)"))?;
.ok_or(Die::Stderr("--nb: Color must be in hex format (#123456 or #123)"
.to_owned()))?;
config.colors[SchemeNorm as usize][ColBg as usize]
.copy_from_slice(color.as_bytes());
}
Expand All @@ -75,7 +109,8 @@ pub fn validate(config: &mut Config) -> Result<(), String> {
let mut color = color.to_string();
color.push('\0');
color_regex.find_iter(&color).nth(0)
.ok_or(format!("--nf: Color must be in hex format (#123456 or #123)"))?;
.ok_or(Die::Stderr("--nf: Color must be in hex format (#123456 or #123)"
.to_owned()))?;
config.colors[SchemeNorm as usize][ColFg as usize]
.copy_from_slice(color.as_bytes());
}
Expand All @@ -85,7 +120,8 @@ pub fn validate(config: &mut Config) -> Result<(), String> {
let mut color = color.to_string();
color.push('\0');
color_regex.find_iter(&color).nth(0)
.ok_or(format!("--sb: Color must be in hex format (#123456 or #123)"))?;
.ok_or(Die::Stderr("--sb: Color must be in hex format (#123456 or #123)"
.to_owned()))?;
config.colors[SchemeSel as usize][ColBg as usize]
.copy_from_slice(color.as_bytes());
}
Expand All @@ -95,22 +131,31 @@ pub fn validate(config: &mut Config) -> Result<(), String> {
let mut color = color.to_string();
color.push('\0');
color_regex.find_iter(&color).nth(0)
.ok_or(format!("--sf: Color must be in hex format (#123456 or #123)"))?;
.ok_or(Die::Stderr("--sf: Color must be in hex format (#123456 or #123)"
.to_owned()))?;
config.colors[SchemeSel as usize][ColFg as usize]
.copy_from_slice(color.as_bytes());
}

// window
if let Some(window) = CLAP_FLAGS.value_of("window") {
config.embed = window.parse::<u64>()
.map_err(|_| format!("-w: Window ID must be a valid X window ID string"))?;
.map_err(|_| Die::Stderr("-w: Window ID must be a valid X window ID string"
.to_owned()))?;
}

// nostdin
if CLAP_FLAGS.occurrences_of("nostdin") == 1 {
config.nostdin = true;
}

// render_minheight
if let Some(minheight) = CLAP_FLAGS.value_of("render_minheight") {
config.render_minheight = minheight.parse::<u32>()
.map_err(|_| Die::Stderr("--render_minheight: Height must be an integet number of \
pixels".to_owned()))?;
}

// render_overrun
if CLAP_FLAGS.occurrences_of("render_overrun") == 1 {
config.render_overrun = true;
Expand All @@ -137,18 +182,18 @@ pub fn validate(config: &mut Config) -> Result<(), String> {
config.render_rightalign = true;
DefaultWidth::Max
},
_ => return Err(format!("--render_default_width: invalid arguement")),
_ => return Die::stderr("--render_default_width: invalid arguement".to_owned()),
}
} else {
let vec: Vec<&str> = arg.split("=").collect();
if vec.len() != 2 || (vec.len() > 0 && vec[0] != "custom") {
return Err(format!("Incorrect format for --render_default_width, \
see help for details"));
return Die::stderr("Incorrect format for --render_default_width, \
see help for details".to_owned());
}
let width = vec[1].parse::<u8>();
if width.is_err() || *width.as_ref().unwrap() > 100 {
return Err(format!("--render_default_width: custom width \
must be a positive integer"));
return Die::stderr("--render_default_width: custom width \
must be a positive integer".to_owned());
}
config.render_default_width = DefaultWidth::Custom(width.unwrap());
}
Expand Down
Loading

0 comments on commit 28e523c

Please sign in to comment.