Class: Term
Instance Attribute Summary
#index
Attributes inherited from ArcadiaExt
#arcadia, #name
Instance Method Summary
collapse
#activate, #activate_main, #active?, #active_instance, #clean_instance, #clone, #deduplicate, #duplicate, #exist_name?, #frame, #initialize, #instance_index, instances, #instances, #main_instance, #main_instance?, #new_name, #on_destroy_instance
Methods inherited from ArcadiaExt
#add_to_conf_property, #array_conf, #conf, #conf_array, #conf_default, #del_from_conf_property, #destroy_frame, #exec, #float_frame, #frame, #frame_def_visible?, #frame_domain, #frame_domain_default, #frame_raised?, #frame_title, #frame_visible?, #hide_frame, #hinner_dialog, #hinner_splitted_dialog, #hinner_splitted_dialog_titled, #initialize, #maximize, #maximized?, #restore_default_conf
Constructor Details
This class inherits a constructor from ArcadiaExtPlus
Instance Method Details
#do_after_run_xterm ⇒ Object
66
67
68
69
70
71
72
|
# File 'ext/ae-term/ae-term.rb', line 66
def do_after_run_xterm
if !@bind_after_run
@bind_after_run = true
frame.hinner_frame.bind_append("Configure", proc{|w,h| resize(w,h)}, "%w %h")
frame.hinner_frame.bind_append("Map", proc{do_run_xterm(conf('dir')) if !xterm_running?})
end
end
|
#do_run_external_term(_dir) ⇒ Object
140
141
142
143
144
145
146
147
148
|
# File 'ext/ae-term/ae-term.rb', line 140
def do_run_external_term(_dir)
if OS.windows?
system("cd #{_dir} & start cmd")
elsif OS.mac?
system("open -a Terminal '#{_dir}'")
else
system("cd #{_dir}; xterm &")
end
end
|
#do_run_xterm(_dir = '~') ⇒ Object
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
|
# File 'ext/ae-term/ae-term.rb', line 81
def do_run_xterm(_dir='~')
return if @running
@running = true
killall_xterm
self.frame.show_anyway
conf("create",'yes')
conf("dir",_dir)
id_int = eval(frame.hinner_frame.winfo_id).to_i
cmd = "cd #{_dir} ; xterm -into #{id_int} -bg '#{conf('color.bg')}' -fg '#{conf('color.fg')}' -fa '#{conf('font')}' -class #{xterm_class} +sb +hold"
fi_pid=-1
Thread.new do
system(cmd)
@xterm_pid = -1
if !@finalizing
do_xterm_exit
end
end
maxtimes = 100
t=0
while (@xterm_pid == -1 || @xterm_pid.nil? || @xterm_pid.length == 0) && t < maxtimes
open("|xdotool search --limit 1 --class #{xterm_class} "){|f| fi_pid = f.read.strip if f }
@xterm_pid = fi_pid
t=t+1
end
resize()
@running = false
end
|
#do_xterm_exit ⇒ Object
117
118
119
120
121
122
123
124
125
126
127
128
|
# File 'ext/ae-term/ae-term.rb', line 117
def do_xterm_exit
@bind_after_run = false
frame.hinner_frame.bind_remove("Configure")
frame.hinner_frame.bind_remove("Map")
if main_instance?
conf("create",'no')
clean_instance
else
clean_instance
end
end
|
#killall_xterm ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
|
# File 'ext/ae-term/ae-term.rb', line 54
def killall_xterm
return if !@has_xdotool
fi_pids_string = open("|xdotool search --class #{xterm_class} "){|f| f.read.strip }
if fi_pids_string && fi_pids_string.length > 0
fi_pids_array = fi_pids_string.split
fi_pids_array.each{|fi_pid| system("xdotool windowkill #{fi_pid}")
}
end
end
|
#on_before_build(_event) ⇒ Object
#on_build(_event) ⇒ Object
27
28
29
30
31
|
# File 'ext/ae-term/ae-term.rb', line 27
def on_build(_event)
if main_instance? && @can_run
Arcadia.attach_listener(self, TermEvent)
end
end
|
#on_finalize(_event) ⇒ Object
48
49
50
51
52
|
# File 'ext/ae-term/ae-term.rb', line 48
def on_finalize(_event)
return if OS.windows? || OS.mac?
@finalizing = true
killall_xterm if @has_xterm && @has_xdotool
end
|
#on_initialize(_event) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'ext/ae-term/ae-term.rb', line 33
def on_initialize(_event)
return if OS.windows? || OS.mac?
@xterm_pid = -1
@finalizing = false
@bind_after_run = false
if conf("create") == "yes" && @has_xterm && @has_xdotool
frame
Thread.new{
do_run_xterm(conf('dir'))
do_after_run_xterm
}
end
end
|
#on_term(_event) ⇒ Object
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
# File 'ext/ae-term/ae-term.rb', line 150
def on_term(_event)
if !@has_xdotool || OS.windows? || OS.mac?
do_run_external_term(_event.dir)
else
if xterm_running?
saved_main_conf = conf('create')
conf("create",'no')
new_instance = duplicate
conf("create",saved_main_conf)
if !new_instance.xterm_running?
new_instance.frame
Thread.new{
new_instance.do_run_xterm(_event.dir)
new_instance.do_after_run_xterm
}
end
else
frame
Thread.new{
do_run_xterm(_event.dir)
do_after_run_xterm
}
end
end
end
|
#resize(w = nil, h = nil) ⇒ Object
130
131
132
133
134
135
136
137
138
|
# File 'ext/ae-term/ae-term.rb', line 130
def resize(w=nil,h=nil)
return if !@has_xdotool
if @xterm_pid != -1
w = TkWinfo.width(frame.hinner_frame) if w.nil?
h = TkWinfo.height(frame.hinner_frame) if h.nil?
cmd = "xdotool windowsize #{@xterm_pid} #{w} #{h}"
system(cmd)
end
end
|
#xterm_class ⇒ Object
74
75
76
77
78
79
|
# File 'ext/ae-term/ae-term.rb', line 74
def xterm_class
if @xterm_class_id.nil?
@xterm_class_id = "xta#{Time.new.to_i}#{instance_index}"
end
@xterm_class_id
end
|
#xterm_running? ⇒ Boolean
113
114
115
|
# File 'ext/ae-term/ae-term.rb', line 113
def xterm_running?
@xterm_pid != -1
end
|