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 1 commit
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
17 changes: 16 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,6 +61,21 @@ 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 "
```

### 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
Expand Down
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
9 changes: 6 additions & 3 deletions src/blocks/apt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ struct AptConfig {

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 @@ -124,7 +124,10 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
1 => format_singular.clone(),
_ => format.clone(),
});
widget.set_values(map!("count" => Value::number(count)));
widget.set_values(map!(
"count" => Value::number(count),
"icon" => Value::icon(api.get_icon("update")?)
));

let warning = warning_updates_regex
.as_ref()
Expand Down
10 changes: 6 additions & 4 deletions src/blocks/backlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! 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. | `" $format $brightness "`
arathunku marked this conversation as resolved.
Show resolved Hide resolved
//! `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`
Expand Down Expand Up @@ -127,7 +127,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 @@ -156,8 +156,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?;

select! {
Expand Down
16 changes: 9 additions & 7 deletions src/blocks/battery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
//! `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>
//! `format` | A string to customise the output of this block. See below for available placeholders. | <code>" $icon $percentage&vert; "</code>
arathunku marked this conversation as resolved.
Show resolved Hide resolved
//! `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`
MaxVerevkin marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -111,7 +111,7 @@ 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 = config.format.with_default(" $icon $percentage ")?;
let format_full = config.full_format.with_default("")?;
let format_empty = config.empty_format.with_default("")?;
let mut widget = api.new_widget();
Expand Down Expand Up @@ -145,7 +145,10 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
_ => 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 @@ -158,7 +161,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 @@ -180,18 +182,18 @@ 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_values(map!("icon" => Value::icon(api.get_icon("bat_not_available")?)));
widget.state = State::Critical;
api.set_widget(&widget).await?;
}
Expand Down
9 changes: 4 additions & 5 deletions src/blocks/bluetooth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
//! ----|--------|--------
//! `mac` | MAC address of the Bluetooth device | **Required**
//! `adapter_mac` | MAC Address of the Bluetooth adapter (in case your device was connected to multiple currently available adapters) | `None`
//! `format` | A string to customise the output of this block. See below for available placeholders. | <code>"$name{ $percentage&vert;}&vert;Unavailable"</code>
//! `format` | A string to customise the output of this block. See below for available placeholders. | <code>" $icon $name{ $percentage&vert;}&vert;Unavailable "</code>
//! `hide_disconnected` | Whether to hide the block when disconnected | `false`
//!
//! Placeholder | Value | Type | Unit
Expand Down Expand Up @@ -65,7 +65,7 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
let mut widget = api.new_widget().with_format(
config
.format
.with_default("$name{ $percentage|}|Unavailable")?,
.with_default(" $icon $name{ $percentage|}|Unavailable ")?,
);

let mut monitor = DeviceMonitor::new(config.mac, config.adapter_mac).await?;
Expand All @@ -77,6 +77,7 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
let connected = device.connected().await?;
if connected || !config.hide_disconnected {
let mut values = map! {
"icon" => Value::icon(api.get_icon(device.icon().await?)?),
"name" => Value::text(device.name().await?),
"available" => Value::flag(),
};
Expand All @@ -92,7 +93,6 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
debug!("Showing device as disconnected");
widget.state = State::Idle;
}
widget.set_icon(device.icon().await?)?;
widget.set_values(values);

api.set_widget(&widget).await?;
Expand All @@ -106,8 +106,7 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
debug!("Showing device as unavailable");
if !config.hide_disconnected {
widget.state = State::Idle;
widget.set_icon("bluetooth")?;
widget.set_values(default());
widget.set_values(map!("icon" => Value::icon(api.get_icon("bluetooth")?)));
api.set_widget(&widget).await?;
} else {
debug!("Hiding block since block is unavailable");
Expand Down
10 changes: 5 additions & 5 deletions src/blocks/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//!
//! Key | Values | Default
//! ----|--------|--------
//! `format` | A string to customise the output of this block. See below for available placeholders. | `"$utilization"`
//! `format` | A string to customise the output of this block. See below for available placeholders. | `" $icon $utilization "`
//! `format_alt` | If set, block will switch between `format` and `format_alt` on every click | `None`
//! `interval` | Update interval in seconds | `5`
//!
Expand All @@ -23,8 +23,8 @@
//! [[block]]
//! block = "cpu"
//! interval = 1
//! format = "$barchart.str() $utilization.eng()"
//! format_alt = "$frequency.eng(){ $boost.str()|}"
//! format = " $icon $barchart.str() $utilization.eng() "
//! format_alt = " $icon $frequency.eng(){ $boost.str()|} "
//! ```
//!
//! # Icons Used
Expand Down Expand Up @@ -55,15 +55,14 @@ struct CpuConfig {
pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
let config = CpuConfig::deserialize(config).config_error()?;

let mut format = config.format.with_default("$utilization")?;
let mut format = config.format.with_default(" $icon $utilization ")?;
let mut format_alt = match config.format_alt {
Some(f) => Some(f.with_default("")?),
None => None,
};

let mut widget = api
.new_widget()
.with_icon("cpu")?
.with_format(format.clone());

let boost_icon_on = api.get_icon("cpu_boost_on")?;
Expand Down Expand Up @@ -105,6 +104,7 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
});

let mut values = map!(
"icon" => Value::icon(api.get_icon("cpu")?),
"barchart" => Value::text(barchart),
"frequency" => Value::hertz(freq_avg),
"utilization" => Value::percents(utilization_avg * 100.),
Expand Down
40 changes: 28 additions & 12 deletions src/blocks/custom.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
//! The output of a custom shell command
//!
//! For further customisation, use the `json` option and have the shell command output valid JSON in the schema below:
//! For further customisation, use the `json` option and have the shell command output valid JSON in the schema below:
//! ```json
//! {"icon": "...", "state": "...", "text": "...", "short_text": "..."}
//! ```
//! `icon` is optional (default "")
//! `state` is optional, it may be Idle, Info, Good, Warning, Critical (default Idle)
//! `icon` is optional (default "")
//! `state` is optional, it may be Idle, Info, Good, Warning, Critical (default Idle)
//! `short_text` is optional.
//!
//! # Configuration
//!
//! Key | Values | Default
//! ----|--------|--------
//! `format` | A string to customise the output of this block. See below for available placeholders. | `" $icon $text "`
MaxVerevkin marked this conversation as resolved.
Show resolved Hide resolved
//! `command` | Shell command to execute & display | `None`
//! `persistent` | Run command in the background; update display for each output line of the command | `false`
//! `cycle` | Commands to execute and change when the button is clicked | `None`
Expand All @@ -21,6 +22,11 @@
//! `hide_when_empty` | Hides the block when the command output (or json text field) is empty | `false`
//! `shell` | Specify the shell to use when running commands | `$SHELL` if set, otherwise fallback to `sh`
//!
//! Placeholder | Value | Type | Unit
//! -----------------|------------------------------------------------------------|--------|---------------
//! `text` | Output of the script or text field from JSON output. | String |
//! `short_text` | short_text field from JSON output | String |
//!
//! # Examples
//!
//! Display temperature, update every 10 seconds:
Expand Down Expand Up @@ -93,6 +99,7 @@ use tokio::process::Command;
#[derive(Deserialize, Debug, SmartDefault)]
#[serde(deny_unknown_fields, default)]
struct CustomConfig {
format: FormatConfig,
command: Option<String>,
persistent: bool,
cycle: Option<Vec<String>>,
Expand All @@ -116,20 +123,20 @@ async fn update_bar(
if json {
match serde_json::from_str::<Input>(stdout).error("Invalid JSON") {
Ok(input) => {
widget.set_icon(&input.icon)?;
widget.state = input.state;
text_empty = input.text.is_empty();
if let Some(short) = input.short_text {
widget.set_texts(input.text, short);
} else {
widget.set_text(input.text);
}
let short_text = input.short_text.unwrap_or_default();
widget.set_values(map!{
"icon" => Value::icon(api.get_icon(&input.icon)?),
arathunku marked this conversation as resolved.
Show resolved Hide resolved
"text" => Value::text(input.text),
"short_text" => Value::text(short_text)
arathunku marked this conversation as resolved.
Show resolved Hide resolved
});
widget.state = input.state;
}
Err(error) => return api.set_error(error).await,
}
} else {
text_empty = stdout.is_empty();
widget.set_text(stdout.into());
widget.set_values(map!("text" => Value::text(stdout.into())));
}

if text_empty && hide_when_empty {
Expand All @@ -141,7 +148,16 @@ async fn update_bar(

pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
let config = CustomConfig::deserialize(config).config_error()?;
let mut widget = api.new_widget();
let mut format_config = FormatConfig { full: config.format.full, short: config.format.short };
let format = if config.json {
if format_config.short.is_none() {
format_config.short = Some(" $icon $short_text ".parse()?);
};
format_config.with_default(" $icon $text ")?
MaxVerevkin marked this conversation as resolved.
Show resolved Hide resolved
} else {
format_config.with_default(" $text ")?
};
let mut widget = api.new_widget().with_format(format);

let mut timer = config.interval.timer();

Expand Down
6 changes: 0 additions & 6 deletions src/blocks/custom_dbus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ struct Block {

#[dbus_interface(name = "rs.i3status.custom")]
impl Block {
async fn set_icon(&mut self, icon: &str) -> fdo::Result<()> {
self.widget.set_icon(icon)?;
arathunku marked this conversation as resolved.
Show resolved Hide resolved
self.api.set_widget(&self.widget).await?;
Ok(())
}

async fn set_text(&mut self, full: String, short: String) -> fdo::Result<()> {
self.widget.set_texts(full, short);
self.api.set_widget(&self.widget).await?;
Expand Down
6 changes: 3 additions & 3 deletions src/blocks/disk_space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//! ----|--------|--------
//! `path` | Path to collect information from. Supports path expansions e.g. `~`. | `"/"`
//! `interval` | Update time in seconds | `20`
//! `format` | A string to customise the output of this block. See below for available placeholders. | `"$available"`
//! `format` | A string to customise the output of this block. See below for available placeholders. | `" $icon $available "`
//! `warning` | A value which will trigger warning block state | `20.0`
//! `alert` | A value which will trigger critical block state | `10.0`
//! `info_type` | Determines which information will affect the block state. Possible values are `"available"`, `"free"` and `"used"` | `"available"`
Expand Down Expand Up @@ -81,8 +81,7 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {
let config = DiskSpaceConfig::deserialize(config).config_error()?;
let mut widget = api
.new_widget()
.with_icon("disk_drive")?
.with_format(config.format.with_default("$available")?);
.with_format(config.format.with_default(" $icon $available ")?);

let unit = match config.alert_unit.as_deref() {
Some("TB") => Some(Prefix::Tera),
Expand Down Expand Up @@ -113,6 +112,7 @@ pub async fn run(config: toml::Value, mut api: CommonApi) -> Result<()> {

let percentage = result / (total as f64) * 100.;
widget.set_values(map! {
"icon" => Value::icon(api.get_icon("disk_drive")?),
"path" => Value::text(path.to_string()),
"percentage" => Value::percents(percentage),
"total" => Value::bytes(total as f64),
Expand Down
Loading