Skip to content

Commit

Permalink
fix: compiling the project with Nim 2.2.0
Browse files Browse the repository at this point in the history
FossilOrigin-Name: 2d804f46ff9c0052791e94591da1e34c21a88a8b6198d0881187dc6251ab94e0
  • Loading branch information
thindil committed Oct 14, 2024
1 parent 227e1b5 commit 289a19e
Show file tree
Hide file tree
Showing 11 changed files with 91 additions and 91 deletions.
20 changes: 10 additions & 10 deletions src/aliases.nim
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ proc setAliases*(aliases; directory: Path; db) {.sideEffect, raises: [
aliases.clear
var
dbQuery: DbString = "SELECT id, name FROM aliases WHERE path='" &
$directory & "'"
directory.string & "'"
remainingDirectory: Path = parentDir(path = directory)
# Construct SQL querry, search for aliases also defined in parent directories
# if they are recursive
while remainingDirectory.len > 0:
dbQuery.add(y = " OR (path='" & $remainingDirectory & "' AND recursive=1)")
dbQuery.add(y = " OR (path='" & remainingDirectory.string & "' AND recursive=1)")
remainingDirectory = parentDir(path = remainingDirectory)
dbQuery.add(y = " ORDER BY id ASC")
# Set the aliases
Expand Down Expand Up @@ -312,7 +312,7 @@ proc showAlias(arguments; db): ResultCode {.sideEffect, raises: [], tags: [
if alias.description.len > 0: alias.description else: "(none)"),
style = color2)])
table.add(parts = [style(ss = "Path:", style = color), style(
ss = $alias.path & (if alias.recursive: " (recursive)" else: ""),
ss = alias.path.string & (if alias.recursive: " (recursive)" else: ""),
style = color2)])
table.add(parts = [style(ss = "Command(s):", style = color), style(
ss = alias.commands, style = color2)])
Expand Down Expand Up @@ -379,12 +379,12 @@ proc addAlias(aliases; db): ResultCode {.sideEffect, raises: [],
path = ($readInput(db = db)).Path
if path.len == 0:
showError(message = "Please enter a path for the alias.", db = db)
elif not dirExists(dir = $path) and $path != "exit":
elif not dirExists(dir = path.string) and path.string != "exit":
path = "".Path
showError(message = "Please enter a path to the existing directory", db = db)
if path.len == 0:
showFormPrompt(prompt = "Path", db = db)
if $path == "exit":
if path.string == "exit":
return showError(message = "Adding a new alias cancelled.", db = db)
# Set the recursiveness for the alias
showFormHeader(message = "(4/6 or 7) Recursiveness", db = db)
Expand Down Expand Up @@ -522,16 +522,16 @@ proc editAlias(arguments; aliases; db): ResultCode {.sideEffect, raises: [],
# Set the working directory for the alias
showFormHeader(message = "(3/6 or 7) Working directory", db = db)
showOutput(message = "The full path to the directory in which the alias will be available. If you want to have a global alias, set it to '/'. Current value: '" &
style(ss = alias.path, style = valueColor) &
style(ss = alias.path.string, style = valueColor) &
"'. Must be a path to the existing directory.", db = db)
showFormPrompt(prompt = "Path", db = db)
var path: Path = ($readInput(db = db)).Path
while path.len > 0 and ($path != "exit" and not dirExists(dir = $path)):
while path.len > 0 and (path.string != "exit" and not dirExists(dir = path.string)):
showError(message = "Please enter a path to the existing directory", db = db)
path = ($readInput(db = db)).Path
if $path == "exit":
if path.string == "exit":
return showError(message = "Editing the alias cancelled.", db = db)
elif $path == "":
elif path.string == "":
path = alias.path
# Set the recursiveness for the alias
showFormHeader(message = "(4/6 or 7) Recursiveness", db = db)
Expand Down Expand Up @@ -720,7 +720,7 @@ proc execAlias*(arguments; aliasId: UserInput; aliases;
try:
setVariables(newDirectory = currentDirectory, db = db,
oldDirectory = getCurrentDirectory())
setCurrentDir(newDir = $currentDirectory)
setCurrentDir(newDir = currentDirectory.string)
aliases.setAliases(directory = currentDirectory, db = db)
except OSError:
return showError(message = "Can't restore aliases and variables. Reason: ",
Expand Down
10 changes: 5 additions & 5 deletions src/commands.nim
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ proc changeDirectory(newDirectory; aliases; db): ResultCode {.sideEffect,
body:
try:
var path: Path = try:
absolutePath(path = expandTilde(path = $newDirectory)).Path
absolutePath(path = expandTilde(path = newDirectory.string)).Path
except ValueError:
return showError(message = "Can't get absolute path to the new directory.", db = db)
if not dirExists(dir = $path):
return showError(message = "Directory '" & $path &
if not dirExists(dir = path.string):
return showError(message = "Directory '" & path.string &
"' doesn't exist.", db = db)
path = expandFilename(filename = $path).Path
path = expandFilename(filename = path.string).Path
setVariables(newDirectory = path, db = db,
oldDirectory = getCurrentDirectory())
setCurrentDir(newDir = $path)
setCurrentDir(newDir = path.string)
aliases.setAliases(directory = path, db = db)
return QuitSuccess.ResultCode
except OSError:
Expand Down
22 changes: 11 additions & 11 deletions src/completion.nim
Original file line number Diff line number Diff line change
Expand Up @@ -161,17 +161,17 @@ proc getDirCompletion*(prefix: CompletionPrefix; completions: var seq[
(localPrefix.parentDir & DirSep).Path
if localPrefix.endsWith(suffix = DirSep):
parentDir = localPrefix.Path
for item in walkDir(dir = $parentDir.absolutePath, relative = true):
for item in walkDir(dir = parentDir.absolutePath.string, relative = true):
if completions.len >= completionAmount:
return
if (cType == files and not fileExists(filename = $parentDir &
item.path)) or (cType == dirs and not dirExists(dir = $parentDir & item.path)):
if (cType == files and not fileExists(filename = parentDir.string &
item.path)) or (cType == dirs and not dirExists(dir = parentDir.string & item.path)):
continue
var completion: CompletionString = (if dirExists(dir = $parentDir &
var completion: CompletionString = (if dirExists(dir = parentDir.string &
item.path): item.path & DirSep else: item.path)
if (completion.toLowerAscii.startsWith(prefix = prefixInsensitive) or
localPrefix.endsWith(suffix = DirSep)) and completion notin completions:
completions.add(y = $parentDir & completion)
completions.add(y = parentDir.string & completion)
except ValueError, OSError:
showError(message = "Can't get completion. Reason: ",
e = getCurrentException(), db = db)
Expand Down Expand Up @@ -223,7 +223,7 @@ proc getCommandCompletion*(prefix: CompletionPrefix; completions: var seq[
completions.add(y = $alias)
# Check for programs in the current directory
try:
for file in walkFiles(pattern = $getCurrentDirectory() & DirSep & prefix & "*"):
for file in walkFiles(pattern = getCurrentDirectory().string & DirSep & prefix & "*"):
if completions.len >= completionAmount:
return
let fileName: CompletionString = (when defined(
Expand Down Expand Up @@ -302,7 +302,7 @@ proc getCompletion*(commandName, prefix: CompletionPrefix; completions: var seq[
getDirCompletion(prefix = prefix, completions = completions, db = db, cType = files)
of dirsfiles:
getDirCompletion(prefix = prefix, completions = completions, db = db)
of commands:
of CompletionType.commands:
getCommandCompletion(prefix = prefix, completions = completions,
aliases = aliases, commands = commands, db = db)
of custom:
Expand Down Expand Up @@ -728,12 +728,12 @@ proc exportCompletion(arguments; db): ResultCode {.sideEffect, raises: [],
if completion.cValues.len > 0:
dict.setSectionKey(section = "", key = "Values",
value = completion.cValues)
dict.writeConfig(filename = $fileName)
dict.writeConfig(filename = fileName.string)
except KeyError, IOError, OSError:
return showError(message = "Can't create the completion export file. Reason: ",
e = getCurrentException(), db = db)
showOutput(message = "Exported the completion with Id: " & $id &
" to file: " & $fileName, color = success, db = db)
" to file: " & fileName.string, color = success, db = db)
return QuitSuccess.ResultCode

proc importCompletion(arguments; db): ResultCode {.sideEffect, raises: [],
Expand All @@ -757,7 +757,7 @@ proc importCompletion(arguments; db): ResultCode {.sideEffect, raises: [],
let fileName: Path = ($arguments[7 .. ^1]).Path
try:
let
dict: Config = loadConfig(filename = $fileName)
dict: Config = loadConfig(filename = fileName.string)
command: CommandName = dict.getSectionValue(section = "",
key = "Command")
if db.exists(T = Completion, cond = "command=?", params = command):
Expand All @@ -771,7 +771,7 @@ proc importCompletion(arguments; db): ResultCode {.sideEffect, raises: [],
except KeyError, ValueError, DbError, IOError, OSError, Exception:
return showError(message = "Can't import the completion from the file. Reason: ",
e = getCurrentException(), db = db)
showOutput(message = "Imported the completion from file : " & $fileName,
showOutput(message = "Imported the completion from file : " & fileName.string,
color = success, db = db)
return QuitSuccess.ResultCode

Expand Down
2 changes: 1 addition & 1 deletion src/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const
## The list of the shell's built-in commands
maxInputLength*: Positive = 4096
## The maximum length of the user input
version*: OutputMessage = "0.8.1"
version*: OutputMessage = "0.8.2"
## The version of the shell

proc getCurrentDirectory*(): Path {.raises: [], tags: [ReadIOEffect],
Expand Down
10 changes: 5 additions & 5 deletions src/db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,14 @@ proc startDb*(dbPath: Path): DbConn {.sideEffect, raises: [], tags: [
dbPath.len > 0
body:
try:
discard existsOrCreateDir(dir = $parentDir(path = dbPath))
discard existsOrCreateDir(dir = parentDir(path = dbPath).string)
except OSError, IOError:
showError(message = "Can't create directory for the shell's database. Reason: ",
e = getCurrentException(), db = nil)
return nil
let dbExists: bool = fileExists(filename = $dbPath)
let dbExists: bool = fileExists(filename = dbPath.string)
try:
result = open(connection = $dbPath, user = "", password = "", database = "")
result = open(connection = dbPath.string, user = "", password = "", database = "")
except DbError:
showError(message = "Can't open the shell's database. Reason: ",
e = getCurrentException(), db = nil)
Expand Down Expand Up @@ -324,7 +324,7 @@ proc exportDb(arguments; db): ResultCode {.sideEffect, raises: [], tags: [
return showError(message = "Unknown type of the shell's data to backup. Available types are: " &
tablesNames.join(sep = ", "), db = db)
try:
args[1].writeFile(content = execCmdEx(command = "sqlite3 " & $dbFile &
args[1].writeFile(content = execCmdEx(command = "sqlite3 " & dbFile.string &
" '.dump " & (if args.len > 2: args[2 .. ^1].join(
sep = " ") else: "") & "'").output)
showOutput(message = "The backup file: '" & $args[1] & "' created.",
Expand Down Expand Up @@ -353,7 +353,7 @@ proc importDb(arguments; db): ResultCode {.sideEffect, raises: [], tags: [
return showError(message = "Enter the name of the file from which the data will be imported to the database.", db = db)
try:
let res: tuple[output: string; exitCode: int] = execCmdEx(
command = "sqlite3 " & $dbFile & " '.read " & args[1] & "'")
command = "sqlite3 " & dbFile.string & " '.read " & args[1] & "'")
if res.exitCode == 0:
showOutput(message = "The data from the file: '" & $args[1] &
"' was imported to the database.", color = success, db = db)
Expand Down
12 changes: 6 additions & 6 deletions src/history.nim
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ proc updateHistory*(commandToAdd: CommandName; db;
var entry: HistoryEntry = newHistoryEntry()
# If the history entry exists, update the amount and time
if db.exists(T = HistoryEntry, cond = "command=? AND path=?", params = [
commandToAdd.dbValue, ($currentDir).dbValue]):
commandToAdd.dbValue, (currentDir.string).dbValue]):
db.select(obj = entry, cond = "command=? AND path=?", params = [
commandToAdd.dbValue, ($currentDir).dbValue])
commandToAdd.dbValue, (currentDir.string).dbValue])
entry.amount.inc
entry.lastUsed = now()
db.update(obj = entry)
Expand Down Expand Up @@ -187,10 +187,10 @@ proc getHistory*(historyIndex: HistoryRange; db;
# Get the command based on the historyIndex parameter
if searchFor.len == 0:
if db.exists(T = HistoryEntry, cond = "path=?",
params = $getCurrentDirectory()):
params = getCurrentDirectory().string):
try:
db.rawSelect(qry = "SELECT command FROM history WHERE path=? ORDER BY lastused DESC, amount ASC LIMIT 1 OFFSET ?",
obj = entry, params = [($getCurrentDirectory()).dbValue, ($(
obj = entry, params = [(getCurrentDirectory().string).dbValue, ($(
historyLength(db = db) - historyIndex)).dbValue])
except NotFoundError:
return searchFor
Expand All @@ -200,10 +200,10 @@ proc getHistory*(historyIndex: HistoryRange; db;
return entry.command
# Get the command based on the searchFor parameter
if db.exists(T = HistoryEntry, cond = "command LIKE ? AND path=?",
params = [(searchFor & "%").dbValue, ($getCurrentDirectory()).dbValue]):
params = [(searchFor & "%").dbValue, (getCurrentDirectory().string).dbValue]):
db.rawSelect(qry = "SELECT command FROM history WHERE command LIKE ? AND path=? ORDER BY lastused DESC, amount DESC",
obj = entry, params = [(searchFor & "%").dbValue,
($getCurrentDirectory()).dbValue])
(getCurrentDirectory().string).dbValue])
if entry.command.len == 0:
if db.exists(T = HistoryEntry, cond = "command LIKE ?", params = (
searchFor & "%").dbValue):
Expand Down
2 changes: 1 addition & 1 deletion src/input.nim
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ proc askForName*[T](db; action: OutputMessage; namesType: OutputMessage;
elif names is seq[Completion]:
itemName = name.command
elif names is seq[Plugin]:
itemName = $name.location
itemName = name.location.string
elif names is seq[Variable]:
itemName = name.name
row[rowIndex] = style(ss = "[" & $(index + 1) & "] ", style = getColor(
Expand Down
6 changes: 3 additions & 3 deletions src/nish.nim
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ proc main() {.sideEffect, raises: [], tags: [ReadIOEffect, WriteIOEffect,
initPlugins(db = db, commands = commands)

# Set the title of the terminal to current directory
setTitle(title = $getFormattedDir(), db = db)
setTitle(title = getFormattedDir().string, db = db)

# Start the shell
while true:
Expand Down Expand Up @@ -540,7 +540,7 @@ proc main() {.sideEffect, raises: [], tags: [ReadIOEffect, WriteIOEffect,
of "exit":
historyIndex = updateHistory(commandToAdd = "exit", db = db)
try:
setTitle(title = $getCurrentDirectory(), db = db)
setTitle(title = getCurrentDirectory().string, db = db)
except OSError:
setTitle(title = "nish", db = db)
closeDb(returnCode = returnCode, db = db)
Expand Down Expand Up @@ -619,7 +619,7 @@ proc main() {.sideEffect, raises: [], tags: [ReadIOEffect, WriteIOEffect,
historyIndex = updateHistory(commandToAdd = lastCommand, db = db,
returnCode = returnCode)
# Restore the terminal title
setTitle(title = $getFormattedDir(), db = db)
setTitle(title = getFormattedDir().string, db = db)
# Execute plugins with postcommand hook
try:
var plugins: seq[Plugin] = @[newPlugin()]
Expand Down
Loading

0 comments on commit 289a19e

Please sign in to comment.