1+ # ' Print method for templates
2+ # '
3+ # ' @param x stamp_template object.
4+ # ' @param ... Additional arguments.
5+ # '
6+ # ' @return The stamp_template object, invisibly.
7+ # ' @export
8+ # ' @method print stamp_template
9+ print.stamp_template <- function (x , ... ) {
10+ cli :: cli_h1(" Template: {x$name}" )
11+
12+ cli :: cli_h2(" Fields:" )
13+ for (field_name in names(x $ fields )) {
14+ field <- x $ fields [[field_name ]]
15+ default <- if (is.null(field $ default )) " <none>" else field $ default
16+ required <- if (field $ required ) " Required" else " Optional"
17+ cli :: cli_li(" {field_name}: {default} ({required})" )
18+ }
19+
20+ cli :: cli_h2(" Content:" )
21+ cli :: cli_code(x $ content )
22+
23+ invisible (x )
24+ }
25+
26+ # ' Print method for stamp preview
27+ # '
28+ # ' @param x stamp_preview object.
29+ # ' @param ... Additional arguments.
30+ # '
31+ # ' @return The stamp_preview object, invisibly.
32+ # ' @export
33+ # ' @method print stamp_preview
34+ print.stamp_preview <- function (x , ... ) {
35+ cli :: cli_h1(" Preview for: {x$file}" )
36+
37+ cli :: cli_h2(" Header to be inserted:" )
38+ cli :: cli_code(x $ header )
39+
40+ cli :: cli_h2(" Insertion point:" )
41+ if (x $ insert_position == 0 ) {
42+ cli :: cli_text(" Beginning of file" )
43+ } else if (x $ insert_position == 1 ) {
44+ cli :: cli_text(" After shebang" )
45+ } else {
46+ cli :: cli_text(" Line {x$insert_position}" )
47+ }
48+
49+ cli :: cli_h2(" File properties:" )
50+ cli :: cli_li(" Encoding: {x$encoding}" )
51+ cli :: cli_li(" Line ending: {if (x$line_ending == '\n ') 'LF' else if (x$line_ending == '\r ') 'CR' else 'CRLF'}" )
52+ cli :: cli_li(" Read-only: {if (x$read_only) 'Yes' else 'No'}" )
53+
54+ invisible (x )
55+ }
56+
57+ # ' Print method for language
58+ # '
59+ # ' @param x stamp_language object.
60+ # ' @param ... Additional arguments.
61+ # '
62+ # ' @return The stamp_language object, invisibly.
63+ # ' @export
64+ # ' @method print stamp_language
65+ print.stamp_language <- function (x , ... ) {
66+ cli :: cli_h1(" Language: {x$name}" )
67+
68+ cli :: cli_h2(" File extensions:" )
69+ extensions <- paste(x $ extensions , collapse = " , " )
70+ cli :: cli_text(extensions )
71+
72+ cli :: cli_h2(" Comment style:" )
73+ cli :: cli_li(" Single line: {x$comment_single}" )
74+
75+ if (! is.null(x $ comment_multi_start ) && ! is.null(x $ comment_multi_end )) {
76+ cli :: cli_li(" Multi-line start: {x$comment_multi_start}" )
77+ cli :: cli_li(" Multi-line end: {x$comment_multi_end}" )
78+ }
79+
80+ invisible (x )
81+ }
82+
83+ # ' Print method for directory results
84+ # '
85+ # ' @param x stamp_dir_results object.
86+ # ' @param ... Additional arguments.
87+ # '
88+ # ' @return The stamp_dir_results object, invisibly.
89+ # ' @export
90+ # ' @method print stamp_dir_results
91+ print.stamp_dir_results <- function (x , ... ) {
92+ cli :: cli_h1(" Directory Stamping Results: {x$dir}" )
93+
94+ cli :: cli_h2(" Action: {x$action}" )
95+
96+ success_count <- sum(sapply(x $ results , function (r ) r $ status == " success" ))
97+ error_count <- sum(sapply(x $ results , function (r ) r $ status == " error" ))
98+
99+ cli :: cli_alert_success(" {success_count} files successfully processed" )
100+
101+ if (error_count > 0 ) {
102+ cli :: cli_alert_danger(" {error_count} files had errors" )
103+
104+ cli :: cli_h2(" Errors:" )
105+ for (result in x $ results ) {
106+ if (result $ status == " error" ) {
107+ cli :: cli_li(" {result$file}: {result$message}" )
108+ }
109+ }
110+ }
111+
112+ invisible (x )
113+ }
114+
115+ # ' Print method for file info
116+ # '
117+ # ' @param x stamp_file_info object.
118+ # ' @param ... Additional arguments.
119+ # '
120+ # ' @return The stamp_file_info object, invisibly.
121+ # ' @export
122+ # ' @method print stamp_file_info
123+ print.stamp_file_info <- function (x , ... ) {
124+ cli :: cli_h1(" File Information: {x$path}" )
125+
126+ cli :: cli_li(" Encoding: {x$encoding}" )
127+ cli :: cli_li(" Line ending: {if (x$line_ending == '\n ') 'LF' else if (x$line_ending == '\r ') 'CR' else 'CRLF'}" )
128+ cli :: cli_li(" Read-only: {if (x$read_only) 'Yes' else 'No'}" )
129+
130+ invisible (x )
131+ }
132+
133+ # ' Print method for update preview
134+ # '
135+ # ' @param x stamp_update_preview object.
136+ # ' @param ... Additional arguments.
137+ # '
138+ # ' @return The stamp_update_preview object, invisibly.
139+ # ' @export
140+ # ' @method print stamp_update_preview
141+ print.stamp_update_preview <- function (x , ... ) {
142+ cli :: cli_h1(" Update Preview for: {x$file}" )
143+
144+ cli :: cli_h2(" Updated fields:" )
145+ for (field_name in names(x $ fields )) {
146+ cli :: cli_li(" {field_name}: {x$fields[[field_name]]}" )
147+ }
148+
149+ cli :: cli_h2(" Header location:" )
150+ cli :: cli_text(" Lines {x$range[1]} to {x$range[2]}" )
151+
152+ cli :: cli_h2(" File properties:" )
153+ cli :: cli_li(" Encoding: {x$encoding}" )
154+ cli :: cli_li(" Line ending: {if (x$line_ending == '\n ') 'LF' else if (x$line_ending == '\r ') 'CR' else 'CRLF'}" )
155+ cli :: cli_li(" Read-only: {if (x$read_only) 'Yes' else 'No'}" )
156+
157+ invisible (x )
158+ }
0 commit comments