You are not logged in.
Pages: 1
I've been searching for the longest time to find a python module that behaves like less or more with no luck. Even if I was able to harness the viewer from help() would be great but I can't figure out where that thing is on my system.
Any ideas?
Offline
From pydoc.py:
pipepager and tempfilepager are constructed by passing os.environ['PAGER'] as the second arg.
def pipepager(text, cmd):
"""Page through text by feeding it to another program."""
pipe = os.popen(cmd, 'w')
try:
pipe.write(text)
pipe.close()
except IOError:
pass # Ignore broken pipes caused by quitting the pager program.
def tempfilepager(text, cmd):
"""Page through text by invoking a program on a temporary file."""
import tempfile
filename = tempfile.mktemp()
file = open(filename, 'w')
file.write(text)
file.close()
try:
os.system(cmd + ' ' + filename)
finally:
os.unlink(filename)
def ttypager(text):
"""Page through text on a text terminal."""
lines = split(plain(text), 'n')
try:
import tty
fd = sys.stdin.fileno()
old = tty.tcgetattr(fd)
tty.setcbreak(fd)
getchar = lambda: sys.stdin.read(1)
except (ImportError, AttributeError):
tty = None
getchar = lambda: sys.stdin.readline()[:-1][:1]
try:
r = inc = os.environ.get('LINES', 25) - 1
sys.stdout.write(join(lines[:inc], 'n') + 'n')
while lines[r:]:
sys.stdout.write('-- more --')
sys.stdout.flush()
c = getchar()
if c in ['q', 'Q']:
sys.stdout.write('r r')
break
elif c in ['r', 'n']:
sys.stdout.write('r r' + lines[r] + 'n')
r = r + 1
continue
if c in ['b', 'B', 'x1b']:
r = r - inc - inc
if r < 0: r = 0
sys.stdout.write('n' + join(lines[r:r+inc], 'n') + 'n')
r = r + inc
finally:
if tty:
tty.tcsetattr(fd, tty.TCSAFLUSH, old)
def plainpager(text):
"""Simply print unformatted text. This is the ultimate fallback."""
sys.stdout.write(plain(text))
Offline
well thats some old f'd up code.
I was hoping for something a little more elaborate but maybe I can do something with this.
Thanks
Offline
Looks like you want something like ttypager. You can edit it, but it should work ok as a minipager
Offline
yeah, I was thinking of ttypager but running that code gives all sorts of errors I guess from old syntax (look at the use of join() and rc = in = line with a string subtracted from an int. I hacked it for a little while and got it running but I really wanted more of the functionality from more and less where /<keyword> and ?<keyword> work for example.
help() has everything I wan't, I just can't figure out how I can manipulate it for the use of random strings like: help('this stringnnext newlinenetcn'). If I could just find that file on my system if it exists...
Offline
help() is using less
vim /usr/lib/python2.4/pydoc.py
Offline
help() is using less
vim /usr/lib/python2.4/pydoc.py
doh! :oops:
Offline
Pages: 1