Skip to main content

terminal_layout

The project help you to quickly build layouts in terminal
(这个一个命令行ui布局工具)
https://github.com/gojuukaze/terminal_layout/raw/master/pic/demo_v2_1.gif https://github.com/gojuukaze/terminal_layout/raw/master/pic/demo.gif

Some extensions base on terminal_layout

progress.gif

choice.gif


** video demo **

https://asciinema.org/a/226120.svg

install

pip install terminal-layout

Dependencies

  • Python 3.5+ (maybe 3.4)

  • Linux, OS X, and Windows systems.

Python Support

Python

terminal_layout

2.7

2.1.x

3.5+

3.x

Usage

  • easy demo:

import time
from terminal_layout import *

ctl = LayoutCtl.quick(TableLayout,
                      # table id: root
                      [
                          [TextView('t1', 'Hello World!', width=Width.fill, back=Back.blue)],  # <- row id: root_row_0,
                          [TextView('t2', '', fore=Fore.magenta)],  # <- row id: root_row_1,
                      ],
                      )

# or layout=ctl.get_layout()
layout = ctl.find_view_by_id('root')
layout.set_width(20)

# default: auto_re_draw=True
ctl.draw()

# call delay_set_text() must be set auto_re_draw=True,
# otherwise you must start a thread to call re_draw() by yourself
ctl.find_view_by_id('t2').delay_set_text('你好,世界!', delay=0.2)

time.sleep(0.5)
row3 = TableRow.quick_init('', [TextView('t3', 'こんにちは、世界!')])
layout.add_view(row3)

# If you call draw() with auto_re_draw=True, you must stop()
ctl.stop()

image2

  • disable auto_re_draw

import time
from terminal_layout import *

ctl = LayoutCtl.quick(TableLayout,
                      # table id: root
                      [
                          [TextView('t1', 'Hello World!', width=Width.fill, back=Back.blue)],  # <- row id: root_row_1,
                          [TextView('t2', '', fore=Fore.magenta)],  # <- row id: root_row_2,
                      ],
                      )


layout = ctl.find_view_by_id('root')
layout.set_width(20)

ctl.draw(auto_re_draw=False)

ctl.find_view_by_id('t2').set_text('你好,世界!')
ctl.re_draw()

time.sleep(0.5)
row3 = TableRow.quick_init('', [TextView('t3', 'こんにちは、世界!')])
layout.add_view(row3)
ctl.re_draw()

# don't need call stop()
# ctl.stop()
  • use python2 unicode

# -*- coding: utf-8 -*-
from terminal_layout import *
import sys
reload(sys)
sys.setdefaultencoding('utf-8')

ctl = LayoutCtl.quick(TableLayout,
                      [
                          [TextView('', u'中文,你好', back=Back.cyan, width=Width.wrap)],
                          [TextView('', u'中文,你好', back=Back.cyan, width=6)],
                          [TextView('', u'日本語,こんにちは', back=Back.cyan, width=Width.wrap)],
                      ]

                      )

ctl.draw()

image3

Properties

  • fore & back

TextView('','fore',fore=Fore.red)
TextView('','back',back=Back.red)
https://github.com/gojuukaze/terminal_layout/raw/master/pic/color.jpeg
  • style

TextView('','style',style=Style.dim)
https://github.com/gojuukaze/terminal_layout/raw/master/pic/style.jpeg
  • width

TextView('','width',width=10)
https://github.com/gojuukaze/terminal_layout/raw/master/pic/width.jpeg
  • weight

TextView('','weight',weight=1)
https://github.com/gojuukaze/terminal_layout/raw/master/pic/weight.jpeg
  • gravity

TextView('','gravity',gravity=Gravity.left)
https://github.com/gojuukaze/terminal_layout/raw/master/pic/gravity.jpeg
  • visibility

TextView('','',visibility=Visibility.visible)
https://github.com/gojuukaze/terminal_layout/raw/master/pic/visibility.jpeg
  • ex_style (not support windows)

TextView('','ex_style',style=Style.ex_blink)
https://github.com/gojuukaze/terminal_layout/raw/master/pic/ex_style.jpeg
  • ex_fore & ex_back (not support windows)

TextView('','ex_fore',fore=Fore.ex_red_1)
TextView('','ex_back',back=Back.ex_red_1)
https://github.com/gojuukaze/terminal_layout/raw/master/pic/ex_color.jpeg

LICENSE

GPLv3

Thanks

  • colorama : Simple cross-platform colored terminal text in Python

  • colored : Very simple Python library for color and formatting in terminal

Release files for terminal-layout 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for terminal-layout 3.0.0
File Size Uploaded
terminal_layout-3.0.0.tar.gz 41.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for terminal-layout 3.0.0
File Interpreter ABI Platform
terminal_layout-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 90.8 kB

Release files / terminal_layout-3.0.0.tar.gz

Download URL terminal_layout-3.0.0.tar.gz
Size 41.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5145db70d5eb120721ae992977c58b300535333a166a6c395fa0674b46115008
BLAKE2b-256 checksum
How to use checksums
73449e3d94444cd9f462e21fe2e31041794bdceb820c3403ae846b5c6cbda11b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release files / terminal_layout-3.0.0-py3-none-any.whl

Download URL terminal_layout-3.0.0-py3-none-any.whl
Size 49.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7479cd823c0464eff4814d0eea87921cc0d790d08dc323a59c4665f0f4bd4699
BLAKE2b-256 checksum
How to use checksums
371286cc069c16bbd12fe949b7ea24d68fb9a3409491bd9e4d2f4eea7df543f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.1

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.1.6

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.0.6

2 release files

2.0.5

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.2

2 release files

2.0.1

1 release file

2.0.0

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

3 release files

1.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page