Exemple #1
0
class PromptCommand(SameThreadCommand):
    name = "prompt"
    description = "Customize and pre-populate prompt with initial data."
    argument_definitions = [
        Argument("prompt-text", "Text forming the actual prompt", default=":"),
        Argument("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
        edit = urwid.Columns([
            ('fixed', len(self.arguments.prompt_text), leftpart),
            ('weight', 1, editpart),
        ])
        self.ui.prompt_bar = urwid.AttrMap(edit, "main_list_dg")

        self.ui.reload_footer()
        self.ui.set_focus("footer")

        urwid.connect_signal(editpart,
                             "change",
                             run_command_callback,
                             user_args=[self.ui])
Exemple #2
0
class MyCommand2(Command):
    name = "test2"
    description = "test desc 2"
    argument_definitions = [
        Argument("test-arg", "test-arg desc", aliases=["x"]),
        Argument("test-arg2", "test-arg2 desc", default="banana"),
    ]
    option_definitions = [
        Option("test-opt", "test-opt desc")
    ]

    def run(self):
        return 42
Exemple #3
0
class MyCommand(Command):
    name = "test"
    description = "test desc"
    argument_definitions = [
        Argument("test-arg", "test-arg desc", aliases=["x"])
    ]

    def run(self):
        return 42
Exemple #4
0
class DisplayBufferCommand(SameThreadCommand):
    name = "display-buffer"  # TODO: make this a universal display function

    arguments_definitions = [Argument("buffer", "Buffer instance to show.")]
    description = "This is an internal command and doesn't work from command line."

    def run(self):
        # TODO: doesn't work!, the method expects buffer class, not string
        self.ui.add_and_display_buffer(self.arguments.buffer)
Exemple #5
0
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)
Exemple #6
0
class SearchCommand(SameThreadCommand, LogTracebackMixin):
    name = "search"
    description = "search and highlight (provide empty string to disable searching)"
    arguments_definitions = [Argument("query", "Input string to search for")]
    aliases = ["/"]

    def run(self):
        # TODO: implement incsearch
        #   - match needs to be highlighted somehow, not with focus though
        #     - a line could split into a Text with multiple markups
        query = self.arguments.query if self.arguments.query is not None else ""
        self.do(self.ui.current_buffer.find_next, query)
Exemple #7
0
class LogsCommand(BackendCommand):
    name = "logs"
    description = "display logs of a container"
    argument_definitions = [
        Argument("follow", "Follow logs.", default=False, aliases=["-f", "f"])
    ]

    def run(self):
        self.ui.add_and_display_buffer(
            LogsBuffer(self.ui,
                       self.docker_object,
                       follow=self.arguments.follow))
Exemple #8
0
class DisplayHelpCommand(SameThreadCommand):
    name = "help"
    description = "Display help about buffer or command. When 'query' is not specified " + \
        "help for current buffer is being displayed."
    arguments_definitions = [
        Argument("query", "input string: command, buffer name")
    ]

    def run(self):
        if self.arguments.query is None:
            self.ui.add_and_display_buffer(HelpBuffer(self.ui, self.buffer))
            return
        try:
            command = self.ui.commander.get_command(self.arguments.query)
        except NoSuchCommand:
            self.ui.notify_message("There is no such command: %r" %
                                   self.arguments.query)
        else:
            self.ui.add_and_display_buffer(HelpBuffer(self.ui, command))
            return
Exemple #9
0
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="")
    ]

    def run(self):
        # TODO: realtime list change would be mindblowing
        self.do(self.ui.current_buffer.filter, self.arguments.query)