Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop hard-coded whitespace and render icon as a placeholder #1618

Merged
merged 62 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
11fa7a6
Drop hard-coded whitespace and render icon as a placeholder
arathunku Aug 18, 2022
6bda6c7
Ensure weather.rs uses api.get_icon/1
arathunku Sep 10, 2022
9c092d4
Add format option to hueshift
arathunku Sep 10, 2022
318db93
Drop useless enumerator in widget.rs
arathunku Sep 10, 2022
d1d57b4
Add spaces around default error format
arathunku Sep 10, 2022
3fcabcd
Handle optional short_error_message placeholder in default_error_format
arathunku Sep 10, 2022
6101b43
Revert format_alt config for temperature block
arathunku Sep 10, 2022
0438269
Adjust short format for custom block
arathunku Sep 10, 2022
00bdd8f
Revert changes to available values in temperature block
arathunku Sep 10, 2022
6a2910a
Single temperature format for both collapsed and expended modes
arathunku Sep 10, 2022
8c313d2
Add format with icon for custom_bus
arathunku Sep 11, 2022
2648594
Remove hide_full from battery block and fix missing icon in default f…
arathunku Sep 11, 2022
56828b5
Drop hide_full and hide_missing in {batter, net} block and add format…
arathunku Sep 12, 2022
249bc40
Add FormatConfig with_defaults
arathunku Sep 12, 2022
da2efac
Drop redundant field names in struct initialization in pomodoro block
arathunku Sep 12, 2022
a1791a2
Fix music block missing icon value
arathunku Sep 13, 2022
627f506
backlight: fix format docs
arathunku Sep 13, 2022
054ab92
{battery, net}: rename format_missing to missing_format
arathunku Sep 13, 2022
f378305
bluetooth: relace hide_disconnected with disconnected_format
arathunku Sep 13, 2022
fb36dbf
net: drop hide_inactive, replaced by missing_format
arathunku Sep 13, 2022
a82e667
Apply suggestions from code review - mainly format fixes in various b…
arathunku Sep 14, 2022
595c1c5
focused_window: drop autohide option
arathunku Sep 15, 2022
5934e5b
bluetooth: drop connected flag
arathunku Sep 15, 2022
d9e5ee7
custom: adjust default short format
arathunku Sep 15, 2022
311111c
Merge branch 'master' into space-free-bar
arathunku Sep 15, 2022
bb50588
formatting: drop Option<> from short field
arathunku Sep 15, 2022
1216fec
docs: fix missing blanks and icon placeholder
arathunku Sep 16, 2022
925c2c3
docs: update NEWS.md with breaking changes and new format config option
arathunku Sep 16, 2022
cdcc704
{apt, dnf, pacman}: drop hide_when_uptodate, empty format_up_to_date …
arathunku Sep 18, 2022
324a132
Merge branch 'master' into space-free-bar
arathunku Sep 18, 2022
d035a0d
Merge branch 'master' into space-free-bar
MaxVerevkin Sep 22, 2022
506cd62
Update src/blocks/sound.rs
ammgws Sep 23, 2022
ac04462
focused_window: update format example for focused_window
arathunku Sep 23, 2022
e8ff30e
toggle: add format option to the example
arathunku Sep 23, 2022
377e50e
Update examples/config.toml with new format icon placeholder
arathunku Sep 23, 2022
910c881
uptime: fix missing icon
arathunku Sep 23, 2022
ecfd687
add icon placeholder to documentation
arathunku Sep 23, 2022
32af2a5
speedtext: fix docs for icon placeholder
arathunku Sep 23, 2022
a0ffad6
drop set_texts from widget
arathunku Sep 24, 2022
95c392e
watson: add format option with text placeholder
arathunku Sep 24, 2022
bbcb24d
Update icon placeholder docs for variable icons
arathunku Sep 24, 2022
ef2e992
Apply suggestions from code review
arathunku Sep 24, 2022
2ac7d7b
maildir: add docs for status placeholder
arathunku Sep 24, 2022
1303997
speedtest: fix spacing in examples
arathunku Sep 24, 2022
9399905
pomodoro: add docs for message placeholder
arathunku Sep 24, 2022
7c49fc0
memory: cleanup values and fix icon on click
arathunku Sep 24, 2022
689256c
maildir: fix formatting and compilation error
arathunku Sep 24, 2022
5cca786
notmuch: add name and count placeholders, drop set_text
arathunku Sep 24, 2022
32aa28a
Update src/blocks/speedtest.rs
arathunku Sep 26, 2022
2d2094f
music: fix format docs default value
arathunku Sep 26, 2022
875f9d3
notmuch: drop name option, format can be used instead
arathunku Sep 26, 2022
0843253
focused_window: drop curly braces from format options
arathunku Sep 26, 2022
04bb48b
time: refactor format config block
arathunku Sep 26, 2022
7b9684c
{pomodoro, custom_dbus, music, bluetooth}: fix rendering of | in tables
arathunku Sep 26, 2022
398fe91
{pomodoro, custom_dbus}: ensure format doc default value is wrapped i…
arathunku Sep 26, 2022
7ad6607
time: apply clippy suggestion
arathunku Sep 26, 2022
4289480
Apply suggestions from code review
arathunku Sep 28, 2022
58b50d0
notify: change styling of set values, inline condition in map
arathunku Sep 28, 2022
ed585d0
music: fix spacing in format docs
arathunku Sep 28, 2022
a4d80cd
custom: value icon available only when it's non-empty, document all p…
arathunku Sep 28, 2022
b052a04
custom_dbus: value icon available only when it's non-empty, document …
arathunku Sep 28, 2022
58875aa
Update src/blocks/custom.rs
MaxVerevkin Sep 29, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# i3status-rust 0.30.0 [unreleased]

Block documentation was moved from `docs/blocks.md` to: https://greshake.github.io/i3status-rust/i3status_rs/blocks/index.html
Block documentation was moved from `docs/blocks.md` to: https://greshake.github.io/i3status-rust/i3status_rs/blocks/index.html
Formatter documentation is available here: https://greshake.github.io/i3status-rust/i3status_rs/formatting/index.html

### Breaking changes
Expand Down Expand Up @@ -61,12 +61,37 @@ This is a major release which rewrites the core code to be asynchronous.
```
- `theme` and `icons`: `name` and `file` options have been merged into `theme`/`icons`. See above for an example.

- Major icons and whitespace change. Icons are now part of `format` option as a placeholder in blocks where format is customizable.
If you've modified `format` and would like to keep the same behaviour (icon, whitespace)
you need to update the value. For example,
```toml
[[block]]
block = "cpu"
format = "cpu:{utilization}"
```
needs to be changed to:
```toml
[[block]]
block = "cpu"
format = " $icon $utilization "
```

- **battery**: `hide_missing` option is replaced with `missing_format`. You can set `missing_format = ""` to maintain the behavior
arathunku marked this conversation as resolved.
Show resolved Hide resolved
- **battery**: `hide_full` option is removed. You can set `full_format = ""` to maintain the behavior
- **bluetooth**: hide_disconnected option is replaced with `disconnected_format`. You can set `disconnected_format = ""` to hide the block
- **focused_window**: `autohide` is removed. You can format to `" $title.str(0,21) | Missing "` to display the block when title is missing
- **net**: `hide_missing` and `hide_inactive` are removed. You can set `missing_format = ""`
- **toggle**: `text` option is removed and now you can use `format` to set the text
- **notmuch**: `name` option is removed and now you can use `format` to set the name
- **{apt, dnf, pacman}**: `hide_when_uptodate` option is removed and now you can use `format_up_to_date = ""` to hide the block

### New features and bugfixes
- When blocks error they no longer take down the entire bar. Instead, they now enter error mode: "X" will be shown and on left click the full error message will be shown in the bar.
- `custom_dbus` block can now be used more than one in your config
- `custom` block has new config option `"persistent"` which runs a command in the background and updates the block text for each received output line.
- `focused_window` block now supports the river window manager if ristate (https://gitlab.com/snakedye/ristate) is installed
- `battery` now supports `empty_threshold` to specify below which percentage the battery is considered empty, and `empty_format` to use a custom format when the battery is empty
- more blocks now support `format` option (custom, custom_dbus, hueshift, maildir, notmuch, pomodoro, time, uptime)

### Dependencies that are no longer required

Expand Down
10 changes: 4 additions & 6 deletions examples/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ unit = "GB"
interval = 20
warning = 20.0
alert = 10.0
format = "root: $available.eng(2)"
format = " $icon root: $available.eng(2) "

[[block]]
block = "memory"
display_type = "memory"
format_mem = "$mem_total_used_percents.eng(2)"
format_swap = "$swap_used_percents.eng(2)"
format_mem = " $icon $mem_total_used_percents.eng(2) "
format_swap = " $icon $swap_used_percents.eng(2) "

[[block]]
block = "sound"
Expand All @@ -40,6 +40,4 @@ cmd = "pavucontrol"
[[block]]
block = "time"
interval = 5
format = "%a %d/%m %R"
[block.icons_overrides]
time = ""
format = " %a %d/%m %R "
2 changes: 1 addition & 1 deletion src/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl CommonApi {
/// let mut widget = api
/// .new_widget()
/// .with_icon("docker")?
/// .with_format(config.format.with_default("$running.eng(1)")?);
/// .with_format(config.format.with_default(" $icon $running.eng(1) ")?);
/// ```
pub fn new_widget(&self) -> Widget {
Widget::new(self.id, self.shared_config.clone())
Expand Down
82 changes: 40 additions & 42 deletions src/blocks/apt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
//! Key | Values | Default
//! ----|--------|--------
//! `interval` | Update interval in seconds. | `600`
//! `format` | A string to customise the output of this block. See below for available placeholders. | `"$count.eng(1)"`
//! `format_singular` | Same as `format`, but for when exactly one update is available. | `"$count.eng(1)"`
//! `format_up_to_date` | Same as `format`, but for when no updates are available. | `"$count.eng(1)"`
//! `format` | A string to customise the output of this block. See below for available placeholders. | `" $icon $count.eng(1) "`
//! `format_singular` | Same as `format`, but for when exactly one update is available. | `" $icon $count.eng(1) "`
//! `format_up_to_date` | Same as `format`, but for when no updates are available. | `" $icon $count.eng(1) "`
//! `warning_updates_regex` | Display block as warning if updates matching regex are available. | `None`
//! `critical_updates_regex` | Display block as critical if updates matching regex are available. | `None`
//! `hide_when_uptodate` | Hides the block when there are no updates available | `false`
//!
//! Key | Value | Type | Unit
//! ----|-------|------|------
//! `count` | Number of updates available | Number | -
//! Placeholder | Value | Type | Unit
//! ------------|-----------------------------|--------|------
//! `icon` | A static icon | Icon | -
//! `count` | Number of updates available | Number | -
//!
//! # Example
//!
Expand All @@ -28,9 +28,9 @@
//! [[block]]
//! block = "apt"
//! interval = 1800
//! format = "$count updates available"
//! format_singular = "One update available"
//! format_up_to_date = "system up to date"
//! format = " $icon $count updates available "
//! format_singular = " $icon One update available "
//! format_up_to_date = " $icon system up to date "
//! critical_updates_regex = "(linux|linux-lts|linux-zen)"
//! [[block.click]]
//! # shows dmenu with cached available updates. Any dmenu alternative should also work.
Expand Down Expand Up @@ -61,14 +61,13 @@ struct AptConfig {
format_up_to_date: FormatConfig,
warning_updates_regex: Option<String>,
critical_updates_regex: Option<String>,
hide_when_uptodate: bool,
}

pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
let config = AptConfig::deserialize(config).config_error()?;
let mut widget = api.new_widget().with_icon("update")?;
let mut widget = api.new_widget();

let format = config.format.with_default("$count.eng(1)")?;
let format = config.format.with_default(" $icon $count.eng(1) ")?;
let format_singular = config.format_singular.with_default("$count.eng(1)")?;
let format_up_to_date = config.format_up_to_date.with_default("$count.eng(1)")?;

Expand Down Expand Up @@ -116,37 +115,36 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
let updates = get_updates_list(config_file.to_str().unwrap()).await?;
let count = get_update_count(&updates);

if count == 0 && config.hide_when_uptodate {
api.hide().await?;
} else {
widget.set_format(match count {
0 => format_up_to_date.clone(),
1 => format_singular.clone(),
_ => format.clone(),
});
widget.set_values(map!("count" => Value::number(count)));

let warning = warning_updates_regex
.as_ref()
.map_or(false, |regex| has_matching_update(&updates, regex));
let critical = critical_updates_regex
.as_ref()
.map_or(false, |regex| has_matching_update(&updates, regex));
widget.state = match count {
0 => State::Idle,
_ => {
if critical {
State::Critical
} else if warning {
State::Warning
} else {
State::Info
}
widget.set_format(match count {
0 => format_up_to_date.clone(),
1 => format_singular.clone(),
_ => format.clone(),
});
widget.set_values(map!(
"count" => Value::number(count),
"icon" => Value::icon(api.get_icon("update")?)
));

let warning = warning_updates_regex
.as_ref()
.map_or(false, |regex| has_matching_update(&updates, regex));
let critical = critical_updates_regex
.as_ref()
.map_or(false, |regex| has_matching_update(&updates, regex));
widget.state = match count {
0 => State::Idle,
_ => {
if critical {
State::Critical
} else if warning {
State::Warning
} else {
State::Info
}
};
}
};

api.set_widget(&widget).await?;
}
api.set_widget(&widget).await?;

loop {
select! {
Expand Down
17 changes: 10 additions & 7 deletions src/blocks/backlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
//! Key | Values | Default
//! ----|--------|--------
//! `device` | The `/sys/class/backlight` device to read brightness information from. When there is no `device` specified, this block will display information from the first device found in the `/sys/class/backlight` directory. If you only have one display, this approach should find it correctly.| Default device
//! `format` | A string to customise the output of this block. See below for available placeholders. | `"$brightness"`
//! `format` | A string to customise the output of this block. See below for available placeholders. | `" $icon $brightness "`
//! `step_width` | The brightness increment to use when scrolling, in percent | `5`
//! `minimum` | The minimum brightness that can be scrolled down to | `5`
//! `maximum` | The maximum brightness that can be scrolled up to | `100`
//! `cycle` | The brightnesses to cycle through on each click | `[minimum, maximum]`
//! `root_scaling` | Scaling exponent reciprocal (ie. root) | `1.0`
//! `invert_icons` | Invert icons' ordering, useful if you have colorful emoji | `false`
//!
//! Placeholder | Value | Type | Unit
//! -------------|--------------------|--------|---------------
//! `brightness` | Current brightness | Number | %
//! Placeholder | Value | Type | Unit
//! -------------|-------------------------------------------|--------|---------------
//! `icon` | Icon based on backlight's state | Icon | -
//! `brightness` | Current brightness | Number | %
//!
//! # Example
//!
Expand Down Expand Up @@ -129,7 +130,7 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
let config = BacklightConfig::deserialize(config).config_error()?;
let mut widget = api
.new_widget()
.with_format(config.format.with_default("$brightness")?);
.with_format(config.format.with_default(" $icon $brightness ")?);

let mut cycle = config
.cycle
Expand Down Expand Up @@ -158,8 +159,10 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
icon_index = BACKLIGHT_ICONS.len() - icon_index - 1;
}

widget.set_icon(BACKLIGHT_ICONS[icon_index])?;
widget.set_values(map! { "brightness" => Value::percents(brightness) });
widget.set_values(map! {
"icon" => Value::icon(api.get_icon(BACKLIGHT_ICONS[icon_index])?),
"brightness" => Value::percents(brightness)
});
api.set_widget(&widget).await?;

loop {
Expand Down
44 changes: 20 additions & 24 deletions src/blocks/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
//! `device` | The device in `/sys/class/power_supply/` to read from. When using UPower, this can also be `"DisplayDevice"`. Regular expressions can be used. | Any battery device
//! `driver` | One of `"sysfs"`, `"apc_ups"`, or `"upower"` | `"sysfs"`
//! `interval` | Update interval, in seconds. Only relevant for `driver = "sysfs"` \|\| "apc_ups"`. | `10`
//! `format` | A string to customise the output of this block. See below for available placeholders. | <code>"$percentage&vert;"</code>
//! `full_format` | Same as `format` but for when the battery is full | `""`
//! `empty_format` | Same as `format` but for when the battery is empty | `""`
//! `hide_missing` | Completely hide this block if the battery cannot be found. | `false`
//! `hide_full` | Hide the block if battery is full | `false`
//! `format` | A string to customise the output of this block. See below for available placeholders. | `" $icon $percentage "`
//! `full_format` | Same as `format` but for when the battery is full | `" $icon "`
//! `empty_format` | Same as `format` but for when the battery is empty | `" $icon "`
//! `missing_format` | Same as `format` if the battery cannot be found. | `" $icon "`
//! `info` | Minimum battery level, where state is set to info | `60`
//! `good` | Minimum battery level, where state is set to good | `60`
//! `warning` | Minimum battery level, where state is set to warning | `30`
Expand All @@ -24,6 +23,7 @@
//!
//! Placeholder | Value | Type | Unit
//! -------------|-------------------------------------------------------------------------|-------------------|-----
//! `icon` | Icon based on battery's state | Icon | -
//! `percentage` | Battery level, in percent | String or Integer | Percents
//! `time` | Time remaining until (dis)charge is complete. Presented only if battery's status is (dis)charging. | String | -
//! `power` | Power consumption by the battery or from the power supply when charging | String or Float | Watts
Expand All @@ -35,15 +35,15 @@
//! ```toml
//! [block]
//! block = "battery"
//! format = "$percentage|N/A"
//! format = " $icon $percentage "
//! ```
//!
//! Hide missing battery:
//!
//! ```toml
//! [block]
//! block = "battery"
//! hide_missing = true
//! missing_format = ""
//! ```
//!
//! # Icons Used
Expand Down Expand Up @@ -83,8 +83,7 @@ struct BatteryConfig {
format: FormatConfig,
full_format: FormatConfig,
empty_format: FormatConfig,
hide_missing: bool,
hide_full: bool,
missing_format: FormatConfig,
#[default(60.0)]
info: f64,
#[default(60.0)]
Expand All @@ -110,9 +109,10 @@ enum BatteryDriver {

pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
let config = BatteryConfig::deserialize(config).config_error()?;
let format = config.format.with_default("$percentage")?;
let format_full = config.full_format.with_default("")?;
let format_empty = config.empty_format.with_default("")?;
let format = config.format.with_default(" $icon $percentage ")?;
let format_full = config.full_format.with_default(" $icon ")?;
let format_empty = config.empty_format.with_default(" $icon ")?;
let missing_format = config.missing_format.with_default(" $icon ")?;
let mut widget = api.new_widget();

let dev_name = DeviceName::new(config.device)?;
Expand All @@ -134,17 +134,17 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
}

match info {
Some(info) if info.status == BatteryStatus::Full && config.hide_full => {
api.hide().await?;
}
Some(info) => {
widget.set_format(match info.status {
BatteryStatus::Empty => format_empty.clone(),
BatteryStatus::Full | BatteryStatus::NotCharging => format_full.clone(),
_ => format.clone(),
});

let mut values = map!("percentage" => Value::percents(info.capacity));
let mut values = map!(
"percentage" => Value::percents(info.capacity)
);

info.power
.map(|p| values.insert("power".into(), Value::watts(p)));
info.time_remaining.map(|t| {
Expand All @@ -157,7 +157,6 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
)),
)
});
widget.set_values(values);

let (icon, state) = match (info.status, info.capacity) {
(BatteryStatus::Empty, _) => (battery_level_icon(0, false), State::Critical),
Expand All @@ -179,18 +178,15 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
},
),
};
values.insert("icon".into(), Value::icon(api.get_icon(icon)?));

widget.set_icon(icon)?;
widget.set_values(values);
widget.state = state;
api.set_widget(&widget).await?;
}
None if config.hide_missing => {
api.hide().await?;
}
None => {
widget.set_icon("bat_not_available")?;
widget.set_format(format.clone());
widget.set_values(default());
widget.set_format(missing_format.clone());
widget.set_values(map!("icon" => Value::icon(api.get_icon("bat_not_available")?)));
widget.state = State::Critical;
api.set_widget(&widget).await?;
}
Expand Down
Loading