<commit_before>from barpyrus import hlwm
from barpyrus import widgets as W
from barpyrus.core import Theme
from barpyrus import lemonbar
from barpyrus import conky
import sys

hc = hlwm.connect()

monitor = sys.argv[1] if len(sys.argv) >= 2 else 0
x, y, monitor_w, monitor_h = hc.monitor_rect(monitor)
height = 16
width = monitor_w

hc(['pad', str(monitor), str(height)])

cg = conky.ConkyGenerator(lemonbar.textpainter())

## CPU / RAM / df
with cg.temp_fg('#9fbc00'):
    cg.symbol(0xe026)
cg.space(5)
for cpu in '1234':
    cg.var('cpu cpu' + cpu)
    cg.text('% ')

with cg.temp_fg('#9fbc00'):
    cg.symbol(0xe021)
cg.space(5)
cg.var('memperc')
cg.text('% ')

with cg.temp_fg('#9fbc00'):
    cg.symbol(0x00e1bb)
cg.space(5)
cg.var('fs_used_perc /')
cg.text('% ')


## Network
wifi_icons = [0xe217, 0xe218, 0xe219, 0xe21a]
wifi_delta = 100 / len(wifi_icons)

with cg.if_('up tun0'):
    with cg.temp_fg('#ff0000'):
        cg.symbol(0xe0a6)

for iface in ['eth', 'wlan', 'ppp0']:
    with cg.if_('up %s' % iface), cg.if_('match "${addr %s}" != "No Address"' % iface):
        with cg.temp_fg('#9fbc00'):
            if iface == 'wlan':
                with cg.cases():
                    for i, icon in enumerate(wifi_icons[:-1]):
                        cg.case('match ${wireless_link_qual_perc wlan} < %d' % ((i+1)*wifi_delta))
                        cg.symbol(icon)

                    cg.else_()
                    cg.symbol(wifi_icons[-1])  # icon for 100 percent
                cg.space(5)
            elif iface == 'eth':
                cg.symbol(0xe0af)
            elif iface == 'ppp0':
                cg.symbol(0xe0f3)
            else:
                assert False

        if iface == 'wlan':
            cg.var('wireless_essid')

        if iface != 'ppp0':
            cg.space(5)
            cg.var('addr %s' % iface)

        cg.space(5)
        with cg.temp_fg('#9fbc00'):
            cg.symbol(0xe13c)
        cg.var('downspeedf %s' % iface)
        cg.text('K ')
        cg.var('totaldown %s' % iface)
        cg.space(5)
        with cg.temp_fg('#9fbc00'):
            cg.symbol(0xe13b)
        cg.var('upspeedf %s' % iface)
        cg.text('K ')
        cg.var('totalup %s' % iface)
        cg.space(5)

## Battery
# first icon: 0 percent
# last icon: 100 percent
bat_icons = [
    0xe242, 0xe243, 0xe244, 0xe245, 0xe246,
    0xe247, 0xe248, 0xe249, 0xe24a, 0xe24b,
]
bat_delta = 100 / len(bat_icons)

with cg.if_('existing /sys/class/power_supply/BAT0'):
    with cg.if_('match "$battery" == "discharging $battery_percent%"'):
        cg.fg('#ffc726')
        cg.else_()
        cg.fg('#9fbC00')

    with cg.cases():
        for i, icon in enumerate(bat_icons[:-1]):
            cg.case('match $battery_percent < %d' % ((i+1)*bat_delta))
            cg.symbol(icon)

        cg.else_()
        cg.symbol(bat_icons[-1])  # icon for 100 percent
    cg.space(5)

    cg.var('battery_percent')
    cg.text('% ')
    cg.var('battery_time')
    cg.fg(None)
    cg.space(5)


conky_config = {
    'update_interval': '5',
}


# Widget configuration:
bar = lemonbar.Lemonbar(geometry = (x,y,width,height))
bar.widget = W.ListLayout([
    W.RawLabel('%{l}'),
    hlwm.HLWMTags(hc, monitor, tag_renderer = hlwm.underlined_tags),
    W.RawLabel('%{c}'),
    hlwm.HLWMWindowTitle(hc),
    W.RawLabel('%{r}'),
    conky.ConkyWidget(text=str(cg), config=conky_config),
    W.RawLabel("%{F#ffffff}"),
    W.DateTime('%d. %B, %H:%M'),
])
<commit_msg>barpyrus: Use orange values over threshold<commit_after>import sys
import contextlib

from barpyrus import hlwm
from barpyrus import widgets as W
from barpyrus.core import Theme
from barpyrus import lemonbar
from barpyrus import conky


@contextlib.contextmanager
def maybe_orange(match, predicate='> 90'):
    with cg.if_('match ${%s} %s' % (match, predicate)):
        cg.fg('#ffc726')
    yield
    cg.fg(None)


hc = hlwm.connect()

monitor = sys.argv[1] if len(sys.argv) >= 2 else 0
x, y, monitor_w, monitor_h = hc.monitor_rect(monitor)
height = 16
width = monitor_w

hc(['pad', str(monitor), str(height)])

cg = conky.ConkyGenerator(lemonbar.textpainter())

## CPU / RAM / df
with cg.temp_fg('#9fbc00'):
    cg.symbol(0xe026)
cg.space(5)
for cpu in '1234':
    with maybe_orange('cpu cpu%s' % cpu):
        cg.var('cpu cpu' + cpu)
        cg.text('% ')

with cg.temp_fg('#9fbc00'):
    cg.symbol(0xe021)
cg.space(5)
with maybe_orange('memperc'):
    cg.var('memperc')
    cg.text('% ')

with cg.temp_fg('#9fbc00'):
    cg.symbol(0x00e1bb)
cg.space(5)
with maybe_orange('fs_used_perc /'):
    cg.var('fs_used_perc /')
    cg.text('% ')


## Network
wifi_icons = [0xe217, 0xe218, 0xe219, 0xe21a]
wifi_delta = 100 / len(wifi_icons)

with cg.if_('up tun0'):
    with cg.temp_fg('#ff0000'):
        cg.symbol(0xe0a6)

for iface in ['eth', 'wlan', 'ppp0']:
    with cg.if_('up %s' % iface), cg.if_('match "${addr %s}" != "No Address"' % iface):
        with cg.temp_fg('#9fbc00'):
            if iface == 'wlan':
                with cg.cases():
                    for i, icon in enumerate(wifi_icons[:-1]):
                        cg.case('match ${wireless_link_qual_perc wlan} < %d' % ((i+1)*wifi_delta))
                        cg.symbol(icon)

                    cg.else_()
                    cg.symbol(wifi_icons[-1])  # icon for 100 percent
                cg.space(5)
            elif iface == 'eth':
                cg.symbol(0xe0af)
            elif iface == 'ppp0':
                cg.symbol(0xe0f3)
            else:
                assert False

        if iface == 'wlan':
            cg.var('wireless_essid')

        if iface != 'ppp0':
            cg.space(5)
            cg.var('addr %s' % iface)

        cg.space(5)
        with cg.temp_fg('#9fbc00'):
            cg.symbol(0xe13c)
        cg.var('downspeedf %s' % iface)
        cg.text('K ')
        cg.var('totaldown %s' % iface)
        cg.space(5)
        with cg.temp_fg('#9fbc00'):
            cg.symbol(0xe13b)
        cg.var('upspeedf %s' % iface)
        cg.text('K ')
        cg.var('totalup %s' % iface)
        cg.space(5)

## Battery
# first icon: 0 percent
# last icon: 100 percent
bat_icons = [
    0xe242, 0xe243, 0xe244, 0xe245, 0xe246,
    0xe247, 0xe248, 0xe249, 0xe24a, 0xe24b,
]
bat_delta = 100 / len(bat_icons)

with cg.if_('existing /sys/class/power_supply/BAT0'):
    cg.fg('#9fbC00')

    with cg.cases():
        for i, icon in enumerate(bat_icons[:-1]):
            cg.case('match $battery_percent < %d' % ((i+1)*bat_delta))
            cg.symbol(icon)

        cg.else_()
        cg.symbol(bat_icons[-1])  # icon for 100 percent

    cg.fg(None)
    cg.space(5)

    with maybe_orange('battery_percent', '< 10'):
        with cg.if_('match "$battery" != "discharging $battery_percent%"'):
            cg.fg('#9fbC00')
        cg.var('battery_percent')
        cg.text('% ')
        cg.var('battery_time')
        cg.space(5)


conky_config = {
    'update_interval': '5',
}


# Widget configuration:
bar = lemonbar.Lemonbar(geometry = (x,y,width,height))
bar.widget = W.ListLayout([
    W.RawLabel('%{l}'),
    hlwm.HLWMTags(hc, monitor, tag_renderer = hlwm.underlined_tags),
    W.RawLabel('%{c}'),
    hlwm.HLWMWindowTitle(hc),
    W.RawLabel('%{r}'),
    conky.ConkyWidget(text=str(cg), config=conky_config),
    W.RawLabel("%{F#ffffff}"),
    W.DateTime('%d. %B, %H:%M'),
])

{'fraction_non_alphanumeric': 0.1667347216550973, 'fraction_numerical': 0.04287464271131074, 'mean_word_length': 2.3939953810623558, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '284831', 'n_tokens_mistral': 3115, 'n_tokens_neox': 2802, 'n_words': 545}