-
Notifications
You must be signed in to change notification settings - Fork 3
/
tkma
executable file
·170 lines (145 loc) · 3.25 KB
/
tkma
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/env ruby
# -*- ruby -*-
require 'tk'
# http://svn.python.org/projects/external/tk-8.5.2.0/library/obsolete.tcl
# Tk.tk_call "::tk::classic::restore"
root = TkRoot.new {
title "tkma"
}
panes = TkPanedWindow.new(root) {
orient "vertical"
}
folders = TkText.new(panes) {
padx 0
pady 0
background panes.background
relief "flat"
pack :expand => true, :fill => :both
height 3
}
$rescan_opts = "-thread"
$scan = TkVariable.new
def rescan(inc=false)
`coma inc #{$folder}` if inc
$scan.value = `coma read #{$folder} -width #{textwidth} #{$rescan_opts}`.split("\n")
end
def textwidth
# XXX good enough for now
($mailcontent.winfo_width - $mailcontent.borderwidth) /
TkFont.measure("TkFixedFont", "0") - 1
end
`coma folders -list`.split("\n").sort.each { |folder|
TkTextWindow.new(folders, "end") {
self.window = TkButton.new {
text folder
padx 3
pady 1
command {
$folder = folder
rescan true
}
pack "side" => "left"
}
}
}
folders.state = 'disabled'
class TkText
def textheight
number(tk_send_without_enc('count', '-ypixels', '1.0', 'end'))
end
end
toc = TkFrame.new(panes) {
pack :expand => true, :fill => "x"
}
tocbuttons = TkFrame.new(toc) {
pack :expand => false, :fill => :both
}
%w{all date from subject thread flagged unflagged replied unreplied seen unseen}.each { |btn|
TkButton.new(tocbuttons) {
text btn
padx 3
pady 1
command {
$rescan_opts = "-" + btn
rescan
}
pack "side" => "right"
}
}
def sel
$mails.get($mails.curselection)[/\d+/]
end
$redisplay_opts = []
def redisplay
$mailcontent.state = 'normal'
$mailcontent.value = `coma show #{sel} #{$redisplay_opts.join(" ")}`
$mailcontent.state = 'disabled'
rescan
end
$mails = TkScrollbox.new(toc) {
insert 0, "foo"
insert 0, "bar"
font "TkFixedFont"
listvariable $scan
pack :expand => true, :fill => "both"
bind("<ListboxSelect>") {
redisplay
}
}
mail = TkFrame.new(panes) {
pack :expand => true, :fill => "both"
}
mailbuttons = TkFrame.new(mail) {
pack :expand => false, :fill => "both", :anchor => "ne"
}
TkButton.new(mailbuttons) {
padx 3
pady 1
text "repl"
command {
system "urxvt", "-e", "coma", "repl", sel
}
pack "side" => "right"
}
TkButton.new(mailbuttons) {
padx 3
pady 1
text "fwd"
command {
system "urxvt", "-e", "coma", "fwd", sel
}
pack "side" => "right"
}
TkButton.new(mailbuttons) {
padx 3
pady 1
text "raw"
command {
unless $redisplay_opts.delete "-raw"
$redisplay_opts << "-raw"
end
redisplay
}
pack "side" => "right"
}
$mailcontent = TkText.new(mail) {
yscrollbar(TkScrollbar.new(mail).pack(:fill=>:y, :side=>:right))
state 'disabled'
insert "0.0", "foobar"
pack :expand => true, :fill => "both", :anchor => "s"
}
panes.add folders
panes.add toc
panes.add mail
panes.pack(:expand => true, :fill => "both")
Tk.update
panes.paneconfigure(folders, :minsize => folders.textheight + 5)
panes.paneconfigure(toc, :minsize => 20)
panes.paneconfigure(mail, :minsize => 20)
prevth = folders.textheight
root.bind("Configure") {
break if folders.textheight == prevth
panes.paneconfigure(folders, :minsize => folders.textheight + 5)
panes.sash_place(0, 0, 0)
}
Tk.mainloop