28
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

golang で端末に色付きで表示する

Posted at

\x1b[31m\x1b[0m で囲む。

fmt.Printf("\x1b[31m%s\x1b[0m", "foo") // =>  foo が赤文字で表示される

色を変えるには、31 の部分を変更すればよい。

code color
30
31
32
33
34
35 マゼンダ
36 シアン
37

カラーコードに続けて、太文字にするとか背景色を指定するとかできるらしいが、詳しくは参考リンクへ。

参考:
SOTA » 標準出力を色付けする
printf in color - Google グループ

28
18
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
28
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?