tobi-wan-kenobi / bumblebee-status

bumblebee-status is a modular, theme-able status line generator for the i3 window manager.
https://bumblebee-status.readthedocs.io/en/main/
MIT License
1.22k stars 229 forks source link

Wiki pages could use some enhancements #486

Closed ghost closed 4 years ago

ghost commented 4 years ago

Feature Request

Reading the wiki, casually peeking at the code and trying to make small changes in default modules to fit my needs has been my weekend project and I gathered a list of questions that I couldn't figure out on my own.

So either I just need to spend more time on this, or the wiki/FAQ could be improved to become even more helpful for new users.

Here are a few questions that I gathered:

  1. Is it possible to have a container module that could be used to group certain "regular" modules?

Practical example: consider the cpu module. It displays total CPU usage as number. Personally, I like to display more things about CPU in my status bars, like:

Being able to have a cpu "metamodule" would make it possible to develop these small things separately, then just "glue" them together, perhaps even letting the user to choose which parts he wants (and in which order) via some metamodule parameter.

Of course, currently this is possible to achieve by writing a full alternative CPU module from scratch and have all the things hardcoded, but this limits the scenario to users who can actually do it.

  1. Is it possible to have a custom "prefix" theme setting for each widget in modules that have many Widget instances? Can we have an explicit trivial example in the docs? I have tried to figure this out by reading the mpd module, but got confused by the fact that the values of the name argument in Widget classes there don't look exactly the same as the settings for the mpd module in awesome-fonts.json. The ones from the icons file seem to be rather related to states (see Module.state() method in mpd.py). So I don't really understand the relationship between widget names and states. Can this be ELI5 in the wiki?

  2. Is it possible to set custom colors, different from "global", per-module color setting from the theme for parts of text in a particular widget? Using the cpu metamodule example above, I am thinking to implement per-core CPU load as a graph, using unicode block elements and I would like each of them to have custom colors depending of core load value.

  3. Is it possible to have regular alphanumeric text and icons in the same widget with different font sizes? I have been experimenting with the Nerd-patched font Iosevka, which is very narrow (to save screen space so I can fit more info in the bar) and I've noticed that for small font size the awesome icons are really tiny compared to letters/digits.

tobi-wan-kenobi commented 4 years ago

Hi,

first off, I do agree that the documentation can use improvement. It's an ongoing struggle to maintain a balance between "short enough that people actually read it" and "detailed enough that it is useful".

My goal is to have a documentation that is primarily useful to the user of bumblebee-status, not a potential developer (that's pretty much non-existing doc right now). Here, my goal is to keep the development of a module simple enough that people should be able to pick up the basics by looking at existing modules - and ask questions in a ticket if they need more specific information.

The reason for that is simple: This is a project I'm driving mostly alone, entirely in my spare time.

Additionally, some of the questions you are asking are outside the scope of bumblebee-status itself and are actually limitations posed by i3 (e.g. different font sizes, graphs), and to most of the questions you are asking "is this possible", my answer would be "not right now" (custom prefix, custom colors), and documenting all of the "negative information" (stuff that is currently not possible) seems daunting, to say the least.

To summarize: The documentation that currently exists is targeted at users, not developers, and while I agree that there's a lot of room for improvement, I think it is at least sufficient. For developers, there is next to no documentation at the moment, for which I apologize, but due to time constraints, unfortunately, I will not be able to change that in the short term.

Regarding your concrete questions:

  1. No, that is currently not possible.
  2. Yes, that is possible by assigning "states" to a widget and adding themes for each state (weather is a pretty straight-forward example, cmus, battery and mpd are more involved)
  3. No, that's an i3wm restriction - each widget can have exactly one foreground and one background color. Graphs seem pretty much impossible as well
  4. No, again, this is an i3wm restriction, only one font type + size for the whole ar.

Hope this helped you a bit, at least.

ghost commented 4 years ago

After reading https://i3wm.org/docs/i3bar-protocol.html I was actually able to achieve 3. and 4. in a non-bumblebee way by using pango markup.

I am attaching a demo script as proof:

#!/usr/bin/env python3

"""
pango markup demo for i3bar

per-CPU core load graphs, mono and colored versions

requires Iosevka and Terminus fonts to be installed
(since they are hardcoded, but feel free to change the names)

i3.conf settings:

bar {
    font pango:Iosevka 12
    status_command python3 cpuload.py
}
"""

import sys
import time

import psutil

def get_char_and_color(load):
    """choose graph char and color based on load"""
    if 0 <= load < 12.5:
        char = "▁"
        color = "green"
    elif 12.5 <= load < 25:
        char = "▂"
        color = "green"
    elif 25 <= load < 37.5:
        char = "▃"
        color = "yellow"
    elif 37.5 <= load < 50:
        char = "▄"
        color = "yellow"
    elif 50 <= load < 62.5:
        char = "▅"
        color = "orange"
    elif 62.5 <= load < 75:
        char = "▆"
        color = "orange"
    elif 75 <= load < 87.5:
        char = "▇"
        color = "red"
    elif 87.5 <= load:
        char = "█"
        color = "red"
    return char, color

def get_colored_txt(cores_data):
    """build pango markup for colored graph"""
    data = "<span font_family=\'Terminus\' foreground=\'blue\'>Colored graph (Terminus) </span>"
    for core in cores_data:
        span = "<span font_family=\'Terminus\' foreground=\'%s\'>%s</span>" % (core["color"], core["char"])
        data += span
    return data

print('{"version": 1}')
print('[')
print('[]')
while True:
    cores_load = [x for x in psutil.cpu_percent(percpu=True)]
    cores_data = [{"char": x, "color": y}
                  for x, y in map(get_char_and_color, cores_load)]
    mono_txt = "Mono graph (Iosevka)%s" % "".join([x["char"] for x in cores_data])
    colored_txt = get_colored_txt(cores_data)
    print(',[{"full_text": "%s"}, {"full_text": "%s", "markup": "pango"}]' %
          (mono_txt, colored_txt))
    sys.stdout.flush()
    time.sleep

Note that this is not a bumblebee module - it's a standalone script that shall be used instead of bumblebee-status. After setting it up - put some load on CPU to see how both graphs change interactively and the color graph bars also change their colors.

This means that 3. and 4. are not an i3wm restriction, they are rather a bumblebee-status restriction.

To me it looks like bumblebee-status only lacks a way to specify that full_text attribute of a widget must be parsed as pango markup through a boolean module parameter. I believe internally this happens at the bottom of I3BarOutput.draw() in output.py. If this suits you - feel free to consider this a feature request and open an issue for it. Unless not supporting pango markup was a design choice.

tobi-wan-kenobi commented 4 years ago

That is interesting, I did not know the i3bar protocol supported pango.

Adding this support should not be too hard, thanks a lot for raising his!

On Dec 23, 2019, 12:22, at 12:22, somospocos notifications@github.com wrote:

After reading https://i3wm.org/docs/i3bar-protocol.html I was actually able to achieve 3. and 4. in a non-bumblebee way by using pango markup.

I am attaching a demo script as proof:

!/usr/bin/env python3

""" pango markup demo for i3bar

per-CPU core load graphs, mono and colored versions

requires Iosevka and Terminus fonts to be installed (since they are hardcoded, but feel free to change the names)

i3.conf settings:

bar { font pango:Iosevka 12 status_command python3 cpuload.py } """

import sys import time

import psutil

def get_char_and_color(load): """choose graph char and color based on load""" if 0 <= load < 12.5: char = "▁" color = "green" elif 12.5 <= load < 25: char = "▂" color = "green" elif 25 <= load < 37.5: char = "▃" color = "yellow" elif 37.5 <= load < 50: char = "▄" color = "yellow" elif 50 <= load < 62.5: char = "▅" color = "orange" elif 62.5 <= load < 75: char = "▆" color = "orange" elif 75 <= load < 87.5: char = "▇" color = "red" elif 87.5 <= load: char = "█" color = "red" return char, color

def get_colored_txt(cores_data): """build pango markup for colored graph""" data = "<span font_family=\'Terminus\' foreground=\'blue\'>Colored graph (Terminus) " for core in cores_data: span = "<span font_family=\'Terminus\' foreground=\'%s\'>%s" % (core["color"], core["char"]) data += span return data

print('{"version": 1}') print('[') print('[]') while True: cores_load = [x for x in psutil.cpu_percent(percpu=True)] cores_data = [{"char": x, "color": y} for x, y in map(get_char_and_color, cores_load)] mono_txt = "Mono graph (Iosevka)%s" % "".join([x["char"] for x in cores_data]) colored_txt = get_colored_txt(cores_data) print(',[{"full_text": "%s"}, {"full_text": "%s", "markup": "pango"}]' % (mono_txt, colored_txt)) sys.stdout.flush() time.sleep

Note that this is not a bumblebee module - it's a standalone script that shall be used instead of bumblebee-status. After setting it up - put some load on CPU to see how both graphs change interactively and the color graph bars also change their colors.

This means that 3. and 4. are not an i3wm restriction, they are rather a bumblebee-status restriction.

To me it looks like bumblebee-status only lacks a way to specify that full_text attribute of a widget must be parsed as pango markup through a boolean module parameter. I believe internally this happens at the bottom of I3BarOutput.draw() in output.py. If this suits you - feel free to consider this a feature request and open an issue for it. Unless not supporting pango markup was a design choice.

-- You are receiving this because you modified the open/close state. Reply to this email directly or view it on GitHub: https://github.com/tobi-wan-kenobi/bumblebee-status/issues/486#issuecomment-568448248

tobi-wan-kenobi commented 4 years ago

Tracking this as #493

ghost commented 4 years ago

Worth documenting 629b3381 in https://github.com/tobi-wan-kenobi/bumblebee-status/wiki/How-to-write-a-theme

ghost commented 4 years ago

Another thing worth being exposed more in the docs is the location of custom themes. I have accidentally discovered this by reading theme.py. My first thought was that this is some new feature that is not production ready, that's why it's not mentioned in the docs (https://github.com/tobi-wan-kenobi/bumblebee-status/wiki/How-to-write-a-theme suggests dropping third party themes to <i3bumblebee folder>/bumblebee/themes/ rather than ~/.config/bumblebee-status/themes). But putting a custom theme file in the latter directory actually worked: bumblebee-status -l themes listed it and bumblebee itself picked it up when running as status program for i3.

I think this is worth mentioning in both the README (for end users, so they can drop there third party themes they eventually download) as well as in https://github.com/tobi-wan-kenobi/bumblebee-status/wiki/How-to-write-a-theme , so module designers could prefer that location as well, rather than dropping additional files into the local clone of the git repository.

tobi-wan-kenobi commented 4 years ago

Added, thanks a lot for the note!

ghost commented 4 years ago

I suppose you meant "theme" not "team". Probably not worth making a pull request just for this, you can fix it directly in master branch.

tobi-wan-kenobi commented 4 years ago

@somospocos Thanks, fixed! Should get more sleep, or do more reviews before pushing :P