textbringer-ghost_text 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/textbringer/ghost_text.rb +6 -0
- data/lib/textbringer/ghost_text/commands.rb +12 -0
- data/lib/textbringer/ghost_text/config.rb +6 -0
- data/lib/textbringer/ghost_text/version.rb +7 -0
- data/lib/textbringer/ghost_text/web_socket_server.rb +70 -0
- data/lib/textbringer_plugin.rb +3 -0
- data/textbringer-ghost_text.gemspec +30 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ee11306209a200392bb926c38709e91edb9151b3
|
4
|
+
data.tar.gz: bbb782882d6590efd34e9f5f58633ccde50eb89b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85940038dca84d2d28755c0db4431b02eaf6636665cb930ef12e4f7da4167929ae2d32c4b5ee368a176fa17b456bca85554e45984fbcc691de562d5d6702c822
|
7
|
+
data.tar.gz: ef886af90ffa9e762a1e319b40fb12b0136a8e256505a426ba72d8e96ce09daf7ff4ca6e55261730ade6348e46e8f4f7d1fb741983ceac6ded968a246d837697
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Shugo Maeda
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# textbringer-ghost_text
|
2
|
+
|
3
|
+
[GhostText](https://github.com/GhostText/GhostText) plugin for Textbringer.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install textbringer-ghost_text
|
8
|
+
|
9
|
+
## Configuration
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
# The host of the GhostText server.
|
13
|
+
CONFIG[:ghost_text_host] = "127.0.0.1"
|
14
|
+
# The port of the GhostText server.
|
15
|
+
CONFIG[:ghost_text_port] = 4001
|
16
|
+
```
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
Type `M-x ghost_text_start` to start the server.
|
21
|
+
|
22
|
+
## Development
|
23
|
+
|
24
|
+
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
25
|
+
|
26
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
27
|
+
|
28
|
+
## Contributing
|
29
|
+
|
30
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/shugo/textbringer-ghost_text.
|
31
|
+
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "textbringer/ghost_text"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
define_command(:ghost_text_start) do
|
4
|
+
background do
|
5
|
+
thin = Rack::Handler.get("thin")
|
6
|
+
thin.run(Textbringer::GhostText::WebSocketServer.new,
|
7
|
+
Host: CONFIG[:ghost_text_host],
|
8
|
+
Port: CONFIG[:ghost_text_port]) do |server|
|
9
|
+
server.silent = true
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "json"
|
4
|
+
require "rack"
|
5
|
+
require "thin"
|
6
|
+
require "faye/websocket"
|
7
|
+
|
8
|
+
Faye::WebSocket.load_adapter("thin")
|
9
|
+
|
10
|
+
module Textbringer
|
11
|
+
module GhostText
|
12
|
+
class WebSocketServer
|
13
|
+
def call(env)
|
14
|
+
if Faye::WebSocket.websocket?(env)
|
15
|
+
ws = Faye::WebSocket.new(env)
|
16
|
+
|
17
|
+
next_tick do
|
18
|
+
buffer = Buffer.new_buffer("*GhostText*")
|
19
|
+
switch_to_buffer(buffer)
|
20
|
+
|
21
|
+
remote_text = nil
|
22
|
+
|
23
|
+
buffer.on_modified do
|
24
|
+
text = buffer.to_s
|
25
|
+
if text != remote_text
|
26
|
+
pos = buffer.substring(0, buffer.point).size
|
27
|
+
data = {
|
28
|
+
"text" => text,
|
29
|
+
"selections" => [{ "start" => pos, "end" => pos }]
|
30
|
+
}
|
31
|
+
ws.send(data.to_json)
|
32
|
+
remote_text = text
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
ws.on :message do |event|
|
37
|
+
data = JSON.parse(event.data)
|
38
|
+
next_tick do
|
39
|
+
buffer.composite_edit do
|
40
|
+
remote_text = data["text"]
|
41
|
+
buffer.delete_region(buffer.point_min, buffer.point_max)
|
42
|
+
buffer.insert(remote_text)
|
43
|
+
pos = data["selections"]&.dig(0, "start")
|
44
|
+
if pos
|
45
|
+
byte_pos = remote_text[0, pos].bytesize
|
46
|
+
buffer.goto_char(byte_pos)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
ws.on :close do |event|
|
53
|
+
next_tick do
|
54
|
+
kill_buffer(buffer, force: true)
|
55
|
+
end
|
56
|
+
ws = nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
ws.rack_response
|
60
|
+
else
|
61
|
+
json = {
|
62
|
+
"WebSocketPort" => 4001,
|
63
|
+
"ProtocolVersion" => 1
|
64
|
+
}.to_json
|
65
|
+
[200, {'Content-Type' => 'application/json'}, [json]]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'textbringer/ghost_text/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "textbringer-ghost_text"
|
8
|
+
spec.version = Textbringer::GhostText::VERSION
|
9
|
+
spec.authors = ["Shugo Maeda"]
|
10
|
+
spec.email = ["shugo@ruby-lang.org"]
|
11
|
+
|
12
|
+
spec.summary = "GhostText plugin for Textbringer."
|
13
|
+
spec.description = "GhostText plugin for Textbringer."
|
14
|
+
spec.homepage = "https://github.com/shugo/textbringer-ghost_text"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_runtime_dependency "textbringer", ">= 0.2.3"
|
25
|
+
spec.add_runtime_dependency "thin"
|
26
|
+
spec.add_runtime_dependency "faye-websocket"
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.14"
|
29
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: textbringer-ghost_text
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Shugo Maeda
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: textbringer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thin
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faye-websocket
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.14'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.14'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '12.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '12.0'
|
83
|
+
description: GhostText plugin for Textbringer.
|
84
|
+
email:
|
85
|
+
- shugo@ruby-lang.org
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- Gemfile
|
92
|
+
- LICENSE.txt
|
93
|
+
- README.md
|
94
|
+
- Rakefile
|
95
|
+
- bin/console
|
96
|
+
- bin/setup
|
97
|
+
- lib/textbringer/ghost_text.rb
|
98
|
+
- lib/textbringer/ghost_text/commands.rb
|
99
|
+
- lib/textbringer/ghost_text/config.rb
|
100
|
+
- lib/textbringer/ghost_text/version.rb
|
101
|
+
- lib/textbringer/ghost_text/web_socket_server.rb
|
102
|
+
- lib/textbringer_plugin.rb
|
103
|
+
- textbringer-ghost_text.gemspec
|
104
|
+
homepage: https://github.com/shugo/textbringer-ghost_text
|
105
|
+
licenses:
|
106
|
+
- MIT
|
107
|
+
metadata: {}
|
108
|
+
post_install_message:
|
109
|
+
rdoc_options: []
|
110
|
+
require_paths:
|
111
|
+
- lib
|
112
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
version: '0'
|
122
|
+
requirements: []
|
123
|
+
rubyforge_project:
|
124
|
+
rubygems_version: 2.6.12
|
125
|
+
signing_key:
|
126
|
+
specification_version: 4
|
127
|
+
summary: GhostText plugin for Textbringer.
|
128
|
+
test_files: []
|
129
|
+
has_rdoc:
|