draw lines package
v0.1.3
端末にスタイルと色付きのラインを描画するためのPythonモジュール。このユーティリティにより、ラインスタイル、色、テキストの配置のカスタマイズが可能になり、CLIアプリケーションの出力を強化するための汎用性の高いツールになります。
coloramaを使用し、異なるオペレーティングシステム全体の互換性を確保します。 pip install wolfsoftware.drawlines主な機能は、テキストの有無にかかわらず端末に行を作成するために使用できるdraw_line関数によって提供されます。
def draw_line ( text = '' , position = 'center' , fill_char = '-' , pad = 2 , width = - 1 , color = '' ):
"""
Draw a line across the terminal with optional text.
Args:
text (str): Text to include in the line. Defaults to '' (no text).
position (str): Position of the text ('left', 'right', 'center'). Defaults to 'center'.
fill_char (str): Character used to fill the line. Defaults to '-'.
pad (int): Padding characters around the text. Defaults to 2.
width (int): Total width of the line; defaults to the terminal width if set to -1.
color (str): Color and style of the text, e.g., 'red', 'blue+bold'. Defaults to no color.
""" from your_module import draw_line
# Draw a simple dashed line
print ( draw_line ())------------------------------------------------------------------------------------------ # Draw a line with centered text
print ( draw_line ( text = "Hello, World!" , position = 'center' ))------------------------------------- Hello, World ! --------------------------------------
fill_char=' 'を設定すると、線なしで中心的なテキストを取得します。
# Draw a line with left-aligned text and asterisk fill character
print ( draw_line ( text = "Left aligned text" , position = 'left' , fill_char = '*' )) ** Left aligned text ********************************************************************* このセクションでは、 draw_line関数パラメーターをカスタマイズする方法の詳細について説明します。以下は、各パラメーター、そのデフォルト値、目的、および許可された値をリストするテーブルです。
| 名前 | デフォルト値 | 目的 | 許可された値 |
|---|---|---|---|
| 文章 | '' | 行内に表示する文字列。 | 任意の文字列 |
| 位置 | '中心' | テキストを配置する場所。 | 「左」、「センター」、「右」 |
| fill_char | ' - ' | ラインを描くときに使用するキャラクター。複数のものが与えられている場合、最初のもののみが使用されます。 | 単一の文字 |
| left_pad | 2 | テキストを整理するときにプレフィックスとして使用するfill_charsの数。 | 正の整数 |
| right_pad | 2 | テキストを正しく整列させるときに、ポストフィックスとして使用するfill_charsの数。 | 正の整数 |
| 幅 | -1 | ラインを描く幅。デフォルトは、指定されていない場合、端子の幅を引いたものを引いたものです。 | 任意の整数; -1端子幅マイナス1の場合 |
| 色 | '' | テキストを作成する色。 | 「大胆」、「黒」、「青」、「シアン」、「緑」、「灰色」、「マゼンタ」、「赤」、「白」、「黄色」、「ブラック+」、「ブラック+太字」、「シアン+太字」、「緑+太字」、「グレー+太字」、「マゼンタ+太字」、「赤+太字」、「白+太字」、「黄色+」 |
| 大胆な | 間違い | テキストが大胆である必要があります。これは、定義された色の有無にかかわらず使用できます。 | 本当、偽 |
色に太字を追加している場合は、色名の後に来なければなりません。 eb cyan+ bold bold+cyanではなく、これは例外をスローするためです。