Skip to content

Commit

Permalink
more python3 adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
koreno committed Oct 5, 2015
1 parent 23c3652 commit 4ad9c2c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion termenu-cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import re
import sys
import termenu
Expand Down
6 changes: 4 additions & 2 deletions termenu/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
6 changes: 3 additions & 3 deletions termenu/termenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 4ad9c2c

Please sign in to comment.