|
54 | 54 | amount: int32
|
55 | 55 | path: Path
|
56 | 56 |
|
57 |
| -proc command*(entry: HistoryEntry): CommandName {.sideEffect, raises: [], tags: [], |
58 |
| - contractual.} = |
| 57 | +proc command*(entry: HistoryEntry): CommandName {.sideEffect, raises: [], |
| 58 | + tags: [], contractual.} = |
59 | 59 | ## The getter of a field of HistoryEntry type
|
60 | 60 | ##
|
61 | 61 | ## * entry - the HistoryEntry object which field will be get
|
@@ -192,7 +192,14 @@ proc getHistory*(historyIndex: HistoryRange; db;
|
192 | 192 | try:
|
193 | 193 | type LocalEntry = ref object
|
194 | 194 | command: CommandName
|
195 |
| - var entry: LocalEntry = LocalEntry() |
| 195 | + proc initLocalEntry(command: CommandName = ""): LocalEntry {.raises: [], |
| 196 | + tags: [], contractual.} = |
| 197 | + ## Initialize a new instance of LocalEntry object |
| 198 | + ## * command - the name of the command executed by the user |
| 199 | + ## |
| 200 | + ## Returns the new instance of LocalEntry object |
| 201 | + result = LocalEntry(command: command) |
| 202 | + var entry: LocalEntry = initLocalEntry() |
196 | 203 | # Get the command based on the historyIndex parameter
|
197 | 204 | if searchFor.len == 0:
|
198 | 205 | if db.exists(T = HistoryEntry, cond = "path=?",
|
@@ -306,7 +313,18 @@ proc showHistory(db; arguments): ResultCode {.sideEffect, raises: [],
|
306 | 313 | command: CommandName
|
307 | 314 | lastUsed: DateTime
|
308 | 315 | amount: int32
|
309 |
| - var entries: seq[LocalEntry] = @[LocalEntry()] |
| 316 | + proc initLocalEntry(command: CommandName = ""; |
| 317 | + lastUsed: DateTime = DateTime(); |
| 318 | + amount: int32 = 0): LocalEntry {.raises: [], tags: [], contractual.} = |
| 319 | + ## Initialize a new instance of LocalEntry object |
| 320 | + ## * command - the name of the command executed by the user |
| 321 | + ## * lastUsed - the time when the command was last executed by the user |
| 322 | + ## * amount - how many times the command was executed by the user |
| 323 | + ## |
| 324 | + ## Returns the new instance of LocalEntry object |
| 325 | + result = LocalEntry(command: command, lastUsed: lastUsed, |
| 326 | + amount: amount) |
| 327 | + var entries: seq[LocalEntry] = @[initLocalEntry()] |
310 | 328 | db.rawSelect(qry = "SELECT command, lastused, amount FROM history ORDER BY " &
|
311 | 329 | historyOrder & " LIMIT 0, ?", objs = entries, params = amount)
|
312 | 330 | let color: ColorCode = getColor(db = db, name = default)
|
@@ -357,7 +375,14 @@ proc findInHistory(db; arguments): ResultCode {.raises: [], tags: [
|
357 | 375 | var currentRow: Natural = 0
|
358 | 376 | type LocalEntry = ref object
|
359 | 377 | command: CommandName
|
360 |
| - var entries: seq[LocalEntry] = @[LocalEntry()] |
| 378 | + proc initLocalEntry(command: CommandName = ""): LocalEntry {.raises: [], |
| 379 | + tags: [], contractual.} = |
| 380 | + ## Initialize a new instance of LocalEntry object |
| 381 | + ## * command - the name of the command executed by the user |
| 382 | + ## |
| 383 | + ## Returns the new instance of LocalEntry object |
| 384 | + result = LocalEntry(command: command) |
| 385 | + var entries: seq[LocalEntry] = @[initLocalEntry()] |
361 | 386 | db.rawSelect(qry = "SELECT command FROM history WHERE command LIKE ? ORDER BY lastused DESC, amount DESC",
|
362 | 387 | objs = entries, params = "%" & searchFor & "%")
|
363 | 388 | for entry in entries:
|
|
0 commit comments