mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-31 13:42:59 +00:00 
			
		
		
		
	Add include_hidden option to fs.complete (#1194)
This commit is contained in:
		| @@ -716,9 +716,17 @@ local tEmpty = {} | ||||
| function fs.complete(sPath, sLocation, bIncludeFiles, bIncludeDirs) | ||||
|     expect(1, sPath, "string") | ||||
|     expect(2, sLocation, "string") | ||||
|     expect(3, bIncludeFiles, "boolean", "nil") | ||||
|     expect(4, bIncludeDirs, "boolean", "nil") | ||||
|     local bIncludeHidden = nil | ||||
|     if type(bIncludeFiles) == "table" then | ||||
|         bIncludeDirs = bIncludeFiles.include_dirs | ||||
|         bIncludeHidden = bIncludeFiles.include_hidden | ||||
|         bIncludeFiles = bIncludeFiles.include_files | ||||
|     else | ||||
|         expect(3, bIncludeFiles, "boolean", "nil") | ||||
|         expect(4, bIncludeDirs, "boolean", "nil") | ||||
|     end | ||||
|  | ||||
|     bIncludeHidden = bIncludeHidden ~= false | ||||
|     bIncludeFiles = bIncludeFiles ~= false | ||||
|     bIncludeDirs = bIncludeDirs ~= false | ||||
|     local sDir = sLocation | ||||
| @@ -755,7 +763,9 @@ function fs.complete(sPath, sLocation, bIncludeFiles, bIncludeDirs) | ||||
|         local tFiles = fs.list(sDir) | ||||
|         for n = 1, #tFiles do | ||||
|             local sFile = tFiles[n] | ||||
|             if #sFile >= #sName and string.sub(sFile, 1, #sName) == sName then | ||||
|             if #sFile >= #sName and string.sub(sFile, 1, #sName) == sName and ( | ||||
|                 bIncludeHidden or sFile:sub(1, 1) ~= "." or sName:sub(1, 1) == "." | ||||
|             ) then | ||||
|                 local bIsDir = fs.isDir(fs.combine(sDir, sFile)) | ||||
|                 local sResult = string.sub(sFile, #sName + 1) | ||||
|                 if bIsDir then | ||||
| @@ -902,7 +912,7 @@ settings.define("paint.default_extension", { | ||||
|  | ||||
| settings.define("list.show_hidden", { | ||||
|     default = false, | ||||
|     description = [[Show hidden files (those starting with "." in the Lua REPL)]], | ||||
|     description = [[Show hidden files (those starting with "." in the Lua REPL).]], | ||||
|     type = "boolean", | ||||
| }) | ||||
|  | ||||
| @@ -937,6 +947,11 @@ settings.define("bios.strict_globals", { | ||||
|     description = "Prevents assigning variables into a program's environment. Make sure you use the local keyword or assign to _G explicitly.", | ||||
|     type = "boolean", | ||||
| }) | ||||
| settings.define("shell.autocomplete_hidden", { | ||||
|     default = false, | ||||
|     description = [[Autocomplete hidden files and folders (those starting with ".").]], | ||||
|     type = "boolean", | ||||
| }) | ||||
|  | ||||
| if term.isColour() then | ||||
|     settings.define("bios.use_multishell", { | ||||
|   | ||||
| @@ -34,7 +34,11 @@ local completion = require "cc.completion" | ||||
| -- @tparam string text Current text to complete. | ||||
| -- @treturn { string... } A list of suffixes of matching files. | ||||
| local function file(shell, text) | ||||
|     return fs.complete(text, shell.dir(), true, false) | ||||
|     return fs.complete(text, shell.dir(), { | ||||
|         include_files = true, | ||||
|         include_dirs = false, | ||||
|         include_hidden = settings.get("shell.autocomplete_hidden"), | ||||
|     }) | ||||
| end | ||||
|  | ||||
| --- Complete the name of a directory relative to the current working directory. | ||||
| @@ -43,7 +47,11 @@ end | ||||
| -- @tparam string text Current text to complete. | ||||
| -- @treturn { string... } A list of suffixes of matching directories. | ||||
| local function dir(shell, text) | ||||
|     return fs.complete(text, shell.dir(), false, true) | ||||
|     return fs.complete(text, shell.dir(), { | ||||
|         include_files = false, | ||||
|         include_dirs = true, | ||||
|         include_hidden = settings.get("shell.autocomplete_hidden"), | ||||
|     }) | ||||
| end | ||||
|  | ||||
| --- Complete the name of a file or directory relative to the current working | ||||
| @@ -55,7 +63,11 @@ end | ||||
| -- @tparam[opt] boolean add_space Whether to add a space after the completed item. | ||||
| -- @treturn { string... } A list of suffixes of matching files and directories. | ||||
| local function dirOrFile(shell, text, previous, add_space) | ||||
|     local results = fs.complete(text, shell.dir(), true, true) | ||||
|     local results = fs.complete(text, shell.dir(), { | ||||
|         include_files = true, | ||||
|         include_dirs = true, | ||||
|         include_hidden = settings.get("shell.autocomplete_hidden"), | ||||
|     }) | ||||
|     if add_space then | ||||
|         for n = 1, #results do | ||||
|             local result = results[n] | ||||
|   | ||||
| @@ -329,9 +329,14 @@ function shell.programs(include_hidden) | ||||
| end | ||||
|  | ||||
| local function completeProgram(sLine) | ||||
|     local bIncludeHidden = settings.get("shell.autocomplete_hidden") | ||||
|     if #sLine > 0 and (sLine:find("/") or sLine:find("\\")) then | ||||
|         -- Add programs from the root | ||||
|         return fs.complete(sLine, sDir, true, false) | ||||
|         return fs.complete(sLine, sDir, { | ||||
|             include_files = true, | ||||
|             include_dirs = false, | ||||
|             include_hidden = bIncludeHidden, | ||||
|         }) | ||||
|  | ||||
|     else | ||||
|         local tResults = {} | ||||
| @@ -349,7 +354,11 @@ local function completeProgram(sLine) | ||||
|         end | ||||
|  | ||||
|         -- Add all subdirectories. We don't include files as they will be added in the block below | ||||
|         local tDirs = fs.complete(sLine, sDir, false, false) | ||||
|         local tDirs = fs.complete(sLine, sDir, { | ||||
|             include_files = false, | ||||
|             include_dirs = false, | ||||
|             include_hidden = bIncludeHidden, | ||||
|         }) | ||||
|         for i = 1, #tDirs do | ||||
|             local sResult = tDirs[i] | ||||
|             if not tSeen[sResult] then | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Ivo Leal
					Ivo Leal