cargo install swaybar_info
# The `swaybar_info` binary should be placed in $HOME/.cargo/bin/
-Put the following in your `~/.config/sway/config`:
+Put the following in your `~/.config/sway/config` (assuming the binary is at
+`$HOME/.config/sway/swaybar_info`):
bar {
position top
# This example gets battery info into the bar.
# Multiple args should be separated with "[SPLIT]".
# Note that the <args...> portion is optional.
+
+
+ # The following uses 24 hour time
+ #status_command $HOME/.config/sway/swaybar_info --time-format="%Y-%m-%d %R:%S"
}
## Dependencies
} else if arg.starts_with("--regex-cmd=") {
let (_, back) = arg.split_at(12);
regex_cmds.push(back.to_owned());
+ } else if arg.starts_with("--time-format=") {
+ let (_, back) = arg.split_at(14);
+ map.insert("time-format".into(), back.to_owned());
} else if arg == "--help" || arg == "-h" {
map.insert("help".into(), "".into());
} else {
b" --regex-cmd=<cmd>[SPLIT]<args...>[SPLIT]<regex>\tUse an output of a command as a metric\n",
)
.ok();
+ stderr_handle
+ .write_all(
+ b" --date-format=<date format string>\t\t\tSet the format string for the date\n",
+ )
+ .ok();
}
use std::time::Duration;
use swaybar_object::*;
+const DEFAULT_FMT_STRING: &str = "%F %r";
+
fn main() {
let args_result = args::get_args();
if args_result.map.contains_key("help") {
let batt_info_enabled: bool = args_result.map.contains_key("acpi-builtin");
let mut batt_info_error: bool = false;
+ let mut time_fmt_str = DEFAULT_FMT_STRING;
+ if let Some(s) = args_result.map.get("time-format") {
+ time_fmt_str = s;
+ }
+
println!(
"{}",
serde_json::to_string(&swaybar_object::SwaybarHeader::new())
// time
if is_empty {
- array.push_object(SwaybarObject::default());
+ let mut time_obj = SwaybarObject::new("current_time".to_owned());
+ time_obj.update_as_date(time_fmt_str);
+ array.push_object(time_obj);
} else if let Some(time_obj) = array.get_by_name_mut("current_time") {
- time_obj.update_as_date();
+ time_obj.update_as_date(time_fmt_str);
}
println!("{}", array);
self.color = Some("#88ff88ff".to_owned());
}
- pub fn update_as_date(&mut self) {
+ pub fn update_as_date(&mut self, format_str: &str) {
let current_time: DateTime<Local> = Local::now();
- let current_time = current_time.format("%F %r");
+ let current_time = current_time.format(format_str);
self.full_text = current_time.to_string();
self.color = None;
}
}
}
-impl Default for SwaybarObject {
- fn default() -> Self {
- let current_time: DateTime<Local> = Local::now();
- let current_time = current_time.format("%F %r");
- Self {
- full_text: current_time.to_string(),
- short_text: None,
- color: None,
- background: None,
- border: Some("#ffffffff".into()),
- border_top: None,
- border_bottom: None,
- border_left: None,
- border_right: None,
- min_width: None,
- align: None,
- name: Some("current_time".to_owned()),
- instance: None,
- urgent: None,
- separator: None,
- separator_block_width: None,
- markup: None,
- }
- }
-}
-
impl SwaybarArray {
pub fn new() -> Self {
Self {