Some renaming

main
Tassilo Horn 3 years ago
parent e15386ad8f
commit 6745321eeb
  1. 26
      swayr/src/shared/fmt.rs
  2. 4
      swayr/src/tree.rs
  3. 4
      swayrbar/src/module/battery.rs
  4. 4
      swayrbar/src/module/sysinfo.rs
  5. 4
      swayrbar/src/module/window.rs

@ -120,7 +120,7 @@ impl FormatArgument for FmtArg {
}
}
pub fn do_format(fmt: &str, arg: FmtArg, clipped_str: &str) -> String {
pub fn rt_format(fmt: &str, arg: FmtArg, clipped_str: &str) -> String {
let arg_string = arg.to_string();
if let Ok(pf) = ParsedFormat::parse(fmt, &[arg], &NoNamedArguments) {
@ -145,21 +145,21 @@ fn remove_last_n_chars(s: &mut String, n: usize) {
#[test]
fn test_format() {
assert_eq!(do_format("{:.10}", FmtArg::from("sway"), ""), "sway");
assert_eq!(do_format("{:.10}", FmtArg::from("sway"), "…"), "sway");
assert_eq!(do_format("{:.4}", FmtArg::from("𝔰𝔴𝔞𝔶"), "……"), "𝔰𝔴𝔞𝔶");
assert_eq!(rt_format("{:.10}", FmtArg::from("sway"), ""), "sway");
assert_eq!(rt_format("{:.10}", FmtArg::from("sway"), "…"), "sway");
assert_eq!(rt_format("{:.4}", FmtArg::from("𝔰𝔴𝔞𝔶"), "……"), "𝔰𝔴𝔞𝔶");
assert_eq!(do_format("{:.3}", FmtArg::from("sway"), ""), "swa");
assert_eq!(do_format("{:.3}", FmtArg::from("sway"), "…"), "sw…");
assert_eq!(rt_format("{:.3}", FmtArg::from("sway"), ""), "swa");
assert_eq!(rt_format("{:.3}", FmtArg::from("sway"), "…"), "sw…");
assert_eq!(
do_format("{:.5}", FmtArg::from("𝔰𝔴𝔞𝔶 𝔴𝔦𝔫𝔡𝔬𝔴"), "…?"),
rt_format("{:.5}", FmtArg::from("𝔰𝔴𝔞𝔶 𝔴𝔦𝔫𝔡𝔬𝔴"), "…?"),
"𝔰𝔴𝔞…?"
);
assert_eq!(
do_format("{:.5}", FmtArg::from("sway window"), "..."),
rt_format("{:.5}", FmtArg::from("sway window"), "..."),
"sw..."
);
assert_eq!(do_format("{:.2}", FmtArg::from("sway"), "..."), "...");
assert_eq!(rt_format("{:.2}", FmtArg::from("sway"), "..."), "...");
}
pub static PLACEHOLDER_RX: Lazy<Regex> = Lazy::new(|| {
@ -202,7 +202,7 @@ pub fn maybe_html_escape(do_it: bool, text: String) -> String {
}
}
macro_rules! format_placeholders {
macro_rules! subst_placeholders {
( $fmt_str:expr, $html_escape:expr,
{ $( $($pat:pat_param)|+ => $exp:expr, )+ }
) => {
@ -229,13 +229,13 @@ macro_rules! format_placeholders {
};
}
pub(crate) use format_placeholders;
pub(crate) use subst_placeholders;
#[test]
fn test_format_placeholders() {
fn test_subst_placeholders() {
let foo = "{a}, {b} = {d}";
let html_escape = true;
let x: String = format_placeholders!(foo, html_escape, {
let x: String = subst_placeholders!(foo, html_escape, {
"a" => "1".to_string(),
"b" | "d" => "2".to_string(),
"c" => "3".to_owned(),

@ -16,7 +16,7 @@
//! Convenience data structures built from the IPC structs.
use crate::config;
use crate::shared::fmt::format_placeholders;
use crate::shared::fmt::subst_placeholders;
use crate::shared::ipc;
use crate::shared::ipc::NodeMethods;
use crate::util;
@ -370,7 +370,7 @@ impl DisplayFormat for DisplayNode<'_> {
.as_str(),
);
format_placeholders!(&fmt, html_escape, {
subst_placeholders!(&fmt, html_escape, {
"id" => self.node.id,
"app_name" => self.node.get_app_name(),
"layout" => format!("{:?}", self.node.layout),

@ -17,7 +17,7 @@
use crate::config;
use crate::module::BarModuleFn;
use crate::shared::fmt::format_placeholders;
use crate::shared::fmt::subst_placeholders;
use battery as bat;
use std::collections::HashSet;
use std::sync::Mutex;
@ -95,7 +95,7 @@ fn refresh_state(state: &mut State) {
}
fn get_text(fmt: &str, html_escape: bool, state: &State) -> String {
format_placeholders!(fmt, html_escape, {
subst_placeholders!(fmt, html_escape, {
"state_of_charge" => state.state_of_charge,
"state_of_health" => state.state_of_health,
"state" => state.state.as_str(),

@ -17,7 +17,7 @@
use crate::config;
use crate::module::BarModuleFn;
use crate::shared::fmt::format_placeholders;
use crate::shared::fmt::subst_placeholders;
use std::collections::HashMap;
use std::sync::Mutex;
use std::sync::Once;
@ -105,7 +105,7 @@ fn refresh_state(sys: &mut si::System, state: &mut State) {
}
fn get_text(fmt: &str, html_escape: bool, state: &State) -> String {
format_placeholders!(fmt, html_escape, {
subst_placeholders!(fmt, html_escape, {
"cpu_usage" => state.cpu_usage,
"mem_usage" => state.mem_usage,
"load_avg_1" => state.load_avg_1,

@ -20,7 +20,7 @@ use std::sync::Mutex;
use crate::config;
use crate::module::BarModuleFn;
use crate::shared::fmt::format_placeholders;
use crate::shared::fmt::subst_placeholders;
use crate::shared::ipc;
use crate::shared::ipc::NodeMethods;
use swaybar_types as s;
@ -54,7 +54,7 @@ fn refresh_state(state: &mut State) {
}
fn subst_placeholders(s: &str, html_escape: bool, state: &State) -> String {
format_placeholders!(s, html_escape, {
subst_placeholders!(s, html_escape, {
"title" | "name" => state.name.clone(),
"app_name" => state.app_name.clone(),
"pid" => state.pid,

Loading…
Cancel
Save