@@ -14,58 +14,39 @@ module fpm_backend_console
14
14
15
15
private
16
16
public :: console_t
17
+ public :: LINE_RESET
18
+ public :: COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_RESET
17
19
18
20
character (len=* ), parameter :: ESC = char (27 )
21
+ ! > Escape code for erasing current line
22
+ character (len=* ), parameter :: LINE_RESET = ESC// " [2K" // ESC// " [1G"
23
+ ! > Escape code for moving up one line
24
+ character (len=* ), parameter :: LINE_UP = ESC// " [1A"
25
+ ! > Escape code for moving down one line
26
+ character (len=* ), parameter :: LINE_DOWN = ESC// " [1B"
27
+ ! > Escape code for red foreground color
28
+ character (len=* ), parameter :: COLOR_RED = ESC// " [31m"
29
+ ! > Escape code for green foreground color
30
+ character (len=* ), parameter :: COLOR_GREEN = ESC// " [32m"
31
+ ! > Escape code for yellow foreground color
32
+ character (len=* ), parameter :: COLOR_YELLOW = ESC// " [93m"
33
+ ! > Escape code to reset foreground color
34
+ character (len=* ), parameter :: COLOR_RESET = ESC// " [0m"
19
35
20
36
! > Console object
21
37
type console_t
22
38
! > Number of lines printed
23
39
integer :: n_line = 1
24
- ! > 'Plain' output (no escape codes)
25
- logical :: plain_mode = .false.
26
- ! > Escape code for erasing current line
27
- character (:), allocatable :: LINE_RESET
28
- ! > Escape code for moving up one line
29
- character (:), allocatable :: LINE_UP
30
- ! > Escape code for moving down one line
31
- character (:), allocatable :: LINE_DOWN
40
+
32
41
contains
33
42
! > Write a single line to the console
34
43
procedure :: write_line = > console_write_line
35
44
! > Update a previously-written console line
36
45
procedure :: update_line = > console_update_line
37
46
end type console_t
38
47
39
- ! > Constructor for console_t
40
- interface console_t
41
- procedure :: new_console
42
- end interface console_t
43
-
44
48
contains
45
49
46
- ! > Initialise a new console object
47
- function new_console (plain_mode ) result(console)
48
- ! > 'Plain' output (no escape codes)
49
- logical , intent (in ), optional :: plain_mode
50
- ! > Console object to initialise
51
- type (console_t) :: console
52
-
53
- if (present (plain_mode)) then
54
- console% plain_mode = plain_mode
55
- end if
56
-
57
- if (console% plain_mode) then
58
- console% LINE_RESET = " "
59
- console% LINE_UP = " "
60
- console% LINE_DOWN = " "
61
- else
62
- console% LINE_RESET = ESC// " [2K" // ESC// " [1G"
63
- console% LINE_UP = ESC// " [1A"
64
- console% LINE_DOWN = ESC// " [1B"
65
- end if
66
-
67
- end function new_console
68
-
69
50
! > Write a single line to the standard output
70
51
subroutine console_write_line (console ,str ,line ,advance )
71
52
! > Console object
@@ -92,7 +73,7 @@ subroutine console_write_line(console,str,line,advance)
92
73
line = console% n_line
93
74
end if
94
75
95
- write (stdout,' (A)' ,advance= trim (adv)) console % LINE_RESET// str
76
+ write (stdout,' (A)' ,advance= trim (adv)) LINE_RESET// str
96
77
97
78
if (adv==" yes" ) then
98
79
console% n_line = console% n_line + 1
@@ -118,12 +99,12 @@ subroutine console_update_line(console,line_no,str)
118
99
n = console% n_line - line_no ! + 1 !+ 1
119
100
120
101
! Step back to line
121
- write (stdout,' (A)' ,advance= " no" ) repeat (console % LINE_UP,n)// console % LINE_RESET
102
+ write (stdout,' (A)' ,advance= " no" ) repeat (LINE_UP,n)// LINE_RESET
122
103
123
104
write (stdout,* ) str
124
105
125
106
! Step forward to end
126
- write (stdout,' (A)' ,advance= " no" ) repeat (console % LINE_DOWN,n)// console % LINE_RESET
107
+ write (stdout,' (A)' ,advance= " no" ) repeat (LINE_DOWN,n)// LINE_RESET
127
108
128
109
! $omp end critical
129
110
0 commit comments