commit 17a9272df0e1daa2f9837db00197f7d11e2d5f39
parent cedf8a2155851dec8d6dfd2b1396d0e919048191
Author: Skylar Hill <stellarskylark@posteo.net>
Date: Sun, 5 Jun 2022 01:04:33 -0500
Add simple tab-completion for writing out expressions
Diffstat:
2 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/rpgsheet.nimble b/rpgsheet.nimble
@@ -1,6 +1,6 @@
# Package
-version = "0.2.2"
+version = "0.2.3"
author = "Skylar Hill"
description = "CLI/TUI application for TTRPG character sheets"
license = "GPL-3.0-only"
diff --git a/src/tui.nim b/src/tui.nim
@@ -84,6 +84,9 @@ proc toAscii(key: Key): string =
of Key.Plus: "+"
of Key.Minus: "-"
of Key.Asterisk: "*"
+ of Key.Underscore: "_"
+ of Key.Tilde: "~"
+ of Key.SingleQuote: "'"
else: ""
proc placeWindows(tb: TerminalBuffer, windows: seq[YamlNode], descY: int): Table[string, (int, int, int, int)] =
@@ -194,6 +197,15 @@ proc runTui*(sheet: YamlDocument, file: string): void =
commandText = commandText[0..^2]
of Key.CtrlU:
commandText = ""
+ of Key.Tab:
+ let words = commandText.split(" ")
+ let last = words[words.high]
+ var matches = newSeqOfCap[string](99)
+ for key in sheet.root["expressions"].fields.keys:
+ if key.content.startsWith(last):
+ matches.add(key.content)
+ if matches.len == 1:
+ commandText = commandText.replace(last, matches[0])
else:
commandText &= key.toAscii()
statusText = ":" & commandText