예제 #1
0
파일: run.py 프로젝트: rwilhelm/bar
async def output(name, block, line):
    final_string = stage(name, fmt_block(name, block, line))
    assert final_string
    if getopt("lemonbar") is True:
        await lemonbar.write(final_string)

    if getopt("print_wrapper") is True:
        stdout(final_string)
예제 #2
0
파일: blocks.py 프로젝트: rwilhelm/bar
def init():
    """Initialize the global BLOCKS dict by creating the dict and the
     keys according to the blocks configured. The values of static
     blocks are immediately stored. For non-static blocks the block
     name will be stored, which acts as a placeholder until the
     value of the block is updated. By creating the keys the order
     of the blocks is preserved in the order they are configured."""

    blocks = {}

    opts = getopt()
    if opts.blocks:
        for name in opts.blocks:
            try:
                blocks[name] = config["blocks"][name]
            except KeyError:
                print("Block not found: {}".format(name))
    else:
        blocks = config["blocks"]

    for name, block in blocks.items():
        if "static" in block:
            BLOCKS[name] = block["static"]
        else:
            # displayed as long as the module has not produced any output
            BLOCKS[name] = name  # LOADING...

    return blocks
예제 #3
0
    async def consume(self, generator: asyncio.streams.StreamReader):
        async for bstring in generator:
            try:
                self.proc.stdin.write(bstring)
                await self.proc.stdin.drain()
            except AttributeError as e:
                raise e

            if getopt("print_actions"):
                print(clean(bstring))
예제 #4
0
파일: main.py 프로젝트: rwilhelm/bar
async def main():
    blocks = init()
    procs = list(map(lambda x: run(x, blocks[x]), blocks))

    if getopt("lemonbar"):
        await lemonbar.init()
        await shell.init()
        procs.append(shell.consume(lemonbar.proc.stdout))
        await asyncio.sleep(.02)
        above()

    await asyncio.gather(*procs)
예제 #5
0
파일: blocks2.py 프로젝트: rwilhelm/bar
        def add_actions(actions):
            for action in actions:

                if not isinstance(action, Action):
                    if getopt("debug"):
                        logger.debug("Action created: %s", action)
                    action = Action(action, actions[action])

                if action.button < 1 or action.button > 7:
                    raise ValueError(
                        "Invalid button assignment for action: {0}".format(
                            actions[action]))

                pfx.append("%{{A{0}:{1}:}}".format(action.button,
                                                   action.command))
                sfx.append("%{A}")
예제 #6
0
파일: blocks2.py 프로젝트: rwilhelm/bar
        def add_colors(fg=None, bg=None, rev=False):
            theme = get_colors("terminal")

            if getopt("debug"):
                logger.debug("Theme: %s", theme)
                logger.debug("Adding colors: fg=%s bg=%s rev=%s", fg, bg, rev)

            if fg:
                c = fg if fg[0] == "#" else theme[fg]
                pfx.append("%{{F{0}}}".format(c))
                sfx.append("%{F-}")

            if bg:
                c = bg if not bg[0] == "#" else theme[bg]
                pfx.append("%{{B{0}}}".format(theme[c]))
                sfx.append("%{B-}")

            if rev:
                pfx.append("%{R}")
                sfx.append("%{R-}")
예제 #7
0
파일: main.py 프로젝트: rwilhelm/bar
async def main():
    blocks = init()
    procs = list(map(lambda x: run(x, blocks[x]), blocks))

    if getopt("lemonbar"):
        await lemonbar.init()
        await shell.init()
        procs.append(shell.consume(lemonbar.proc.stdout))
        await asyncio.sleep(.02)
        above()

    await asyncio.gather(*procs)


if __name__ == "__main__":
    print("A {}".format(__name__), file=sys.stderr)

    #tracemalloc.start()

    if getopt("daemon"):
        fpid = os.fork()  # fork to 0
        if fpid != 0:
            sys.exit(0)  # exit old process

    signal.signal(signal.SIGINT, signal_handler)
    asyncio.run(main())  # loops forever

else:
    print("B {}".format(__name__), file=sys.stderr)
예제 #8
0
파일: blocks2.py 프로젝트: rwilhelm/bar
    def fmt(self, line: str, **kwargs):
        """Format the output string (ie a block) to be parsed by lemonbar."""

        actions = kwargs.get("actions", [])
        colors = kwargs.get("colors", {})
        pad = kwargs.get("pad", None)
        pfx = kwargs.get("pfx", [])
        sfx = kwargs.get("sfx", [])

        def add_actions(actions):
            for action in actions:

                if not isinstance(action, Action):
                    if getopt("debug"):
                        logger.debug("Action created: %s", action)
                    action = Action(action, actions[action])

                if action.button < 1 or action.button > 7:
                    raise ValueError(
                        "Invalid button assignment for action: {0}".format(
                            actions[action]))

                pfx.append("%{{A{0}:{1}:}}".format(action.button,
                                                   action.command))
                sfx.append("%{A}")

        def add_colors(fg=None, bg=None, rev=False):
            theme = get_colors("terminal")

            if getopt("debug"):
                logger.debug("Theme: %s", theme)
                logger.debug("Adding colors: fg=%s bg=%s rev=%s", fg, bg, rev)

            if fg:
                c = fg if fg[0] == "#" else theme[fg]
                pfx.append("%{{F{0}}}".format(c))
                sfx.append("%{F-}")

            if bg:
                c = bg if not bg[0] == "#" else theme[bg]
                pfx.append("%{{B{0}}}".format(theme[c]))
                sfx.append("%{B-}")

            if rev:
                pfx.append("%{R}")
                sfx.append("%{R-}")

        add_actions(actions)
        add_colors(**colors)

        if sfx:
            sfx.reverse()

        try:
            if pad:
                fmt_out = "".join(pfx + [pad + str(line) + pad] + sfx)
            else:
                fmt_out = "".join(pfx + [str(line)] + sfx)
            if getopt("debug"):
                logger.debug('Fmt out: "%s" (%s)', fmt_out, len(fmt_out))
            return fmt_out
        except TypeError as e:
            raise e