Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gruve-p committed Jan 29, 2024
2 parents 6d53ca1 + 522e948 commit 5528e0e
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions electrum_grs/gui/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
import locale
from decimal import Decimal
import getpass
import logging
import pyperclip
from typing import TYPE_CHECKING, Optional

# 3rd-party dependency:
import pyperclip

import electrum_grs
from electrum_grs.gui import BaseElectrumGui
from electrum_grs.bip21 import parse_bip21_URI
Expand All @@ -22,7 +23,6 @@
from electrum_grs.network import NetworkParameters, TxBroadcastError, BestEffortRequestFailed
from electrum_grs.interface import ServerAddr
from electrum_grs.invoices import Invoice
from electrum_grs.invoices import PR_DEFAULT_EXPIRATION_WHEN_CREATING

if TYPE_CHECKING:
from electrum_grs.daemon import Daemon
Expand All @@ -33,6 +33,12 @@
_ = lambda x:x # i18n


# ascii key codes
KEY_BACKSPACE = 8
KEY_ESC = 27
KEY_DELETE = 127


def parse_bip21(text):
try:
return parse_bip21_URI(text)
Expand Down Expand Up @@ -233,9 +239,9 @@ def run_receive_tab(self, c):
self.str_recv_description = self.edit_str(self.str_recv_description, c)
elif self.pos == 1:
self.str_recv_amount = self.edit_str(self.str_recv_amount, c)
elif self.pos in self.buttons and c == 10:
elif self.pos in self.buttons and c == ord("\n"):
self.buttons[self.pos]()
elif self.pos >= 5 and c == 10:
elif self.pos >= 5 and c == ord("\n"):
key = self.requests[self.pos - 5]
self.show_request(key)

Expand Down Expand Up @@ -434,7 +440,7 @@ def getch(self, redraw=False):
if self.need_update and redraw:
self.update()
if self.tab == -1:
return 27
return KEY_ESC

def main_command(self):
c = self.getch(redraw=True)
Expand All @@ -443,7 +449,7 @@ def main_command(self):
self.tab = (self.tab + 1)%self.num_tabs
elif c == curses.KEY_LEFT:
self.tab = (self.tab - 1)%self.num_tabs
elif c in [curses.KEY_DOWN, 9]:
elif c in [curses.KEY_DOWN, ord("\t")]:
self.increase_cursor(1)
elif c == curses.KEY_UP:
self.increase_cursor(-1)
Expand All @@ -466,15 +472,15 @@ def run_tab(self, i, print_func, exec_func):

def run_history_tab(self, c):
# Get txid from cursor position
if c == 10:
if c == ord("\n"):
out = self.run_popup('', ['Transaction ID:', self.txid[self.pos]])

def edit_str(self, target, c, is_num=False):
if target is None:
target = ''
# detect backspace
cc = curses.unctrl(c).decode()
if c in [8, 127, 263] and target:
if c in [KEY_BACKSPACE, KEY_DELETE, curses.KEY_BACKSPACE] and target:
target = target[:-1]
elif not is_num or cc in '0123456789.':
target += cc
Expand All @@ -488,13 +494,13 @@ def run_send_tab(self, c):
self.str_description = self.edit_str(self.str_description, c)
elif self.pos == 2:
self.str_amount = self.edit_str(self.str_amount, c, True)
elif self.pos in self.buttons and c == 10:
elif self.pos in self.buttons and c == ord("\n"):
self.buttons[self.pos]()
elif self.pos >= 7 and c == 10:
elif self.pos >= 7 and c == ord("\n"):
self.show_invoice_menu()

def run_contacts_tab(self, c):
if c == 10 and self.contacts:
if c == ord("\n") and self.contacts:
out = self.run_popup('Address', ["Copy", "Pay to", "Edit label", "Delete"]).get('button')
key = list(self.contacts.keys())[self.pos%len(self.contacts.keys())]
if out == "Pay to":
Expand All @@ -513,7 +519,7 @@ def run_utxos_tab(self, c):
pass

def run_channels_tab(self, c):
if c == 10:
if c == ord("\n"):
out = self.run_popup('Channel Details', ['Short channel ID:', self.channel_ids[self.pos]])

def run_banner_tab(self, c):
Expand Down Expand Up @@ -811,15 +817,15 @@ def run_dialog(self, title, items, interval=2, buttons=None, y_pos=3):
w.refresh()

c = self.getch()
if c in [ord('q'), 27]:
if c in [ord('q'), KEY_ESC]:
break
elif c in [curses.KEY_LEFT, curses.KEY_UP]:
self.popup_pos -= 1
elif c in [curses.KEY_RIGHT, curses.KEY_DOWN]:
self.popup_pos +=1
else:
i = self.popup_pos%numpos
if buttons and c==10:
if buttons and c == ord("\n"):
if i == numpos-2:
return out
elif i == numpos -1:
Expand Down Expand Up @@ -906,9 +912,9 @@ def show_request(self, key):
c = self.getch()
if c in [curses.KEY_UP]:
pos -= 1
elif c in [curses.KEY_DOWN, 9]:
pos +=1
elif c == 10:
elif c in [curses.KEY_DOWN, ord("\t")]:
pos += 1
elif c == ord("\n"):
if pos in [0,1,2]:
pyperclip.copy(text)
self.show_message('Text copied to clipboard')
Expand Down

0 comments on commit 5528e0e

Please sign in to comment.