How to use the sen.tui.commands.base.SameThreadCommand function in sen

To help you get started, we’ve selected a few sen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TomasTomecek / sen / sen / tui / commands / ui.py View on Github external
try:
            ui.run_command(inp, docker_object=docker_object)
        except NoSuchCommand as ex:
            logger.info("non-existent command initiated: %r", inp)
            ui.notify_message(str(ex), level="error")
        except Exception as ex:
            logger.info("command %r failed: %r", inp, ex)
            ui.notify_message("Error while running command '{}': {}".format(
                inp, ex
            ), level="error")
            log_last_traceback()
        ui.reload_footer()


@register_command
class PromptCommand(SameThreadCommand):
    name = "prompt"
    description = "Customize and pre-populate prompt with initial data."
    options_definitions = [
        Option("prompt-text", "Text forming the actual prompt", default=":"),
        Option("initial-text", "Prepopulated text", default="")
    ]

    def run(self):
        """
        prompt for text input.
        """
        # set up widgets
        leftpart = urwid.Text(self.arguments.prompt_text, align='left')
        editpart = urwid.Edit(multiline=True, edit_text=self.arguments.initial_text)

        # build promptwidget
github TomasTomecek / sen / sen / tui / commands / ui.py View on Github external
class LogTracebackMixin:
    @log_traceback
    def do(self, fn, *args, **kwargs):
        try:
            fn(*args, **kwargs)
        except NotifyError as ex:
            logger.error(repr(ex))
            self.ui.notify_message(str(ex), level="error")
        except Exception as ex:
            logger.error(repr(ex))
            self.ui.notify_message("Command failed: %s" % str(ex), level="error")
            raise


@register_command
class QuitCommand(SameThreadCommand):
    name = "quit"
    # TODO: make this configurable by asking whether to quit or not
    description = "Quit sen. No questions asked."

    def run(self):
        self.ui.quit()


@register_command
class KillBufferCommand(SameThreadCommand):
    name = "kill-buffer"
    description = "Remove currently displayed buffer."
    options_definitions = [
        Option("quit-if-no-buffer", "Quit when there's no buffer left", default=False)
    ]
github TomasTomecek / sen / sen / tui / commands / ui.py View on Github external
def run(self):
        self.do(self.ui.current_buffer.find_next)


@register_command
class SearchPreviousCommand(SameThreadCommand, LogTracebackMixin):
    name = "search-previous"
    description = "previous search occurrence"

    def run(self):
        self.do(self.ui.current_buffer.find_previous)


@register_command
class SearchCommand(SameThreadCommand, LogTracebackMixin):
    name = "filter"
    description = """\
Display only lines matching provided query (provide empty query to clear filtering)

In main listing, you may specify more precise query with these space-separated filters:
* t[ype]=c[ontainer[s]]
* t[ype]=i[mage[s]]
* s[tate]=r[unning])

Examples
* "type=container" - show only containers (short equivalent is "t=c")
* "type=image fedora" - show images with string "fedora" in name (equivalent "t=i fedora")\
"""

    arguments_definitions = [
        Argument("query", "Input query string", default="")
github TomasTomecek / sen / sen / tui / commands / ui.py View on Github external
name = "kill-buffer"
    description = "Remove currently displayed buffer."
    options_definitions = [
        Option("quit-if-no-buffer", "Quit when there's no buffer left", default=False)
    ]

    def run(self):
        buffers_left = self.ui.remove_current_buffer(close_if_no_buffer=self.arguments.quit_if_no_buffer)
        if buffers_left is None:
            self.ui.notify_message("Last buffer will not be removed.")
        elif buffers_left == 0:
            self.ui.run_command(QuitCommand.name)


@register_command
class SelectBufferCommand(SameThreadCommand):
    name = "select-buffer"
    description = "Display buffer with selected index."
    arguments_definitions = [
        Argument("index", "Index of buffer to display", default=1, action=int)
    ]

    def run(self):
        self.ui.pick_and_display_buffer(self.arguments.index)


@register_command
class SelectNextBufferCommand(SelectBufferCommand):
    name = "select-next-buffer"
    description = "Display next buffer."

    def run(self):
github TomasTomecek / sen / sen / tui / commands / widget.py View on Github external
description = "go 10 lines up"

    def run(self):
        if isinstance(self.buffer.widget, urwidtrees.TreeBox):
            self.ui.notify_message("This movement is not available.", level="error")
            return
        try:
            self.buffer.widget.set_focus(self.buffer.widget.get_focus()[1] - 10)
        except IndexError:
            self.buffer.widget.set_focus(0)
        self.buffer.widget.reload_widget()
        return


@register_command
class NavigateDownwardsCommand(SameThreadCommand):
    name = "navigate-downwards"
    description = "go 10 lines down"

    def run(self):
        if isinstance(self.buffer.widget, urwidtrees.TreeBox):
            self.ui.notify_message("This movement is not available.", level="error")
            return
        try:
            self.buffer.widget.set_focus(self.buffer.widget.get_focus()[1] + 10)
        except IndexError:
            self.buffer.widget.set_focus(len(self.buffer.widget.body) - 1)
        self.buffer.widget.reload_widget()
        return
github TomasTomecek / sen / sen / tui / commands / widget.py View on Github external
def run(self):
        return super(self.buffer.widget.__class__, self.buffer.widget).keypress(self.size, "up")


@register_command
class NavigateDownCommand(SameThreadCommand):
    name = "navigate-down"
    description = "go one line down"

    def run(self):
        return super(self.buffer.widget.__class__, self.buffer.widget).keypress(self.size, "down")


@register_command
class NavigateUpwardsCommand(SameThreadCommand):
    name = "navigate-upwards"
    description = "go 10 lines up"

    def run(self):
        if isinstance(self.buffer.widget, urwidtrees.TreeBox):
            self.ui.notify_message("This movement is not available.", level="error")
            return
        try:
            self.buffer.widget.set_focus(self.buffer.widget.get_focus()[1] - 10)
        except IndexError:
            self.buffer.widget.set_focus(0)
        self.buffer.widget.reload_widget()
        return


@register_command
github TomasTomecek / sen / sen / tui / commands / ui.py View on Github external
def run(self):
        # TODO: realtime list change would be mindblowing
        self.do(self.ui.current_buffer.filter, self.arguments.query)


@register_command
class RefreshCurrentBufferCommand(SameThreadCommand):
    name = "refresh"
    description = "Refresh current buffer."

    def run(self):
        self.ui.current_buffer.refresh()


@register_command
class SearchPreviousCommand(SameThreadCommand):
    name = "toggle-live-updates"
    description = "Toggle realtime updates of the interface (this is useful when you are " + \
                  "removing multiple objects and don't want the listing change during " + \
                  "the process so you accidentally remove something)."

    def run(self):
        self.ui.current_buffer.widget.toggle_realtime_events()


@register_command
class RedrawUI(SameThreadCommand):
    name = "redraw"
    description = "Redraw user interface."

    def run(self):
        self.ui.loop.screen.clear()
github TomasTomecek / sen / sen / tui / commands / widget.py View on Github external
widget specific commands
"""

import logging

from sen.tui.commands.base import register_command, SameThreadCommand


import urwidtrees


logger = logging.getLogger(__name__)


@register_command
class NavigateTopCommand(SameThreadCommand):
    name = "navigate-top"
    description = "go to first line"

    def run(self):
        # FIXME: refactor
        if isinstance(self.buffer.widget, urwidtrees.TreeBox):
            self.buffer.widget.focus_first()
        else:
            self.buffer.widget.set_focus(0)
            self.buffer.widget.reload_widget()


@register_command
class NavigateBottomCommand(SameThreadCommand):
    name = "navigate-bottom"
    description = "go to last line"
github TomasTomecek / sen / sen / tui / commands / widget.py View on Github external
@register_command
class NavigateBottomCommand(SameThreadCommand):
    name = "navigate-bottom"
    description = "go to last line"

    def run(self):
        # FIXME: refactor
        if isinstance(self.buffer.widget, urwidtrees.TreeBox):
            self.buffer.widget.focus_last()
        else:
            self.buffer.widget.set_focus(len(self.buffer.widget.body) - 1)
            self.buffer.widget.reload_widget()


@register_command
class NavigateUpCommand(SameThreadCommand):
    name = "navigate-up"
    description = "go one line up"

    def run(self):
        return super(self.buffer.widget.__class__, self.buffer.widget).keypress(self.size, "up")


@register_command
class NavigateDownCommand(SameThreadCommand):
    name = "navigate-down"
    description = "go one line down"

    def run(self):
        return super(self.buffer.widget.__class__, self.buffer.widget).keypress(self.size, "down")
github TomasTomecek / sen / sen / tui / commands / widget.py View on Github external
else:
            self.buffer.widget.set_focus(len(self.buffer.widget.body) - 1)
            self.buffer.widget.reload_widget()


@register_command
class NavigateUpCommand(SameThreadCommand):
    name = "navigate-up"
    description = "go one line up"

    def run(self):
        return super(self.buffer.widget.__class__, self.buffer.widget).keypress(self.size, "up")


@register_command
class NavigateDownCommand(SameThreadCommand):
    name = "navigate-down"
    description = "go one line down"

    def run(self):
        return super(self.buffer.widget.__class__, self.buffer.widget).keypress(self.size, "down")


@register_command
class NavigateUpwardsCommand(SameThreadCommand):
    name = "navigate-upwards"
    description = "go 10 lines up"

    def run(self):
        if isinstance(self.buffer.widget, urwidtrees.TreeBox):
            self.ui.notify_message("This movement is not available.", level="error")
            return