Commit 7ab10cce authored by Matthias Putz's avatar Matthias Putz

facing pager: make original work on linux + added test pager files for creating windows version

parent 7288b06b
This diff is collapsed.
...@@ -24,6 +24,7 @@ import sys ...@@ -24,6 +24,7 @@ import sys
import traceback import traceback
import time import time
import urllib.request import urllib.request
import portable
from repo_trace import SetTrace from repo_trace import SetTrace
from git_command import git, GitCommand from git_command import git, GitCommand
from git_config import init_ssh, close_ssh from git_config import init_ssh, close_ssh
...@@ -45,7 +46,12 @@ from subcmds import all_commands ...@@ -45,7 +46,12 @@ from subcmds import all_commands
# TODO workaround: disabled git pager since ideally it would fork to use less as pager # TODO workaround: disabled git pager since ideally it would fork to use less as pager
os.environ['GIT_PAGER'] = '' if portable.isLinux():
# will be set to less automatically, but let it be the default
#os.environ['GIT_PAGER'] = 'less'
pass
else:
os.environ['GIT_PAGER'] = ''
......
...@@ -820,7 +820,7 @@ class Project(object): ...@@ -820,7 +820,7 @@ class Project(object):
out.project('project %s/' % self.relpath) out.project('project %s/' % self.relpath)
out.nl() out.nl()
has_diff = True has_diff = True
print(line[:-1]) print(portable.stream2str(line)[:-1])
p.Wait() p.Wait()
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
</content> </content>
<orderEntry type="jdk" jdkName="Python 3.3.0 (/usr/bin/python3.3)" jdkType="Python SDK" /> <orderEntry type="jdk" jdkName="Python 3.3.0 (/usr/bin/python3.3)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Python 3.3.0 (/usr/bin/python3.3) interpreter library" level="application" />
</component> </component>
</module> </module>
import os
import sys
import select
__author__ = 'mputz'
def RunPager():
global active
if not os.isatty(0) or not os.isatty(1):
return
pager = 'less'
if pager == '' or pager == 'cat':
return
# This process turns into the pager; a child it forks will
# do the real processing and output back to the pager. This
# is necessary to keep the pager in control of the tty.
#
try:
r, w = os.pipe()
pid = os.fork()
if not pid:
os.dup2(w, 1)
os.dup2(w, 2)
os.close(r)
os.close(w)
active = True
return
os.dup2(r, 0)
os.close(r)
os.close(w)
_BecomePager(pager)
except Exception:
print("fatal: cannot start pager '%s'" % pager, file=sys.stderr)
sys.exit(255)
def _BecomePager(pager):
# Delaying execution of the pager until we have output
# ready works around a long-standing bug in popularly
# available versions of 'less', a better 'more'.
#
_a, _b, _c = select.select([0], [], [0])
os.environ['LESS'] = 'FRSX'
try:
os.execvp(pager, [pager])
except OSError:
os.execv('/bin/sh', ['sh', '-c', pager])
if __name__ == '__main__':
RunPager()
for i in range(0, 100):
print("%d" % i)
\ No newline at end of file
import os
import sys
import select
__author__ = 'mputz'
def RunPager():
global active
if not os.isatty(0) or not os.isatty(1):
return
pager = 'less'
if pager == '' or pager == 'cat':
return
# This process turns into the pager; a child it forks will
# do the real processing and output back to the pager. This
# is necessary to keep the pager in control of the tty.
#
try:
r, w = os.pipe()
pid = os.fork()
if not pid:
os.dup2(w, 1)
os.dup2(w, 2)
os.close(r)
os.close(w)
active = True
return
os.dup2(r, 0)
os.close(r)
os.close(w)
_BecomePager(pager)
except Exception:
print("fatal: cannot start pager '%s'" % pager, file=sys.stderr)
sys.exit(255)
def _BecomePager(pager):
# Delaying execution of the pager until we have output
# ready works around a long-standing bug in popularly
# available versions of 'less', a better 'more'.
#
_a, _b, _c = select.select([0], [], [0])
os.environ['LESS'] = 'FRSX'
try:
os.execvp(pager, [pager])
except OSError:
os.execv('/bin/sh', ['sh', '-c', pager])
if __name__ == '__main__':
RunPager()
for i in range(0, 100):
print("%d" % i)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment