##// END OF EJS Templates
add missing colors arg to console
Min RK -
Show More
@@ -1,145 +1,146 b''
1 """ A minimal application using the ZMQ-based terminal IPython frontend.
1 """ A minimal application using the ZMQ-based terminal IPython frontend.
2
2
3 This is not a complete console app, as subprocess will not be able to receive
3 This is not a complete console app, as subprocess will not be able to receive
4 input, there is no real readline support, among other limitations.
4 input, there is no real readline support, among other limitations.
5 """
5 """
6
6
7 # Copyright (c) IPython Development Team.
7 # Copyright (c) IPython Development Team.
8 # Distributed under the terms of the Modified BSD License.
8 # Distributed under the terms of the Modified BSD License.
9
9
10 import signal
10 import signal
11
11
12 from IPython.terminal.ipapp import TerminalIPythonApp, frontend_flags as term_flags
12 from IPython.terminal.ipapp import TerminalIPythonApp, frontend_flags as term_flags
13
13
14 from IPython.utils.traitlets import (
14 from IPython.utils.traitlets import (
15 Dict, Any
15 Dict, Any
16 )
16 )
17 from IPython.utils.warn import error
17 from IPython.utils.warn import error
18
18
19 from IPython.consoleapp import (
19 from IPython.consoleapp import (
20 IPythonConsoleApp, app_aliases, app_flags, aliases, flags
20 IPythonConsoleApp, app_aliases, app_flags, aliases, flags
21 )
21 )
22
22
23 from IPython.terminal.console.interactiveshell import ZMQTerminalInteractiveShell
23 from IPython.terminal.console.interactiveshell import ZMQTerminalInteractiveShell
24
24
25 #-----------------------------------------------------------------------------
25 #-----------------------------------------------------------------------------
26 # Globals
26 # Globals
27 #-----------------------------------------------------------------------------
27 #-----------------------------------------------------------------------------
28
28
29 _examples = """
29 _examples = """
30 ipython console # start the ZMQ-based console
30 ipython console # start the ZMQ-based console
31 ipython console --existing # connect to an existing ipython session
31 ipython console --existing # connect to an existing ipython session
32 """
32 """
33
33
34 #-----------------------------------------------------------------------------
34 #-----------------------------------------------------------------------------
35 # Flags and Aliases
35 # Flags and Aliases
36 #-----------------------------------------------------------------------------
36 #-----------------------------------------------------------------------------
37
37
38 # copy flags from mixin:
38 # copy flags from mixin:
39 flags = dict(flags)
39 flags = dict(flags)
40 # start with mixin frontend flags:
40 # start with mixin frontend flags:
41 frontend_flags = dict(app_flags)
41 frontend_flags = dict(app_flags)
42 # add TerminalIPApp flags:
42 # add TerminalIPApp flags:
43 frontend_flags.update(term_flags)
43 frontend_flags.update(term_flags)
44 # disable quick startup, as it won't propagate to the kernel anyway
44 # disable quick startup, as it won't propagate to the kernel anyway
45 frontend_flags.pop('quick')
45 frontend_flags.pop('quick')
46 # update full dict with frontend flags:
46 # update full dict with frontend flags:
47 flags.update(frontend_flags)
47 flags.update(frontend_flags)
48
48
49 # copy flags from mixin
49 # copy flags from mixin
50 aliases = dict(aliases)
50 aliases = dict(aliases)
51 # start with mixin frontend flags
51 # start with mixin frontend flags
52 frontend_aliases = dict(app_aliases)
52 frontend_aliases = dict(app_aliases)
53 # load updated frontend flags into full dict
53 # load updated frontend flags into full dict
54 aliases.update(frontend_aliases)
54 aliases.update(frontend_aliases)
55 aliases['colors'] = 'InteractiveShell.colors'
55
56
56 # get flags&aliases into sets, and remove a couple that
57 # get flags&aliases into sets, and remove a couple that
57 # shouldn't be scrubbed from backend flags:
58 # shouldn't be scrubbed from backend flags:
58 frontend_aliases = set(frontend_aliases.keys())
59 frontend_aliases = set(frontend_aliases.keys())
59 frontend_flags = set(frontend_flags.keys())
60 frontend_flags = set(frontend_flags.keys())
60
61
61
62
62 #-----------------------------------------------------------------------------
63 #-----------------------------------------------------------------------------
63 # Classes
64 # Classes
64 #-----------------------------------------------------------------------------
65 #-----------------------------------------------------------------------------
65
66
66
67
67 class ZMQTerminalIPythonApp(TerminalIPythonApp, IPythonConsoleApp):
68 class ZMQTerminalIPythonApp(TerminalIPythonApp, IPythonConsoleApp):
68 name = "ipython-console"
69 name = "ipython-console"
69 """Start a terminal frontend to the IPython zmq kernel."""
70 """Start a terminal frontend to the IPython zmq kernel."""
70
71
71 description = """
72 description = """
72 The IPython terminal-based Console.
73 The IPython terminal-based Console.
73
74
74 This launches a Console application inside a terminal.
75 This launches a Console application inside a terminal.
75
76
76 The Console supports various extra features beyond the traditional
77 The Console supports various extra features beyond the traditional
77 single-process Terminal IPython shell, such as connecting to an
78 single-process Terminal IPython shell, such as connecting to an
78 existing ipython session, via:
79 existing ipython session, via:
79
80
80 ipython console --existing
81 ipython console --existing
81
82
82 where the previous session could have been created by another ipython
83 where the previous session could have been created by another ipython
83 console, an ipython qtconsole, or by opening an ipython notebook.
84 console, an ipython qtconsole, or by opening an ipython notebook.
84
85
85 """
86 """
86 examples = _examples
87 examples = _examples
87
88
88 classes = [ZMQTerminalInteractiveShell] + IPythonConsoleApp.classes
89 classes = [ZMQTerminalInteractiveShell] + IPythonConsoleApp.classes
89 flags = Dict(flags)
90 flags = Dict(flags)
90 aliases = Dict(aliases)
91 aliases = Dict(aliases)
91 frontend_aliases = Any(frontend_aliases)
92 frontend_aliases = Any(frontend_aliases)
92 frontend_flags = Any(frontend_flags)
93 frontend_flags = Any(frontend_flags)
93
94
94 subcommands = Dict()
95 subcommands = Dict()
95
96
96 force_interact = True
97 force_interact = True
97
98
98 def parse_command_line(self, argv=None):
99 def parse_command_line(self, argv=None):
99 super(ZMQTerminalIPythonApp, self).parse_command_line(argv)
100 super(ZMQTerminalIPythonApp, self).parse_command_line(argv)
100 self.build_kernel_argv(self.extra_args)
101 self.build_kernel_argv(self.extra_args)
101
102
102 def init_shell(self):
103 def init_shell(self):
103 IPythonConsoleApp.initialize(self)
104 IPythonConsoleApp.initialize(self)
104 # relay sigint to kernel
105 # relay sigint to kernel
105 signal.signal(signal.SIGINT, self.handle_sigint)
106 signal.signal(signal.SIGINT, self.handle_sigint)
106 self.shell = ZMQTerminalInteractiveShell.instance(parent=self,
107 self.shell = ZMQTerminalInteractiveShell.instance(parent=self,
107 display_banner=False, profile_dir=self.profile_dir,
108 display_banner=False, profile_dir=self.profile_dir,
108 ipython_dir=self.ipython_dir,
109 ipython_dir=self.ipython_dir,
109 manager=self.kernel_manager,
110 manager=self.kernel_manager,
110 client=self.kernel_client,
111 client=self.kernel_client,
111 )
112 )
112
113
113 def init_gui_pylab(self):
114 def init_gui_pylab(self):
114 # no-op, because we don't want to import matplotlib in the frontend.
115 # no-op, because we don't want to import matplotlib in the frontend.
115 pass
116 pass
116
117
117 def handle_sigint(self, *args):
118 def handle_sigint(self, *args):
118 if self.shell._executing:
119 if self.shell._executing:
119 if self.kernel_manager:
120 if self.kernel_manager:
120 # interrupt already gets passed to subprocess by signal handler.
121 # interrupt already gets passed to subprocess by signal handler.
121 # Only if we prevent that should we need to explicitly call
122 # Only if we prevent that should we need to explicitly call
122 # interrupt_kernel, until which time, this would result in a
123 # interrupt_kernel, until which time, this would result in a
123 # double-interrupt:
124 # double-interrupt:
124 # self.kernel_manager.interrupt_kernel()
125 # self.kernel_manager.interrupt_kernel()
125 pass
126 pass
126 else:
127 else:
127 self.shell.write_err('\n')
128 self.shell.write_err('\n')
128 error("Cannot interrupt kernels we didn't start.\n")
129 error("Cannot interrupt kernels we didn't start.\n")
129 else:
130 else:
130 # raise the KeyboardInterrupt if we aren't waiting for execution,
131 # raise the KeyboardInterrupt if we aren't waiting for execution,
131 # so that the interact loop advances, and prompt is redrawn, etc.
132 # so that the interact loop advances, and prompt is redrawn, etc.
132 raise KeyboardInterrupt
133 raise KeyboardInterrupt
133
134
134
135
135 def init_code(self):
136 def init_code(self):
136 # no-op in the frontend, code gets run in the backend
137 # no-op in the frontend, code gets run in the backend
137 pass
138 pass
138
139
139
140
140 launch_new_instance = ZMQTerminalIPythonApp.launch_instance
141 launch_new_instance = ZMQTerminalIPythonApp.launch_instance
141
142
142
143
143 if __name__ == '__main__':
144 if __name__ == '__main__':
144 launch_new_instance()
145 launch_new_instance()
145
146
General Comments 0
You need to be logged in to leave comments. Login now