Exemplo n.º 1
0
 def view(self, pager=False, pause=True, terse=False):
     o = self.format_view(terse=terse).encode('utf8')
     if pager: do_pager(o)
     else:
         msg_r(o)
         from mmgen.term import get_char
         if pause:
             get_char('Press any key to continue: ')
             msg('')
Exemplo n.º 2
0
def keypress_confirm(prompt, default_yes=False, verbose=False, no_nl=False):

    from mmgen.term import get_char

    q = ('(y/N)', '(Y/n)')[bool(default_yes)]
    p = u'{} {}: '.format(prompt, q)
    nl = ('\n', '\r{}\r'.format(' ' * len(p)))[no_nl]

    if opt.accept_defaults:
        msg(p)
        return (False, True)[default_yes]

    while True:
        reply = get_char(p).strip('\n\r')
        if not reply:
            if default_yes:
                msg_r(nl)
                return True
            else:
                msg_r(nl)
                return False
        elif reply in 'yY':
            msg_r(nl)
            return True
        elif reply in 'nN':
            msg_r(nl)
            return False
        else:
            if verbose: msg('\nInvalid reply')
            else: msg_r('\r')
Exemplo n.º 3
0
def _get_random_data_from_user(uchars):
	m = 'Enter {} random symbols' if opt.quiet else crmsg['usr_rand_notice']
	msg(m.format(uchars))
	prompt = 'You may begin typing.  {} symbols left: '
	msg_r(prompt.format(uchars))

	import time
	from mmgen.term import get_char
	# time.clock() always returns zero, so we'll use time.time()
	saved_time = time.time()
	key_data,time_data,pp = '',[],True

	for i in range(uchars):
		key_data += get_char(immed_chars='ALL',prehold_protect=pp)
		pp = False
		msg_r('\r'+prompt.format(uchars-i-1))
		now = time.time()
		time_data.append(now - saved_time)
		saved_time = now

	if opt.quiet: msg_r('\r')
	else: msg_r("\rThank you.  That's enough.{}\n\n".format(' '*18))

	fmt_time_data = ['{:.22f}'.format(i) for i in time_data]
	dmsg('\nUser input:\n{}\nKeystroke time intervals:\n{}\n'.format(key_data,'\n'.join(fmt_time_data)))
	prompt = 'User random data successfully acquired.  Press ENTER to continue'
	prompt_and_get_char(prompt,'',enter_ok=True)

	return key_data+''.join(fmt_time_data)
Exemplo n.º 4
0
 def choose_mn_len():
     prompt = 'Choose a mnemonic length: 1) 12 words, 2) 18 words, 3) 24 words: '
     urange = [str(i + 1) for i in range(len(self.mn_lens))]
     while True:
         r = get_char('\r' + prompt).decode()
         if r in urange: break
     msg_r('\r' + ' ' * len(prompt) + '\r')
     return self.mn_lens[int(r) - 1]
Exemplo n.º 5
0
		def choose_mn_len():
			prompt = 'Choose a mnemonic length: 1) 12 words, 2) 18 words, 3) 24 words: '
			urange = [str(i+1) for i in range(len(self.mn_lens))]
			while True:
				r = get_char('\r'+prompt)
				if r in urange: break
			msg_r('\r' + ' '*len(prompt) + '\r')
			return self.mn_lens[int(r)-1]
Exemplo n.º 6
0
	def view_and_sort(self,tx):
		fs = 'Total to spend, excluding fees: {} {}\n\n'
		txos = fs.format(tx.sum_outputs().hl(),g.coin) if tx.outputs else ''
		prompt = """
{}Sort options: [t]xid, [a]mount, a[d]dress, [A]ge, [r]everse, [M]mgen addr
Display options: show [D]ays, [g]roup, show [m]mgen addr, r[e]draw screen
	""".format(txos).strip()
		self.display()
		msg(prompt)

		from mmgen.term import get_char
		p = "'q'=quit view, 'p'=print to file, 'v'=pager view, 'w'=wide view, 'l'=add label:\b"
		while True:
			reply = get_char(p, immed_chars='atDdAMrgmeqpvw')
			if   reply == 'a': self.do_sort('amt')
			elif reply == 'A': self.do_sort('age')
			elif reply == 'd': self.do_sort('addr')
			elif reply == 'D': self.show_days = not self.show_days
			elif reply == 'e': msg('\n%s\n%s\n%s' % (self.fmt_display,prompt,p))
			elif reply == 'g': self.group = not self.group
			elif reply == 'l':
				idx,lbl = self.get_idx_and_label_from_user()
				if idx:
					e = self.unspent[idx-1]
					if type(self).add_label(e.twmmid,lbl,addr=e.addr):
						self.get_unspent_data()
						self.do_sort()
						msg('%s\n%s\n%s' % (self.fmt_display,prompt,p))
					else:
						msg('Label could not be added\n%s\n%s' % (prompt,p))
			elif reply == 'M': self.do_sort('mmid'); self.show_mmid = True
			elif reply == 'm': self.show_mmid = not self.show_mmid
			elif reply == 'p':
				msg('')
				of = 'listunspent[%s].out' % ','.join(self.sort_info(include_group=False)).lower()
				write_data_to_file(of,self.format_for_printing(),'unspent outputs listing')
				m = yellow("Data written to '%s'" % of)
				msg('\n%s\n%s\n\n%s' % (self.fmt_display,m,prompt))
				continue
			elif reply == 'q': return self.unspent
			elif reply == 'r': self.unspent.reverse(); self.reverse = not self.reverse
			elif reply == 't': self.do_sort('txid')
			elif reply == 'v':
				do_pager(self.fmt_display)
				continue
			elif reply == 'w':
				do_pager(self.format_for_printing(color=True))
				continue
			else:
				msg('\nInvalid input')
				continue

			msg('\n')
			self.display()
			msg(prompt)
Exemplo n.º 7
0
	def view_and_sort(self,tx):
		fs = 'Total to spend, excluding fees: {} {}\n\n'
		txos = fs.format(tx.sum_outputs().hl(),g.coin) if tx.outputs else ''
		prompt = """
{}Sort options: [t]xid, [a]mount, a[d]dress, [A]ge, [r]everse, [M]mgen addr
Display options: show [D]ays, [g]roup, show [m]mgen addr, r[e]draw screen
	""".format(txos).strip()
		self.display()
		msg(prompt)

		from mmgen.term import get_char
		p = "'q'=quit view, 'p'=print to file, 'v'=pager view, 'w'=wide view, 'l'=add label:\b"
		while True:
			reply = get_char(p, immed_chars='atDdAMrgmeqpvw')
			if   reply == 'a': self.do_sort('amt')
			elif reply == 'A': self.do_sort('age')
			elif reply == 'd': self.do_sort('addr')
			elif reply == 'D': self.show_days = not self.show_days
			elif reply == 'e': msg('\n%s\n%s\n%s' % (self.fmt_display,prompt,p))
			elif reply == 'g': self.group = not self.group
			elif reply == 'l':
				idx,lbl = self.get_idx_and_label_from_user()
				if idx:
					e = self.unspent[idx-1]
					if type(self).add_label(e.twmmid,lbl,addr=e.addr):
						self.get_unspent_data()
						self.do_sort()
						msg('%s\n%s\n%s' % (self.fmt_display,prompt,p))
					else:
						msg('Label could not be added\n%s\n%s' % (prompt,p))
			elif reply == 'M': self.do_sort('mmid'); self.show_mmid = True
			elif reply == 'm': self.show_mmid = not self.show_mmid
			elif reply == 'p':
				msg('')
				of = 'listunspent[%s].out' % ','.join(self.sort_info(include_group=False)).lower()
				write_data_to_file(of,self.format_for_printing(),'unspent outputs listing')
				m = yellow("Data written to '%s'" % of)
				msg('\n%s\n%s\n\n%s' % (self.fmt_display,m,prompt))
				continue
			elif reply == 'q': return self.unspent
			elif reply == 'r': self.unspent.reverse(); self.reverse = not self.reverse
			elif reply == 't': self.do_sort('txid')
			elif reply == 'v':
				do_pager(self.fmt_display)
				continue
			elif reply == 'w':
				do_pager(self.format_for_printing(color=True))
				continue
			else:
				msg('\nInvalid input')
				continue

			msg('\n')
			self.display()
			msg(prompt)
Exemplo n.º 8
0
def prompt_and_get_char(prompt,chars,enter_ok=False,verbose=False):

	while True:
		reply = get_char("%s: " % prompt).strip("\n\r")

		if reply in chars or (enter_ok and not reply):
			msg("")
			return reply

		if verbose: msg("\nInvalid reply")
		else: msg_r("\r")
Exemplo n.º 9
0
def prompt_and_get_char(prompt,chars,enter_ok=False,verbose=False):

	from mmgen.term import get_char

	while True:
		reply = get_char('%s: ' % prompt).strip('\n\r')

		if reply in chars or (enter_ok and not reply):
			msg('')
			return reply

		if verbose: msg('\nInvalid reply')
		else: msg_r('\r')
Exemplo n.º 10
0
def prompt_and_get_char(prompt, chars, enter_ok=False, verbose=False):

    from mmgen.term import get_char

    while True:
        reply = get_char('{}: '.format(prompt)).strip('\n\r')

        if reply in chars or (enter_ok and not reply):
            msg('')
            return reply

        if verbose: msg('\nInvalid reply')
        else: msg_r('\r')
Exemplo n.º 11
0
Arquivo: util.py Projeto: mmgen/mmgen
def prompt_and_get_char(prompt,chars,enter_ok=False,verbose=False):

	from mmgen.term import get_char

	while True:
		reply = get_char('{}: '.format(prompt)).strip(b'\n\r')

		if reply in chars.encode() or (enter_ok and not reply):
			msg('')
			return reply.decode()

		if verbose: msg('\nInvalid reply')
		else: msg_r('\r')
Exemplo n.º 12
0
def keypress_confirm(prompt,default_yes=False,verbose=False):

	q = "(Y/n)" if default_yes else "(y/N)"

	while True:
		reply = get_char("%s %s: " % (prompt, q)).strip("\n\r")

		if not reply:
			if default_yes: msg(""); return True
			else:           msg(""); return False
		elif reply in 'yY': msg(""); return True
		elif reply in 'nN': msg(""); return False
		else:
			if verbose: msg("\nInvalid reply")
			else: msg_r("\r")
Exemplo n.º 13
0
def do_license_msg(immed=False):

	import mmgen.license as gpl
	if opt.quiet or g.no_license: return

	p = "Press 'w' for conditions and warranty info, or 'c' to continue:"
	msg(gpl.warning)
	prompt = "%s " % p.strip()

	while True:
		reply = get_char(prompt, immed_chars="wc" if immed else "")
		if reply == 'w':
			from mmgen.term import do_pager
			do_pager(gpl.conditions)
		elif reply == 'c':
			msg(""); break
		else:
			msg_r("\r")
	msg("")
Exemplo n.º 14
0
Arquivo: util.py Projeto: mmgen/mmgen
def do_license_msg(immed=False):

	if opt.quiet or g.no_license or opt.yes or not g.stdin_tty: return

	import mmgen.license as gpl

	p = "Press 'w' for conditions and warranty info, or 'c' to continue:"
	msg(gpl.warning)
	prompt = '{} '.format(p.strip())

	from mmgen.term import get_char

	while True:
		reply = get_char(prompt, immed_chars=('','wc')[bool(immed)])
		if reply == b'w':
			do_pager(gpl.conditions)
		elif reply == b'c':
			msg(''); break
		else:
			msg_r('\r')
	msg('')
Exemplo n.º 15
0
def do_license_msg(immed=False):

	if opt.quiet or g.no_license or opt.yes or not g.stdin_tty: return

	import mmgen.license as gpl

	p = "Press 'w' for conditions and warranty info, or 'c' to continue:"
	msg(gpl.warning)
	prompt = '{} '.format(p.strip())

	from mmgen.term import get_char

	while True:
		reply = get_char(prompt, immed_chars=('','wc')[bool(immed)])
		if reply == b'w':
			do_pager(gpl.conditions)
		elif reply == b'c':
			msg(''); break
		else:
			msg_r('\r')
	msg('')
Exemplo n.º 16
0
Arquivo: util.py Projeto: mmgen/mmgen
def keypress_confirm(prompt,default_yes=False,verbose=False,no_nl=False,complete_prompt=False):

	from mmgen.term import get_char

	q = ('(y/N)','(Y/n)')[bool(default_yes)]
	p = prompt if complete_prompt else '{} {}: '.format(prompt,q)
	nl = ('\n','\r{}\r'.format(' '*len(p)))[no_nl]

	if opt.accept_defaults:
		msg(p)
		return default_yes

	while True:
		r = get_char(p).strip(b'\n\r')
		if not r:
			if default_yes: msg_r(nl); return True
			else:           msg_r(nl); return False
		elif r in b'yY': msg_r(nl); return True
		elif r in b'nN': msg_r(nl); return False
		else:
			if verbose: msg('\nInvalid reply')
			else: msg_r('\r')
Exemplo n.º 17
0
def keypress_confirm(prompt,default_yes=False,verbose=False,no_nl=False,complete_prompt=False):

	from mmgen.term import get_char

	q = ('(y/N)','(Y/n)')[bool(default_yes)]
	p = prompt if complete_prompt else '{} {}: '.format(prompt,q)
	nl = ('\n','\r{}\r'.format(' '*len(p)))[no_nl]

	if opt.accept_defaults:
		msg(p)
		return default_yes

	while True:
		r = get_char(p).strip(b'\n\r')
		if not r:
			if default_yes: msg_r(nl); return True
			else:           msg_r(nl); return False
		elif r in b'yY': msg_r(nl); return True
		elif r in b'nN': msg_r(nl); return False
		else:
			if verbose: msg('\nInvalid reply')
			else: msg_r('\r')
Exemplo n.º 18
0
def _get_random_data_from_user(uchars):

    if opt.quiet:
        msg("Enter %s random symbols" % uchars)
    else:
        msg(crmsg["usr_rand_notice"] % uchars)

    prompt = "You may begin typing.  %s symbols left: "
    msg_r(prompt % uchars)

    import time

    # time.clock() always returns zero, so we'll use time.time()
    saved_time = time.time()

    key_data, time_data, pp = "", [], True

    for i in range(uchars):
        key_data += get_char(immed_chars="ALL", prehold_protect=pp)
        pp = False
        msg_r("\r" + prompt % (uchars - i - 1))
        now = time.time()
        time_data.append(now - saved_time)
        saved_time = now

    if opt.quiet:
        msg_r("\r")
    else:
        msg_r("\rThank you.  That's enough.%s\n\n" % (" " * 18))

    fmt_time_data = ["{:.22f}".format(i) for i in time_data]

    dmsg("\nUser input:\n%s\nKeystroke time intervals:\n%s\n" % (key_data, "\n".join(fmt_time_data)))

    prompt = "User random data successfully acquired.  Press ENTER to continue"
    prompt_and_get_char(prompt, "", enter_ok=True)

    return key_data + "".join(fmt_time_data)
Exemplo n.º 19
0
    def view_and_sort(self, tx):
        from mmgen.term import get_char
        prompt = self.prompt.strip() + '\b'
        no_output, oneshot_msg = False, None
        while True:
            msg_r('' if no_output else '\n\n' if opt.no_blank else CUR_HOME +
                  ERASE_ALL)
            reply = get_char('' if no_output else self.format_for_display() +
                             '\n' + (oneshot_msg or '') + prompt,
                             immed_chars=self.key_mappings)
            no_output = False
            oneshot_msg = '' if oneshot_msg else None  # tristate, saves previous state
            if reply not in self.key_mappings:
                msg_r('\ninvalid keypress ')
                time.sleep(0.5)
                continue

            action = self.key_mappings[reply]
            if action[:2] == 's_':
                self.do_sort(action[2:])
                if action == 's_twmmid': self.show_mmid = True
            elif action == 'd_days': self.show_days = not self.show_days
            elif action == 'd_mmid': self.show_mmid = not self.show_mmid
            elif action == 'd_group':
                if self.can_group:
                    self.group = not self.group
            elif action == 'd_redraw':
                pass
            elif action == 'd_reverse':
                self.unspent.reverse()
                self.reverse = not self.reverse
            elif action == 'a_quit':
                msg('')
                return self.unspent
            elif action == 'a_lbl_add':
                idx, lbl = self.get_idx_from_user(get_label=True)
                if idx:
                    e = self.unspent[idx - 1]
                    if TrackingWallet(mode='w').add_label(e.twmmid,
                                                          lbl,
                                                          addr=e.addr):
                        self.get_unspent_data()
                        self.do_sort()
                        a = 'added to' if lbl else 'removed from'
                        oneshot_msg = yellow("Label {} {} #{}\n\n".format(
                            a, self.item_desc, idx))
                    else:
                        oneshot_msg = red('Label could not be added\n\n')
            elif action == 'a_addr_remove':
                idx = self.get_idx_from_user()
                if idx:
                    e = self.unspent[idx - 1]
                    if TrackingWallet(mode='w').remove_address(e.addr):
                        self.get_unspent_data()
                        self.do_sort()
                        self.total = self.get_total_coin()
                        oneshot_msg = yellow("{} #{} removed\n\n".format(
                            capfirst(self.item_desc), idx))
                    else:
                        oneshot_msg = red('Address could not be removed\n\n')
            elif action == 'a_print':
                of = '{}-{}[{}].out'.format(
                    self.dump_fn_pfx, g.dcoin,
                    ','.join(self.sort_info(include_group=False)).lower())
                msg('')
                try:
                    write_data_to_file(of,
                                       self.format_for_printing(),
                                       desc='{} listing'.format(self.desc))
                except UserNonConfirmation as e:
                    oneshot_msg = red(
                        "File '{}' not overwritten by user request\n\n".format(
                            of))
                else:
                    oneshot_msg = yellow("Data written to '{}'\n\n".format(of))
            elif action in ('a_view', 'a_view_wide'):
                do_pager(self.fmt_display if action ==
                         'a_view' else self.format_for_printing(color=True))
                if g.platform == 'linux' and oneshot_msg == None:
                    msg_r(CUR_RIGHT(len(prompt.split('\n')[-1]) - 2))
                    no_output = True
Exemplo n.º 20
0
Arquivo: tw.py Projeto: mmgen/mmgen
	def view_and_sort(self,tx):
		from mmgen.term import get_char
		prompt = self.prompt.strip() + '\b'
		no_output,oneshot_msg = False,None
		while True:
			msg_r('' if no_output else '\n\n' if opt.no_blank else CUR_HOME+ERASE_ALL)
			reply = get_char('' if no_output else self.format_for_display()+'\n'+(oneshot_msg or '')+prompt,
								immed_chars=''.join(self.key_mappings.keys())).decode()
			no_output = False
			oneshot_msg = '' if oneshot_msg else None # tristate, saves previous state
			if reply not in self.key_mappings:
				msg_r('\ninvalid keypress ')
				time.sleep(0.5)
				continue

			action = self.key_mappings[reply]
			if action[:2] == 's_':
				self.do_sort(action[2:])
				if action == 's_twmmid': self.show_mmid = True
			elif action == 'd_days': self.age_fmt = ('days','confs')[self.age_fmt=='days']
			elif action == 'd_mmid': self.show_mmid = not self.show_mmid
			elif action == 'd_group':
				if self.can_group:
					self.group = not self.group
			elif action == 'd_redraw': pass
			elif action == 'd_reverse': self.unspent.reverse(); self.reverse = not self.reverse
			elif action == 'a_quit': msg(''); return self.unspent
			elif action == 'a_lbl_add':
				idx,lbl = self.get_idx_from_user(get_label=True)
				if idx:
					e = self.unspent[idx-1]
					if TrackingWallet(mode='w').add_label(e.twmmid,lbl,addr=e.addr):
						self.get_unspent_data()
						self.do_sort()
						a = 'added to' if lbl else 'removed from'
						oneshot_msg = yellow("Label {} {} #{}\n\n".format(a,self.item_desc,idx))
					else:
						oneshot_msg = red('Label could not be added\n\n')
			elif action == 'a_addr_remove':
				idx = self.get_idx_from_user()
				if idx:
					e = self.unspent[idx-1]
					if TrackingWallet(mode='w').remove_address(e.addr):
						self.get_unspent_data()
						self.do_sort()
						self.total = self.get_total_coin()
						oneshot_msg = yellow("{} #{} removed\n\n".format(capfirst(self.item_desc),idx))
					else:
						oneshot_msg = red('Address could not be removed\n\n')
			elif action == 'a_print':
				of = '{}-{}[{}].out'.format(self.dump_fn_pfx,g.dcoin,
										','.join(self.sort_info(include_group=False)).lower())
				msg('')
				try:
					write_data_to_file(of,self.format_for_printing(),desc='{} listing'.format(self.desc))
				except UserNonConfirmation as e:
					oneshot_msg = red("File '{}' not overwritten by user request\n\n".format(of))
				else:
					oneshot_msg = yellow("Data written to '{}'\n\n".format(of))
			elif action in ('a_view','a_view_wide'):
				do_pager(self.fmt_display if action == 'a_view' else self.format_for_printing(color=True))
				if g.platform == 'linux' and oneshot_msg == None:
					msg_r(CUR_RIGHT(len(prompt.split('\n')[-1])-2))
					no_output = True
Exemplo n.º 21
0
    def view_and_sort(self, tx):
        fs = 'Total to spend, excluding fees: {} {}\n\n'
        txos = fs.format(tx.sum_outputs().hl(), g.coin) if tx.outputs else ''
        prompt = txos + self.prompt.strip()
        self.display()
        msg(prompt)

        from mmgen.term import get_char
        p = "'q'=quit view, 'p'=print to file, 'v'=pager view, 'w'=wide view, 'l'=add label:\b"
        while True:
            reply = get_char(p, immed_chars='atDdAMrgmeqpvw')
            if reply == 'a': self.do_sort('amt')
            elif reply == 'A': self.do_sort('age')
            elif reply == 'd': self.do_sort('addr')
            elif reply == 'D': self.show_days = not self.show_days
            elif reply == 'e':
                msg('\n{}\n{}\n{}'.format(self.fmt_display, prompt, p))
            elif reply == 'g':
                if self.can_group:
                    self.group = not self.group
            elif reply == 'l':
                idx, lbl = self.get_idx_and_label_from_user()
                if idx:
                    e = self.unspent[idx - 1]
                    if TrackingWallet().add_label(e.twmmid, lbl, addr=e.addr):
                        self.get_unspent_data()
                        self.do_sort()
                        msg(u'{}\n{}\n{}'.format(self.fmt_display, prompt, p))
                    else:
                        msg('Label could not be added\n{}\n{}'.format(
                            prompt, p))
            elif reply == 'M':
                self.do_sort('twmmid')
                self.show_mmid = True
            elif reply == 'm':
                self.show_mmid = not self.show_mmid
            elif reply == 'p':
                msg('')
                of = '{}-{}[{}].out'.format(
                    self.dump_fn_pfx, g.coin,
                    ','.join(self.sort_info(include_group=False)).lower())
                write_data_to_file(of, self.format_for_printing(),
                                   '{} listing'.format(self.desc))
                m = yellow("Data written to '{}'".format(of))
                msg('\n{}\n{}\n\n{}'.format(self.fmt_display, m, prompt))
                continue
            elif reply == 'q':
                return self.unspent
            elif reply == 'r':
                self.unspent.reverse()
                self.reverse = not self.reverse
            elif reply == 't':
                self.do_sort('txid')
            elif reply == 'v':
                do_pager(self.fmt_display)
                continue
            elif reply == 'w':
                do_pager(self.format_for_printing(color=True))
                continue
            else:
                msg('\nInvalid input')
                continue

            msg('\n')
            self.display()
            msg(prompt)