-
Notifications
You must be signed in to change notification settings - Fork 109
Cleanup the backend output #622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
22ec97a
Fix: os_is_unix function
LKedward d9520ce
Update: mkdir with optional echo argument
LKedward 2654623
Update: run command with optional verbose argument
LKedward 30d730f
Update: backend with verbose argument
LKedward 6ea3493
Update: fpm_compiler objects with verbose field
LKedward 995fb2e
Update: run command with optional verbose argument
LKedward bfd9b06
Add: backend_output to manage pretty printing of build progress
LKedward 5728b54
Bump bootstrap fpm version to 0.3.0
LKedward 229761a
Fix: backend c_isatty for bootstrapping
LKedward 7787632
Update: fpm_backend as preprocessed file.
LKedward 2e2f0e3
Fix for checking isatty in MSYS2 mintty.
LKedward 8b4f3a6
Update: Windows CI to use gfortran 9 from winlibs.
LKedward b628302
Update: run to allow output redirection to file
LKedward ab7cb42
Update: fpm_compiler & backend to redirect output to log files
LKedward 37ba9d7
Simplify implementation and cleanup plain mode output
LKedward 93b629e
Add: developer documentation to new files
LKedward fc058ec
Update: backend to print message if up to date.
LKedward 4556e7a
Apply suggestion: move echo/verbosity into constructors
LKedward 6aba40d
Apply suggestion: don't use TBP for new constructors
LKedward b0115d1
Apply suggestion: don't use M_attr, simplify implementation
LKedward 0c561b0
Apply suggestion: move run to filesystem and use getline
LKedward b1b6a7b
Apply suggestions from code review
LKedward e8c0854
Merge branch 'main' into backend-output
LKedward 6cd53f7
Fix: for consistent alignment of backend console output.
LKedward d2009f1
Merge branch 'main' into backend-output
LKedward File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
!># Build Backend Console | ||
!> This module provides a lightweight implementation for printing to the console | ||
!> and updating previously-printed console lines. It used by `[[fpm_backend_output]]` | ||
!> for pretty-printing build status and progress. | ||
!> | ||
!> @note The implementation for updating previous lines relies on no other output | ||
!> going to `stdout`/`stderr` except through the `console_t` object provided. | ||
!> | ||
!> @note All write statements to `stdout` are enclosed within OpenMP `critical` regions | ||
!> | ||
module fpm_backend_console | ||
use iso_fortran_env, only: stdout=>output_unit | ||
implicit none | ||
|
||
private | ||
public :: console_t | ||
public :: LINE_RESET | ||
public :: COLOR_RED, COLOR_GREEN, COLOR_YELLOW, COLOR_RESET | ||
|
||
character(len=*), parameter :: ESC = char(27) | ||
!> Escape code for erasing current line | ||
character(len=*), parameter :: LINE_RESET = ESC//"[2K"//ESC//"[1G" | ||
!> Escape code for moving up one line | ||
character(len=*), parameter :: LINE_UP = ESC//"[1A" | ||
!> Escape code for moving down one line | ||
character(len=*), parameter :: LINE_DOWN = ESC//"[1B" | ||
!> Escape code for red foreground color | ||
character(len=*), parameter :: COLOR_RED = ESC//"[31m" | ||
!> Escape code for green foreground color | ||
character(len=*), parameter :: COLOR_GREEN = ESC//"[32m" | ||
!> Escape code for yellow foreground color | ||
character(len=*), parameter :: COLOR_YELLOW = ESC//"[93m" | ||
!> Escape code to reset foreground color | ||
character(len=*), parameter :: COLOR_RESET = ESC//"[0m" | ||
|
||
!> Console object | ||
type console_t | ||
!> Number of lines printed | ||
integer :: n_line = 1 | ||
|
||
contains | ||
!> Write a single line to the console | ||
procedure :: write_line => console_write_line | ||
!> Update a previously-written console line | ||
procedure :: update_line => console_update_line | ||
end type console_t | ||
|
||
contains | ||
|
||
!> Write a single line to the standard output | ||
subroutine console_write_line(console,str,line,advance) | ||
!> Console object | ||
class(console_t), intent(inout) :: console | ||
!> String to write | ||
character(*), intent(in) :: str | ||
!> Integer needed to later update console line | ||
integer, intent(out), optional :: line | ||
!> Advancing output (print newline?) | ||
logical, intent(in), optional :: advance | ||
|
||
character(3) :: adv | ||
|
||
adv = "yes" | ||
if (present(advance)) then | ||
if (.not.advance) then | ||
adv = "no" | ||
end if | ||
end if | ||
|
||
!$omp critical | ||
|
||
if (present(line)) then | ||
line = console%n_line | ||
end if | ||
|
||
write(stdout,'(A)',advance=trim(adv)) LINE_RESET//str | ||
|
||
if (adv=="yes") then | ||
console%n_line = console%n_line + 1 | ||
end if | ||
|
||
!$omp end critical | ||
|
||
end subroutine console_write_line | ||
|
||
!> Overwrite a previously-written line in standard output | ||
subroutine console_update_line(console,line_no,str) | ||
!> Console object | ||
class(console_t), intent(in) :: console | ||
!> Integer output from `[[console_write_line]]` | ||
integer, intent(in) :: line_no | ||
!> New string to overwrite line | ||
character(*), intent(in) :: str | ||
|
||
integer :: n | ||
|
||
!$omp critical | ||
|
||
n = console%n_line - line_no | ||
|
||
! Step back to line | ||
write(stdout,'(A)',advance="no") repeat(LINE_UP,n)//LINE_RESET | ||
|
||
write(stdout,'(A)') str | ||
|
||
! Step forward to end | ||
write(stdout,'(A)',advance="no") repeat(LINE_DOWN,n)//LINE_RESET | ||
|
||
!$omp end critical | ||
|
||
end subroutine console_update_line | ||
|
||
end module fpm_backend_console |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.