i3pyblocks.blocks.shell
Blocks based on asyncio.subprocess
This is a collection of Blocks based on asyncio.subprocess, allowing you
to run an external program, parse its output and show it in i3pyblocks.
All Blocks in this module are based on PollingBlock, since it is more
difficult to have proper event based updates when coordinating subprocess.
There is some alternatives that to try in the future, for example using inotify
or dbus based approaches.
Module Contents
Classes
Block that shows the result of a command running in shell. |
|
Block that shows a toggle on or off accordingly to command's output. |
- class i3pyblocks.blocks.shell.ShellBlock(command: i3pyblocks._internal.models.CommandArgs, format: str = '{output}', command_on_click: Mapping[int, Optional[str]] = {types.MouseButton.LEFT_BUTTON: None, types.MouseButton.MIDDLE_BUTTON: None, types.MouseButton.RIGHT_BUTTON: None, types.MouseButton.SCROLL_UP: None, types.MouseButton.SCROLL_DOWN: None}, color_by_returncode: Mapping[int, Optional[str]] = {}, sleep: int = 1, **kwargs)
Bases:
i3pyblocks.blocks.PollingBlockBlock that shows the result of a command running in shell.
- Parameters
command_state – Command to be run. By default this will be parsed by shell, so it can also be multiple arbitrary commands separated by newlines, or multiple commands connected by pipes.
format – Format string to shown. Supports both
{output}(stdout) and{output_err}(stderr) placeholders.command_on_click – Mapping with commands to be called when the user interacts with mouse inside this block. After running this Block will be updated. Can be useful to change the keyboard layout for example.
sleep – Sleep in seconds between each call to
run().**kwargs – Extra arguments to be passed to
PollingBlockclass.
- async click_handler(self, button: int, **_kwargs) None
- async run(self) None
- class i3pyblocks.blocks.shell.ToggleBlock(command_state: i3pyblocks._internal.models.CommandArgs, command_on: i3pyblocks._internal.models.CommandArgs, command_off: i3pyblocks._internal.models.CommandArgs, format_on: str = 'ON', format_off: str = 'OFF', sleep: int = 1, shell: bool = True, **kwargs)
Bases:
i3pyblocks.blocks.PollingBlockBlock that shows a toggle on or off accordingly to command’s output.
This block output is determined by
command_state. When the command outputs something in stdout, this is interpreted as ON, while when the command outputs nothing in stdout, this is interpreted as OFF.- Parameters
command_state – Command to be run to determine state. By default this will be parsed by shell, so it can also be multiple arbitrary commands separated by newlines, or multiple commands connected by pipes.
command_on – Command to be called when the current state is OFF, so it can be turned to ON.
command_off – Command to be called when the current state is ON, so it can be turned to OFF.
format_on – Format string to be shown when state is ON.
format_off – Format string to be shown when state is OFF.
sleep – Sleep in seconds between each call to
run().**kwargs – Extra arguments to be passed to
PollingBlockclass.
- async get_state(self) bool
- async click_handler(self, **_kwargs) None
- async run(self) None