summaryrefslogtreecommitdiffstats
path: root/src/components/utils/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/utils/mod.rs')
-rw-r--r--src/components/utils/mod.rs64
1 files changed, 32 insertions, 32 deletions
diff --git a/src/components/utils/mod.rs b/src/components/utils/mod.rs
index 6d1adb4f..ab45bbea 100644
--- a/src/components/utils/mod.rs
+++ b/src/components/utils/mod.rs
@@ -10,50 +10,50 @@ pub mod statustree;
/// It will show a popup in that case
#[macro_export]
macro_rules! try_or_popup {
- ($self:ident, $msg:literal, $e:expr) => {
- if let Err(err) = $e {
- ::log::error!("{} {}", $msg, err);
- $self.queue.push(InternalEvent::ShowErrorMsg(format!(
- "{}\n{}",
- $msg, err
- )));
- }
- };
+ ($self:ident, $msg:literal, $e:expr) => {
+ if let Err(err) = $e {
+ ::log::error!("{} {}", $msg, err);
+ $self.queue.push(InternalEvent::ShowErrorMsg(format!(
+ "{}\n{}",
+ $msg, err
+ )));
+ }
+ };
}
/// helper func to convert unix time since epoch to formated time string in local timezone
pub fn time_to_string(secs: i64, short: bool) -> String {
- let time = DateTime::<Local>::from(DateTime::<Utc>::from_utc(
- NaiveDateTime::from_timestamp(secs, 0),
- Utc,
- ));
- time.format(if short {
- "%Y-%m-%d"
- } else {
- "%Y-%m-%d %H:%M:%S"
- })
- .to_string()
+ let time = DateTime::<Local>::from(DateTime::<Utc>::from_utc(
+ NaiveDateTime::from_timestamp(secs, 0),
+ Utc,
+ ));
+ time.format(if short {
+ "%Y-%m-%d"
+ } else {
+ "%Y-%m-%d %H:%M:%S"
+ })
+ .to_string()
}
#[inline]
pub fn string_width_align(s: &str, width: usize) -> String {
- static POSTFIX: &str = "..";
+ static POSTFIX: &str = "..";
- let len = UnicodeWidthStr::width(s);
- let width_wo_postfix = width.saturating_sub(POSTFIX.len());
+ let len = UnicodeWidthStr::width(s);
+ let width_wo_postfix = width.saturating_sub(POSTFIX.len());
- if (len >= width_wo_postfix && len <= width)
- || (len <= width_wo_postfix)
- {
- format!("{:w$}", s, w = width)
- } else {
- let mut s = s.to_string();
- s.truncate(find_truncate_point(&s, width_wo_postfix));
- format!("{}{}", s, POSTFIX)
- }
+ if (len >= width_wo_postfix && len <= width)
+ || (len <= width_wo_postfix)
+ {
+ format!("{:w$}", s, w = width)
+ } else {
+ let mut s = s.to_string();
+ s.truncate(find_truncate_point(&s, width_wo_postfix));
+ format!("{}{}", s, POSTFIX)
+ }
}
#[inline]
fn find_truncate_point(s: &str, chars: usize) -> usize {
- s.chars().take(chars).map(char::len_utf8).sum()
+ s.chars().take(chars).map(char::len_utf8).sum()
}