!>
attr_update(3f) - [M_attr] update internal dictionary given keyword
and value
(LICENSE:MIT)
subroutine attr_update(key,val)
character(len=*),intent(in) :: key
character(len=*),intent(in),optional :: val
character(len=*),intent(in),optional :: mono_val
Update internal dictionary in M_attr(3fm) module.
key name of keyword to add, replace, or delete from dictionary
val if present add or replace value associated with keyword. If
not present remove keyword entry from dictionary.
mono_val if present add or replace second value associated with
keyword used for plain text mode.
Must only be specified if VAL is also specified.
The following keywords are defined by default
colors:
r,red c,cyan w,white
g,green m,magenta e,ebony
b,blue y,yellow
If the color keywords are capitalized they control the text background
instead of the text color.
attributes:
ul,underline
it,italics (often produces inverse colors on many devices
Sample program
program demo_update
use M_attr, only : attr, attr_update
write(*,'(a)') attr('<clear>TEST CUSTOMIZATIONS:')
! add custom keywords
call attr_update('blink',char(27)//'[5m')
call attr_update('/blink',char(27)//'[25m')
write(*,*)
write(*,'(a)') attr('<blink>Items for Friday</blink>')
call attr_update('ouch',attr( &
' <R><bo><w>BIG mistake!</R></w> '))
write(*,*)
write(*,'(a)') attr('<ouch> Did not see that coming.')
write(*,*)
write(*,'(a)') attr( &
'ORIGINALLY: <r>Apple</r>, <b>Sky</b>, <g>Grass</g>')
! delete
call attr_update('r')
call attr_update('/r')
! replace (or create)
call attr_update('b','<<<<')
call attr_update('/b','>>>>')
write(*,*)
write(*,'(a)') attr( &
'CUSTOMIZED: <r>Apple</r>, <b>Sky</b>, <g>Grass</g>')
end program demo_update
John S. Urban, 2021
MIT
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | key | |||
character(len=*), | intent(in), | optional | :: | valin | ||
character(len=*), | intent(in), | optional | :: | mono_valin |
subroutine attr_update(key,valin,mono_valin) character(len=*),intent(in) :: key character(len=*),intent(in),optional :: valin character(len=*),intent(in),optional :: mono_valin integer :: place character(len=:),allocatable :: val character(len=:),allocatable :: mono_val if(.not.allocated(mode))then ! set substitution mode mode='color' ! 'color'|'raw'|'plain' call vt102() endif if(present(mono_valin))then mono_val=mono_valin else mono_val='' endif if(present(valin))then val=valin ! find where string is or should be call locate(keywords,key,place) ! if string was not found insert it if(place.lt.1)then call insert(keywords,key,iabs(place)) call insert(values,val,iabs(place)) call insert(mono_values,mono_val,iabs(place)) else call replace(values,val,place) call replace(mono_values,mono_val,place) endif else call locate(keywords,key,place) if(place.gt.0)then call remove(keywords,place) call remove(values,place) call remove(mono_values,place) endif endif end subroutine attr_update