final receipt update

This commit is contained in:
EugeneTes
2026-01-22 11:09:38 +01:00
parent 9fbc61dede
commit fcb192b797
31 changed files with 2679 additions and 655 deletions

View File

@@ -41,78 +41,77 @@ public class TemplateInterpreter
List<PrintCommand> commands,
StyleContext style)
{
var lineBuffer = new StringBuilder();
var hasInlineContent = false;
void FlushLineBuffer()
{
if (hasInlineContent)
{
var text = ApplyAlignment(lineBuffer.ToString(), style);
commands.Add(CreateCommand(text, style));
lineBuffer.Clear();
hasInlineContent = false;
}
}
foreach (var node in nodes)
{
InterpretNode(node, context, commands, style);
switch (node)
{
// Inline nodes - accumulate into line buffer
case TextNode textNode:
lineBuffer.Append(textNode.Text);
hasInlineContent = true;
break;
case BindingNode bindingNode:
var element = context.Resolve(bindingNode.Path);
lineBuffer.Append(_formatter.Format(element, bindingNode.Format));
hasInlineContent = true;
break;
// Styled text - flush buffer, emit styled content, continue accumulating
case StyledTextNode styledNode:
FlushLineBuffer();
InterpretStyledText(styledNode, context, commands, style);
break;
// Block nodes - flush buffer first, then process
case SeparatorNode separatorNode:
FlushLineBuffer();
InterpretSeparator(separatorNode, commands, style);
break;
case EmptyLineNode:
FlushLineBuffer();
commands.Add(CreateCommand(string.Empty, style));
break;
case IfNode ifNode:
FlushLineBuffer();
InterpretIf(ifNode, context, commands, style);
break;
case ForeachNode foreachNode:
FlushLineBuffer();
InterpretForeach(foreachNode, context, commands, style);
break;
case RowNode rowNode:
FlushLineBuffer();
InterpretRow(rowNode, context, commands, style);
break;
case ColumnNode columnNode:
FlushLineBuffer();
InterpretColumn(columnNode, context, commands, style);
break;
}
}
}
private void InterpretNode(
ITemplateNode node,
DataContext context,
List<PrintCommand> commands,
StyleContext style)
{
switch (node)
{
case TextNode textNode:
InterpretText(textNode, context, commands, style);
break;
case BindingNode bindingNode:
InterpretBinding(bindingNode, context, commands, style);
break;
case StyledTextNode styledNode:
InterpretStyledText(styledNode, context, commands, style);
break;
case SeparatorNode separatorNode:
InterpretSeparator(separatorNode, commands, style);
break;
case EmptyLineNode:
commands.Add(CreateCommand(string.Empty, style));
break;
case IfNode ifNode:
InterpretIf(ifNode, context, commands, style);
break;
case ForeachNode foreachNode:
InterpretForeach(foreachNode, context, commands, style);
break;
case RowNode rowNode:
InterpretRow(rowNode, context, commands, style);
break;
case ColumnNode columnNode:
InterpretColumn(columnNode, context, commands, style);
break;
}
}
private void InterpretText(
TextNode node,
DataContext context,
List<PrintCommand> commands,
StyleContext style)
{
var text = ApplyAlignment(node.Text, style);
commands.Add(CreateCommand(text, style));
}
private void InterpretBinding(
BindingNode node,
DataContext context,
List<PrintCommand> commands,
StyleContext style)
{
var element = context.Resolve(node.Path);
var text = _formatter.Format(element, node.Format);
text = ApplyAlignment(text, style);
commands.Add(CreateCommand(text, style));
// Flush any remaining content
FlushLineBuffer();
}
private void InterpretStyledText(
@@ -217,7 +216,11 @@ public class TemplateInterpreter
List<PrintCommand> commands,
StyleContext style)
{
var lineWidth = style.IsBig ? _profile.BigLineWidth : _profile.LineWidth;
// Apply row-level styles
var rowStyle = style.Clone();
ApplyStyles(node.Styles, rowStyle);
var lineWidth = rowStyle.IsBig ? _profile.BigLineWidth : _profile.LineWidth;
var rowBuilder = new StringBuilder();
foreach (var column in node.Columns)
@@ -270,7 +273,7 @@ public class TemplateInterpreter
rowBuilder.Append(aligned);
}
commands.Add(CreateCommand(rowBuilder.ToString(), style));
commands.Add(CreateCommand(rowBuilder.ToString(), rowStyle));
}
private void InterpretColumn(