commit 515da219f2915c965b0639819bfdb584787ac22f
parent 331db01fca60fed57fc9971951abf38d6e56e52a
Author: Skylar Hill <stellarskylark@posteo.net>
Date: Sun, 5 Jun 2022 14:41:24 -0500
Small refactor after discovering NimYaml actually defines a pairs iterator for nodes
Diffstat:
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/src/tui.nim b/src/tui.nim
@@ -227,13 +227,13 @@ proc command(state: State, file: string): string =
proc initializeState(state: State): void =
let tabs = state.sheet.root["tabs"]
for tab in tabs:
- for name, windows in tab.fields.pairs:
+ for name, windows in tab.pairs:
for win in windows.elems:
state.itemsByWindow[win.content] = newSeqOfCap[string](100)
state.selectedByWindow[win.content] = 0
state.scrollByWindow[win.content] = 0
- for name, content in state.sheet.root["expressions"].fields.pairs:
+ for name, content in state.sheet.root["expressions"].pairs:
let win = content.field("window")
if win == "":
exitProc(fmt"Error reading {name.content}: no window specified.")
@@ -248,7 +248,7 @@ proc initializeState(state: State): void =
for win in state.itemsByWindow.keys:
state.itemsbyWindow[win] = state.itemsByWindow[win].sorted
- for n, w in tabs[state.tabIndex].fields.pairs:
+ for n, w in tabs[state.tabIndex].pairs:
state.tabName = n.content
state.tabWindows = w.elems
@@ -258,7 +258,7 @@ proc addToItem(state: State, amt: int): void =
let node = state.sheet.expression(sel)
try:
let val = node.field("modifier").parseInt
- for key, content in node.fields.pairs:
+ for key, content in node.pairs:
if key.content == "modifier":
node[key] = newYamlNode($(val + amt))
except ValueError:
@@ -296,7 +296,7 @@ proc handleInput(state: State, file: string): int =
let words = state.commandText.split(" ")
let last = words[words.high]
var matches = newSeqOfCap[string](99)
- for key in state.sheet.root["expressions"].fields.keys:
+ for key, _ in state.sheet.root["expressions"].pairs:
if key.content.startsWith(last):
matches.add(key.content)
if matches.len == 1:
@@ -315,13 +315,13 @@ proc handleInput(state: State, file: string): int =
# There should only be one item, but because
# fields is a Table, it's necessary to use an iterator
# to get the name and content
- for n, w in tabs[state.tabIndex].fields.pairs:
+ for n, w in tabs[state.tabIndex].pairs:
state.tabName = n.content
state.tabWindows = w.elems
of Key.ShiftK:
state.tabIndex = state.tabIndex.loopDec(tabs.elems)
state.selWinIndex = 0
- for n, w in tabs[state.tabIndex].fields.pairs:
+ for n, w in tabs[state.tabIndex].pairs:
state.tabName = n.content
state.tabWindows = w.elems
diff --git a/src/utils.nim b/src/utils.nim
@@ -43,13 +43,13 @@ proc deFancy*(display: string): string =
result = result.toLowerAscii()
proc contains*(node: YamlNode, search: string): bool =
- for key in keys(node.fields):
+ for key, _ in node.pairs:
if key.content == search:
return true
return false
proc field*(node: YamlNode, search: string): string =
- for key, value in pairs(node.fields):
+ for key, value in node.pairs:
if key.content == search:
return value.content
return ""