from i3pystatus import IntervalModule
from i3pystatus.core.command import run_through_shell
import logging


class Shell(IntervalModule):
    """
    Shows output of shell command

    .. rubric:: Available formatters

    * `{output}` — just the striped command output without newlines
    """

    color = "#FFFFFF"
    error_color = "#FF0000"

    settings = (
        ("command", "command to be executed"),
        ("color", "standard color"),
        ("error_color", "color to use when non zero exit code is returned"),
        "format"
    )

    required = ("command",)
    format = "{output}"

    def run(self):
        retvalue, out, stderr = run_through_shell(self.command, enable_shell=True)

        if retvalue != 0:
            self.logger.error(stderr if stderr else "Unknown error")

        if out:
            out = out.replace("\n", " ").strip()
        elif stderr:
            out = stderr

        self.output = {
            "full_text": self.format.format(output=out) if out else "Command `%s` returned %d" % (self.command, retvalue),
            "color": self.color if retvalue == 0 else self.error_color
        }

@@ -89,23 +89,8 @@
 ell%0A
-import logging%0A
 %0A%0Acl
@@ -323,16 +323,48 @@
 #FF0000%22
+%0A    ignore_emtpy_stdout = False
 %0A%0A    se
@@ -417,24 +417,83 @@
 executed%22),%0A
+        (%22ignore_emtpy_stdout%22, %22Let the block be empty%22),%0A
         (%22co
@@ -994,37 +994,8 @@
     
-self.output = %7B%0A            %22
 full
@@ -999,18 +999,18 @@
 ull_text
-%22:
+ =
  self.fo
@@ -1036,74 +1036,213 @@
 out)
- if out else %22Command %60%25s%60 returned %25d%22 %25 (self.command, retvalue)
+.strip()%0A        if not full_text and not self.ignore_emtpy_stdout:%0A            full_text = %22Command %60%25s%60 returned %25d%22 %25 (self.command, retvalue)%0A%0A        self.output = %7B%0A            %22full_text%22: full_text
 ,%0A  

Allow empty stdout on shell module