Skip to main content

uiblack

Code style: black

Streamlined cross-platform Textual UI.

Attractive console output should not be walled behind libCurses! It should not take dozens of lines just to describe ordinary things like menus or basic prompts. Lastly, attractive console applications should not be limited to only Linux & OSX.

Those are the guiding thoughts behind uiblack. A truly cross-platform, dead simple, concise library that handles several mundane development tasks all at once.

Installation

OS X, Linux & Windows:

pip install uiblack

Logging

To keep things simple and cross-platform, logs are generated in the execution directory. (This particular behavior may be subject to change in future builds.)

By default, [INFO] level messages are logged.

To update the logging level, please use the syslog values specified here: https://en.wikipedia.org/wiki/Syslog#Severity_level

from uiblack.terminal import UIBlackTerminal

# If you want to specify logging parameters:

# Name of log file to be written in local directory (Only Alphanumeric chars permitted)
log_name = "yourprogram"

# Whether the log should be started anew upon each execution
restart_log = False

# 0 - 7 Conforms to https://en.wikipedia.org/wiki/Syslog#Severity_level
log_level = 4

ui = UIBlackTerminal(log_name, restart_log=restart_log, log_level=log_level)

Error handling

If you want to wrap a troublesome function or your entire program in a exception handler that correctly prints to the screen and logs, just add some "pie"!

This process:

  • Catches all exceptions
  • Formats them into a single line
  • Keeps only the last segment of the traceback (the part we actually care about)
  • Prints correctly to the virtual UIBlack console
  • Logs the event WITH traceback in the log file under a single human-readable line
from uiblack.terminal import UIBlackTerminal

ui = UIBlackTerminal("yourprogram")

@ui.wrapper  # Notice the function is wrapped using "pie" syntax before each function
def troublesome_func():
    raise KeyError

@ui.wrapper
def some_other_func(param):
    raise ImportError

Console output

Example Traceback

Syslog output

Example syslog

Dual Consoles

Starting in version 1.1.4 the terminal supports dual console output similar to GNU Screen or tmux.

The upper console is "a" the lower is "b". Address them with keywords appended to the end of the syslog display functions.

from uiblack.terminal import UIBlackTerminal

ui = UIBlackTerminal("yourprogram")

ui.debug("Debug text")
ui.notice("Info text console a", console="a")
ui.notice("Info text console b", console="b")
ui.error("error text")
ui.console("regular text console b", console="b")
ui.warn("This is a warning on console b", console="b")

Example Dual Consoles

Usage examples

Keep it simple. Just import, instance the library, and use it!

from uiblack.terminal import UIBlackTerminal

# Run with defaults works just fine if logging parameters do not need to be altered
ui = UIBlackTerminal("yourprogram")
ui.clear()

result = ui.input("This is the input question")
ui.print_center(result)

result = ui.ask_yn("This is the question")
ui.print_center(result)

Example ask_yn

for items in range(0, 5000, 2):
    ui.load_bar("This is the title of a bar", items, 5000)

ui.set_main_title("this is a test title")

result = ui.ask_list("Question text goes here",
                     ["first item here",
                      "this is the second item",
                      "and this is the third"],
                     )

Example ask_list

ui.warn("warning here")
ui.error("error here")
ui.notice("Just a notice")

ui.console("this simulates regular print() command")
ui.console("And you can see, it scrolls output like the console.")

Example text

Performant

One major goal has remained from the start, remain performant. To that end, support for thread-safe operation is baked in. Additionally, various functions support "low_latency" mode. This mode causes the screen to be updated every N-number of iterations to prevent wasting cycles to display content.

Meta

Brandon Blackburn – PGP Encrypted Chat @ Keybase

Distributed under the Apache 2.0 license. See LICENSE for more information.

TL;DR: For a human-readable & fast explanation of the Apache 2.0 license visit: http://www.tldrlegal.com/l/apache2

https://github.com/BlackburnHax/uiblack

Release files for uiblack 1.2.2

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

Built distribution (wheel)

Table of built distributions (wheels) for uiblack 1.2.2
File Interpreter ABI Platform
uiblack-1.2.2-py3-none-any.whl Python 3 none any Details

Release files / uiblack-1.2.2-py3-none-any.whl

Download URL uiblack-1.2.2-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
16ba4f27679831d128b4fe107087f85d680eee8d5a63dcba93f171331333c971
BLAKE2b-256 checksum
How to use checksums
5c0ea3e6f11aa1ba000418fd5b3d1b8c925920f144e0ffbb1a4dfaeaaf62e312
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.0 CPython/3.10.0b4

Release history Release notifications | RSS feed

This release

1.2.2 This release

1 release file

1.2.1

1 release file

1.2.0

1 release file

1.1.9

1 release file

1.1.7

1 release file

1.1.6

1 release file

1.1.5

1 release file

1.1.4

1 release file

1.1.3

1 release file

1.1.2

1 release file

1.1.1

1 release file

1.1.0

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

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