3
2

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 3 years have passed since last update.

【Nim】コマンドプロンプトにカラフルな文字を出力できるライブラリを作ったよ!

Last updated at Posted at 2021-01-14

初めに

最近、Nimを始めました。
さわりとして、コマンドプロンプトにカラフルな文字を出力できるcolorizeEchoというライブラリを作りました!

インストール

nimbleを使って今すぐインストールできます。

nimble install colorizeEcho

使い方

echoの代わりにcechoという関数を使います。
第一引数に特定の書式に基づいた文字を渡すだけで簡単に文字の前景/背景の色を変えることができます。また、文字の太さを変えることもできます。

  • 前景を変える場合 = [red], [cyan]

  • 背景を変える場合 = [bRed], [bCyan]

  • 文字の太さを変える場合、 [bold] もしくは [regular] を文字の直前においてください。

####実際のコード例

import colorizeEcho

initColorizeEcho() # cechoを呼ぶ前にこの関数を一度呼ぶ必要があります。

cecho "[magenta]Every [green]color [cyan]is [default]beautiful."

cecho "[black][bgMagenta]Background [bgGreen]color [bgLightRed]is [bgCyan]changable [bgYellow]too."

cecho "[lightYellow][bold]THICC TEXT [regular]REGULAR TEXT"

####出力結果↓

result

####使えるオプション

前景 背景 文字の太さ
[default] [bgDefault] [regular]
[black] [bgBlack] [bold]
[red] [bgRed]
[green] [bgGreen]
[yellow] [bgYellow]
[blue] [bgBlue]
[magenta] [bgMagenta]
[cyan] [bgCyan]
[white] [bgWhite]
[darkGray] [bgDarkGray]
[lightRed] [bgLightRed]
[lightGreen] [bgLightGreen]
[lightYellow] [bgLightYellow]
[lightBlue] [bgLightBlue]
[lightMagenta] [bgLightMagenta]
[lightCyan] [bgLightCyan]
[lightWhite] [bgLightWhite]
3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?