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