11
4

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.

Nimの標準出力に色を付ける

Last updated at Posted at 2018-02-10
import terminal

var s:string = "Hello,World!"
setForegroundColor(stdout, fgRed)
echo s    # 文字色赤

setBackgroundColor(stdout, bgGreen)
echo s    # 背景色緑,文字色赤

resetAttributes(stdout)  # リセット
echo s    # デフォルト

# 1行のみなら
styledWriteLine(stdout, fgBlack, bgWhite, s, resetStyle) # 背景色白,文字色黒
# or
styledEcho(fgWhite, bgRed, s, resetStyle) # 背景色赤, 文字色白



# true colorをサポートしているターミナルなら
import colors

enableTrueColors()
setBackgroundColor(stdout, parseColor("#F0324A"))
echo s    # 微妙な色

プログラム終了時デフォルトに戻るようにsystem.addQuitProc(resetAttributes)を使いましょう。

公式ドキュメント
https://nim-lang.org/docs/terminal.html
https://nim-lang.org/docs/colors.html より

11
4
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
11
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?