Hello everyone,
I recently found out that the UTF-8 character set has a nice set of characters for drawing boxes on the terminal. I thought these would be nice for creating simple text-based interfaces for my programs.
However, the box drawing characters don’t seem to work very well with ordinary Fortran character
strings. I tried them with following program. It should print a square on the terminal.
program main
implicit none
integer, parameter :: NW = 1
integer, parameter :: SW = 3
integer, parameter :: NE = 2
integer, parameter :: SE = 4
character(len=*), parameter :: hline = '─'
character(len=*), parameter :: vline = '│'
character(len=*), parameter :: corners = '┌┐└┘'
integer :: box_size
integer :: line
write(*, '(a)', advance='no') 'Enter box size: '
read (*, '(i3)') box_size
print '(a,i0,a)', 'Printing a box of size ', box_size, '.'
do line = 1, box_size
if (line == 1) then
write(*,'(a)',advance='no') corners(NW:NW)
write(*,'(a)',advance='no') repeat(hline, box_size - 2)
write(*,'(a)',advance='yes') corners(NE:NE)
end if
if ((line > 1) .and. (line < box_size)) then
write(*,'(a,a,a)') vline, repeat(' ', box_size - 2), vline
end if
if (line == box_size) then
write(*,'(a)',advance='no') corners(SW:SW)
write(*,'(a)',advance='no') repeat(hline, box_size - 2)
write(*,'(a)',advance='yes') corners(SE:SE)
end if
end do
end program main
This is the output:
As can be seen, the “corner” characters are not printed correctly. Is there any way to use these characters with Fortran? Thanks in advance!
GFortran version: GNU Fortran (GCC) 10.2.1 20201125 (Red Hat 10.2.1-9)