Class: Term

Inherits:
ArcadiaExtPlus show all
Defined in:
ext/ae-term/ae-term.rb

Instance Attribute Summary

Attributes inherited from ArcadiaExtPlus

#index

Attributes inherited from ArcadiaExt

#arcadia, #name

Instance Method Summary collapse

Methods inherited from ArcadiaExtPlus

#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, #exec, #float_frame, #frame, #frame_def_visible?, #frame_domain, #frame_domain_default, #frame_visible?, #hide_frame, #initialize, #maximize, #maximized?, #restore_default_conf

Constructor Details

This class inherits a constructor from ArcadiaExtPlus

Instance Method Details

#do_after_run_xtermObject



65
66
67
68
69
70
71
# File 'ext/ae-term/ae-term.rb', line 65

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



131
132
133
134
135
136
137
# File 'ext/ae-term/ae-term.rb', line 131

def do_run_external_term(_dir)
  if Arcadia.is_windows?
    system("cd #{_dir} & start cdm")
  else
    system("cd #{_dir}; xterm &")
  end
end

#do_run_xterm(_dir = '~') ⇒ Object



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
# File 'ext/ae-term/ae-term.rb', line 77

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
  #Arcadia.runtime_error_msg("CREO XTERM #{xterm_class} con id #{id_int}")
  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
    #open("|#{cmd}"){|f|  @xterm_pid = f.read.strip if f }
    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
  #Arcadia.runtime_error_msg("assegno al xterm #{xterm_class} xterm_pid #{@xterm_pid}")
  resize()
  @running = false
end

#do_xterm_exitObject



112
113
114
115
116
117
118
119
# File 'ext/ae-term/ae-term.rb', line 112

def do_xterm_exit
  if main_instance?
    conf("create",'no')
    hide_frame
  else
    clean_instance
  end
end

#killall_xtermObject



53
54
55
56
57
58
59
60
61
62
63
# File 'ext/ae-term/ae-term.rb', line 53

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}")
      #p "KILLO XTERM #{xterm_class} pid #{fi_pid}"
    }
    #Arcadia.runtime_error_msg("kill per #{xterm_class} #{ fi_pids_string }")
  end
end

#on_before_build(_event) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'ext/ae-term/ae-term.rb', line 10

def on_before_build(_event)
  @has_xterm = !Arcadia.which("xterm").nil?
  @has_xdotool = !Arcadia.which("xdotool").nil?
  @can_run = @has_xterm || Arcadia.is_windows? 
  if !Arcadia.is_windows?
    if !@has_xterm
      msg = Arcadia.text("ext.term.dependences_missing.xterm.msg")
      ArcadiaProblemEvent.new(self, "type"=>ArcadiaProblemEvent::DEPENDENCE_MISSING_TYPE,"title"=>Arcadia.text("ext.term.dependences_missing.xterm.title"), "detail"=>msg).go!
    end
    if !@has_xdotool
      msg = Arcadia.text("ext.term.dependences_missing.xdotool.msg")
      ArcadiaProblemEvent.new(self, "type"=>ArcadiaProblemEvent::DEPENDENCE_MISSING_TYPE,"title"=>Arcadia.text("ext.term.dependences_missing.xdotool.title"), "detail"=>msg).go!
    end
  end
end

#on_build(_event) ⇒ Object



26
27
28
29
30
# File 'ext/ae-term/ae-term.rb', line 26

def on_build(_event)
  if main_instance? && @can_run
    Arcadia.attach_listener(self, TermEvent)
  end
end

#on_finalize(_event) ⇒ Object



47
48
49
50
51
# File 'ext/ae-term/ae-term.rb', line 47

def on_finalize(_event)
  return if Arcadia.is_windows?
  @finalizing = true
  killall_xterm if @has_xterm && @has_xdotool
end

#on_initialize(_event) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'ext/ae-term/ae-term.rb', line 32

def on_initialize(_event)
  # called at startup
  return if Arcadia.is_windows?
  @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



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
# File 'ext/ae-term/ae-term.rb', line 139

def on_term(_event)
  if !@has_xdotool || Arcadia.is_windows?
    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



121
122
123
124
125
126
127
128
129
# File 'ext/ae-term/ae-term.rb', line 121

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_classObject



73
74
75
# File 'ext/ae-term/ae-term.rb', line 73

def xterm_class
  "xarc#{instance_index}"
end

#xterm_running?Boolean

Returns:

  • (Boolean)


108
109
110
# File 'ext/ae-term/ae-term.rb', line 108

def xterm_running?
  @xterm_pid != -1
end