class TopinambourTerminal
The default vte terminal customized
Constants
- REGEXES
Attributes
last_match[R]
pid[R]
Public Class Methods
new(command_string, toplevel, working_dir = nil)
click to toggle source
Create a new TopinambourTerminal
instance that runs command_string
Calls superclass method
# File lib/terminal.rb, line 43 def initialize(command_string, toplevel, working_dir = nil) super() @toplevel = toplevel @settings = toplevel.application.settings set_name('topinambour-terminal') command_array = parse_command(command_string) rescued_spawn(command_array, working_dir) signal_connect('child-exited') {@toplevel.quit_gracefully} load_settings add_matches add_popup_menu handle_mouse_clic end
Public Instance Methods
colors=(colors)
click to toggle source
# File lib/terminal.rb, line 103 def colors=(colors) set_colors(colors[0], colors[1], colors[2..-1]) end
font=(font_str)
click to toggle source
# File lib/terminal.rb, line 107 def font=(font_str) @settings['font'] = font_str font = Pango::FontDescription.new(font_str) set_font(font) @font = font end
load_colors()
click to toggle source
# File lib/terminal.rb, line 92 def load_colors colors_strings = @settings['colorscheme'] @colors = colors_strings.map { |c| Gdk::RGBA.parse(c) } @colors end
load_font()
click to toggle source
# File lib/terminal.rb, line 98 def load_font font_str = @settings['font'] @font = Pango::FontDescription.new(font_str) end
load_settings()
click to toggle source
Methods used to load Gio::Settings #
# File lib/terminal.rb, line 79 def load_settings load_colors set_colors(@colors[0], @colors[1], @colors[2..-1]) set_font(load_font) set_size(*load_size_settings) end
load_size_settings()
click to toggle source
# File lib/terminal.rb, line 86 def load_size_settings h = @settings['height'] w = @settings['width'] [w, h] end
pid_dir()
click to toggle source
# File lib/terminal.rb, line 59 def pid_dir File.readlink("/proc/#{@pid}/cwd") end
size()
click to toggle source
# File lib/terminal.rb, line 67 def size col = column_count char_w = char_width row = row_count char_h = char_height [col * char_w, row * char_h] end
terminal_title()
click to toggle source
# File lib/terminal.rb, line 63 def terminal_title @custom_title.class == String ? @custom_title : window_title.to_s end
Private Instance Methods
add_matches()
click to toggle source
Regexes related methods #
# File lib/terminal.rb, line 140 def add_matches REGEXES.each do |name| regex_name = TopinambourRegex.const_get(name) regex = if Vte::Regex Vte::Regex.new(regex_name, Pcre2::ALL_FLAGS, for_match: true) else compile_options = %i[optimize multiline] GLib::Regex.new(regex_name, compile_options: compile_options) end match_add_regex(regex, 0) end end
handle_mouse_clic()
click to toggle source
# File lib/terminal.rb, line 159 def handle_mouse_clic signal_connect 'button-press-event' do |widget, event| if event.type == Gdk::EventType::BUTTON_PRESS && event.button == Gdk::BUTTON_SECONDARY manage_regex_on_right_click(widget, event) display_copy_past_menu(event) true elsif event.button == Gdk::BUTTON_PRIMARY manage_regex_on_left_click(widget, event) false # let false so that it doesn't block the event else false end end end
launch_color_visualizer(color_name)
click to toggle source
# File lib/terminal.rb, line 212 def launch_color_visualizer(color_name) dialog = Gtk::ColorChooserDialog.new(title: color_name, parent: parent.toplevel) dialog.show_editor = true dialog.use_alpha = true dialog.rgba = Gdk::RGBA.parse(color_name) if dialog.run == Gtk::ResponseType::OK clipboard = Gtk::Clipboard.get_default(Gdk::Display.default) clipboard.text = dialog.rgba.to_s end dialog.destroy end
launch_default_for_regex_match(match, regex_type)
click to toggle source
Open default application on a left click.
# File lib/terminal.rb, line 206 def launch_default_for_regex_match(match, regex_type) Gio::AppInfo.launch_default_for_uri(match) rescue => e puts "error : #{e.message}\n\tfor match: #{match} of type :#{regex_type}" end
manage_regex_on_left_click(widget, event)
click to toggle source
# File lib/terminal.rb, line 190 def manage_regex_on_left_click(widget, event) match, regex_type = match_check_event(event) return nil if regex_type == -1 case REGEXES[regex_type] when :REGEX_EMAIL launch_default_for_regex_match('mailto:' + match, REGEXES[regex_type]) when :REGEX_URL_HTTP launch_default_for_regex_match('http://' + match, REGEXES[regex_type]) when :CSS_COLORS launch_color_visualizer(match) else launch_default_for_regex_match(match, REGEXES[regex_type]) end end
manage_regex_on_right_click(_widget, event)
click to toggle source
# File lib/terminal.rb, line 175 def manage_regex_on_right_click(_widget, event) @last_match, _regex_type = match_check_event(event) end
parse_command(command_string)
click to toggle source
Terminal command functions #
# File lib/terminal.rb, line 120 def parse_command(command_string) GLib::Shell.parse(command_string) rescue GLib::ShellError => e STDERR.puts "domain = #{e.domain}" STDERR.puts "code = #{e.code}" STDERR.puts "message = #{e.message}" end
rescued_spawn(command_array, working_dir)
click to toggle source
# File lib/terminal.rb, line 128 def rescued_spawn(command_array, working_dir) @pid = spawn(argv: command_array, working_directory: working_dir, spawn_flags: GLib::Spawn::SEARCH_PATH) rescue => e STDERR.puts e.message end