dev-pty-screen 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.markdown +30 -16
- data/bin/dev-pty-client +14 -4
- data/bin/dev-pty-server +2 -2
- data/dev-pty-screen.gemspec +0 -1
- data/doc/welcome.txt +3 -1
- data/lib/server/{vim_interface.rb → application_interface.rb} +1 -1
- data/lib/server/options.rb +16 -2
- data/lib/server/pty_server.rb +17 -16
- data/lib/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07d88e540bdcbc42e947294026fb92a8de5f7c4a
|
4
|
+
data.tar.gz: ce402f29c2ce458cde567512c843401a36522e7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88f51147a68273b19fe389aeb1dfe5e112b34f6b9394b5ff84eaf70cd0dd19b8337694e7cc05ca5c04495e3ec2b9781f4c7d803c6390234cf857d1e934365075
|
7
|
+
data.tar.gz: b821d4d0d5ad9f2b76d3bf62dc66aba3efd341f8f9936cdfae4c388969cd860c24a60217a5d975f49d9f29bb93292790db58c11bb5e0dcccd8445d30177937b9
|
data/README.markdown
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# /dev/pty/screen
|
2
|
-
>
|
2
|
+
> Terminal pair programming without raster graphics.
|
3
3
|
|
4
4
|
> Desktop sharing is for windows devs!
|
5
5
|
|
@@ -11,10 +11,10 @@
|
|
11
11
|
> Yo dawg, anyone want to pair with me on my pair programming program?
|
12
12
|
|
13
13
|
## What's It Do:
|
14
|
-
- Only the server runs
|
14
|
+
- Only the server runs the application (or even needs it installed for that matter).
|
15
|
+
- VIM will be used for example purposes in the rest of this document, but any program can be used
|
15
16
|
- Everyone who wishes to be part of the paring session connects to the server.
|
16
17
|
- This is a very similar technique to what GNU Screen or TMux do.
|
17
|
-
- [Here's an animated demo](http://dapplebeforedawn.github.io/dev-pty-vim/)
|
18
18
|
|
19
19
|
## How's It Work:
|
20
20
|
- The server's VIM is loaded into a pseudoterminal that is controlled by the server
|
@@ -22,6 +22,7 @@
|
|
22
22
|
- The server then passes those on to the captive VIM
|
23
23
|
- STDOUT from the pseudoterminal is forwarded to the server and the broadcast to cleints
|
24
24
|
- Clients have their display updated to match the forwareded STDOUT
|
25
|
+
- `ctrl-z` allows clients to disconnect.
|
25
26
|
|
26
27
|
## TL;DR - An Animated Gif
|
27
28
|
![dev-pyt-screen](https://raw.github.com/dapplebeforedawn/dev-pty-screen/master/dev-pty-screen.gif)
|
@@ -51,19 +52,32 @@ or:
|
|
51
52
|
- On the computer hosting the code to work on.
|
52
53
|
```bash
|
53
54
|
cd /a/directory/with/some/code
|
54
|
-
dev-pty-server
|
55
|
+
dev-pty-server "vim"
|
55
56
|
```
|
56
57
|
|
57
58
|
- On each client
|
58
59
|
```bash
|
59
|
-
dev-pty-
|
60
|
-
|
61
|
-
#program will appear to hang
|
62
|
-
:tabnew <cr>
|
60
|
+
dev-pty-client
|
63
61
|
```
|
64
62
|
|
65
63
|
- Quitting: ^Z (ctrl+z) prompts your client to quit. All other keys are forwarded to the server.
|
66
64
|
|
65
|
+
## Another Example:
|
66
|
+
- Any terminal program can be used (say, the Guard your probably running with your vim)
|
67
|
+
```bash
|
68
|
+
dev-pty-server "tail -f log/development.log"
|
69
|
+
```
|
70
|
+
|
71
|
+
- On the client, for a quick log sharing session:
|
72
|
+
```bash
|
73
|
+
dev-pty-client
|
74
|
+
```
|
75
|
+
|
76
|
+
- With non-interactive programs, like tail, the clients screen will refresh when the server has new data.
|
77
|
+
|
78
|
+
## Defaults:
|
79
|
+
Since the terminal output from the server is shared with the clients directly, the number of rows/columns on the screen is set by the server. When starting dev-pty-server, rows/columns are defaulted to the size of the terminal window housing the server. This can be changed by using the `--rows` and `--columns` options.
|
80
|
+
|
67
81
|
## Considerations:
|
68
82
|
This approach has a few draw-backs compared to the run-your-own-VIM tact that /dev/pty/vim uses (and a few advantages)
|
69
83
|
|
@@ -87,19 +101,19 @@ or:
|
|
87
101
|
## Application Structure
|
88
102
|
```
|
89
103
|
├── bin
|
90
|
-
│ ├── dev-pty-client
|
91
|
-
│ └── dev-pty-server
|
104
|
+
│ ├── dev-pty-client # Run this to start a client
|
105
|
+
│ └── dev-pty-server # Run this to start a server
|
92
106
|
├── lib
|
93
107
|
│ ├── client
|
94
108
|
│ │ ├── app.rb
|
95
|
-
│ │ └── options.rb
|
109
|
+
│ │ └── options.rb # Options parser for the client
|
96
110
|
│ └── server
|
97
111
|
│ ├── app.rb
|
98
|
-
│ ├── key_server.rb
|
99
|
-
│ ├── options.rb
|
100
|
-
│ ├── pty_server.rb
|
101
|
-
│ ├── screen_server.rb
|
102
|
-
│ └──
|
112
|
+
│ ├── key_server.rb # Listens for keys strokes from clients
|
113
|
+
│ ├── options.rb # Options parser for the server
|
114
|
+
│ ├── pty_server.rb # Manages the screen/key servers and the application_interface
|
115
|
+
│ ├── screen_server.rb # Pushes STDOUT updates to clients
|
116
|
+
│ └── application_interface.rb # Sends keystrokes to the captive VIM
|
103
117
|
|
|
104
118
|
├── spec
|
105
119
|
├── client
|
data/bin/dev-pty-client
CHANGED
@@ -12,7 +12,6 @@ class DevPtyClient
|
|
12
12
|
CLEAR = "\e[H\e[2J"
|
13
13
|
SUSPEND = ?\C-z
|
14
14
|
|
15
|
-
|
16
15
|
def initialize
|
17
16
|
startup_message
|
18
17
|
|
@@ -25,11 +24,23 @@ class DevPtyClient
|
|
25
24
|
|
26
25
|
def screen_loop
|
27
26
|
-> do
|
28
|
-
loop { STDOUT.write
|
27
|
+
loop { STDOUT.write read_screen }
|
29
28
|
end
|
30
29
|
end
|
31
30
|
private :screen_loop
|
32
31
|
|
32
|
+
def read_screen
|
33
|
+
return @screen_sock.readpartial( READSIZE )
|
34
|
+
rescue EOFError; disconnected
|
35
|
+
end
|
36
|
+
private :read_screen
|
37
|
+
|
38
|
+
def disconnected
|
39
|
+
clear_screen
|
40
|
+
abort("The dev-pty-server has closed the session.")
|
41
|
+
end
|
42
|
+
private :disconnected
|
43
|
+
|
33
44
|
def key_loop
|
34
45
|
-> do
|
35
46
|
loop {
|
@@ -60,7 +71,7 @@ class DevPtyClient
|
|
60
71
|
private :will_exit
|
61
72
|
|
62
73
|
def wont_exit
|
63
|
-
print "Run any
|
74
|
+
print "Run any command to re-draw the screen."
|
64
75
|
return true
|
65
76
|
end
|
66
77
|
private :wont_exit
|
@@ -83,5 +94,4 @@ class DevPtyClient
|
|
83
94
|
private :startup_message
|
84
95
|
end
|
85
96
|
|
86
|
-
at_exit { `reset` }
|
87
97
|
DevPtyClient.new and sleep
|
data/bin/dev-pty-server
CHANGED
data/dev-pty-screen.gemspec
CHANGED
data/doc/welcome.txt
CHANGED
data/lib/server/options.rb
CHANGED
@@ -2,16 +2,30 @@ require 'optparse'
|
|
2
2
|
module Options
|
3
3
|
def self.parse!
|
4
4
|
# default_key_file = File.join(__dir__, '../', 'tmp/keys')
|
5
|
-
|
6
|
-
|
5
|
+
default_rows = `tput lines`.to_i
|
6
|
+
default_cols = `tput cols`.to_i
|
7
|
+
options = OpenStruct.new key_port: 2000, screen_port: 2001,
|
8
|
+
rows: default_rows, columns: default_cols
|
7
9
|
|
8
10
|
OptionParser.new do |opts|
|
11
|
+
opts.banner =<<HEREDOC
|
12
|
+
dev/pty/server: Quickly share any terminal application with remote users
|
13
|
+
Usage: dev-pty-server <application name and arguments> [opts]
|
14
|
+
Example: dev-pty-server "vim"
|
15
|
+
|
16
|
+
Defaults:
|
17
|
+
#{options.to_h.map{|k,v| "#{k} = #{v}"}.join("\n ")}
|
18
|
+
|
19
|
+
Options:
|
20
|
+
HEREDOC
|
21
|
+
|
9
22
|
opts.on("-k", "--key_port=val", Integer) { |arg| options.key_port = arg }
|
10
23
|
opts.on("-s", "--screen_port=val", Integer) { |arg| options.screen_port = arg }
|
11
24
|
opts.on("-r", "--rows=val", Integer) { |arg| options.rows = arg }
|
12
25
|
opts.on("-c", "--columns=val", Integer) { |arg| options.columns = arg }
|
13
26
|
opts.on("-h", "--help") { puts opts; exit }
|
14
27
|
end.parse!
|
28
|
+
options.application = ARGV[0] or abort( "An application name is required." )
|
15
29
|
options
|
16
30
|
end
|
17
31
|
end
|
data/lib/server/pty_server.rb
CHANGED
@@ -3,7 +3,7 @@ require 'io/console'
|
|
3
3
|
|
4
4
|
require_relative 'screen_server'
|
5
5
|
require_relative 'key_server'
|
6
|
-
require_relative '
|
6
|
+
require_relative 'application_interface'
|
7
7
|
require_relative 'app'
|
8
8
|
|
9
9
|
Thread.abort_on_exception = true
|
@@ -13,25 +13,26 @@ class PtyServer
|
|
13
13
|
ENTER_KEY = ?\C-m
|
14
14
|
|
15
15
|
def initialize
|
16
|
-
@pty_m, @pty_s
|
17
|
-
@
|
18
|
-
@screen_server
|
19
|
-
@key_server
|
20
|
-
@pty_s.winsize
|
16
|
+
@pty_m, @pty_s = PTY.open
|
17
|
+
@application_interface = ApplicationInterface.new @pty_m
|
18
|
+
@screen_server = ScreenServer.new App.options.screen_port
|
19
|
+
@key_server = KeyServer.new App.options.key_port, key_callback
|
20
|
+
@pty_s.winsize = [ App.options.rows, App.options.columns ]
|
21
|
+
@application = App.options.application
|
21
22
|
end
|
22
23
|
|
23
24
|
def start
|
24
|
-
spawn_vim
|
25
25
|
initialize_pty
|
26
26
|
@screen_server.listen
|
27
27
|
@key_server.listen
|
28
28
|
screen_loop
|
29
|
+
spawn_application
|
29
30
|
end
|
30
31
|
|
31
32
|
def key_callback
|
32
33
|
->(key){
|
33
34
|
print key
|
34
|
-
@
|
35
|
+
@application_interface << key
|
35
36
|
}
|
36
37
|
end
|
37
38
|
|
@@ -43,11 +44,10 @@ class PtyServer
|
|
43
44
|
end
|
44
45
|
end
|
45
46
|
|
46
|
-
def
|
47
|
-
spawn(
|
48
|
-
sleep 0.2 # give it a moment to boot
|
47
|
+
def spawn_application
|
48
|
+
spawn(@application, in: @pty_s, out: @pty_s)
|
49
49
|
end
|
50
|
-
private :
|
50
|
+
private :spawn_application
|
51
51
|
|
52
52
|
# WTH? -- Let me 'splain:
|
53
53
|
# There a difference between the mode that PTY
|
@@ -56,7 +56,7 @@ class PtyServer
|
|
56
56
|
#
|
57
57
|
# This means the cursor moves around the screen on the server
|
58
58
|
# when you press the arrow keys, but when they are transmitted
|
59
|
-
# through the PTY to
|
59
|
+
# through the PTY to application, the escape encoding is different,
|
60
60
|
# this results in vim just honking at you and not moving the cursor.
|
61
61
|
#
|
62
62
|
# By running `tput rmkx` from vim we are setting the PTY to
|
@@ -78,9 +78,10 @@ class PtyServer
|
|
78
78
|
# That is just too cool.
|
79
79
|
#
|
80
80
|
def initialize_pty
|
81
|
-
|
82
|
-
|
83
|
-
|
81
|
+
# # `printf "\033?1h\033=" > #{@pty_s.path}`
|
82
|
+
# @application_interface << ENTER_KEY
|
83
|
+
# @application_interface << ":!tput rmkx"
|
84
|
+
# @application_interface << ENTER_KEY
|
84
85
|
end
|
85
86
|
private :initialize_pty
|
86
87
|
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev-pty-screen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Lorenz
|
@@ -78,11 +78,11 @@ files:
|
|
78
78
|
- lib/client/app.rb
|
79
79
|
- lib/client/options.rb
|
80
80
|
- lib/server/app.rb
|
81
|
+
- lib/server/application_interface.rb
|
81
82
|
- lib/server/key_server.rb
|
82
83
|
- lib/server/options.rb
|
83
84
|
- lib/server/pty_server.rb
|
84
85
|
- lib/server/screen_server.rb
|
85
|
-
- lib/server/vim_interface.rb
|
86
86
|
- lib/version.rb
|
87
87
|
- outline.markdown
|
88
88
|
- spec/server/key_server_spec.rb
|