From 6745321eeb104eba6a8b6eaf08a4544a89359856 Mon Sep 17 00:00:00 2001 From: Tassilo Horn Date: Sun, 10 Apr 2022 10:22:58 +0200 Subject: [PATCH] Some renaming --- swayr/src/shared/fmt.rs | 26 +++++++++++++------------- swayr/src/tree.rs | 4 ++-- swayrbar/src/module/battery.rs | 4 ++-- swayrbar/src/module/sysinfo.rs | 4 ++-- swayrbar/src/module/window.rs | 4 ++-- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/swayr/src/shared/fmt.rs b/swayr/src/shared/fmt.rs index f317069..e9ef6bd 100644 --- a/swayr/src/shared/fmt.rs +++ b/swayr/src/shared/fmt.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 = 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(), diff --git a/swayr/src/tree.rs b/swayr/src/tree.rs index edbe3e0..5362bdd 100644 --- a/swayr/src/tree.rs +++ b/swayr/src/tree.rs @@ -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), diff --git a/swayrbar/src/module/battery.rs b/swayrbar/src/module/battery.rs index 036c775..9dc3b4e 100644 --- a/swayrbar/src/module/battery.rs +++ b/swayrbar/src/module/battery.rs @@ -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(), diff --git a/swayrbar/src/module/sysinfo.rs b/swayrbar/src/module/sysinfo.rs index 7e74f56..7c6ee3e 100644 --- a/swayrbar/src/module/sysinfo.rs +++ b/swayrbar/src/module/sysinfo.rs @@ -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, diff --git a/swayrbar/src/module/window.rs b/swayrbar/src/module/window.rs index 4b2d81e..c13d19f 100644 --- a/swayrbar/src/module/window.rs +++ b/swayrbar/src/module/window.rs @@ -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,