terminalwire 0.1.10 → 0.1.12

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
  SHA256:
3
- metadata.gz: 9cd319cc4f277520d44209f8317dabcb9113f1cb925f1ee6090e842ec007770b
4
- data.tar.gz: 1a7f2c111dfd9ac6576ae63d52b8342ebaff87e64c7a41202a8baf96cd786434
3
+ metadata.gz: 0ffa1e8b55e7c09d41b9a57fc645e950e65f6658767022cf67cac994823fb760
4
+ data.tar.gz: 32fb995746b753eeed71543b954aa2376c2af4b1e61721b14eac8704c9f555f6
5
5
  SHA512:
6
- metadata.gz: baf4b6ba33de5b317ce0fb52322b5b77c3bdc9cb7804245abf0b4969458024c24d58b08a45df88890d1bd902efdc61fbb7b78aef9a14be8ccde633eb10a7b2c8
7
- data.tar.gz: 3b553a00a66b9b6f26fbca86efa973058e6fca4ae3a13a5182772e3f2cfe83db8467ef49d0400e448fb55d70604f3207804aafcb550231fb0bd0decb06d494bd
6
+ metadata.gz: cb3ca0210a84eb64c924522d4eeb04f75a59bf8d785581a232216c8c417ecc837a66001947449e4da91127ebe942c12bce6ea07f8de1be2fe1fc69e5dcfdc332
7
+ data.tar.gz: e9e0ea45f77040fc503acf2c09f22671d2a09f26315cad69ce1de8e62d4d0578b96663db13414446b7e99ce4abd3dd792ccb6b9191462ae6f67ff8789750856a
data/LICENSE.txt CHANGED
@@ -1 +1,9 @@
1
- Copyright (c) 2024 Brad Gessler. Email brad@terminalwire.com to discuss licensing.
1
+ Copyright (c) 2024 Brad Gessler.
2
+
3
+ License is propietary. Here's the deal:
4
+
5
+ * You need to pay for Terminalwire if your business has more than $1m in assets or makes more than $100k/year in revenue.
6
+ * Terminalwire is free for personal use, hobbyists, or businesses that are just starting out, but server licenses still need to be registered at https://terminalwire.com/developers/licenses.
7
+ * You can only use the Terminalwire client with licensed Terminalwire servers.
8
+
9
+ This list is not exhaustive, please read the full license text at https://terminalwire.com/license.
@@ -7,6 +7,7 @@ class Terminalwire::InstallGenerator < Rails::Generators::Base
7
7
 
8
8
  def create_terminal_files
9
9
  template "application_terminal.rb.tt", Rails.root.join("app/terminal/application_terminal.rb")
10
+ template "main_terminal.rb", Rails.root.join("app/terminal/main_terminal.rb")
10
11
  end
11
12
 
12
13
  def create_binary_files
@@ -17,7 +18,7 @@ class Terminalwire::InstallGenerator < Rails::Generators::Base
17
18
  def add_route
18
19
  route <<~ROUTE
19
20
  match "/terminal",
20
- to: Terminalwire::Server::Thor.new(ApplicationTerminal),
21
+ to: Terminalwire::Server::Thor.new(MainTerminal),
21
22
  via: [:get, :connect]
22
23
  ROUTE
23
24
  end
@@ -1,44 +1,11 @@
1
1
  # Learn how to use Thor at http://whatisthor.com.
2
2
  class ApplicationTerminal < Thor
3
+ # Enables IO Streaming.
3
4
  include Terminalwire::Thor
4
5
 
6
+ # The name of your binary. Thor uses this for its help output.
5
7
  def self.basename = "<%= binary_name %>"
6
8
 
7
- desc "hello NAME", "say hello to NAME"
8
- def hello(name)
9
- puts "Hello #{name}"
10
- end
11
-
12
- desc "login", "Login to your account"
13
- def login
14
- print "Email: "
15
- email = gets
16
-
17
- print "Password: "
18
- password = getpass
19
-
20
- if self.current_user = User.authenticate(email, password)
21
- puts "Successfully logged in as #{user.email}."
22
- else
23
- puts "Could not find a user with that email and password."
24
- end
25
- end
26
-
27
- desc "whoami", "Displays current user information."
28
- def whoami
29
- if self.current_user
30
- puts "Logged in as #{user.email}."
31
- else
32
- puts "Not logged in. Run `#{self.class.basename} login` to login."
33
- end
34
- end
35
-
36
- desc "logout", "Logout of your account"
37
- def logout
38
- session.reset
39
- puts "Successfully logged out."
40
- end
41
-
42
9
  private
43
10
 
44
11
  def current_user=(user)
@@ -49,6 +16,6 @@ class ApplicationTerminal < Thor
49
16
  end
50
17
 
51
18
  def current_user
52
- @current_user ||= User.find(session.fetch("user_id"))
19
+ @current_user ||= User.find(session["user_id"])
53
20
  end
54
21
  end
@@ -0,0 +1,40 @@
1
+ class MainTerminal < ApplicationTerminal
2
+ desc "hello NAME", "say hello to NAME"
3
+ def hello(name)
4
+ puts "Hello #{name}"
5
+ end
6
+
7
+ desc "login", "Login to your account"
8
+ def login
9
+ print "Email: "
10
+ email = gets.chomp
11
+
12
+ print "Password: "
13
+ password = getpass
14
+
15
+ # Replace this with your own authentication logic; this is an example
16
+ # of how you might do this with Devise.
17
+ user = User.find_for_authentication(email: email)
18
+ if user && user.valid_password?(password)
19
+ self.current_user = user
20
+ puts "Successfully logged in as #{current_user.email}."
21
+ else
22
+ puts "Could not find a user with that email and password."
23
+ end
24
+ end
25
+
26
+ desc "whoami", "Displays current user information."
27
+ def whoami
28
+ if self.current_user
29
+ puts "Logged in as #{current_user.email}."
30
+ else
31
+ puts "Not logged in. Run `#{self.class.basename} login` to login."
32
+ end
33
+ end
34
+
35
+ desc "logout", "Logout of your account"
36
+ def logout
37
+ session.reset
38
+ puts "Successfully logged out."
39
+ end
40
+ end
@@ -17,7 +17,7 @@ module Terminalwire::Adapter
17
17
  @transport.write(packed_data)
18
18
  end
19
19
 
20
- def recv
20
+ def read
21
21
  logger.debug "Adapter: Reading"
22
22
  packed_data = @transport.read
23
23
  return nil if packed_data.nil?
@@ -1,4 +1,5 @@
1
1
  require "fileutils"
2
+ require "io/console"
2
3
 
3
4
  module Terminalwire::Client::Resource
4
5
  # Dispatches messages from the Client::Handler to the appropriate resource.
@@ -37,7 +37,7 @@ module Terminalwire
37
37
  })
38
38
 
39
39
  loop do
40
- handle @adapter.recv
40
+ handle @adapter.read
41
41
  end
42
42
  end
43
43
 
@@ -12,7 +12,7 @@ module Terminalwire::Server
12
12
  parameters: parameters
13
13
  )
14
14
 
15
- response = @adapter.recv
15
+ response = @adapter.read
16
16
  case response.fetch(:status)
17
17
  when "success"
18
18
  response.fetch(:response)
@@ -53,13 +53,15 @@ module Terminalwire
53
53
  private
54
54
 
55
55
  def run(adapter)
56
- while message = adapter.recv
56
+ while message = adapter.read
57
57
  puts message
58
58
  end
59
59
  end
60
60
  end
61
61
 
62
62
  class Thor < WebSocket
63
+ Rails = ::Rails
64
+
63
65
  include Logging
64
66
 
65
67
  def initialize(cli_class)
@@ -70,13 +72,29 @@ module Terminalwire
70
72
  end
71
73
  end
72
74
 
75
+ def error_message
76
+ "An error occurred. Please try again."
77
+ end
78
+
73
79
  def run(adapter)
74
80
  logger.info "ThorServer: Running #{@cli_class.inspect}"
75
- while message = adapter.recv
81
+ while message = adapter.read
76
82
  case message
77
83
  in { event: "initialization", protocol:, program: { arguments: }, entitlement: }
78
- Terminalwire::Server::Context.new(adapter:, entitlement:) do |context|
84
+ context = Terminalwire::Server::Context.new(adapter:, entitlement:)
85
+
86
+ begin
79
87
  @cli_class.start(arguments, context:)
88
+ context.exit
89
+ rescue StandardError => e
90
+ if Rails.application.config.consider_all_requests_local
91
+ # Show the full error message with stack trace in development
92
+ context.stderr.puts "#{e.inspect}\n#{e.backtrace.join("\n")}"
93
+ else
94
+ # Show a generic message in production
95
+ context.stderr.puts error_message
96
+ end
97
+ context.exit 1
80
98
  end
81
99
  end
82
100
  end
@@ -93,7 +111,7 @@ module Terminalwire
93
111
  def run
94
112
  logger.info "Server Handler: Running"
95
113
  loop do
96
- message = @adapter.recv
114
+ message = @adapter.read
97
115
  case message
98
116
  in { event: "initialization", protocol:, program: { arguments: }, entitlement: }
99
117
  Context.new(adapter: @adapter) do |context|
@@ -35,7 +35,7 @@ module Terminalwire
35
35
  def_delegators :stdout,
36
36
  :puts, :print
37
37
  def_delegators :stdin,
38
- :gets
38
+ :gets, :getpass
39
39
 
40
40
  # Feels more naturual to call `client.files` etc. from
41
41
  # the serve since it's more apparent that it's a client.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Terminalwire
4
- VERSION = "0.1.10"
4
+ VERSION = "0.1.12"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminalwire
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brad Gessler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-09-28 00:00:00.000000000 Z
11
+ date: 2024-10-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-websocket
@@ -158,6 +158,7 @@ files:
158
158
  - lib/generators/terminalwire/install/install_generator.rb
159
159
  - lib/generators/terminalwire/install/templates/application_terminal.rb.tt
160
160
  - lib/generators/terminalwire/install/templates/bin/terminalwire
161
+ - lib/generators/terminalwire/install/templates/main_terminal.rb
161
162
  - lib/terminalwire.rb
162
163
  - lib/terminalwire/adapter.rb
163
164
  - lib/terminalwire/client.rb
@@ -175,7 +176,7 @@ files:
175
176
  - sig/terminalwire.rbs
176
177
  homepage: https://terminalwire.com/ruby
177
178
  licenses:
178
- - Proprietary
179
+ - Proprietary (https://terminalwire.com/license)
179
180
  metadata:
180
181
  allowed_push_host: https://rubygems.org/
181
182
  homepage_uri: https://terminalwire.com/ruby