Giter Club home page Giter Club logo

reprint's Introduction

reprint reprint

reprint is a module for Python 2/3 to binding variables and refresh multi line output in terminal.

The solution for calculating Unicode char width is from urwid

中文版README

Feature

  • Support Python 2/3
  • variables binding, automatically refresh command line output when variables changed
  • multi line contents flush-able, every line of output comes from different variable in output object, changes on variable will refresh output
  • thread safe, using threading.Lock to do that

Setup

pip install reprint

DEMO

Demo_gif

Guidance

  1. Import the output object

    from reprint import output
  2. Use with block to control the initalization ,output object contain these following parameters:

    • output_type: "list" or "dict", indicating list mode and dict mode, default as "list"
    • initial_len: int, only work in list mode, indicating the initial length of the list, for do some modification on the content without initialization, default as 1
    • interval: int, the interval of refresh,only greater than this interval will trigger the refresh function, default as 0
    with output(output_type="list", initial_len=1, interval=0) as output_list:
  3. Change the variables in output_list will trigger the refresh of the command line output

Note

  • Within with block, any print/logging/Exception that do output on terminal would cause the format of reprint output abnormal. If you need to append some content to the end of output, use append function of output instance (works both in list or dict mode)

  • Don't assign a new list or dict to output instance. If you want to entirely change the list or dict, use change function of output instance (works both in list or dict mode)

  • If the lines of output exceed the height of terminal windows, that will cause the former output remained and keep adding new lines to the terminal. So maybe you should control the length of your output instance.

    • or you can use force_single_line mode, to force the output stay in single line
     with output(output_type="list", initial_len=1, interval=0, force_single_line=True) as output_list:
  • The initialization of threading should be within the with block if you use reprint in threading

  • When using non-terminal output, reprint will use normal build-in print function.

reprint's People

Contributors

yinzo avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.