Fixes handling of EOF(CTRL+D) within penalty warning during superfast mode where it would accept the purchase instead of asking the user again for a proper yes/no answer. Also fixes prompt in this situation, while having the input handling be slightly less ugly when timeouts are involved.
This commit is contained in:
parent
9122f5b579
commit
3f838a3de8
|
@ -6,6 +6,7 @@ from sqlalchemy.sql import func
|
||||||
from sqlalchemy import desc
|
from sqlalchemy import desc
|
||||||
import re, sys, os, traceback, signal, readline
|
import re, sys, os, traceback, signal, readline
|
||||||
from select import select
|
from select import select
|
||||||
|
import os
|
||||||
from helpers import *
|
from helpers import *
|
||||||
import random
|
import random
|
||||||
from statistikkHelpers import statisticsTextOnly
|
from statistikkHelpers import statisticsTextOnly
|
||||||
|
@ -95,7 +96,7 @@ class Menu():
|
||||||
return self.items[i]
|
return self.items[i]
|
||||||
|
|
||||||
def input_str(self, prompt=None, regex=None, length_range=(None,None),
|
def input_str(self, prompt=None, regex=None, length_range=(None,None),
|
||||||
empty_string_is_none=False, timeout=0):
|
empty_string_is_none=False, timeout=None):
|
||||||
if prompt == None:
|
if prompt == None:
|
||||||
prompt = self.prompt
|
prompt = self.prompt
|
||||||
if regex != None:
|
if regex != None:
|
||||||
|
@ -123,18 +124,21 @@ class Menu():
|
||||||
print 'Value must have length at most %d' % length_range[1]
|
print 'Value must have length at most %d' % length_range[1]
|
||||||
else:
|
else:
|
||||||
return result
|
return result
|
||||||
if timeout:
|
|
||||||
print prompt,
|
|
||||||
rlist, _, _ = select([sys.stdin], [], [], timeout)
|
|
||||||
if rlist:
|
|
||||||
s = sys.stdin.readline()
|
|
||||||
return s
|
|
||||||
else:
|
|
||||||
return ''
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
result = unicode(raw_input(safe_str(prompt)),
|
result = None
|
||||||
conf.input_encoding).strip()
|
if timeout:
|
||||||
|
# assuming line buffering
|
||||||
|
sys.stdout.write(safe_str(prompt))
|
||||||
|
sys.stdout.flush()
|
||||||
|
rlist, _, _ = select([sys.stdin], [], [], timeout)
|
||||||
|
if not rlist:
|
||||||
|
# timeout occurred, simulate empty line
|
||||||
|
result = ''
|
||||||
|
else:
|
||||||
|
result = unicode(raw_input(), conf.input_encoding).strip()
|
||||||
|
else:
|
||||||
|
result = unicode(raw_input(safe_str(prompt)), conf.input_encoding).strip()
|
||||||
except EOFError:
|
except EOFError:
|
||||||
print 'quit'
|
print 'quit'
|
||||||
self.exit_menu()
|
self.exit_menu()
|
||||||
|
@ -378,7 +382,7 @@ class Menu():
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def confirm(self, prompt, default=None, timeout=0):
|
def confirm(self, prompt, default=None, timeout=None):
|
||||||
return ConfirmMenu(prompt, default, timeout).execute()
|
return ConfirmMenu(prompt, default, timeout).execute()
|
||||||
|
|
||||||
def print_header(self):
|
def print_header(self):
|
||||||
|
|
Loading…
Reference in New Issue