diff --git a/termenu-cmd b/termenu-cmd index 26181f2..77989fa 100755 --- a/termenu-cmd +++ b/termenu-cmd @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 import re import sys import termenu diff --git a/termenu/colors.py b/termenu/colors.py index c030a97..f9221ef 100644 --- a/termenu/colors.py +++ b/termenu/colors.py @@ -169,12 +169,14 @@ def inner(self, *args): def __getitem__(self, idx): if isinstance(idx, slice) and idx.step is None: + start = idx.start or 0 + stop = idx.stop or len(self) cursor = 0 tokens = [] for token in self.tokens: - tokens.append(token[max(0, idx.start - cursor):idx.stop - cursor]) + tokens.append(token[max(0, start - cursor):stop - cursor]) cursor += len(token) - if cursor > idx.stop: + if cursor > stop: break return self.__class__("".join(t.raw() for t in tokens if t)) diff --git a/termenu/termenu.py b/termenu/termenu.py index 2abf1ed..f389578 100644 --- a/termenu/termenu.py +++ b/termenu/termenu.py @@ -571,16 +571,16 @@ def redirect_std(): stdin = sys.stdin stdout = sys.stdout if not sys.stdin.isatty(): - sys.stdin = open("/dev/tty", "r", 0) + sys.stdin = open("/dev/tty", "rb", 0) if not sys.stdout.isatty(): - sys.stdout = open("/dev/tty", "w", 0) + sys.stdout = open("/dev/tty", "wb", 0) return stdin, stdout def shorten(s, l=100): if len(s) <= l or l < 3: return s - return s[:l/2-2] + "..." + s[-l/2+1:] + return s[:l//2-2] + "..." + s[-l//2+1:] try: