From a34a29277d3fd7107b351c2075e181bd81557769 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 4 Jul 2019 14:25:15 +0200 Subject: [PATCH] More directory completion --- confutils.nim | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/confutils.nim b/confutils.nim index 4cb66a4..3bfc226 100644 --- a/confutils.nim +++ b/confutils.nim @@ -257,7 +257,7 @@ proc completeCmdArg(T: type bool, val: TaintedString): seq[string] = proc completeCmdArg(T: type string, val: TaintedString): seq[string] = return @[] -proc completeCmdArg*(T: type[InputFile|InputDir], val: TaintedString): seq[string] = +proc completeCmdArg*(T: type[InputFile|InputDir|OutFile|OutDir|OutPath], val: TaintedString): seq[string] = let (dir, name, ext) = splitFile(val) let tail = name & ext # Expand the directory component for the directory walker routine @@ -272,22 +272,18 @@ proc completeCmdArg*(T: type[InputFile|InputDir], val: TaintedString): seq[strin # Do not show files if asked for directories, on the other hand we must show # directories even if a file is requested to allow the user to select a file # inside those - if type(T) is InputDir and kind notin {pcDir, pcLinkToDir}: + if type(T) is InputDir|OutDir and kind notin {pcDir, pcLinkToDir}: continue # Note, no normalization is needed here if path.startsWith(tail): - let match = if kind in {pcDir, pcLinkToDir}: - # Add a trailing slash so that completions can be chained - dir_path & DirSep & path & DirSep - else: - dir_path & DirSep & path + var match = dir_path / path + # Add a trailing slash so that completions can be chained + if kind in {pcDir, pcLinkToDir}: + match &= DirSep result.add(shellPathEscape(match)) -proc completeCmdArg*(T: type[OutFile|OutDir|OutPath], val: TaintedString): seq[string] = - return @[] - proc completeCmdArg[T](_: type seq[T], val: TaintedString): seq[string] = return @[]