1+ # Copyright (c) 2025
2+ # Author: James J Balamuta
3+ # License: GNU Affero General Public License v3.0 or later
4+ #
5+ # This program is free software: you can redistribute it and/or modify
6+ # it under the terms of the GNU Affero General Public License as published
7+ # by the Free Software Foundation, either version 3 of the License, or
8+ # (at your option) any later version.
9+ #
10+ # This program is distributed in the hope that it will be useful,
11+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+ # GNU Affero General Public License for more details.
14+ #
15+ # You should have received a copy of the GNU Affero General Public License
16+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
118# ' Print method for templates
219# '
320# ' @param x stamp_template object.
825# ' @method print stamp_template
926print.stamp_template <- function (x , ... ) {
1027 cli :: cli_h1(" Template: {x$name}" )
11-
28+
1229 cli :: cli_h2(" Fields:" )
1330 for (field_name in names(x $ fields )) {
1431 field <- x $ fields [[field_name ]]
1532 default <- if (is.null(field $ default )) " <none>" else field $ default
1633 required <- if (field $ required ) " Required" else " Optional"
1734 cli :: cli_li(" {field_name}: {default} ({required})" )
1835 }
19-
36+
2037 cli :: cli_h2(" Content:" )
2138 cli :: cli_code(x $ content )
22-
39+
2340 invisible (x )
2441}
2542
@@ -33,10 +50,10 @@ print.stamp_template <- function(x, ...) {
3350# ' @method print stamp_preview
3451print.stamp_preview <- function (x , ... ) {
3552 cli :: cli_h1(" Preview for: {x$file}" )
36-
53+
3754 cli :: cli_h2(" Header to be inserted:" )
3855 cli :: cli_code(x $ header )
39-
56+
4057 cli :: cli_h2(" Insertion point:" )
4158 if (x $ insert_position == 0 ) {
4259 cli :: cli_text(" Beginning of file" )
@@ -45,12 +62,12 @@ print.stamp_preview <- function(x, ...) {
4562 } else {
4663 cli :: cli_text(" Line {x$insert_position}" )
4764 }
48-
65+
4966 cli :: cli_h2(" File properties:" )
5067 cli :: cli_li(" Encoding: {x$encoding}" )
5168 cli :: cli_li(" Line ending: {if (x$line_ending == '\n ') 'LF' else if (x$line_ending == '\r ') 'CR' else 'CRLF'}" )
5269 cli :: cli_li(" Read-only: {if (x$read_only) 'Yes' else 'No'}" )
53-
70+
5471 invisible (x )
5572}
5673
@@ -64,19 +81,19 @@ print.stamp_preview <- function(x, ...) {
6481# ' @method print stamp_language
6582print.stamp_language <- function (x , ... ) {
6683 cli :: cli_h1(" Language: {x$name}" )
67-
84+
6885 cli :: cli_h2(" File extensions:" )
6986 extensions <- paste(x $ extensions , collapse = " , " )
7087 cli :: cli_text(extensions )
71-
88+
7289 cli :: cli_h2(" Comment style:" )
7390 cli :: cli_li(" Single line: {x$comment_single}" )
74-
91+
7592 if (! is.null(x $ comment_multi_start ) && ! is.null(x $ comment_multi_end )) {
7693 cli :: cli_li(" Multi-line start: {x$comment_multi_start}" )
7794 cli :: cli_li(" Multi-line end: {x$comment_multi_end}" )
7895 }
79-
96+
8097 invisible (x )
8198}
8299
@@ -90,25 +107,25 @@ print.stamp_language <- function(x, ...) {
90107# ' @method print stamp_dir_results
91108print.stamp_dir_results <- function (x , ... ) {
92109 cli :: cli_h1(" Directory Stamping Results: {x$dir}" )
93-
110+
94111 cli :: cli_h2(" Action: {x$action}" )
95-
112+
96113 success_count <- sum(sapply(x $ results , function (r ) r $ status == " success" ))
97114 error_count <- sum(sapply(x $ results , function (r ) r $ status == " error" ))
98-
115+
99116 cli :: cli_alert_success(" {success_count} files successfully processed" )
100-
117+
101118 if (error_count > 0 ) {
102119 cli :: cli_alert_danger(" {error_count} files had errors" )
103-
120+
104121 cli :: cli_h2(" Errors:" )
105122 for (result in x $ results ) {
106123 if (result $ status == " error" ) {
107124 cli :: cli_li(" {result$file}: {result$message}" )
108125 }
109126 }
110127 }
111-
128+
112129 invisible (x )
113130}
114131
@@ -122,11 +139,11 @@ print.stamp_dir_results <- function(x, ...) {
122139# ' @method print stamp_file_info
123140print.stamp_file_info <- function (x , ... ) {
124141 cli :: cli_h1(" File Information: {x$path}" )
125-
142+
126143 cli :: cli_li(" Encoding: {x$encoding}" )
127144 cli :: cli_li(" Line ending: {if (x$line_ending == '\n ') 'LF' else if (x$line_ending == '\r ') 'CR' else 'CRLF'}" )
128145 cli :: cli_li(" Read-only: {if (x$read_only) 'Yes' else 'No'}" )
129-
146+
130147 invisible (x )
131148}
132149
@@ -140,19 +157,19 @@ print.stamp_file_info <- function(x, ...) {
140157# ' @method print stamp_update_preview
141158print.stamp_update_preview <- function (x , ... ) {
142159 cli :: cli_h1(" Update Preview for: {x$file}" )
143-
160+
144161 cli :: cli_h2(" Updated fields:" )
145162 for (field_name in names(x $ fields )) {
146163 cli :: cli_li(" {field_name}: {x$fields[[field_name]]}" )
147164 }
148-
165+
149166 cli :: cli_h2(" Header location:" )
150167 cli :: cli_text(" Lines {x$range[1]} to {x$range[2]}" )
151-
168+
152169 cli :: cli_h2(" File properties:" )
153170 cli :: cli_li(" Encoding: {x$encoding}" )
154171 cli :: cli_li(" Line ending: {if (x$line_ending == '\n ') 'LF' else if (x$line_ending == '\r ') 'CR' else 'CRLF'}" )
155172 cli :: cli_li(" Read-only: {if (x$read_only) 'Yes' else 'No'}" )
156-
173+
157174 invisible (x )
158- }
175+ }
0 commit comments