1
+ ! ># Build Backend Progress Output
2
+ ! > This module provides a derived type `build_progress_t` for printing build status
3
+ ! > and progress messages to the console while the backend is building the package.
4
+ ! >
5
+ ! > The `build_progress_t` type supports two modes: `normal` and `plain`
6
+ ! > where the former does 'pretty' output and the latter does not.
7
+ ! > The `normal` mode is intended for typical interactive usage whereas
8
+ ! > 'plain' mode is used with the `--verbose` flag or when `stdout` is not attached
9
+ ! > to a terminal (e.g. when piping or redirecting `stdout`). In these cases,
10
+ ! > the pretty output must be suppressed to avoid control codes being output.
11
+
1
12
module fpm_backend_output
2
13
use iso_fortran_env, only: stdout= >output_unit
3
14
use fpm_filesystem, only: basename
@@ -6,33 +17,43 @@ module fpm_backend_output
6
17
use M_attr, only: attr, attr_mode
7
18
implicit none
8
19
9
- type build_progress_t
20
+ private
21
+ public build_progress_t
10
22
23
+ ! > Build progress object
24
+ type build_progress_t
25
+ ! > Console object for updating console lines
11
26
type (console_t) :: console
12
-
27
+ ! > Number of completed targets
13
28
integer :: n_complete
14
-
29
+ ! > Total number of targets scheduled
15
30
integer :: n_target
16
-
31
+ ! > 'Plain' output (no colors or updating)
17
32
logical :: plain_mode = .true.
18
-
33
+ ! > Store needed when updating previous console lines
19
34
integer , allocatable :: output_lines(:)
20
-
35
+ ! > Queue of scheduled build targets
21
36
type (build_target_ptr), pointer :: target_queue(:)
22
-
23
37
contains
38
+ ! > Initialise build progress object
24
39
procedure :: init = > output_init
40
+ ! > Output 'compiling' status for build target
25
41
procedure :: compiling_status = > output_status_compiling
42
+ ! > Output 'complete' status for build target
26
43
procedure :: completed_status = > output_status_complete
44
+ ! > Output finished status for whole package
27
45
procedure :: success = > output_progress_success
28
-
29
46
end type build_progress_t
30
47
31
48
contains
32
49
50
+ ! > Initialise build progress object
33
51
subroutine output_init (progress ,target_queue ,plain_mode )
52
+ ! > Progress object to initialise
34
53
class(build_progress_t), intent (out ) :: progress
54
+ ! > The queue of scheduled targets
35
55
type (build_target_ptr), intent (in ), target :: target_queue(:)
56
+ ! > Enable 'plain' output for progress object
36
57
logical , intent (in ), optional :: plain_mode
37
58
38
59
if (plain_mode) then
@@ -51,8 +72,11 @@ subroutine output_init(progress,target_queue,plain_mode)
51
72
52
73
end subroutine output_init
53
74
75
+ ! > Output 'compiling' status for build target and overall percentage progress
54
76
subroutine output_status_compiling (progress , queue_index )
77
+ ! > Progress object
55
78
class(build_progress_t), intent (inout ) :: progress
79
+ ! > Index of build target in the target queue
56
80
integer , intent (in ) :: queue_index
57
81
58
82
character (:), allocatable :: target_name
@@ -69,13 +93,13 @@ subroutine output_status_compiling(progress, queue_index)
69
93
70
94
write (overall_progress,' (A,I4,A)' ) ' [' ,100 * progress% n_complete/ progress% n_target,' %]'
71
95
72
- if (progress% plain_mode) then
96
+ if (progress% plain_mode) then ! Plain output
73
97
74
98
! $omp critical
75
99
write (* ,' (A8,A30)' ) trim (overall_progress),target_name
76
100
! $omp end critical
77
101
78
- else
102
+ else ! Pretty output
79
103
80
104
write (output_string,' (A,T40,A,A)' ) target_name,attr(' <yellow>compiling...</yellow>' )
81
105
call progress% console% write_line(trim (output_string),progress% output_lines(queue_index))
@@ -88,10 +112,13 @@ subroutine output_status_compiling(progress, queue_index)
88
112
89
113
end subroutine output_status_compiling
90
114
91
-
115
+ ! > Output 'complete' status for build target and update overall percentage progress
92
116
subroutine output_status_complete (progress , queue_index , build_stat )
117
+ ! > Progress object
93
118
class(build_progress_t), intent (inout ) :: progress
119
+ ! > Index of build target in the target queue
94
120
integer , intent (in ) :: queue_index
121
+ ! > Build status flag
95
122
integer , intent (in ) :: build_stat
96
123
97
124
character (:), allocatable :: target_name
@@ -118,13 +145,13 @@ subroutine output_status_complete(progress, queue_index, build_stat)
118
145
119
146
write (overall_progress,' (A,I4,A)' ) ' [' ,100 * progress% n_complete/ progress% n_target,' %] '
120
147
121
- if (progress% plain_mode) then
148
+ if (progress% plain_mode) then ! Plain output
122
149
123
150
! $omp critical
124
151
write (* ,' (A8,A30,A7)' ) trim (overall_progress),target_name, ' done.'
125
152
! $omp end critical
126
153
127
- else
154
+ else ! Pretty output
128
155
129
156
call progress% console% update_line(progress% output_lines(queue_index),trim (output_string))
130
157
@@ -136,14 +163,15 @@ subroutine output_status_complete(progress, queue_index, build_stat)
136
163
137
164
end subroutine output_status_complete
138
165
166
+ ! > Output finished status for whole package
139
167
subroutine output_progress_success (progress )
140
168
class(build_progress_t), intent (inout ) :: progress
141
169
142
- if (progress% plain_mode) then
170
+ if (progress% plain_mode) then ! Plain output
143
171
144
172
write (* ,' (A)' ) attr(' <green>[100%] Project compiled successfully.</green>' )
145
173
146
- else
174
+ else ! Pretty output
147
175
148
176
write (* ,' (A)' ) progress% console% LINE_RESET// attr(' <green>[100%] Project compiled successfully.</green>' )
149
177
0 commit comments