-4

Here's the script to color the text and to give bold, blinking, highlighting effect on ansi console.

import (
    "fmt"
    "github.com/mgutz/ansi"
)

color1Func := ansi.ColorFunc(fmt.Sprintf("%v+bh:%v", 181, 255))
color2Func := ansi.ColorFunc(fmt.Sprintf("%v+B:%v", 121, 255))

io.WriteString(os.Stdout, color1Func(text1))
io.WriteString(os.Stdout, color2Func(text2))

I tried to print italic font to style better console application, but couldn't find it anywhere for several days of struggling. Is this something that's not possible with ansi console?

Update:

This is what I did checked for mgutz/ansi library

        if strings.Contains(fgStyle, "b") {
            buf.WriteString(bold)
        }
        if strings.Contains(fgStyle, "B") {
            buf.WriteString(blink)
        }
        if strings.Contains(fgStyle, "u") {
            buf.WriteString(underline)
        }
        if strings.Contains(fgStyle, "i") {
            buf.WriteString(inverse)
        }
        if strings.Contains(fgStyle, "s") {
            buf.WriteString(strikethrough)
        }
        if strings.Contains(fgStyle, "h") {
            base = highIntensityFG
        }

It has "i" but it's not italic.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
artgb
  • 3,177
  • 6
  • 19
  • 36
  • 1
    I don't know who did downvote for my question, but you should just comment something before downvote. This problem is critical for me and I need some discussion at least. – artgb May 14 '20 at 08:57
  • https://meta.stackexchange.com/questions/325416/why-isnt-providing-feedback-mandatory-on-downvotes-and-why-are-ideas-suggestin – Adrian May 14 '20 at 13:15

1 Answers1

2

Is there anyway to print italic font on ansi console?

No.

From https://en.wikipedia.org/wiki/ANSI_escape_code:

Italic Not widely supported. Sometimes treated as inverse.

This depends so much in the details of your terminal that there is no reliable portable way to do so.

Volker
  • 40,468
  • 7
  • 81
  • 87
  • Thanks for your answer. Can you tell me what can be used to give comment like effect on Ansi console? – artgb May 14 '20 at 09:05
  • @artgb The only really reliable way is to indicate such stuff via _text_, e.g. quotes or prefixes/suffixes. Relying on color and font in a terminal is very hard. – Volker May 14 '20 at 09:53
  • Ok, thanks for the answer. – artgb May 14 '20 at 13:09
  • Do you think this question is meaningless? 2 guys suggested to close but I was trying to find solution for 2 days and got clarification about this. – artgb May 14 '20 at 13:11