##// END OF EJS Templates
Add init_environment(), %less, %more, %man and %clear/%cls, in zmq shell....
Fernando Perez -
Show More
@@ -227,6 +227,7 b' class InteractiveShell(Configurable, Magic):'
227 # These are relatively independent and stateless
227 # These are relatively independent and stateless
228 self.init_ipython_dir(ipython_dir)
228 self.init_ipython_dir(ipython_dir)
229 self.init_instance_attrs()
229 self.init_instance_attrs()
230 self.init_environment()
230
231
231 # Create namespaces (user_ns, user_global_ns, etc.)
232 # Create namespaces (user_ns, user_global_ns, etc.)
232 self.init_create_namespaces(user_ns, user_global_ns)
233 self.init_create_namespaces(user_ns, user_global_ns)
@@ -396,6 +397,10 b' class InteractiveShell(Configurable, Magic):'
396 # interactive statements or whole blocks.
397 # interactive statements or whole blocks.
397 self.input_splitter = IPythonInputSplitter()
398 self.input_splitter = IPythonInputSplitter()
398
399
400 def init_environment(self):
401 """Any changes we need to make to the user's environment."""
402 pass
403
399 def init_encoding(self):
404 def init_encoding(self):
400 # Get system encoding at startup time. Certain terminals (like Emacs
405 # Get system encoding at startup time. Certain terminals (like Emacs
401 # under Win32 have it set to None, and we need to have a known valid
406 # under Win32 have it set to None, and we need to have a known valid
@@ -1869,7 +1874,7 b' class InteractiveShell(Configurable, Magic):'
1869 Parameters
1874 Parameters
1870 ----------
1875 ----------
1871 cmd : str
1876 cmd : str
1872 Command to execute (can not end in '&', as bacground processes are
1877 Command to execute (can not end in '&', as background processes are
1873 not supported.
1878 not supported.
1874 split : bool, optional
1879 split : bool, optional
1875
1880
@@ -577,7 +577,6 b' Currently the magic system has the following functions:\\n"""'
577 """Provide extra detailed information about an object.
577 """Provide extra detailed information about an object.
578
578
579 '%pinfo2 object' is just a synonym for object?? or ??object."""
579 '%pinfo2 object' is just a synonym for object?? or ??object."""
580 print 'pinfo2 par: <%s>' % parameter_s # dbg
581 self.shell._inspect('pinfo', parameter_s, detail_level=1,
580 self.shell._inspect('pinfo', parameter_s, detail_level=1,
582 namespaces=namespaces)
581 namespaces=namespaces)
583
582
@@ -2509,6 +2508,7 b' Defaulting color scheme to \'NoColor\'"""'
2509 # atab.append(k, v[0])
2508 # atab.append(k, v[0])
2510
2509
2511 print "Total number of aliases:", len(aliases)
2510 print "Total number of aliases:", len(aliases)
2511 sys.stdout.flush()
2512 return aliases
2512 return aliases
2513
2513
2514 # Now try to define a new one
2514 # Now try to define a new one
@@ -2917,11 +2917,8 b' Defaulting color scheme to \'NoColor\'"""'
2917 except ValueError:
2917 except ValueError:
2918 var,cmd = '',''
2918 var,cmd = '',''
2919 # If all looks ok, proceed
2919 # If all looks ok, proceed
2920 out = self.shell.getoutput(cmd)
2920 split = 'l' in opts
2921 if opts.has_key('l'):
2921 out = self.shell.getoutput(cmd, split=split)
2922 out = SList(out.splitlines())
2923 else:
2924 out = LSString(out)
2925 if opts.has_key('v'):
2922 if opts.has_key('v'):
2926 print '%s ==\n%s' % (var,pformat(out))
2923 print '%s ==\n%s' % (var,pformat(out))
2927 if var:
2924 if var:
@@ -2965,9 +2962,7 b' Defaulting color scheme to \'NoColor\'"""'
2965 system commands."""
2962 system commands."""
2966
2963
2967 if parameter_s:
2964 if parameter_s:
2968 out = self.shell.getoutput(parameter_s)
2965 return self.shell.getoutput(parameter_s)
2969 if out is not None:
2970 return SList(out.splitlines())
2971
2966
2972 def magic_r(self, parameter_s=''):
2967 def magic_r(self, parameter_s=''):
2973 """Repeat previous input.
2968 """Repeat previous input.
@@ -24,6 +24,7 b' import re'
24 from IPython.core.interactiveshell import (
24 from IPython.core.interactiveshell import (
25 InteractiveShell, InteractiveShellABC
25 InteractiveShell, InteractiveShellABC
26 )
26 )
27 from IPython.core import page
27 from IPython.core.displayhook import DisplayHook
28 from IPython.core.displayhook import DisplayHook
28 from IPython.core.macro import Macro
29 from IPython.core.macro import Macro
29 from IPython.core.payloadpage import install_payload_page
30 from IPython.core.payloadpage import install_payload_page
@@ -78,6 +79,19 b' class ZMQInteractiveShell(InteractiveShell):'
78
79
79 displayhook_class = Type(ZMQDisplayHook)
80 displayhook_class = Type(ZMQDisplayHook)
80
81
82 def init_environment(self):
83 """Configure the user's environment.
84
85 """
86 env = os.environ
87 # These two ensure 'ls' produces nice coloring on BSD-derived systems
88 env['TERM'] = 'xterm-color'
89 env['CLICOLOR'] = '1'
90 # Since normal pagers don't work at all (over pexpect we don't have
91 # single-key control of the subprocess), try to disable paging in
92 # subprocesses as much as possible.
93 env['PAGER'] = 'cat'
94 env['GIT_PAGER'] = 'cat'
81
95
82 def auto_rewrite_input(self, cmd):
96 def auto_rewrite_input(self, cmd):
83 """Called to show the auto-rewritten input for autocall and friends.
97 """Called to show the auto-rewritten input for autocall and friends.
@@ -485,5 +499,37 b' class ZMQInteractiveShell(InteractiveShell):'
485 raise NotImplementedError(
499 raise NotImplementedError(
486 'pylab support must be enabled in command line options.')
500 'pylab support must be enabled in command line options.')
487
501
502 # A few magics that are adapted to the specifics of using pexpect and a
503 # remote terminal
504
505 def magic_clear(self, arg_s):
506 """Clear the terminal."""
507 if os.name == 'posix':
508 self.shell.system("clear")
509 else:
510 self.shell.system("cls")
511
512 if os.name == 'nt':
513 # This is the usual name in windows
514 magic_cls = magic_clear
515
516 # Terminal pagers won't work over pexpect, but we do have our own pager
517
518 def magic_less(self, arg_s):
519 """Show a file through the pager.
520
521 Files ending in .py are syntax-highlighted."""
522 cont = open(arg_s).read()
523 if arg_s.endswith('.py'):
524 cont = self.shell.pycolorize(cont)
525 page.page(cont)
526
527 magic_more = magic_less
528
529 # Man calls a pager, so we also need to redefine it
530 if os.name == 'posix':
531 def magic_man(self, arg_s):
532 """Find the man page for the given command and display in pager."""
533 page.page(self.shell.getoutput('man %s' % arg_s, split=False))
488
534
489 InteractiveShellABC.register(ZMQInteractiveShell)
535 InteractiveShellABC.register(ZMQInteractiveShell)
General Comments 0
You need to be logged in to leave comments. Login now