From c36d692f0de3b8114f92711bcc57586334faca56 Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Wed, 21 Jan 2009 00:32:18 -0600 Subject: [PATCH] add functionality to screen-profiles-helper to change the escape key sequence --- debian/changelog | 5 ++- screen-profiles-helper | 86 ++++++++++++++++++++++++++++++++++++------ 2 files changed, 78 insertions(+), 13 deletions(-) diff --git a/debian/changelog b/debian/changelog index 6c6e046f..cb5baa64 100644 --- a/debian/changelog +++ b/debian/changelog @@ -10,9 +10,10 @@ screen-profiles (1.12) UNRELEASED; urgency=low [ Dustin Kirkland and Nicolas Barcet] * screen-profiles-helper: add HOME, SHARE, DOC global variables and use - them where possible + them where possible; add functionality to change the escape key + sequence - -- Dustin Kirkland Tue, 20 Jan 2009 23:06:36 -0600 + -- Dustin Kirkland Tue, 20 Jan 2009 23:41:20 -0600 screen-profiles (1.11-0ubuntu1) jaunty; urgency=low diff --git a/screen-profiles-helper b/screen-profiles-helper index 93dc2c71..2b8139c1 100755 --- a/screen-profiles-helper +++ b/screen-profiles-helper @@ -1,6 +1,6 @@ #! /usr/bin/env python # -# GNU screen-profiles-helper +# screen-profiles-helper # Copyright (C) 2008 Canonical Ltd. # # Authors: Nick Barcet @@ -24,6 +24,7 @@ from snack import * HOME=os.getenv("HOME") SHARE='/usr/share/screen-profiles' DOC='/usr/share/doc/screen-profiles' +DEF_ESC="A" gettext.bindtextdomain('screen-profiles-helper', SHARE+'/po') gettext.textdomain('screen-profiles-helper') @@ -66,15 +67,16 @@ def menu(screen, size, isInstalled): installtext=_("Install screen by default at login") - li = Listbox(height = 5, width = 60, returnExit = 1) + li = Listbox(height = 6, width = 60, returnExit = 1) li.append(_("Help"), 1) li.append(_("Change screen profile"), 2) - li.append(_("Create new window(s)"), 3) - li.append(_("Manage default windows"), 4) - li.append(installtext, 5) + li.append(_("Change escape sequence"), 3) + li.append(_("Create new window(s)"), 4) + li.append(_("Manage default windows"), 5) + li.append(installtext, 6) bb = ButtonBar(screen, ((_("Ok"), "ok"), (_("Exit"), "exit")), compact = 1) - g = GridForm(screen, _("GNU Screen Profiles Menu"), 1, 2) + g = GridForm(screen, _("Screen Profiles Menu"), 1, 2) g.add(li, 0, 0, padding=(4,2,4,2)) g.add(bb, 0, 1, padding=(1,1,0,0)) @@ -113,7 +115,7 @@ def help(screen, size, config): cb=Checkbox(_("Display this help on startup"), isOn=cbOn) - g = GridForm(screen, _("GNU Screen Profiles Help"), 1, 3) + g = GridForm(screen, _("Screen Profiles Help"), 1, 3) g.add(t, 0, 0, padding=(0,0,0,0)) g.add(cb, 0, 1, padding=(1,0,0,0)) g.add(bb, 0, 2, padding=(1,1,0,0)) @@ -320,6 +322,66 @@ def install(screen, size, isInstalled): return 101 +def getesckey(): + path=HOME+'/.screenrc-keybindings' + if not os.path.exists(path): + return DEF_ESC + line = commands.getoutput("grep ^escape "+path) + if line == "": + return DEF_ESC + return line[line.find('^')+1] + +def setesckey(key): + path = HOME+'/.screenrc-keybindings' + if key != "": + val = key[0].upper()+key[0].lower() + if os.path.exists(path): + out = commands.getoutput("grep ^escape "+path) + if out != "": + out = commands.getoutput("sed -i -e 's/^escape \^.*/escape ^"+val+"/' "+path) + return + f = open(path, 'a') + try: + f.write("escape ^"+val+"\n") + except IOError: + return + finally: + f.close() + +def chgesc(screen, size): + esc=Entry(2, text=getesckey(), returnExit=1) + escl=Label(_("Escape key: ctrl-")) + bb = ButtonBar(screen, ((_("Save"), "save"), (_("Cancel"), "cancel")), compact = 1) + g = GridForm(screen, _("Change escape sequence:"), 2, 4 ) + g.add(escl, 0, 0, anchorLeft=1, padding=(1,0,0,1)) + g.add(esc, 1, 0, anchorLeft=1) + g.add(bb, 1, 1) + g.setTimer(100) + loop=1 + while loop: + which=g.run() + if which == "TIMER": + val=esc.value() + if len(val) > 1: + esc.set(val[1]) + # Ensure that the escape sequence is not set to a number + try: + dummy = int(esc.value()) + esc.set(DEF_ESC) + except: + # do nothing + dummy = "foo" + else: + loop=0 + screen.popWindow() + if bb.buttonPressed(which) != "cancel": + setesckey(esc.value()) + button = messagebox(screen, 60, 2, _("Message"), \ + _("Restart screen to enact your changes."), \ + buttons=((_("Ok"),"ok"), (_("Exit"), "exit")) ) + if button == "exit": + return 0 + return 100 def main(): """This is the main loop of our screen helper. @@ -327,7 +389,7 @@ def main(): size = terminal_size() screen = SnackScreen() - screen.drawRootText(1,0,_('GNU Screen Profiles Helper')) + screen.drawRootText(1,0,_('Screen Profiles Helper')) screen.pushHelpLine(_('/ between elements | Validates')) config = SafeConfigParser() @@ -353,11 +415,13 @@ def main(): tag = help(screen, size, config) elif tag == 2: tag = profile(screen, size) - elif tag == 3: - tag = newwindow(screen, size) + elif tag == 3: + tag = chgesc(screen, size) elif tag == 4: - tag = defaultwindows(screen, size) + tag = newwindow(screen, size) elif tag == 5: + tag = defaultwindows(screen, size) + elif tag == 6: tag = install(screen, size, isInstalled) isInstalled=(tag == 100)