~ubuntu-branches/debian/wheezy/byobu/wheezy

« back to all changes in this revision

Viewing changes to usr/bin/byobu-config

  • Committer: Package Import Robot
  • Author(s): Alexander Chernyakhovsky
  • Date: 2012-01-11 19:37:34 UTC
  • mfrom: (0.5.3) (0.1.162 precise)
  • Revision ID: package-import@ubuntu.com-20120111193734-89083z97py39gj05
Tags: 5.2-1
* Syncing from Ubuntu. Remaining changes:
  - Switch to dh short syntax
  - Added a substvar ${perl:Depends} dependency into debian/control

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
HOME=os.getenv("HOME")
31
31
USER=os.getenv("USER")
32
32
BYOBU_CONFIG_DIR=os.getenv("BYOBU_CONFIG_DIR", HOME+"/.byobu")
33
 
BYOBU_BACKEND=os.getenv("BYOBU_BACKEND", "screen")
 
33
BYOBU_BACKEND=os.getenv("BYOBU_BACKEND", "tmux")
34
34
BYOBU_SOCKETDIR=os.getenv("SOCKETDIR", "/var/run/screen")
35
35
BYOBU_PREFIX = os.getenv("BYOBU_PREFIX", "/usr")
36
36
SHARE=BYOBU_PREFIX+'/share/'+PKG
54
54
gettext.textdomain(PKG)
55
55
_ = gettext.gettext
56
56
 
57
 
# Command presets for windows creation
58
 
cmd=(   ("System activity", "top", "top"),
59
 
        ("System log", "log", "watch -n 10 tail -n 5 /var/log/syslog /var/log/auth.log /var/log/dmesg"),
60
 
        ("Disk and ram usage", "mem", 'watch -n 30 "df -h; echo ""; free -mt"'))
61
 
 
62
 
 
63
57
def ioctl_GWINSZ(fd):                  #### TABULATION FUNCTIONS
64
58
    try:                                ### Discover terminal width
65
59
        import fcntl, termios, struct, os
69
63
    return cr
70
64
 
71
65
def reload_required():
72
 
    f = open(RELOAD_FLAG,'w')
73
 
    f.close()
74
 
    commands.getoutput(RELOAD_CMD)
 
66
    try:
 
67
        if not os.path.exists(BYOBU_CONFIG_DIR):
 
68
            os.makedirs(BYOBU_CONFIG_DIR, 0755)
 
69
        f = open(RELOAD_FLAG,'w')
 
70
        f.close()
 
71
        commands.getoutput(RELOAD_CMD)
 
72
    except:
 
73
        True
75
74
 
76
75
def terminal_size():                    ### decide on *some* terminal size
77
76
    cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)  # try open fds
94
93
        installtext=_("Byobu currently launches at login (toggle off)")
95
94
    else:
96
95
        installtext=_("Byobu currently does not launch at login (toggle on)")
97
 
 
98
 
 
99
 
    li = Listbox(height = 9, width = 60, returnExit = 1)
 
96
    li = Listbox(height = 6, width = 60, returnExit = 1)
100
97
    li.append(_("Help -- Quick Start Guide"), 1)
101
 
    li.append(_("Change Byobu's background color"), 2)
102
 
    li.append(_("Change Byobu's foreground color"), 3)
103
 
    li.append(_("Toggle status notifications"), 4)
104
 
    li.append(_("Change keybinding set"), 5)
105
 
    li.append(_("Change escape sequence"), 6)
106
 
    li.append(_("Create new windows"), 7)
107
 
    li.append(_("Manage default windows"), 8)
108
 
    li.append(installtext, 9)
 
98
    li.append(_("Toggle status notifications"), 2)
 
99
    li.append(_("Change escape sequence"), 3)
 
100
    li.append(installtext, 4)
109
101
    bb = ButtonBar(snackScreen, (("Exit", "exit", ESC),), compact=1)
110
 
 
111
102
    g = GridForm(snackScreen, _(" Byobu Configuration Menu"), 1, 2)
112
103
    g.add(li, 0, 0, padding=(4,2,4,2))
113
104
    g.add(bb, 0, 1, padding=(1,1,0,0))
114
 
 
115
105
    if bb.buttonPressed(g.runOnce()) == "exit":
116
106
        return 0
117
107
    else:
119
109
 
120
110
def messagebox(snackScreen, width, height, title, text, scroll=0, \
121
111
    buttons=((_("Okay"), "okay"),(_("Cancel"), "cancel", ESC)) ):
122
 
 
123
112
    t = Textbox(width, height, text, scroll=scroll )
124
113
    bb = ButtonBar(snackScreen, buttons, compact = 1)
125
114
    g = GridForm(snackScreen, title, 1, 2)
126
115
    g.add(t, 0, 0, padding=(0,0,0,0))
127
116
    g.add(bb, 0, 1, padding=(1,1,0,0))
128
 
 
129
117
    return bb.buttonPressed(g.runOnce())
130
118
 
131
119
def help(snackScreen, size, config):
132
 
    f=file(DOC+'/help.txt')
 
120
    f=file(DOC+'/help.'+BYOBU_BACKEND+'.txt')
133
121
    text=f.read()
134
122
    f.close()
135
 
 
136
123
    text=text.replace("<esckey>", getesckey(), 1)
137
124
    text=text.replace("_VER_", commands.getoutput("byobu -v | head -n1 | " + SED + " 's/.* //'"), 1)
138
 
 
139
 
    t = Textbox(70, 14, text, scroll=0)
 
125
    t = Textbox(67, 16, text, scroll=1, wrap=1)
140
126
    bb = ButtonBar(snackScreen, ((_("Menu"), "menu", ESC),), compact = 1)
141
 
    g = GridForm(snackScreen, _("Byobu Help"), 1, 3)
142
 
    g.add(t, 0, 0, padding=(0,0,0,0))
143
 
    g.add(bb, 0, 2, padding=(1,1,0,0))
144
 
 
 
127
    g = GridForm(snackScreen, _("Byobu Help"), 2, 4)
 
128
    g.add(t, 1, 0)
 
129
    g.add(bb, 1, 1, padding=(1,1,0,0))
145
130
    button = bb.buttonPressed(g.runOnce())
146
 
 
147
 
    return 100
148
 
 
149
 
def select_color(snackScreen, size, layer):
150
 
    li = Listbox(height = 8, width = 60, scroll = 1, returnExit = 1)
151
 
 
152
 
    for choice in commands.getoutput('byobu-select-profile -l').splitlines():
153
 
        li.append(choice, choice)
154
 
 
155
 
    bb = ButtonBar(snackScreen, ((_("Apply"), "apply"), (_("Cancel"), "cancel", ESC)), compact = 1)
156
 
 
157
 
    if layer == "foreground":
158
 
        g = GridForm(snackScreen, _("Choose a foreground color:"), 1, 2)
159
 
    else:
160
 
        g = GridForm(snackScreen, _("Choose a background color:"), 1, 2)
161
 
 
162
 
    g.add(li, 0, 0, padding=(4,2,4,2))
163
 
    g.add(bb, 0, 1, padding=(1,1,0,0))
164
 
 
165
 
    if bb.buttonPressed(g.runOnce()) != "cancel":
166
 
        if layer == "foreground":
167
 
            commands.getoutput('byobu-select-profile --foreground %s' % li.current())
168
 
        else:
169
 
            commands.getoutput('byobu-select-profile --background %s' % li.current())
170
 
        reload_required()
171
 
    return 100
172
 
 
173
 
def keybindings(snackScreen, size):
174
 
    li = Listbox(height = 6, width = 60, returnExit = 1)
175
 
    for choice in commands.getoutput('ls '+SHARE+'/keybindings').splitlines():
176
 
        if choice != "common" and choice != "none":
177
 
            li.append(choice, choice)
178
 
    li.append("none", "none")
179
 
    bb = ButtonBar(snackScreen, ((_("Apply"), "apply"), (_("Cancel"), "cancel", ESC)), compact = 1)
180
 
    g = GridForm(snackScreen, _("Which set of keybindings would you like to use?"), 1, 2)
181
 
    g.add(li, 0, 0, padding=(4,2,4,2))
182
 
    g.add(bb, 0, 1, padding=(1,1,0,0))
183
 
    if bb.buttonPressed(g.runOnce()) != "cancel":
184
 
        switch_keybindings(li.current())
185
 
        reload_required()
186
 
    return 100
187
 
 
188
 
def switch_keybindings(set):
189
 
    commands.getoutput(SED + " -i -e 's:^source .*$:source "+SHARE+"/keybindings/"+set+":' "+BYOBU_CONFIG_DIR+"/keybindings")
190
 
 
191
 
def newwindow(snackScreen, size):
192
 
    title=Entry(8, text="shell", returnExit=1)
193
 
    titlel=Label(_("Title: "))
194
 
    command=Entry(20, text="/bin/sh", returnExit=1)
195
 
    commandl=Label(_("Command: "))
196
 
    path=Entry(20, text="~", returnExit=1)
197
 
    pathl=Label(_("Path: "))
198
 
 
199
 
    rl=Label(_("Presets: "))
200
 
    if len(cmd) > 10:
201
 
        scroll=1
202
 
        size=10
203
 
    else:
204
 
        scroll=0
205
 
        size = len(cmd)
206
 
 
207
 
    r=CheckboxTree(size, scroll=scroll)
208
 
    count=0
209
 
    for cur in cmd:
210
 
        r.append(cur[0], count)
211
 
        count=count+1
212
 
 
213
 
    cb=Checkbox(_("Add to default windows"))
214
 
 
215
 
    bb = ButtonBar(snackScreen, ((_("Apply"), "apply"), (_("Cancel"), "cancel", ESC)), compact = 1)
216
 
 
217
 
    g = GridForm(snackScreen, _("Create new window(s):"), 2, 6 )
218
 
    g.add(titlel, 0, 0, anchorLeft=1,padding=(4,1,0,1))
219
 
    g.add(title, 1, 0, anchorLeft=1)
220
 
    g.add(commandl, 0, 1, anchorLeft=1, anchorTop=1,padding=(4,0,0,1))
221
 
    g.add(command, 1, 1, anchorLeft=1)
222
 
    g.add(pathl, 0, 2, anchorLeft=1, anchorTop=1,padding=(4,0,0,1))
223
 
    g.add(path, 1, 2, anchorLeft=1)
224
 
    g.add(rl, 0, 3, anchorLeft=1,padding=(4,0,0,1))
225
 
    g.add(r, 1, 3)
226
 
    g.add(cb, 1, 4, padding=(4,1,0,1))
227
 
    g.add(bb, 1, 5, padding=(4,1,0,0))
228
 
 
229
 
    if bb.buttonPressed(g.runOnce()) != "cancel":
230
 
        sel=r.getSelection()
231
 
        if sel:
232
 
            for s in sel:
233
 
                win='%s -t %s %s' % (BYOBU_BACKEND, cmd[s][1], cmd[s][2])
234
 
                commands.getoutput(win)
235
 
                if cb.value():
236
 
                    appendwindow(win)
237
 
        else:
238
 
            cpath='%s -X setenv newpath %s' % (BYOBU_BACKEND, path.value())
239
 
            win='%s -X eval \'chdir $newpath\' \"%s -t %s %s\"' % (BYOBU_BACKEND, BYOBU_BACKEND, title.value(), command.value())
240
 
            commands.getoutput(cpath)
241
 
            commands.getoutput(win)
242
 
            if cb.value():
243
 
                cpath='chdir %s' % (path.value())
244
 
                win='%s -t %s %s' % (BYOBU_BACKEND, title.value(), command.value())
245
 
                appendwindow(cpath)
246
 
                appendwindow(win)
247
 
 
248
 
    return 100
249
 
 
250
 
def appendwindow(win):
251
 
    f=open(BYOBU_CONFIG_DIR+'/windows', 'a')
252
 
    try:
253
 
        f.write(win+"\n")
254
 
 
255
 
    except IOError:
256
 
        f.close()
257
 
        return None
258
 
 
259
 
    f.close()
260
 
 
261
 
def readwindows():
262
 
    if not os.path.isfile(BYOBU_CONFIG_DIR+'/windows'):
263
 
        windowsfile=SHARE+'/windows/common'
264
 
    elif os.path.getsize(BYOBU_CONFIG_DIR+'/windows') == 0:
265
 
        windowsfile=SHARE+'/windows/common'
266
 
    else:
267
 
        windowsfile=BYOBU_CONFIG_DIR+'/windows'
268
 
    f=open(windowsfile)
269
 
    try:
270
 
        li=[]
271
 
        for line in f.readlines():
272
 
            if line.startswith("# "):
273
 
               # this is a comment
274
 
               window=[-1, line]
275
 
            elif line.startswith("#"):
276
 
               # this is an inactive window
277
 
               window=[0, line.lstrip("#")]
278
 
            else:
279
 
               window=[1, line]
280
 
            li.append(window)
281
 
 
282
 
        return li
283
 
 
284
 
    except IOError:
285
 
        f.close()
286
 
        return None
287
 
 
288
 
    f.close()
 
131
    return 100
289
132
 
290
133
def readstatus():
291
134
    status={}
356
199
            r.append(item[1],count,selected=item[0])
357
200
       count=count+1
358
201
    bb = ButtonBar(snackScreen, ((_("Apply"), "apply"), (_("Cancel"), "cancel", ESC)), compact = 1)
359
 
    g = GridForm(snackScreen, _("Toggle status notifications:"), 2, 4 )
 
202
    g = GridForm(snackScreen, _("Toggle status notifications"), 2, 4 )
360
203
    g.add(rl, 0, 0, anchorLeft=1, anchorTop=1, padding=(4,0,0,1))
361
204
    g.add(r, 1, 0)
362
205
    g.add(bb, 1, 1, padding=(4,1,0,0))
370
213
        reload_required()
371
214
    return 100
372
215
 
373
 
def writewindows(winlist):
374
 
    f=open(BYOBU_CONFIG_DIR+'/windows', 'w')
375
 
    try:
376
 
        for win in winlist:
377
 
            if win[0] == -1:
378
 
                f.write(win[1])
379
 
            elif win[0] == 0:
380
 
                f.write("#"+win[1])
381
 
            else:
382
 
                f.write(win[1])
383
 
    except IOError:
384
 
        f.close()
385
 
        return None
386
 
    f.close()
387
 
 
388
 
def defaultwindows(snackScreen, size):
389
 
    winlist=readwindows()
390
 
 
391
 
    rl=Label(_("Windows:"))
392
 
    r=CheckboxTree(10, scroll=1)
393
 
    count=0
394
 
    for win in winlist:
395
 
       if win[0] != -1:
396
 
            r.append(win[1],count,selected=win[0])
397
 
       count=count+1
398
 
 
399
 
    bb = ButtonBar(snackScreen, ((_("Apply"), "apply"), (_("Cancel"), "cancel", ESC)), compact = 1)
400
 
 
401
 
    g = GridForm(snackScreen, _("Select window(s) to create by default:"), 2, 4 )
402
 
    g.add(rl, 0, 0, anchorLeft=1, anchorTop=1, padding=(4,0,0,1))
403
 
    g.add(r, 1, 0)
404
 
    g.add(bb, 1, 1, padding=(4,1,0,0))
405
 
 
406
 
    if bb.buttonPressed(g.runOnce()) != "cancel":
407
 
        count=0
408
 
        for win in winlist:
409
 
            if win[0] != -1:
410
 
                win[0] = r.getEntryValue(count)[1]
411
 
            count=count+1
412
 
 
413
 
        writewindows(winlist)
414
 
 
415
 
    return 100
416
 
 
417
216
def install(snackScreen, size, isInstalled):
418
217
    if isInstalled:
419
218
        out = commands.getoutput("byobu-launcher-uninstall")
420
219
        if out == "":
421
 
            out = _("Byobu will not be used next time you login.")
 
220
            out = _("Byobu will not be launched next time you login.")
422
221
        button = messagebox(snackScreen, 60, 2, _("Message"), out, buttons=((_("Menu"), )))
423
222
        return 101
424
223
    else:
438
237
    f.close()
439
238
    return
440
239
 
441
 
 
442
240
def getesckey():
443
241
    path=BYOBU_CONFIG_DIR+'/keybindings'
444
242
    if not os.path.exists(path):
471
269
    esc=Entry(2, text=getesckey(), returnExit=1)
472
270
    escl=Label(_("Escape key: ctrl-"))
473
271
    bb = ButtonBar(snackScreen, ((_("Apply"), "apply"), (_("Cancel"), "cancel", ESC)), compact = 1)
474
 
 
475
 
    g = GridForm(snackScreen, _("Change escape sequence:"), 2, 4 )
 
272
    g = GridForm(snackScreen, _("Change escape sequence"), 2, 4 )
476
273
    g.add(escl, 0, 0, anchorLeft=1, padding=(1,0,0,1))
477
274
    g.add(esc, 1, 0, anchorLeft=1)
478
275
    g.add(bb, 1, 1)
518
315
def main():
519
316
    """This is the main loop of our utility
520
317
    """
521
 
 
522
318
    size = terminal_size()
523
319
    snackScreen = SnackScreen()
524
 
    snackScreen.drawRootText(1,0,_(' Byobu Configuration Menu'))
525
 
    snackScreen.pushHelpLine(_('<Tab>/<Alt-Tab> between elements | <Enter> selects | <Esc> exits'))
526
 
 
 
320
    snackScreen.drawRootText(1,0,_('Byobu Configuration Menu'))
 
321
    snackScreen.pushHelpLine(_('<Tab> between elements | <Enter> selects | <Esc> exits'))
527
322
    config = SafeConfigParser()
528
 
 
529
323
    isInstalled = autolaunch()
530
 
 
531
324
    tag = 100
532
 
 
533
325
    while tag > 0 :
534
326
        tag = menu(snackScreen, size, isInstalled)
535
327
        if tag == 1:
536
328
            tag = help(snackScreen, size, config)
537
329
        elif tag == 2:
538
 
            tag = select_color(snackScreen, size, "background")
539
 
        elif tag == 3:
540
 
            tag = select_color(snackScreen, size, "foreground")
541
 
        elif tag == 4:
542
330
            tag = togglestatus(snackScreen, size)
543
 
        elif tag == 5:
544
 
            tag = keybindings(snackScreen, size)
545
 
        elif tag == 6:
 
331
        elif tag == 3:
546
332
            tag = chgesc(snackScreen, size)
547
 
        elif tag == 7:
548
 
            tag = newwindow(snackScreen, size)
549
 
        elif tag == 8:
550
 
            tag = defaultwindows(snackScreen, size)
551
 
        elif tag == 9:
 
333
        elif tag == 4:
552
334
            tag = install(snackScreen, size, isInstalled)
553
335
            isInstalled = autolaunch()
554
 
 
555
336
    snackScreen.finish()
556
337
    sys.exit(0)
557
338