Fine-tune completion a bit.

This commit is contained in:
Aldo Cortesi 2011-02-03 13:50:57 +13:00
parent 6c89749f0a
commit 7924f07971
5 changed files with 16 additions and 1 deletions

View File

@ -562,10 +562,13 @@ class _PathCompleter:
if os.path.isdir(path): if os.path.isdir(path):
files = glob.glob(os.path.join(path, "*")) files = glob.glob(os.path.join(path, "*"))
prefix = txt prefix = txt
elif os.path.isfile(path):
prefix = os.path.dirname(txt)
files = glob.glob(prefix+"/*")
else: else:
files = glob.glob(path+"*") files = glob.glob(path+"*")
prefix = os.path.dirname(txt) prefix = os.path.dirname(txt)
prefix = prefix.rstrip("/") or "./" prefix = prefix or "./"
for f in files: for f in files:
display = os.path.join(prefix, os.path.basename(f)) display = os.path.join(prefix, os.path.basename(f))
if os.path.isdir(f): if os.path.isdir(f):

0
test/completion/aaa Normal file
View File

0
test/completion/aab Normal file
View File

0
test/completion/aac Normal file
View File

View File

@ -123,6 +123,17 @@ class uformat_flow(libpry.AutoTree):
class uPathCompleter(libpry.AutoTree): class uPathCompleter(libpry.AutoTree):
def test_lookup_construction(self):
c = console._PathCompleter()
assert c.complete("/tm") == "/tmp/"
c.reset()
assert c.complete("./completion/a") == "./completion/aaa"
c.reset()
assert c.complete("./completion/aaa") == "./completion/aaa"
assert c.complete("./completion/aaa") == "./completion/aab"
def test_completion(self): def test_completion(self):
c = console._PathCompleter(True) c = console._PathCompleter(True)
c.reset() c.reset()
@ -152,6 +163,7 @@ class uPathCompleter(libpry.AutoTree):
tests = [ tests = [
uformat_keyvals(), uformat_keyvals(),
uformat_flow(), uformat_flow(),