File: bottom.py

package info (click to toggle)
iredis 1.9.1-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,388 kB
  • sloc: python: 6,494; sh: 16; makefile: 13
file content (35 lines) | stat: -rw-r--r-- 988 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import logging
from .commands import commands_summary
from .utils import command_syntax

BUTTOM_TEXT = "Ctrl-D to exit;"
logger = logging.getLogger(__name__)


class BottomToolbar:
    CHAR = "⣾⣷⣯⣟⡿⢿⣻⣽"

    def __init__(self, command_holder):
        self.index = 0
        # BottomToolbar can only read this variable
        self.command_holder = command_holder

    def get_animation_char(self):
        animation = self.CHAR[self.index]

        self.index += 1
        if self.index == len(self.CHAR):
            self.index = 0
        return animation

    def render(self):
        text = BUTTOM_TEXT
        # add command help if valide
        if self.command_holder.command:
            try:
                command_info = commands_summary[self.command_holder.command]
                text = command_syntax(self.command_holder.command, command_info)
            except KeyError as e:
                logger.exception(e)
                pass
        return text