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

I'm having trouble getting fixed-width strings to work on i3blocks. #468

Open
anthony-S93 opened this issue Oct 24, 2022 · 1 comment
Open

Comments

@anthony-S93
Copy link

anthony-S93 commented Oct 24, 2022

I wrote a simple python script to obtain my internet traffic

#!/usr/bin/python

import os
download_speed = 0.0
upload_speed = 0.0
nmcli_command = "nmcli device status | grep -w 'connected' | cut -d ' ' -f 1"
device_type = os.popen(nmcli_command).read().rstrip()
get_traffic = "awk '{{if(l1){{print ($2-l1)/1024,($10-l2)/1024}} else{{l1=$2; l2=$10;}}}}' <(grep {0} /proc/net/dev) <(sleep 0.5; grep {0} /proc/net/dev)".format(device_type)
traffic = os.popen(get_traffic).read().rstrip()

output_format = "<span foreground='#89ca78' weight='bold'> {down:7.2f} kb/s</span> <span foreground='#ef596f' weight='bold'>      {up:7.2f} kb/s</span>"


if traffic:
    # network is available.
    rates = traffic.split(" ")
    download_speed = float(rates[0])
    upload_speed = float(rates[1])

output = output_format.format(down=download_speed, up=upload_speed)
print(output)

Then, I have the following entry in my i3blocks.conf:

markup=pango

[internet-traffic]
command=~/.config/i3/scripts/internet-traffic
interval=1
separator_block_width=10

Everything works as expected except for the "fixed-width" feature. The final output string inside the python script has a fixed length, yet i3blocks still added extra spaces to the string displayed when the numbers get large. Why is this the case? If the resulting string has a fixed length, shouldn't the entire block have a fixed length?

Fixed_length_string

Notice how the length of the block lengthens every time the numbers get larger.

@anthony-S93 anthony-S93 changed the title Fixed-width strings not working on i3blocks. I'm having trouble getting fixed-width strings to work on i3blocks. Oct 24, 2022
@smlx
Copy link

smlx commented Jun 1, 2023

Is your font fixed width?

dllud pushed a commit to dllud/i3blocks that referenced this issue Jan 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants