superterm 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,19 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ gem "gtk2"
7
+ gem "vte"
8
+ gem "gettext"
9
+ gem "sqlite3"
10
+ gem "knjrbfw"
11
+
12
+ # Add dependencies to develop your gem here.
13
+ # Include everything needed to run rake, tests, features, etc.
14
+ group :development do
15
+ gem "rspec", "~> 2.8.0"
16
+ gem "rdoc", "~> 3.12"
17
+ gem "bundler", ">= 1.0.0"
18
+ gem "jeweler", "~> 1.8.4"
19
+ end
@@ -0,0 +1,71 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ atk (1.1.4)
5
+ glib2 (>= 1.1.4)
6
+ cairo (1.12.2)
7
+ pkg-config
8
+ datet (0.0.15)
9
+ diff-lcs (1.1.3)
10
+ gdk_pixbuf2 (1.1.4)
11
+ glib2 (>= 1.1.4)
12
+ gettext (2.2.1)
13
+ locale
14
+ git (1.2.5)
15
+ glib2 (1.1.4)
16
+ pkg-config
17
+ gtk2 (1.1.4)
18
+ atk (>= 1.1.4)
19
+ gdk_pixbuf2 (>= 1.1.4)
20
+ pango (>= 1.1.4)
21
+ http2 (0.0.10)
22
+ jeweler (1.8.4)
23
+ bundler (~> 1.0)
24
+ git (>= 1.2.5)
25
+ rake
26
+ rdoc
27
+ json (1.7.5)
28
+ knjrbfw (0.0.87)
29
+ datet
30
+ http2
31
+ php4r
32
+ tsafe
33
+ wref
34
+ locale (2.0.5)
35
+ pango (1.1.4)
36
+ cairo (>= 1.10.0)
37
+ glib2 (>= 1.1.4)
38
+ php4r (0.0.3)
39
+ datet
40
+ http2
41
+ pkg-config (1.1.4)
42
+ rake (0.9.2.2)
43
+ rdoc (3.12)
44
+ json (~> 1.4)
45
+ rspec (2.8.0)
46
+ rspec-core (~> 2.8.0)
47
+ rspec-expectations (~> 2.8.0)
48
+ rspec-mocks (~> 2.8.0)
49
+ rspec-core (2.8.0)
50
+ rspec-expectations (2.8.0)
51
+ diff-lcs (~> 1.1.2)
52
+ rspec-mocks (2.8.0)
53
+ sqlite3 (1.3.6)
54
+ tsafe (0.0.11)
55
+ vte (1.1.4)
56
+ gtk2 (>= 1.1.4)
57
+ wref (0.0.5)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ bundler (>= 1.0.0)
64
+ gettext
65
+ gtk2
66
+ jeweler (~> 1.8.4)
67
+ knjrbfw
68
+ rdoc (~> 3.12)
69
+ rspec (~> 2.8.0)
70
+ sqlite3
71
+ vte
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Kasper Johansen
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ = superterm
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to superterm
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 Kasper Johansen. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,49 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "superterm"
18
+ gem.homepage = "http://github.com/kaspernj/superterm"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Got tired of various terminals that didnt work as I wanted them to.}
21
+ gem.description = %Q{A terminal that focuses on remote control for various events.}
22
+ gem.email = "k@spernj.org"
23
+ gem.authors = ["Kasper Johansen"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rspec/core'
29
+ require 'rspec/core/rake_task'
30
+ RSpec::Core::RakeTask.new(:spec) do |spec|
31
+ spec.pattern = FileList['spec/**/*_spec.rb']
32
+ end
33
+
34
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
35
+ spec.pattern = 'spec/**/*_spec.rb'
36
+ spec.rcov = true
37
+ end
38
+
39
+ task :default => :spec
40
+
41
+ require 'rdoc/task'
42
+ Rake::RDocTask.new do |rdoc|
43
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
44
+
45
+ rdoc.rdoc_dir = 'rdoc'
46
+ rdoc.title = "superterm #{version}"
47
+ rdoc.rdoc_files.include('README*')
48
+ rdoc.rdoc_files.include('lib/**/*.rb')
49
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require "#{File.realpath(File.dirname(__FILE__))}/../lib/superterm.rb"
4
+
5
+ Superterm.start
@@ -0,0 +1,59 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <interface>
3
+ <requires lib="gtk+" version="2.24"/>
4
+ <!-- interface-naming-policy project-wide -->
5
+ <object class="GtkWindow" id="window">
6
+ <property name="can_focus">False</property>
7
+ <property name="border_width">5</property>
8
+ <property name="default_width">640</property>
9
+ <property name="default_height">480</property>
10
+ <signal name="delete-event" handler="on_window_delete_event" swapped="no"/>
11
+ <child>
12
+ <object class="GtkVBox" id="vbox1">
13
+ <property name="visible">True</property>
14
+ <property name="can_focus">False</property>
15
+ <property name="spacing">4</property>
16
+ <child>
17
+ <object class="GtkNotebook" id="nbTerminals">
18
+ <property name="visible">True</property>
19
+ <property name="can_focus">True</property>
20
+ </object>
21
+ <packing>
22
+ <property name="expand">True</property>
23
+ <property name="fill">True</property>
24
+ <property name="position">0</property>
25
+ </packing>
26
+ </child>
27
+ <child>
28
+ <object class="GtkHButtonBox" id="hbuttonbox1">
29
+ <property name="visible">True</property>
30
+ <property name="can_focus">False</property>
31
+ <property name="spacing">5</property>
32
+ <property name="layout_style">start</property>
33
+ <child>
34
+ <object class="GtkButton" id="btnAdd">
35
+ <property name="label">gtk-add</property>
36
+ <property name="visible">True</property>
37
+ <property name="can_focus">True</property>
38
+ <property name="receives_default">True</property>
39
+ <property name="use_action_appearance">False</property>
40
+ <property name="use_stock">True</property>
41
+ <signal name="clicked" handler="on_btnAdd_clicked" swapped="no"/>
42
+ </object>
43
+ <packing>
44
+ <property name="expand">False</property>
45
+ <property name="fill">False</property>
46
+ <property name="position">0</property>
47
+ </packing>
48
+ </child>
49
+ </object>
50
+ <packing>
51
+ <property name="expand">False</property>
52
+ <property name="fill">True</property>
53
+ <property name="position">1</property>
54
+ </packing>
55
+ </child>
56
+ </object>
57
+ </child>
58
+ </object>
59
+ </interface>
@@ -0,0 +1,91 @@
1
+ class Superterm::Gui::Win_main
2
+ attr_reader :terms, :gui
3
+
4
+ def initialize(args = {})
5
+ @args = args
6
+ @terms = {}
7
+ @term_next_id = 0
8
+ self.show
9
+ end
10
+
11
+ def show
12
+ if !@gui or @gui.destroyed? or @gui["window"].destroyed?
13
+ @gui = Gtk::Builder.new.add("#{File.dirname(__FILE__)}/../glade/win_main.glade")
14
+ @gui.connect_signals{|h| method(h)}
15
+
16
+ self.add_terminal
17
+ @gui["window"].show_all
18
+ else
19
+ @gui["window"].show_all
20
+ end
21
+ end
22
+
23
+ def on_window_delete_event
24
+ @gui["window"].hide
25
+ return true
26
+ end
27
+
28
+ #Handels the event when the 'Add'-button is clicked.
29
+ def on_btnAdd_clicked
30
+ puts "Add clicked."
31
+ self.add_terminal
32
+ end
33
+
34
+ #Adds a new terminal to the notebook.
35
+ def add_terminal
36
+ puts "Add new terminal."
37
+
38
+ @term_next_id += 1
39
+ id = @term_next_id
40
+
41
+ term = Superterm::Gui::Win_main::Terminal.new(:id => id, :win_main => self)
42
+ @terms[id] = term
43
+
44
+ @gui["nbTerminals"].append_page(term.term, term.label)
45
+ @gui["nbTerminals"].show_all
46
+
47
+ term.change_to_page
48
+
49
+ term.term.grab_focus
50
+ end
51
+
52
+ class Terminal
53
+ attr_reader :label, :term
54
+
55
+ def initialize(args)
56
+ @args = args
57
+ @label = Gtk::Label.new(sprintf(_("Terminal %s"), @args[:id]))
58
+
59
+ @term = Vte::Terminal.new
60
+ @term.signal_connect("child-exited", &self.method(:on_child_exit))
61
+ @term.signal_connect("window-title-changed", &self.method(:on_windowTitle_changed))
62
+
63
+ @bash_pid = @term.fork_command("bash")
64
+ end
65
+
66
+ def on_child_exit(*args)
67
+ self.remove_term
68
+
69
+ if @args[:win_main].terms.empty?
70
+ @args[:win_main].gui["window"].destroy
71
+ end
72
+ end
73
+
74
+ def on_windowTitle_changed(*args)
75
+ @label.label = @term.window_title
76
+ end
77
+
78
+ def page_num
79
+ page_num = @args[:win_main].gui["nbTerminals"].page_num(@term)
80
+ end
81
+
82
+ def remove_term
83
+ @args[:win_main].gui["nbTerminals"].remove_page(self.page_num)
84
+ @args[:win_main].terms.delete(@args[:id])
85
+ end
86
+
87
+ def change_to_page
88
+ @args[:win_main].gui["nbTerminals"].page = self.page_num
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,77 @@
1
+ require "rubygems"
2
+ require "gtk2"
3
+ require "vte"
4
+ require "gettext"
5
+ require "sqlite3"
6
+ require "knjrbfw"
7
+
8
+ require "fileutils"
9
+
10
+ path = "#{Knj::Os.homedir}/.superterm"
11
+ Dir.mkdir(path) if !File.exists?(path)
12
+
13
+ class Superterm
14
+ CONFIG = {
15
+ :path => "#{Knj::Os.homedir}",
16
+ :sock_path => "#{Knj::Os.homedir}/.superterm/sock",
17
+ :run_path => "#{Knj::Os.homedir}/.superterm/run"
18
+ }
19
+
20
+ def self.const_missing(name)
21
+ require "#{File.dirname(__FILE__)}/superterm_#{name.to_s.downcase}.rb"
22
+ raise "Still not defined: '#{name}'." if !Superterm.const_defined?(name)
23
+ return Superterm.const_get(name)
24
+ end
25
+
26
+ def self.start
27
+ do_start = false
28
+ FileUtils.touch(CONFIG[:run_path]) if !File.exists?(CONFIG[:run_path])
29
+
30
+ File.open(CONFIG[:run_path]) do |fp|
31
+ fp.flock(File::LOCK_EX)
32
+ pid = File.read(CONFIG[:run_path]).to_i
33
+
34
+ if pid <= 0 or !Knj::Unix_proc.pid_running?(pid)
35
+ do_start = true
36
+ File.open(CONFIG[:run_path], "w") do |fp_w|
37
+ fp_w.write Process.pid
38
+ end
39
+
40
+ Kernel.at_exit do
41
+ File.unlink(CONFIG[:run_path])
42
+ end
43
+ end
44
+ end
45
+
46
+ if do_start
47
+ win_main = Superterm::Gui::Win_main.new
48
+ Superterm::Unix_socket.new(:win_main => win_main)
49
+
50
+ Gtk.main
51
+ else
52
+ cmd = nil
53
+ ARGV.each do |val|
54
+ if match = val.match(/^--cmd=(.+)$/)
55
+ cmd = match[1]
56
+ break
57
+ else
58
+ $stderr.puts "Unknown argument: '#{val}'."
59
+ exit
60
+ end
61
+ end
62
+
63
+ if cmd
64
+ puts "Executing command through sock: #{cmd}"
65
+
66
+ require "socket"
67
+ UNIXSocket.open(CONFIG[:sock_path]) do |sock|
68
+ sock.puts(cmd)
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
74
+
75
+ def _(str)
76
+ return str.to_s
77
+ end
@@ -0,0 +1,7 @@
1
+ class Superterm::Gui
2
+ def self.const_missing(name)
3
+ require "#{File.dirname(__FILE__)}/../gui/#{name.to_s.downcase}.rb"
4
+ raise "Still not defined: '#{name}'." if !Superterm::Gui.const_defined?(name)
5
+ return Superterm::Gui.const_get(name)
6
+ end
7
+ end
@@ -0,0 +1,37 @@
1
+ class Superterm::Unix_socket
2
+ def initialize(args)
3
+ @args = args
4
+
5
+ #Remove the sock-file if it already exists.
6
+ File.unlink(Superterm::CONFIG[:sock_path]) if File.exists?(Superterm::CONFIG[:sock_path])
7
+
8
+ #Start Unix-socket.
9
+ require "socket"
10
+ @usock = UNIXServer.new(Superterm::CONFIG[:sock_path])
11
+
12
+ #Remove the sock-file after this process is done.
13
+ Kernel.at_exit do
14
+ File.unlink(Superterm::CONFIG[:sock_path]) if File.exists?(Superterm::CONFIG[:sock_path])
15
+ end
16
+
17
+ #Start thread that listens for connections through the Unix-socket.
18
+ Thread.new do
19
+ begin
20
+ while client = @usock.accept
21
+ client.each_line do |line|
22
+ line = line.strip
23
+
24
+ if line.strip == "open_win_main"
25
+ @args[:win_main].show
26
+ else
27
+ print "Unknown line: #{line}\n"
28
+ end
29
+ end
30
+ end
31
+ rescue => e
32
+ $stderr.puts e.inspect
33
+ $stderr.puts e.backtrace
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'superterm'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "Superterm" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: superterm
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - Kasper Johansen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-08-21 00:00:00 +02:00
14
+ default_executable: superterm.rb
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: gtk2
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: *id001
27
+ - !ruby/object:Gem::Dependency
28
+ name: vte
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: "0"
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: *id002
38
+ - !ruby/object:Gem::Dependency
39
+ name: gettext
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ type: :runtime
47
+ prerelease: false
48
+ version_requirements: *id003
49
+ - !ruby/object:Gem::Dependency
50
+ name: sqlite3
51
+ requirement: &id004 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: *id004
60
+ - !ruby/object:Gem::Dependency
61
+ name: knjrbfw
62
+ requirement: &id005 !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ type: :runtime
69
+ prerelease: false
70
+ version_requirements: *id005
71
+ - !ruby/object:Gem::Dependency
72
+ name: rspec
73
+ requirement: &id006 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ~>
77
+ - !ruby/object:Gem::Version
78
+ version: 2.8.0
79
+ type: :development
80
+ prerelease: false
81
+ version_requirements: *id006
82
+ - !ruby/object:Gem::Dependency
83
+ name: rdoc
84
+ requirement: &id007 !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: "3.12"
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: *id007
93
+ - !ruby/object:Gem::Dependency
94
+ name: bundler
95
+ requirement: &id008 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 1.0.0
101
+ type: :development
102
+ prerelease: false
103
+ version_requirements: *id008
104
+ - !ruby/object:Gem::Dependency
105
+ name: jeweler
106
+ requirement: &id009 !ruby/object:Gem::Requirement
107
+ none: false
108
+ requirements:
109
+ - - ~>
110
+ - !ruby/object:Gem::Version
111
+ version: 1.8.4
112
+ type: :development
113
+ prerelease: false
114
+ version_requirements: *id009
115
+ description: A terminal that focuses on remote control for various events.
116
+ email: k@spernj.org
117
+ executables:
118
+ - superterm.rb
119
+ extensions: []
120
+
121
+ extra_rdoc_files:
122
+ - LICENSE.txt
123
+ - README.rdoc
124
+ files:
125
+ - .document
126
+ - .rspec
127
+ - Gemfile
128
+ - Gemfile.lock
129
+ - LICENSE.txt
130
+ - README.rdoc
131
+ - Rakefile
132
+ - VERSION
133
+ - bin/superterm.rb
134
+ - glade/win_main.glade
135
+ - gui/win_main.rb
136
+ - lib/superterm.rb
137
+ - lib/superterm_gui.rb
138
+ - lib/superterm_unix_socket.rb
139
+ - spec/spec_helper.rb
140
+ - spec/superterm_spec.rb
141
+ has_rdoc: true
142
+ homepage: http://github.com/kaspernj/superterm
143
+ licenses:
144
+ - MIT
145
+ post_install_message:
146
+ rdoc_options: []
147
+
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ none: false
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ hash: -1201154430522433688
156
+ segments:
157
+ - 0
158
+ version: "0"
159
+ required_rubygems_version: !ruby/object:Gem::Requirement
160
+ none: false
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: "0"
165
+ requirements: []
166
+
167
+ rubyforge_project:
168
+ rubygems_version: 1.6.2
169
+ signing_key:
170
+ specification_version: 3
171
+ summary: Got tired of various terminals that didnt work as I wanted them to.
172
+ test_files: []
173
+