base_code Function

private pure function base_code(color, base) result(code)

SGR number for a named colour: base + n, or base + 60 + n bright.

Arguments

Type IntentOptional Attributes Name
integer(kind=int32), intent(in) :: color
integer(kind=int32), intent(in) :: base

30 for foreground, 40 for background.

Return Value integer(kind=int32)


Called by

proc~~base_code~~CalledByGraph proc~base_code base_code proc~ansi_bg ansi_bg proc~ansi_bg->proc~base_code proc~ansi_fg ansi_fg proc~ansi_fg->proc~base_code proc~styled styled proc~styled->proc~ansi_bg proc~styled->proc~ansi_fg

Variables

Type Visibility Attributes Name Initial
integer(kind=int32), private :: clamped

Source Code

   pure function base_code(color, base) result(code)
      !! SGR number for a named colour: `base + n`, or `base + 60 + n` bright.
      integer(int32), intent(in) :: color
      integer(int32), intent(in) :: base
         !! 30 for foreground, 40 for background.
      integer(int32) :: code

      integer(int32) :: clamped

      clamped = max(0_int32, min(15_int32, color))
      if (clamped < 8_int32) then
         code = base + clamped
      else
         code = base + 60_int32 + (clamped - 8_int32)
      end if
   end function base_code