iti/HandMesh
0
1# -*- coding: utf-8 -*-2 3# Copyright (c) 2012 Giorgos Verigakis <verigak@gmail.com>4#5# Permission to use, copy, modify, and distribute this software for any6# purpose with or without fee is hereby granted, provided that the above7# copyright notice and this permission notice appear in all copies.8#9# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES10# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF11# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR12# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES13# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN14# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF15# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.16 17from __future__ import unicode_literals18 19import sys20 21from . import Progress22 23 24class Bar(Progress):25 width = 3226 suffix = '%(index)d/%(max)d'27 bar_prefix = ' |'28 bar_suffix = '| '29 empty_fill = ' '30 fill = '#'31 32 def update(self):33 filled_length = int(self.width * self.progress)34 empty_length = self.width - filled_length35 36 message = self.message % self37 bar = self.fill * filled_length38 empty = self.empty_fill * empty_length39 suffix = self.suffix % self40 line = ''.join([message, self.bar_prefix, bar, empty, self.bar_suffix,41 suffix])42 self.writeln(line)43 44 45class ChargingBar(Bar):46 suffix = '%(percent)d%%'47 bar_prefix = ' '48 bar_suffix = ' '49 empty_fill = '∙'50 fill = '█'51 52 53class FillingSquaresBar(ChargingBar):54 empty_fill = '▢'55 fill = '▣'56 57 58class FillingCirclesBar(ChargingBar):59 empty_fill = '◯'60 fill = '◉'61 62 63class IncrementalBar(Bar):64 if sys.platform.startswith('win'):65 phases = (u' ', u'▌', u'█')66 else:67 phases = (' ', '▏', '▎', '▍', '▌', '▋', '▊', '▉', '█')68 69 def update(self):70 nphases = len(self.phases)71 filled_len = self.width * self.progress72 nfull = int(filled_len) # Number of full chars73 phase = int((filled_len - nfull) * nphases) # Phase of last char74 nempty = self.width - nfull # Number of empty chars75 76 message = self.message % self77 bar = self.phases[-1] * nfull78 current = self.phases[phase] if phase > 0 else ''79 empty = self.empty_fill * max(0, nempty - len(current))80 suffix = self.suffix % self81 line = ''.join([message, self.bar_prefix, bar, current, empty,82 self.bar_suffix, suffix])83 self.writeln(line)84 85 86class PixelBar(IncrementalBar):87 phases = ('⡀', '⡄', '⡆', '⡇', '⣇', '⣧', '⣷', '⣿')88 89 90class ShadyBar(IncrementalBar):91 phases = (' ', '░', '▒', '▓', '█')92 