Giter Club home page Giter Club logo

curtsies's Introduction

Build Status Documentation Status Curtsies Logo

Curtsies is a Python 2.6+ & 3.3+ compatible library for interacting with the terminal. This is what using (nearly every feature of) curtsies looks like:

from __future__ import unicode_literals # convenient for Python 2
import random

from curtsies import FullscreenWindow, Input, FSArray
from curtsies.fmtfuncs import red, bold, green, on_blue, yellow

print(yellow('this prints normally, not to the alternate screen'))
with FullscreenWindow() as window:
    with Input() as input_generator:
        msg = red(on_blue(bold('Press escape to exit')))
        a = FSArray(window.height, window.width)
        a[0:1, 0:msg.width] = [msg]
        for c in input_generator:
            if c == '<ESC>':
                break
            elif c == '<SPACE>':
                a = FSArray(window.height, window.width)
            else:
                s = repr(c).decode()
                row = random.choice(range(window.height))
                column = random.choice(range(window.width-len(s)))
                color = random.choice([red, green, on_blue, yellow])
                a[row, column:column+len(s)] = [color(s)]
            window.render_to_terminal(a)

Paste it in a something.py file and try it out!

Installation: pip install curtsies

Documentation

Primer

FmtStr objects are strings formatted with colors and styles displayable in a terminal with ANSI escape sequences.

(the import statement shown below is outdated)

FSArray objects contain multiple such strings with each formatted string on its own row, and FSArray objects can be superimposed on each other to build complex grids of colored and styled characters through composition.

(the import statement shown below is outdated)

Such grids of characters can be rendered to the terminal in alternate screen mode (no history, like Vim, top etc.) by FullscreenWindow objects or normal history-preserving screen by CursorAwareWindow objects. User keyboard input events like pressing the up arrow key are detected by an Input object.

Examples

About

  • Curtsies Documentation
  • Curtsies was written to for bpython-curtsies
  • #bpython on irc is a good place to talk about Curtsies, but feel free to open an issue if you're having a problem!
  • Thanks to the many contributors!
  • If all you need are colored strings, consider one of these other libraries!

curtsies's People

Contributors

thomasballinger avatar darius avatar feinomenon avatar dputtick avatar sebastinas avatar chena avatar jvns avatar macroscopicentric avatar myint avatar amanda avatar adusca avatar amjith avatar benwiederhake avatar calebstewart avatar ggilmore avatar gnclmorais avatar lynnagara avatar maxpblum avatar tpoliaw avatar sharellb avatar zunayed avatar siecje 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.