You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
(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.
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.
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:
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?
The text was updated successfully, but these errors were encountered: