Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should blessings have convenience functions? #70

Open
ccorcos opened this issue Nov 18, 2014 · 1 comment
Open

Should blessings have convenience functions? #70

ccorcos opened this issue Nov 18, 2014 · 1 comment
Assignees
Labels

Comments

@ccorcos
Copy link

ccorcos commented Nov 18, 2014

Hey, I'm don't write command line applications terribly often, but when I do, I always find myself writing a variety of helper functions. For example here's what I have thus far for my current project:

from blessings import Terminal

term = Terminal()

def selectInput(options):
    for i in range(len(options)):
        print "%d) %s?" % (i+1, str(options[i]))

    select = -1
    while select == -1:
        value = raw_input("select [%d-%d]: " % (1, len(options)))
        try:
            i = int(value) - 1
            if i in range(len(options)):
                select = i
            else:
                print term.move_up, term.clear_eol, term.move_up
        except:
            print term.move_up, term.clear_eol, term.move_up

    print ""
    return options[select]

def validatedInput(question, validate):
    value = -1
    while True:
        value = raw_input(question)
        try:
            if validate(value):
                break
            else:
                print term.move_up, term.clear_eol, term.move_up
        except:
            print term.move_up, term.clear_eol, term.move_up
    return value

selectInput basically gives you a number of options and returns the option you selected. validatedInput is basically just a wrapper for "raw input" but makes sure you have entered in a valid input.

Its super simple, but I'm curious if you know of any resources that have these kinds of UI functions? Maybe it could be a good addition to this project?

@jquast jquast added the question label Apr 7, 2015
@jquast jquast changed the title convenience functions Should blessings have convenience functions? Apr 7, 2015
@jquast
Copy link
Collaborator

jquast commented Apr 7, 2015

(I am not the project leader, only a minor contributor so far, but you deserve some reply)

Probably not a good addition for this project: blessings is meant to be only a thin API above curses and related functions. Though it may be used directly to write applications, it may also be used by another library to provide more high-level functions such as user interfaces that you propose.

In some terms you can think of blessings as comparable to the OpenGL library, but for terminals -- what you are seeking is something more like what the GTK library is for terminals.

I would personally like to see some sort of UI library that uses blessings -- there are a number of people working on that. @thomasballinger for example has project https://github.com/thomasballinger/curtsies

https://github.com/wardi/urwid is also a popular choice. It does not use blessings (and in my opinion is very unpythonic, it could be said to be javaish if there such a term). But you may find what you need there if you don't particularly care about how you compose code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants