Exemplo n.º 1
0
    def _format_value(self, msg, percent=0.0):
        _, col = get_window_dim()
        bar_len = int(col) - len(msg) - 10

        completed = int(bar_len * percent)
        message = '{}['.format(msg)
        message += ('#' * completed).ljust(bar_len)
        message += ']  {:.1%}'.format(percent)
        return message
Exemplo n.º 2
0
    def _format_value(self, msg, percent=0.0):
        _, col = get_window_dim()
        bar_len = int(col) - len(msg) - 10

        completed = int(bar_len * percent)
        message = '{}['.format(msg)
        message += ('#' * completed).ljust(bar_len)
        message += ']  {:.1%}'.format(percent)
        return message
Exemplo n.º 3
0
def progress_view(shell):
    """ updates the view """
    global HEART_BEAT, DONE, PROGRESS_BAR
    while not DONE:
        _, col = get_window_dim()
        col = int(col)
        progress = get_progress_message()
        if '\n' in progress:
            prog_list = progress.split('\n')
            prog_val = len(prog_list[-1])
        else:
            prog_val = len(progress)
        buffer_size = col - prog_val - 4

        if PROGRESS_BAR:
            doc = u'{}:{}'.format(progress, PROGRESS_BAR)
            shell.spin_val = -1
            counter = 0
            HEART_BEAT = ''
        else:
            if progress and not DONE:
                if shell.spin_val >= 0:
                    beat = HEART_BEAT_VALUES[_get_heart_frequency()]
                    HEART_BEAT += beat
                    HEART_BEAT = HEART_BEAT[len(beat):]
                    len_beat = len(HEART_BEAT)
                    if len_beat > buffer_size:
                        HEART_BEAT = HEART_BEAT[len_beat - buffer_size:]

                    while len(HEART_BEAT) < buffer_size:
                        beat = HEART_BEAT_VALUES[_get_heart_frequency()]
                        HEART_BEAT += beat

                else:
                    shell.spin_val = 0
                    counter = 0
                    while counter < buffer_size:
                        beat = HEART_BEAT_VALUES[_get_heart_frequency()]
                        HEART_BEAT += beat
                        counter += len(beat)
            doc = u'{}:{}'.format(progress, HEART_BEAT)
        shell.cli.buffers['progress'].reset(
            initial_document=Document(doc))
        shell.cli.request_redraw()
        sleep(shell.intermediate_sleep)

    DONE = False
    PROGRESS_BAR = ''
    shell.spin_val = -1
    sleep(shell.final_sleep)
    return True
def progress_view(shell):
    """ updates the view """
    global HEART_BEAT, DONE, PROGRESS_BAR
    while not DONE:
        _, col = get_window_dim()
        col = int(col)
        progress = get_progress_message()
        if '\n' in progress:
            prog_list = progress.split('\n')
            prog_val = len(prog_list[-1])
        else:
            prog_val = len(progress)
        buffer_size = col - prog_val - 4

        if PROGRESS_BAR:
            doc = u'{}:{}'.format(progress, PROGRESS_BAR)
            shell.spin_val = -1
            counter = 0
            HEART_BEAT = ''
        else:
            if progress and not DONE:
                if shell.spin_val >= 0:
                    beat = HEART_BEAT_VALUES[_get_heart_frequency()]
                    HEART_BEAT += beat
                    HEART_BEAT = HEART_BEAT[len(beat):]
                    len_beat = len(HEART_BEAT)
                    if len_beat > buffer_size:
                        HEART_BEAT = HEART_BEAT[len_beat - buffer_size:]

                    while len(HEART_BEAT) < buffer_size:
                        beat = HEART_BEAT_VALUES[_get_heart_frequency()]
                        HEART_BEAT += beat

                else:
                    shell.spin_val = 0
                    counter = 0
                    while counter < buffer_size:
                        beat = HEART_BEAT_VALUES[_get_heart_frequency()]
                        HEART_BEAT += beat
                        counter += len(beat)
            doc = u'{}:{}'.format(progress, HEART_BEAT)
        shell.cli.buffers['progress'].reset(initial_document=Document(doc))
        shell.cli.request_redraw()
        sleep(shell.intermediate_sleep)

    DONE = False
    PROGRESS_BAR = ''
    shell.spin_val = -1
    sleep(shell.final_sleep)
    return True
Exemplo n.º 5
0
    def generate_help_text(self, text):
        """ generates the help text based on commands typed """
        command = param_descrip = example = ""
        any_documentation = False
        is_command = True
        rows, _ = get_window_dim()
        rows = int(rows)
        if not self.completer:
            return param_descrip, example

        for word in text.split():
            if word.startswith("-"):
                # any parameter
                is_command = False
            if is_command:
                command += str(word) + " "

            if self.completer and self.completer.is_completable(
                    command.rstrip()):
                cmdstp = command.rstrip()
                any_documentation = True

                if word in self.completer.command_parameters[
                        cmdstp] and self.completer.has_description(cmdstp +
                                                                   " " + word):
                    param_descrip = word + ":\n" + \
                        self.completer.param_description.get(cmdstp + " " + word, '')

                self.description_docs = u'{}'.format(
                    self.completer.command_description[cmdstp])

                if cmdstp in self.completer.command_examples:
                    string_example = ""
                    for example in self.completer.command_examples[cmdstp]:
                        for part in example:
                            string_example += part
                    example = self._space_examples(
                        self.completer.command_examples[cmdstp], rows,
                        self._section)

        if not any_documentation:
            self.description_docs = u''
        return param_descrip, example
Exemplo n.º 6
0
    def _update_toolbar(self):
        cli = self.cli
        _, cols = get_window_dim()
        cols = int(cols)

        empty_space = ""
        for _ in range(cols):
            empty_space += " "

        delta = datetime.datetime.utcnow() - START_TIME
        if self.user_feedback and delta.seconds < DISPLAY_TIME:
            toolbar = [
                ' Try out the \'feedback\' command',
                'If refreshed disappear in: {}'.format(str(DISPLAY_TIME - delta.seconds))]
        else:
            toolbar = self._toolbar_info()

        toolbar, empty_space = space_toolbar(toolbar, cols, empty_space)
        cli.buffers['bottom_toolbar'].reset(
            initial_document=Document(u'{}{}{}'.format(NOTIFICATIONS, toolbar, empty_space)))
Exemplo n.º 7
0
    def _update_toolbar(self):
        cli = self.cli
        _, cols = get_window_dim()
        cols = int(cols)

        empty_space = ""
        for _ in range(cols):
            empty_space += " "

        delta = datetime.datetime.utcnow() - START_TIME
        if self.user_feedback and delta.seconds < DISPLAY_TIME:
            toolbar = [
                ' Try out the \'feedback\' command',
                'If refreshed disappear in: {}'.format(str(DISPLAY_TIME - delta.seconds))]
        else:
            toolbar = self._toolbar_info()

        toolbar, empty_space = space_toolbar(toolbar, cols, empty_space)
        cli.buffers['bottom_toolbar'].reset(
            initial_document=Document(u'{}{}{}'.format(NOTIFICATIONS, toolbar, empty_space)))
Exemplo n.º 8
0
    def generate_help_text(self, text):
        """ generates the help text based on commands typed """
        command = param_descrip = example = ""
        any_documentation = False
        is_command = True
        rows, _ = get_window_dim()
        rows = int(rows)
        if not self.completer:
            return param_descrip, example

        for word in text.split():
            if word.startswith("-"):
                # any parameter
                is_command = False
            if is_command:
                command += str(word) + " "

            if self.completer and self.completer.is_completable(command.rstrip()):
                cmdstp = command.rstrip()
                any_documentation = True

                if word in self.completer.command_parameters[cmdstp] and self.completer.has_description(
                        cmdstp + " " + word):
                    param_descrip = word + ":\n" + \
                        self.completer.param_description.get(cmdstp + " " + word, '')

                self.description_docs = u'{}'.format(
                    self.completer.command_description[cmdstp])

                if cmdstp in self.completer.command_examples:
                    string_example = ""
                    for example in self.completer.command_examples[cmdstp]:
                        for part in example:
                            string_example += part
                    example = space_examples(
                        self.completer.command_examples[cmdstp], rows, get_section())

        if not any_documentation:
            self.description_docs = u''
        return param_descrip, example
Exemplo n.º 9
0
    def _update_toolbar(self):
        cli = self.cli
        _, cols = get_window_dim()
        cols = int(cols)

        empty_space = " " * cols

        delta = datetime.datetime.utcnow() - START_TIME
        if self.user_feedback and delta.seconds < DISPLAY_TIME:
            toolbar = [
                ' Try out the \'feedback\' command',
                'If refreshed disappear in: {}'.format(
                    str(DISPLAY_TIME - delta.seconds))
            ]
        elif self.command_table_thread.is_alive():
            toolbar = [' Loading...', 'Hit [enter] to refresh']
        else:
            toolbar = self._toolbar_info()

        toolbar, empty_space = space_toolbar(toolbar, empty_space)
        cli.buffers['bottom_toolbar'].reset(initial_document=Document(
            u'{}{}{}'.format(NOTIFICATIONS, toolbar, empty_space)))
Exemplo n.º 10
0
def progress_view(shell):
    """ updates the view """
    global HEART_BEAT, DONE, PROGRESS_BAR
    _, col = get_window_dim()
    col = int(col)
    progress = get_progress_message()
    buffer_size = col - len(progress) - 4

    if PROGRESS_BAR:
        doc = u'{}:{}'.format(progress, PROGRESS_BAR)
        shell.spin_val = -1
        counter = 0
        HEART_BEAT = ''
    else:
        if progress and not DONE:
            if shell.spin_val >= 0:
                beat = HEART_BEAT_VALUES[_get_heart_frequency()]
                HEART_BEAT += beat
                HEART_BEAT = HEART_BEAT[len(beat):]
                len_beat = len(HEART_BEAT)
                if len_beat > buffer_size:
                    HEART_BEAT = HEART_BEAT[len_beat - buffer_size:]

            else:
                shell.spin_val = 0
                counter = 0
                while counter < buffer_size:
                    beat = HEART_BEAT_VALUES[_get_heart_frequency()]
                    HEART_BEAT += beat
                    counter += len(beat)
        doc = u'{}:{}'.format(progress, HEART_BEAT)
    shell.cli.buffers['progress'].reset(
        initial_document=Document(doc))
    shell.cli.request_redraw()
    if DONE:
        DONE = False
        PROGRESS_BAR = ''
        shell.spin_val = -1
        return True
Exemplo n.º 11
0
    def on_input_timeout(self, cli):
        """
        brings up the metadata for the command if there is a valid command already typed
        """
        _, cols = get_window_dim()
        cols = int(cols)
        document = cli.current_buffer.document
        text = document.text
        empty_space = ""
        for i in range(cols):  # pylint: disable=unused-variable
            empty_space += " "

        text = text.replace('az', '')
        if self.default_command:
            text = self.default_command + ' ' + text

        param_info, example = self.generate_help_text(text)

        self.param_docs = u'{}'.format(param_info)
        self.example_docs = u'{}'.format(example)

        self._update_default_info()

        settings, empty_space = space_toolbar(_toolbar_info(), cols,
                                              empty_space)

        cli.buffers['description'].reset(initial_document=Document(
            self.description_docs, cursor_position=0))
        cli.buffers['parameter'].reset(
            initial_document=Document(self.param_docs))
        cli.buffers['examples'].reset(
            initial_document=Document(self.example_docs))
        cli.buffers['bottom_toolbar'].reset(initial_document=Document(
            u'{}{}{}'.format(NOTIFICATIONS, settings, empty_space)))
        cli.buffers['default_values'].reset(initial_document=Document(
            u'{}'.format(self.config_default if self.
                         config_default else 'No Default Values')))
        cli.request_redraw()
Exemplo n.º 12
0
    def _update_toolbar(self):
        cli = self.cli
        _, cols = get_window_dim()
        cols = int(cols)

        empty_space = " " * cols

        delta = datetime.datetime.utcnow() - START_TIME
        if self.user_feedback and delta.seconds < DISPLAY_TIME:
            toolbar = [
                ' Try out the \'feedback\' command',
                'If refreshed disappear in: {}'.format(str(DISPLAY_TIME - delta.seconds))]
        elif self.command_table_thread.is_alive():
            toolbar = [
                ' Loading...',
                'Hit [enter] to refresh'
            ]
        else:
            toolbar = self._toolbar_info()

        toolbar, empty_space = space_toolbar(toolbar, empty_space)
        cli.buffers['bottom_toolbar'].reset(
            initial_document=Document(u'{}{}{}'.format(NOTIFICATIONS, toolbar, empty_space)))
Exemplo n.º 13
0
def _get_window_columns():
    _, col = get_window_dim()
    return col
Exemplo n.º 14
0
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import math
import os
import json

import azclishell.configuration
from azclishell.command_tree import CommandBranch, CommandHead
from azclishell.util import get_window_dim

CONFIGURATION = azclishell.configuration.CONFIGURATION

ROWS, COLS = get_window_dim()

TOLERANCE = 10
LINE_MINIMUM = math.floor(int(COLS) / 2 - 15)

GLOBAL_PARAM_DESCRIPTIONS = {
    '--output': 'Output format',
    '-o': 'Output format',
    '--help': 'Get more information about a command',
    '-h': "Get more information about a command"
}
OUTPUT_CHOICES = ['json', 'tsv', 'table', 'jsonc']
OUTPUT_OPTIONS = ['--output', '-o']
GLOBAL_PARAM = list(GLOBAL_PARAM_DESCRIPTIONS.keys())

Exemplo n.º 15
0
def _get_window_columns():
    _, col = get_window_dim()
    return col
Exemplo n.º 16
0
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import math
import os
import json

import azclishell.configuration
from azclishell.command_tree import CommandBranch, CommandHead
from azclishell.util import get_window_dim

CONFIGURATION = azclishell.configuration.CONFIGURATION

ROWS, COLS = get_window_dim()

TOLERANCE = 10
LINE_MINIMUM = math.floor(int(COLS) / 2 - 15)

GLOBAL_PARAM_DESCRIPTIONS = {
    '--verbose':
    'Increase logging verbosity. Use --debug for full debug logs.',
    '--debug': 'Increase logging verbosity to show all debug logs.',
    '--output': 'Output format',
    '-o': 'Output format',
    '--help': 'Get more information about a command',
    '-h': "Get more information about a command"
}
OUTPUT_CHOICES = ['json', 'tsv', 'table', 'jsonc']
OUTPUT_OPTIONS = ['--output', '-o']
Exemplo n.º 17
0
    def on_input_timeout(self, cli):
        """
        When there is a pause in typing
        Brings up the metadata for the command if
        there is a valid command already typed
        """
        rows, cols = get_window_dim()
        rows = int(rows)
        cols = int(cols)
        document = cli.current_buffer.document
        text = document.text
        command = ""
        all_params = ""
        example = ""
        empty_space = ""
        for i in range(cols):
            empty_space += " "
        any_documentation = False
        is_command = True
        for word in text.split():
            if word.startswith("-"):
                is_command = False
            if is_command:
                if not word == 'az':
                    command += str(word) + " "

            if self.completer.is_completable(command.rstrip()):
                cmdstp = command.rstrip()
                any_documentation = True

                if word in self.completer.command_parameters[cmdstp] and \
                self.completer.has_description(cmdstp + " " + word):
                    all_params = word + ":\n" + \
                    self.completer.get_param_description(cmdstp+ \
                    " " + word)

                self.description_docs = u"%s" % \
                self.completer.get_description(cmdstp)

                if cmdstp in self.completer.command_examples:
                    string_example = ""
                    for example in self.completer.command_examples[cmdstp]:
                        for part in example:
                            string_example += part
                    example = self.space_examples(
                        self.completer.command_examples[cmdstp], rows)

        if not any_documentation:
            self.description_docs = u''

        self.param_docs = u"%s" % all_params
        self.example_docs = u'%s' % example

        options = az_config.config_parser.options(DEFAULTS_SECTION)
        self.config_default = ""
        for opt in options:
            self.config_default += opt + ": " + az_config.get(DEFAULTS_SECTION, opt) + "  "
        

        settings, empty_space = self._toolbar_info(cols, empty_space)

        cli.buffers['description'].reset(
            initial_document=Document(self.description_docs, cursor_position=0)
        )
        cli.buffers['parameter'].reset(
            initial_document=Document(self.param_docs)
        )
        cli.buffers['examples'].reset(
            initial_document=Document(self.example_docs)
        )
        cli.buffers['bottom_toolbar'].reset(
            initial_document=Document(u'%s%s%s' % \
            (NOTIFICATIONS, settings, empty_space))
        )
        cli.buffers['default_values'].reset(
            initial_document=Document(u'%s' %self.config_default)
        )
        cli.request_redraw()