Giter Site home page Giter Site logo

spgill / python-draftlog Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cooperhammond/python-draftlog

0.0 2.0 0.0 57 KB

:scroll: Update your previous lines in the terminal.

Home Page: https://pypi.python.org/pypi/draftlog

License: MIT License

Python 100.00%

python-draftlog's Introduction

Draftlog

๐Ÿ“œ Fancy logs with expandable tools. Bring life to your terminal!

demo

License: MIT Build Status PyPI Say Thanks

A module useful for CLI's, logs and pretty much any cool multi-line python tool.

All inspiration goes to Ivan Seidel with node-draftlog.

Works with Python 2 and 3.

Install

$ pip install draftlog

Intro Example

Here's about the simplest program with draftlog that actually does something:

import draftlog
import time

draft = draftlog.inject()

print ("The line below me will be updated!")
update_me = draft.log("I will be updated!")
print ("The line above me will be updated!")

time.sleep(3)

update_me.update("I've been updated!")

Here's a more complicated program: a scrolling banner . If you want to see some more examples in this thread, check out the examples folder!

import draftlog

draft = draftlog.inject()

class Banner:
    def __init__(self, string):
        self.string = string
        self.counter = 0
    def scroll(self):
        if self.counter >= 50:
            # This is what exits out of the loop in:
            # "draft.log().set_interval"
            raise draftlog.Exception
        self.counter += 1
        self.string = self.string[1:] + self.string[0]
        return self.string

string = "  Wow! Banners!     This is so cool!     All with draftlog!   "

print ("*" * len(string))
banner = draft.log()
print ("*" * len(string))

banner.set_interval(Banner(string).scroll, 0.1)

draft.start()

# You can still print stuff after starting the draft as well:
import time
time.sleep(2)
print ("Wow, some more text!")

set_interval is a function that takes another function and the time to wait. It overwrites the draft.log() line with whatever the function returns. The function will stop being called once it raises draftlog.Exception. draft.start() will actually start all intervals that have been set.

How

draft.log() creates a DraftLog object that keeps track of what line it was created on. You can call update(text) on it to update the line that it's set on.

draft.log().set_interval(function, time) primes an interval in a background threading process called DaemonDrafter. When draft.start() is called, it generates interval timing based off of the time specified and then runs it in "frames."

Since I've made the program open-ended, you can create a lot (see the examples folder) of stuff.

Questions

If you still have questions or need some help, check out the wiki or email me at [email protected], all feedback is appreciated!

python-draftlog's People

Contributors

cooperhammond 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.