A Python implementation of the curses tputs function; the curses one can't really be wrapped in a sane manner. I have the strong suspicion that this is complexity that will never do anyone any good.
(self, fmt, prog=delayprog)
| 783 | self.screen = ns |
| 784 | |
| 785 | def __tputs(self, fmt, prog=delayprog): |
| 786 | """A Python implementation of the curses tputs function; the |
| 787 | curses one can't really be wrapped in a sane manner. |
| 788 | |
| 789 | I have the strong suspicion that this is complexity that |
| 790 | will never do anyone any good.""" |
| 791 | # using .get() means that things will blow up |
| 792 | # only if the bps is actually needed (which I'm |
| 793 | # betting is pretty unlkely) |
| 794 | bps = ratedict.get(self.__svtermstate.ospeed) |
| 795 | while 1: |
| 796 | m = prog.search(fmt) |
| 797 | if not m: |
| 798 | os.write(self.output_fd, fmt) |
| 799 | break |
| 800 | x, y = m.span() |
| 801 | os.write(self.output_fd, fmt[:x]) |
| 802 | fmt = fmt[y:] |
| 803 | delay = int(m.group(1)) |
| 804 | if b"*" in m.group(2): |
| 805 | delay *= self.height |
| 806 | if self._pad and bps is not None: |
| 807 | nchars = (bps * delay) / 1000 |
| 808 | os.write(self.output_fd, self._pad * nchars) |
| 809 | else: |
| 810 | time.sleep(float(delay) / 1000.0) |