rpgsheet

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 331db01fca60fed57fc9971951abf38d6e56e52a
parent e88d351065a7c5516bb6c032bcb1e495a1196c1e
Author: Skylar Hill <stellarskylark@posteo.net>
Date:   Sun,  5 Jun 2022 09:58:38 -0500

Support multi-line description

Diffstat:
Msrc/tui.nim | 23++++++++++++++---------
Mtemplates/dnd5e.yaml | 14+++++++++++++-
2 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/tui.nim b/src/tui.nim @@ -2,6 +2,7 @@ import illwill, std/algorithm, std/os, + std/sequtils, std/strutils, std/tables, std/wordwrap, @@ -448,8 +449,7 @@ proc drawWindows(state: State, tb: var TerminalBuffer, proc drawDescription(state: State, tb: var TerminalBuffer, bb: var BoxBuffer): void = let descY = tb.height - 10 - bb.drawRect(1, descY, - tb.width - 1, tb.height - 1, doubleStyle = true) + bb.drawRect(1, descY, tb.width - 1, tb.height - 1, doubleStyle = true) let sel = state.selectedItem if sel == "": @@ -465,13 +465,18 @@ proc drawDescription(state: State, tb: var TerminalBuffer, else: "hardcoded" else: "Press ENTER to roll" tb.write(3, descY + 1, fmt"Value: {val} [{roll}]") - if desc != "": - let formattedDesc = desc.wrapWords(maxLineWidth = min(60, tb.width - 6)) - let lines = formattedDesc.splitLines - for i in 0..lines.high: - if i < state.descScroll: - continue - tb.write(3, descY + 2 + i - state.descScroll, lines[i]) + + if desc == "": + return + var formattedDesc = newSeqOfCap[string](99) + for line in desc.splitLines: + let wrapped = line.wrapWords(maxLineWidth = min(60, tb.width - 6)) + formattedDesc = concat(formattedDesc, wrapped.splitLines) + for i in 0..formattedDesc.high: + if i < state.descScroll: + continue + let lineY = descY + 2 + i - state.descScroll + tb.write(3, lineY, formattedDesc[i]) proc runTui*(sheet: YamlDocument, file: string): void = diff --git a/templates/dnd5e.yaml b/templates/dnd5e.yaml @@ -283,5 +283,17 @@ expressions: modifier: spellcasting_ability+proficiency window: spellcasting_stats prestidigitation: - desc: "Cantrip. This spell is a minor magical trick that novice spellcasters use for practice. You create one of the following magical effects within range: 1) You create an instantaneous, harmless sensory effect, such as a shower of sparks, a puff of wind, faint musical notes, or an odd odor. 2) You instantaneously light or snuff out a candle, a torch, or a small campfire. 3) You instantaneously clean or soil an object no larger than 1 cubic foot. 4) You chill, warm, or flavor up to 1 cubic foot of nonliving material for 1 hour. 5) You make a color, a small mark, or a symbol appear on an object or a surface for 1 hour. 6) You create a nonmagical trinket or an illusory image that can fit in your hand and that lasts until the end of your next turn. If you cast this spell multiple times, you can have up to three of its non-instantaneous effects active at a time, and you can dismiss such an effect as an action." + desc: "Cantrip. This spell is a minor magical trick that novice spellcasters use for practice. You create one of the following magical effects within range: + + 1) You create an instantaneous, harmless sensory effect, such as a shower of sparks, a puff of wind, faint musical notes, or an odd odor. + + 2) You instantaneously light or snuff out a candle, a torch, or a small campfire. + + 3) You instantaneously clean or soil an object no larger than 1 cubic foot. + + 4) You chill, warm, or flavor up to 1 cubic foot of nonliving material for 1 hour. + + 5) You make a color, a small mark, or a symbol appear on an object or a surface for 1 hour. + + 6) You create a nonmagical trinket or an illusory image that can fit in your hand and that lasts until the end of your next turn. If you cast this spell multiple times, you can have up to three of its non-instantaneous effects active at a time, and you can dismiss such an effect as an action." window: spells