Git Product home page Git Product logo

cursed's Introduction

cursed!:

 ______     __  __     ______     ______     ______     _____
/\  ___\   /\ \/\ \   /\  == \   /\  ___\   /\  ___\   /\  __-.
\ \ \____  \ \ \_\ \  \ \  __<   \ \___  \  \ \  __\   \ \ \/\ \
 \ \_____\  \ \_____\  \ \_\ \_\  \/\_____\  \ \_____\  \ \____-
  \/_____/   \/_____/   \/_/ /_/   \/_____/   \/_____/   \/____/

Simplified curses interface with concurrency, for quick and sane curses apps.

Allows easy creation of windows and menus. Code for each window runs concurrently.

Please see full documentation available here: http://pythonhosted.org/cursed/

cursed was tested with Python 3.4 and 2.7, and depends on the Python package six for compatibility.

Installation

With pip, for the latest stable:

$ pip install cursed

Or from the project root directory:

$ python setup.py install

Usage

Example:

from cursed import CursedApp, CursedWindow

# the main context of the curses application
app = CursedApp()

# Derive from CursedWindow to declare curses windows to be created after app.run()
# It is required to declare X, Y, WIDTH, and HEIGHT for each window.
# You'll want to put the main looping code for each window thread in the `update` class function.

class MainWindow(CursedWindow):

    # Coordinate for top-left of window.
    X, Y = (0, 0)

    # WIDTH and HEIGHT can be 'max' or integers.
    WIDTH, HEIGHT = ('max', 'max')

    # Create a default border around the window.
    BORDERED = True

    @classmethod
    def update(cls):
        ''' update runs every tick '''

        # Hello world printed at x,y of 0,0
        cls.addstr('Hello, world!', 0, 0)

        # Get character keycode of keypress, or None.
        if cls.getch() == 27:
            # Escape was pressed. Quit.
            # 'quit' must be triggered for each open window for the program to quit.
            # Call cls.trigger('quit') to quit the window you're in, and to quit the other
            # declared windows, call OtherWindow.trigger('quit') which will run in that
            # window's thread, regardless of where it's called.
            cls.trigger('quit')

# To trigger app to start
result = app.run()

# check if ctrl-C was pressed
if result.interrupted():
    print('Quit!')
else:
    # Raises an exception if any thread ran into a different exception.
    result.unwrap()

Many more examples are available in the root of the repository at examples/

Release Notes

0.2.0:
  • exposed gevent.sleep through a classmethod cls.sleep(seconds=0). This allows users to fix issues with long running update functions causing other windows to not respond.
  • Added a CursedWindow PAD, like the curses pad. This can have a huge width and height greater than the terminal width, but allow you to scroll around it. Useful for windows which need only display a smaller rectange of a larger window, like a map that scrolls around with arrow keys.
0.1.9:
  • fixed the write and getstr classmethods, since they called _fix_xy twice
  • added info to menu example to explain addstr in update will overwrite menu display
0.1.8:
  • added tons of documentation and examples
0.1.7:
  • Better CursedMenu API
0.1.6:
  • WIDTH or HEIGHT specified as 'max' will stretch to the full width or height of the terminal
0.1.5:
  • patched issue with returning bytes in getstr
0.1.4:
  • Implemented getstr
0.1.3:
  • Fixed menu to fill up right side with whitespace
0.1.2:
  • fixed menus stealing keypresses
0.1.1:
  • left and right open menus to sides
  • refactored menus
0.1.0:
  • implemented menus!
0.0.2:
0.0.1:
  • Project created

cursed's People

Contributors

johannestaas avatar

Stargazers

Austin Jackson avatar Vincenzo Mercuri avatar Jonathan Egol avatar Jonathan Pyers avatar Danny Zhu avatar Yegor Yefremov avatar Wenliang Lu avatar DaVinci789 avatar Shane Brown avatar  avatar Anqur avatar Zoom.Quiet avatar Miguel Angel Rojas Aquino avatar Murali Ravipudi avatar David Morgan avatar Dave avatar Douglas Camata avatar Murat Sincan avatar  avatar Sean Nelson avatar Cooper avatar Tanel Puhu avatar Padraic Harley avatar Jürgen Hermann avatar Francesco Tamagni avatar Minho Ryang avatar Rudi Grinberg avatar Peter Forsberg avatar Lukas Šalkauskas avatar  avatar fuzzy-focus avatar John Jenkins avatar Easton Elliott avatar James Milne avatar Ethan Willoner avatar Rich avatar  avatar Dan LaManna avatar Luiz Felipe da Costa Pericolo Barbosa avatar  avatar Benjamin Summerton avatar  avatar Iury Alves de Souza avatar  avatar Bruno Rocha avatar Piotr Mielnik avatar  avatar Giulio Ungaretti avatar Teemu avatar Nazeeruddin Ikram avatar Mladen Mijatov avatar  avatar Jacek Bajor avatar  avatar Jesse Dubay avatar

Watchers

Rudi Grinberg avatar  avatar James Cloos avatar Shane Brown avatar Jonathan Pyers avatar

cursed's Issues

Error when running examples: "Segmentation fault: 11" from gevent

Hello,

I've installed your library and am trying to run the examples given, but am getting a gevent-related segmentation fault error immediately when running it. My terminal is cleared, this error printed, and I'm brought back to bash.

I'm running Python 2.7.9 on a mac, and pip freeze reports:

cursed==0.2.0
gevent==1.2.0
greenlet==0.4.11
six==1.10.0

This is the line it's failing on:
https://github.com/johannestaas/cursed/blob/master/cursed/app.py#L255

    def _run_windows(self):
        CursedWindowClass._fix_windows(self.MAX_WIDTH, self.MAX_HEIGHT)
        self.windows = CursedWindowClass.WINDOWS
        self.active_window = None
        for i, cw in enumerate(self.windows):
            thread = gevent.spawn(cw._cw_run, self, self.window) # crash
            cw.THREAD = thread
            self.threads += [thread]

Might be an issue with gevent on my system, but I figured I'd report it just in case.

Thanks for your hard work on the project, it looks very useful!

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.