Changeset 423
- Timestamp:
- 05/17/07 09:02:10 (2 years ago)
- Files:
-
- cly/trunk/cly/console.py (modified) (2 diffs)
- cly/trunk/cly/interactive.py (modified) (1 diff)
- cly/trunk/cly/rlext.c (modified) (1 diff)
- cly/trunk/cly/variables.py (modified) (6 diffs)
- cly/trunk/doc/html4css1.css (deleted)
- cly/trunk/doc/Makefile (deleted)
- cly/trunk/doc/pygments.css (deleted)
- cly/trunk/doc/stylesheet.css (added)
- cly/trunk/doc/tutorial.py (added)
- cly/trunk/doc/tutorial.rst (added)
- cly/trunk/README (added)
- cly/trunk/setup.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
cly/trunk/cly/console.py
r422 r423 52 52 53 53 54 try: 55 import curses 56 curses.setupterm() 57 if curses.tigetnum('colors') >= 0: 58 _colour_terminal = 1 59 except: 60 pass 54 if sys.stdout.isatty(): 55 try: 56 import curses 57 curses.setupterm() 58 if curses.tigetnum('colors') >= 0: 59 _colour_terminal = 1 60 except: 61 pass 62 63 try: 64 import msvcrt 65 def getch(): 66 """Get a single character from the terminal.""" 67 return msvcrt.getch() 68 except ImportError: 69 def getch(): 70 """Get a single character from the terminal.""" 71 import tty 72 import termios 73 74 fd = sys.stdin.fileno() 75 old_settings = termios.tcgetattr(fd) 76 try: 77 tty.setraw(sys.stdin.fileno()) 78 ch = sys.stdin.read(1) 79 finally: 80 termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) 81 return ch 61 82 62 83 … … 440 461 rowalt += 1 441 462 442 try:443 import msvcrt444 def getch():445 """Get a single character from the terminal."""446 return msvcrt.getch()447 except ImportError:448 import tty, sys, termios449 450 def getch():451 """Get a single character from the terminal."""452 fd = sys.stdin.fileno()453 old_settings = termios.tcgetattr(fd)454 try:455 tty.setraw(sys.stdin.fileno())456 ch = sys.stdin.read(1)457 finally:458 termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)459 return ch460 461 getch.__doc__ = " Read a single character from stdin. "462 463 463 464 464 if __name__ == '__main__': cly/trunk/cly/interactive.py
r421 r423 61 61 user_context=None, history_file=None, history_length=500, 62 62 completion_key='tab', 63 completion_delimiters='`!#$%^&*()=+[{]}\|;\'",<>? \t', 63 #completion_delimiters='`!#$%^&*()=+[{]}\|;\'",<>? \t', 64 completion_delimiters=' \t', 64 65 help_key='?'): 65 66 if prompt is None: cly/trunk/cly/rlext.c
r403 r423 1 /* 2 * 3 * Copyright (C) 2006-2007 Alec Thomas <alec@swapoff.org> 4 * 5 * This software is licensed as described in the file COPYING, which 6 * you should have received as part of this distribution. 7 * 8 * 9 */ 1 10 #include "Python.h" 2 11 #include <readline/readline.h> cly/trunk/cly/variables.py
r413 r423 17 17 18 18 __all__ = ['Word', 'String', 'URI', 'LDAPDN', 'Integer', 'Float', 'IP', 19 'Hostname', 'Host', 'EMail', ' LocalFile']19 'Hostname', 'Host', 'EMail', 'File'] 20 20 21 21 … … 179 179 180 180 181 class LocalFile(Variable):181 class File(Variable): 182 182 """Match and provide completion candidates for local files. 183 183 184 184 >>> from cly import * 185 >>> parser = Parser(Grammar(foo= LocalFile('Foo')))185 >>> parser = Parser(Grammar(foo=File('Foo', allow_directories=True))) 186 186 >>> parser.parse('.').vars['foo'] 187 187 '.' … … 190 190 includes = ['*'] 191 191 excludes = [] 192 dotfiles = False 192 allow_dotfiles = False 193 allow_directories = False 193 194 194 195 def match(self, context): 195 196 match = Variable.match(self, context) 196 if match and os.path.exists(os.path.expanduser(match.group())):197 if match and self.match_file(match.group(), self.allow_directories): 197 198 return match 199 200 def match_file(self, file, match_directories=True): 201 from fnmatch import fnmatch 202 file = os.path.expanduser(file) 203 if match_directories and os.path.isdir(file): 204 return True 205 if not self.allow_dotfiles and os.path.basename(file).startswith('.'): 206 return False 207 for exclude in self.excludes: 208 if fnmatch(file, exclude): 209 return False 210 for include in self.includes: 211 if fnmatch(file, include): 212 return True 213 return False 198 214 199 215 def candidates(self, context, text): 200 216 """Return list of valid file candidates.""" 201 from fnmatch import fnmatch202 217 203 218 if text.startswith('~'): … … 223 238 return file 224 239 225 def match(file):226 if os.path.isdir(file):227 return True228 for exclude in self.excludes:229 if fnmatch(file, exclude):230 return False231 for include in self.includes:232 if fnmatch(file, include):233 return True234 return False235 236 240 def get_candidates(dir, file): 237 241 return [f for f in os.listdir(dir) if f.startswith(file) 238 and match(os.path.join(dir, f))]242 and self.match_file(os.path.join(dir, f))] 239 243 240 244 candidates = get_candidates(dir, file) … … 242 246 if os.path.isdir(os.path.join(dir, candidates[0])): 243 247 dir = os.path.join(dir, candidates[0] + '/') 248 return [dir] 244 249 file = '' 245 250 candidates = get_candidates(dir, file) … … 247 252 return [clean(os.path.join(dir, candidates[0] + ' '))] 248 253 return [clean(os.path.join(dir, f)) 249 for f in candidates if self. dotfiles or f[0] != '.']254 for f in candidates if self.allow_dotfiles or f[0] != '.'] 250 255 251 256 cly/trunk/setup.py
r413 r423 11 11 author_email='alec@swapoff.org', 12 12 version=cly.__version__, 13 description="CLY is a Python module for simplifying the creation of interactive shells. Kind of like the builtin `cmd` module on steroids.", 14 long_description=cly.__doc__, 15 license='BSD', 16 platforms=['any'], 13 17 packages=['cly'], 14 18 test_suite='cly.test.suite', 19 classifiers=['Development Status :: 3 - Alpha', 20 'Intended Audience :: Developers', 21 'License :: OSI Approved :: BSD License', 22 'Operating System :: OS Independent', 23 'Topic :: System :: Shells', 24 'Environment :: Console', 25 'Topic :: Software Development :: Libraries'], 15 26 ext_modules=[Extension('cly.rlext', ['cly/rlext.c'], 16 27 libraries = ['readline', 'curses'])])
