From 37ba9d7cf61d6b9ddbfe59a4456311fda62ef101 Mon Sep 17 00:00:00 2001 From: Laurence Kedward Date: Fri, 26 Nov 2021 17:32:07 +0000 Subject: Simplify implementation and cleanup plain mode output --- src/fpm_backend_output.f90 | 157 ++++++++++++++++++++++++++++++--------------- 1 file changed, 107 insertions(+), 50 deletions(-) (limited to 'src/fpm_backend_output.f90') diff --git a/src/fpm_backend_output.f90 b/src/fpm_backend_output.f90 index 82c019f..4eb2889 100644 --- a/src/fpm_backend_output.f90 +++ b/src/fpm_backend_output.f90 @@ -1,15 +1,38 @@ module fpm_backend_output use iso_fortran_env, only: stdout=>output_unit use fpm_filesystem, only: basename -use fpm_targets, only: build_target_t +use fpm_targets, only: build_target_ptr use fpm_backend_console, only: console_t use M_attr, only: attr, attr_mode implicit none +type build_progress_t + + type(console_t) :: console + + integer :: n_complete + + integer :: n_target + + logical :: plain_mode = .true. + + integer, allocatable :: output_lines(:) + + type(build_target_ptr), pointer :: target_queue(:) + +contains + procedure :: init => output_init + procedure :: compiling_status => output_status_compiling + procedure :: completed_status => output_status_complete + procedure :: success => output_progress_success + +end type build_progress_t contains - subroutine output_init(plain_mode) + subroutine output_init(progress,target_queue,plain_mode) + class(build_progress_t), intent(out) :: progress + type(build_target_ptr), intent(in), target :: target_queue(:) logical, intent(in), optional :: plain_mode if (plain_mode) then @@ -18,80 +41,114 @@ contains call attr_mode('color') end if + call progress%console%init(plain_mode) + + progress%n_target = size(target_queue,1) + progress%target_queue => target_queue + progress%plain_mode = plain_mode + + allocate(progress%output_lines(progress%n_target)) + end subroutine output_init - subroutine output_status_compiling(console, line, target) - type(console_t), intent(inout), target :: console - integer, intent(inout) :: line - type(build_target_t), intent(in) :: target + subroutine output_status_compiling(progress, queue_index) + class(build_progress_t), intent(inout) :: progress + integer, intent(in) :: queue_index character(:), allocatable :: target_name character(100) :: output_string + character(100) :: overall_progress - if (allocated(target%source)) then - target_name = basename(target%source%file_name) - else - target_name = basename(target%output_file) - end if + associate(target=>progress%target_queue(queue_index)%ptr) + + if (allocated(target%source)) then + target_name = basename(target%source%file_name) + else + target_name = basename(target%output_file) + end if + + write(overall_progress,'(A,I4,A)') '[',100*progress%n_complete/progress%n_target,'%]' + + if (progress%plain_mode) then + + !$omp critical + write(*,'(A8,A30)') trim(overall_progress),target_name + !$omp end critical - write(output_string,'(A,T40,A,A)') target_name,attr('compiling...') + else - line = console%write_line(trim(output_string)) + write(output_string,'(A,T40,A,A)') target_name,attr('compiling...') + call progress%console%write_line(trim(output_string),progress%output_lines(queue_index)) + + call progress%console%write_line(trim(overall_progress)//'Compiling...',advance=.false.) + + end if + + end associate end subroutine output_status_compiling - subroutine output_status_complete(console, line, target, build_stat, n_complete) - type(console_t), intent(inout), target :: console - integer, intent(in) :: line - type(build_target_t), intent(in) :: target + + subroutine output_status_complete(progress, queue_index, build_stat) + class(build_progress_t), intent(inout) :: progress + integer, intent(in) :: queue_index integer, intent(in) :: build_stat - integer, intent(inout) :: n_complete character(:), allocatable :: target_name character(100) :: output_string - - if (allocated(target%source)) then - target_name = basename(target%source%file_name) - else - target_name = basename(target%output_file) - end if - - if (build_stat == 0) then - write(output_string,'(A,T40,A,A)') target_name,attr('done.') - else - write(output_string,'(A,T40,A,A)') target_name,attr('failed.') - end if - - call console%update_line(line,trim(output_string)) + character(100) :: overall_progress !$omp critical - n_complete = n_complete + 1 + progress%n_complete = progress%n_complete + 1 !$omp end critical - end subroutine output_status_complete + associate(target=>progress%target_queue(queue_index)%ptr) - subroutine output_progress(n_complete, total, plain_mode) - integer, intent(in) :: n_complete, total - logical :: plain_mode + if (allocated(target%source)) then + target_name = basename(target%source%file_name) + else + target_name = basename(target%output_file) + end if - character(:), allocatable :: advance + if (build_stat == 0) then + write(output_string,'(A,T40,A,A)') target_name,attr('done.') + else + write(output_string,'(A,T40,A,A)') target_name,attr('failed.') + end if - if (plain_mode) then - advance = "yes" - else - advance = "no" - end if + write(overall_progress,'(A,I4,A)') '[',100*progress%n_complete/progress%n_target,'%] ' - !$omp critical - write(*,'(A,I4,A,A)',advance=advance) '[',100*n_complete/total,'%] Compiling project...' - !$omp end critical + if (progress%plain_mode) then + + !$omp critical + write(*,'(A8,A30,A7)') trim(overall_progress),target_name, 'done.' + !$omp end critical + + else - end subroutine output_progress + call progress%console%update_line(progress%output_lines(queue_index),trim(output_string)) - subroutine output_progress_complete() + call progress%console%write_line(trim(overall_progress)//'Compiling...',advance=.false.) - write(*,'(A)') char(27)//"[2K"//char(27)//"[1G"//attr('[100%] Project compiled successfully.') + end if + + end associate + + end subroutine output_status_complete + + subroutine output_progress_success(progress) + class(build_progress_t), intent(inout) :: progress + + if (progress%plain_mode) then + + write(*,'(A)') attr('[100%] Project compiled successfully.') + + else + + write(*,'(A)') progress%console%LINE_RESET//attr('[100%] Project compiled successfully.') + + end if - end subroutine output_progress_complete + end subroutine output_progress_success end module fpm_backend_output \ No newline at end of file -- cgit v1.2.3