dev-pty-screen 0.0.1 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8413b6443bdf23c7d815c537cd2cc7f406bff86a
4
- data.tar.gz: 59ae1732cd1bc370eb32ac029fc0f82c8702a24b
3
+ metadata.gz: 07d88e540bdcbc42e947294026fb92a8de5f7c4a
4
+ data.tar.gz: ce402f29c2ce458cde567512c843401a36522e7f
5
5
  SHA512:
6
- metadata.gz: bbabc50f961876b31fd38b15d00f2031495e38abc6728c05f66cae10c0a0d8874b0bc59aceac25e2d44eb12125bd35c2b581f5e90a59c9cbf03fdcc0f1863e5d
7
- data.tar.gz: 41d24a6784db21dbb14f6854a823cc7f6e49ec7fd3fb257fb492145a0ebc65ded1eeeda68943e9132a6b84f85d42e4cf64491a088dac4b53ac284cb9be276e4a
6
+ metadata.gz: 88f51147a68273b19fe389aeb1dfe5e112b34f6b9394b5ff84eaf70cd0dd19b8337694e7cc05ca5c04495e3ec2b9781f4c7d803c6390234cf857d1e934365075
7
+ data.tar.gz: b821d4d0d5ad9f2b76d3bf62dc66aba3efd341f8f9936cdfae4c388969cd860c24a60217a5d975f49d9f29bb93292790db58c11bb5e0dcccd8445d30177937b9
@@ -1,5 +1,5 @@
1
1
  # /dev/pty/screen
2
- > VIM pair programming without raster graphics.
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 VIM (or even needs it installed for that matter).
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-server
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 # Run this to start a client
91
- │   └── dev-pty-server # Run this to start a 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 # Options parser for the client
109
+ │   │   └── options.rb # Options parser for the client
96
110
  │   └── server
97
111
  │   ├── app.rb
98
- │   ├── key_server.rb # Listens for keys strokes from clients
99
- │   ├── options.rb # Options parser for the server
100
- │   ├── pty_server.rb # Manages the screen/key servers and the vim_interface
101
- │   ├── screen_server.rb # Pushes STDOUT updates to clients
102
- │   └── vim_interface.rb # Sends keystrokes to the captive VIM
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
@@ -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 @screen_sock.readpartial( READSIZE ) }
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 vim command to re-draw the screen."
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
@@ -3,5 +3,5 @@
3
3
  require_relative '../lib/server/pty_server'
4
4
  Thread.abort_on_exception = true
5
5
 
6
- PtyServer.new.start
7
- sleep
6
+ pid = PtyServer.new.start
7
+ Process.wait(pid)
@@ -5,7 +5,6 @@ require 'version'
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'dev-pty-screen'
8
- s.version = '0.0.1'
9
8
  s.version = DevPtyScreen::VERSION
10
9
  s.date = '2013-10-13'
11
10
  s.summary = 'VIM screen sharing as the neckbeards intended'
@@ -4,9 +4,11 @@
4
4
  Welcome to dev/pty/screen!
5
5
  --------------------------
6
6
 
7
- Type any vim command to
7
+ Type any application command to
8
8
  refresh the screen.
9
9
 
10
+ [ctrl+z quits]
11
+
10
12
 
11
13
  Support:
12
14
  https://github.com/dapplebeforedawn/dev-pty-screen
@@ -1,6 +1,6 @@
1
1
  require 'thread'
2
2
 
3
- class VimInterface
3
+ class ApplicationInterface
4
4
  def initialize pty_m
5
5
  @pty_m = pty_m
6
6
  @queue = Queue.new
@@ -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
- options = OpenStruct.new key_port: 2000, screen_port: 2001,
6
- rows: 35, columns: 100
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
@@ -3,7 +3,7 @@ require 'io/console'
3
3
 
4
4
  require_relative 'screen_server'
5
5
  require_relative 'key_server'
6
- require_relative 'vim_interface'
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 = PTY.open
17
- @vim_interface = VimInterface.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 ]
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
- @vim_interface << key
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 spawn_vim
47
- spawn("vim", in: @pty_s, out: @pty_s)
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 :spawn_vim
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 vim, the escape encoding is different,
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
- @vim_interface << ENTER_KEY
82
- @vim_interface << ":!tput rmkx"
83
- @vim_interface << ENTER_KEY
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
 
@@ -1,3 +1,3 @@
1
1
  module DevPtyScreen
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
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.1
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