NAFPack_terminal.f90 Source File


This file depends on

sourcefile~~nafpack_terminal.f90~~EfferentGraph sourcefile~nafpack_terminal.f90 NAFPack_terminal.f90 sourcefile~nafpack_ansi.f90 NAFPack_ANSI.f90 sourcefile~nafpack_terminal.f90->sourcefile~nafpack_ansi.f90 sourcefile~nafpack_kinds.f90 NAFPack_kinds.f90 sourcefile~nafpack_terminal.f90->sourcefile~nafpack_kinds.f90 sourcefile~nafpack_ansi.f90->sourcefile~nafpack_kinds.f90 sourcefile~nafpack_io_utils.f90 NAFPack_io_utils.f90 sourcefile~nafpack_ansi.f90->sourcefile~nafpack_io_utils.f90 sourcefile~nafpack_io_utils.f90->sourcefile~nafpack_kinds.f90

Files dependent on this one

sourcefile~~nafpack_terminal.f90~~AfferentGraph sourcefile~nafpack_terminal.f90 NAFPack_terminal.f90 sourcefile~nafpack_logger_mod.f90 NAFPack_Logger_mod.f90 sourcefile~nafpack_logger_mod.f90->sourcefile~nafpack_terminal.f90 sourcefile~nafpack_iterative_methods.f90 NAFPack_Iterative_methods.f90 sourcefile~nafpack_iterative_methods.f90->sourcefile~nafpack_logger_mod.f90 sourcefile~nafpack_linalg.f90 NAFPack_linalg.f90 sourcefile~nafpack_linalg.f90->sourcefile~nafpack_iterative_methods.f90

Source Code

module NAFPack_terminal

    use NAFPack_kinds, only: ascii, ucs4

    ! ASCII colors for the terminal
    ! use NAFPack_terminal_colors, only: &
    !     red_color, green_color, yellow_color, blue_color, &
    !     white_color, cyan_color, purple_color, reset_color

    ! ! UCS4 colors for the terminal (Unicode)
    ! use NAFPack_terminal_colors, only: &
    !     red_color_ucs4, green_color_ucs4, yellow_color_ucs4, blue_color_ucs4, &
    !     white_color_ucs4, cyan_color_ucs4, purple_color_ucs4, reset_color_ucs4

    use NAFPack_ANSI, only: output_unit, ColorsAscii, ColorsUcs4

    implicit none(type, external)

    interface print_colored_message
        module procedure print_colored_message_ucs4
        module procedure print_colored_message_ascii
    end interface print_colored_message

    private

    public :: output_unit, print_colored_message

contains

    subroutine print_colored_message_ascii(color, message)
        character(kind=ascii, len=*), intent(in) :: message
        character(kind=ascii, len=*), intent(in) :: color
        type(ColorsAscii) :: ansii_colors

        CALL ansii_colors%init()

        open (output_unit, encoding='DEFAULT')

        write (output_unit, '(A)', advance='no') trim(color)
        write (output_unit, '(A)', advance='no') trim(message)
        write (output_unit, '(A)', advance='yes') trim(ansii_colors%reset)

        close (output_unit)

    end subroutine print_colored_message_ascii

    subroutine print_colored_message_ucs4(color, message)
        character(kind=ucs4, len=*), intent(in) :: message
        character(kind=ucs4, len=*), intent(in) :: color
        type(ColorsUcs4) :: ucs4_colors

        CALL ucs4_colors%init()

        open (output_unit, encoding='UTF-8')

        write (output_unit, '(A)', advance='no') trim(color)
        write (output_unit, '(A)', advance='no') trim(message)
        write (output_unit, '(A)', advance='yes') trim(ucs4_colors%reset)

        close (output_unit)

    end subroutine print_colored_message_ucs4

end module NAFPack_terminal