Package jazzparser :: Package utils :: Module interface
[hide private]
[frames] | no frames]

Source Code for Module jazzparser.utils.interface

 1  """Generic interface utilities (e.g. interactive command-line processing). 
 2   
 3  """ 
 4  """ 
 5  ============================== License ======================================== 
 6   Copyright (C) 2008, 2010-12 University of Edinburgh, Mark Granroth-Wilding 
 7    
 8   This file is part of The Jazz Parser. 
 9    
10   The Jazz Parser is free software: you can redistribute it and/or modify 
11   it under the terms of the GNU General Public License as published by 
12   the Free Software Foundation, either version 3 of the License, or 
13   (at your option) any later version. 
14    
15   The Jazz Parser is distributed in the hope that it will be useful, 
16   but WITHOUT ANY WARRANTY; without even the implied warranty of 
17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
18   GNU General Public License for more details. 
19    
20   You should have received a copy of the GNU General Public License 
21   along with The Jazz Parser.  If not, see <http://www.gnu.org/licenses/>. 
22   
23  ============================ End license ====================================== 
24   
25  """ 
26  __author__ = "Mark Granroth-Wilding <mark.granroth-wilding@ed.ac.uk>"  
27   
28   
29 -def boolean_input(prompt):
30 """ 31 Displays a prompt with a yes/no choice. Returns True is the user 32 selects yes, False otherwise. 33 34 """ 35 response = raw_input("%s [y/N] " % prompt) 36 if response.lower() == "y": 37 return True 38 else: 39 return False
40
41 -def input_iterator(prompt):
42 """ 43 Creates an iterator that will accept command line input indefinitely 44 and terminate when Ctrl+D is received. 45 46 The iterator uses C{raw_input}, so you can use it in conjunction with 47 C{readline}. 48 49 """ 50 # Define an iterator (via a generator) to get cmd line input 51 def _get_input(): 52 try: 53 while True: 54 yield raw_input(prompt) 55 except EOFError: 56 return
57 return iter(_get_input()) 58