meshchat 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01c4f397703dbfd3299712e33207dffb16edfdea
4
- data.tar.gz: 2679cafaa50569456444ab222dfd976db1dc724c
3
+ metadata.gz: d133b88895ed07267fb0e6b02806c2ebe998ce59
4
+ data.tar.gz: b01e8f93f830e3ecc211ff165947479319fd600b
5
5
  SHA512:
6
- metadata.gz: f660b1820794d8b40657ae757ae54730ed5c605128781d8f6aa49fd57dc6746a3ac6cd3668e6cddef905f76380a1791da6e072117bdc38d08232f9d697c5dc52
7
- data.tar.gz: 923524a79e5fd5f858d48d8a2fb8b6cb53d5b770150f88accc5d2a92132c34f3459952258fb1e8652a0dbea0984bef4b02e78dc9f25a255a12e1242bca80d044
6
+ metadata.gz: 81e2789b1f3ad8d44cfba19a8e736f330e78564743530909c94aa036d5b381749775036754f72af6a40bde5b2ff2856be051d61521230a05346ddfae7c0f0b86
7
+ data.tar.gz: d6678a4ff966e8e5de7a73057f109e8a41badb5baf12387a13b5190ea083221514cf0619915e3d4302a960b803c515b13853c31b19f4418dd675c8d3d0100008
data/README.md CHANGED
@@ -5,3 +5,15 @@ This is the core functionality for implementing a [mesh-chat](https://github.com
5
5
  #Usage
6
6
 
7
7
  See [Spiced Gracken](https://github.com/NullVoxPopuli/spiced_gracken)
8
+
9
+ For now, all that needs to be implemented is the Display.
10
+ Take a look at `Display::Base` to see what you need to override.
11
+
12
+ ```ruby
13
+ MeshChat.start(
14
+ client_name: NAME, # name of your client
15
+ client_version: VERSION, # version of your client
16
+ display: ui, # your class of your implementation of `Display::Base`
17
+ on_display_start: ->{ MeshChat::CLI.check_startup_settings } # optional
18
+ )
19
+ ```
@@ -58,7 +58,8 @@ module MeshChat
58
58
  defaults = {
59
59
  display: Display::Base,
60
60
  client_name: NAME,
61
- client_version: VERSION
61
+ client_version: VERSION,
62
+ input: CLI::Base
62
63
  }
63
64
  options = defaults.merge(overrides)
64
65
 
@@ -1,44 +1,48 @@
1
1
  require 'meshchat/cli/input'
2
- require 'meshchat/cli/command'
3
- require 'meshchat/cli/identity'
4
- require 'meshchat/cli/irb'
5
- require 'meshchat/cli/config'
6
- require 'meshchat/cli/ping'
7
- require 'meshchat/cli/ping_all'
8
- require 'meshchat/cli/server'
9
- require 'meshchat/cli/whisper'
10
- require 'meshchat/cli/exit'
11
- require 'meshchat/cli/listen'
12
- require 'meshchat/cli/stop_listening'
13
- require 'meshchat/cli/who'
14
- require 'meshchat/cli/init'
15
- require 'meshchat/cli/share'
16
- require 'meshchat/cli/import'
2
+ require 'meshchat/cli/base'
3
+ require 'meshchat/command/base'
4
+ require 'meshchat/command/identity'
5
+ require 'meshchat/command/irb'
6
+ require 'meshchat/command/config'
7
+ require 'meshchat/command/ping'
8
+ require 'meshchat/command/ping_all'
9
+ require 'meshchat/command/server'
10
+ require 'meshchat/command/whisper'
11
+ require 'meshchat/command/exit'
12
+ require 'meshchat/command/listen'
13
+ require 'meshchat/command/stop_listening'
14
+ require 'meshchat/command/who'
15
+ require 'meshchat/command/init'
16
+ require 'meshchat/command/share'
17
+ require 'meshchat/command/import'
18
+
17
19
 
18
20
  module MeshChat
19
21
  # A user interface is responsible for for creating a client
20
22
  # and sending messages to that client
21
23
  class CLI
22
24
  COMMAND_MAP = {
23
- Command::CONFIG => CLI::Config,
24
- Command::PING => CLI::Ping,
25
- Command::PING_ALL => CLI::PingAll,
26
- Command::STOP_LISTENING => CLI::StopListening,
27
- Command::SERVERS => CLI::Server,
28
- Command::SERVER => CLI::Server,
29
- Command::EXIT => CLI::Exit,
30
- Command::QUIT => CLI::Exit,
31
- Command::LISTEN => CLI::Listen,
32
- Command::WHO => CLI::Who,
33
- Command::IDENTITY => CLI::Identity,
34
- Command::IRB => CLI::IRB,
35
- Command::INIT => CLI::Init,
36
- Command::SHARE => CLI::Share,
37
- Command::IMPORT => CLI::Import,
38
- Command::EXPORT => CLI::Share
25
+ MeshChat::Command::Base::CONFIG => MeshChat::Command::Config,
26
+ MeshChat::Command::Base::PING => MeshChat::Command::Ping,
27
+ MeshChat::Command::Base::PING_ALL => MeshChat::Command::PingAll,
28
+ MeshChat::Command::Base::STOP_LISTENING => MeshChat::Command::StopListening,
29
+ MeshChat::Command::Base::SERVERS => MeshChat::Command::Server,
30
+ MeshChat::Command::Base::SERVER => MeshChat::Command::Server,
31
+ MeshChat::Command::Base::EXIT => MeshChat::Command::Exit,
32
+ MeshChat::Command::Base::QUIT => MeshChat::Command::Exit,
33
+ MeshChat::Command::Base::LISTEN => MeshChat::Command::Listen,
34
+ MeshChat::Command::Base::WHO => MeshChat::Command::Who,
35
+ MeshChat::Command::Base::IDENTITY => MeshChat::Command::Identity,
36
+ MeshChat::Command::Base::IRB => MeshChat::Command::IRB,
37
+ MeshChat::Command::Base::INIT => MeshChat::Command::Init,
38
+ MeshChat::Command::Base::SHARE => MeshChat::Command::Share,
39
+ MeshChat::Command::Base::IMPORT => MeshChat::Command::Import,
40
+ MeshChat::Command::Base::EXPORT => MeshChat::Command::Share
39
41
  }
40
42
 
41
43
 
44
+ attr_accessor :_input_device
45
+
42
46
  class << self
43
47
 
44
48
  delegate :server_location, :listen_for_commands,
@@ -46,25 +50,21 @@ module MeshChat
46
50
  :check_startup_settings, :create_input, :close_server,
47
51
  to: :instance
48
52
 
49
- def instance
50
- @instance ||= new
53
+ def create(input_klass)
54
+ @instance = new(input_klass)
51
55
  end
52
56
 
53
- # TODO: extract this for sub commands
54
- def autocompletes
55
- commands = COMMAND_MAP.map{ |k, v| "/#{k}" }
56
- aliases = MeshChat::Node.all.map{ |n| "#{n.alias_name}" }
57
- commands + aliases
57
+ def instance
58
+ # default input collector
59
+ @instance ||= new
58
60
  end
59
-
60
61
  end
61
62
 
62
63
 
63
- def initialize
64
- # Set up auto complete
65
- completion = proc{ |s| self.class.autocompletes.grep(/^#{Regexp.escape(s)}/) }
66
- Readline.completion_proc = completion
67
-
64
+ def initialize(input_klass = nil)
65
+ input_klass ||= MeshChat::CLI::Base
66
+ # instantiate the interface with which we are communicated with
67
+ self._input_device = input_klass.new
68
68
  # this will allow our listener / server to print exceptions,
69
69
  # rather than silently fail
70
70
  Thread.abort_on_exception = true
@@ -75,7 +75,7 @@ module MeshChat
75
75
  end
76
76
 
77
77
  def process_input
78
- msg = get_input
78
+ msg = _input_device.get_input
79
79
  create_input(msg)
80
80
  rescue SystemExit, Interrupt
81
81
  close_program
@@ -94,11 +94,6 @@ module MeshChat
94
94
  Display.error e.backtrace.join("\n").colorize(:red)
95
95
  end
96
96
 
97
-
98
- def get_input
99
- Readline.readline('> ', true)
100
- end
101
-
102
97
  def start_server
103
98
 
104
99
  unless Settings.valid?
@@ -0,0 +1,13 @@
1
+ module MeshChat
2
+ class CLI
3
+ class Base
4
+ # override this to alter how input is gathered
5
+ #
6
+ # the returned value of this method should be a whole line / command
7
+ # that will be passed to MeshChat::CLI.create_input
8
+ def get_input
9
+ gets
10
+ end
11
+ end
12
+ end
13
+ end
@@ -9,9 +9,9 @@ module MeshChat
9
9
  def create(input)
10
10
  klass =
11
11
  if is_command(input)
12
- CLI::Command
12
+ Command::Base
13
13
  elsif is_whisper?(input)
14
- CLI::Whisper
14
+ Command::Whisper
15
15
  else
16
16
  # TODO: maybe change this to a chat command?
17
17
  CLI::Input
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Command < CLI::Input
2
+ class Command
3
+ class Base < CLI::Input
4
4
  attr_accessor :_input
5
5
 
6
6
  # Commands
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Config < CLI::Command
2
+ class Command
3
+ class Config < Command::Base
4
4
  def handle
5
5
  case sub_command
6
6
  when SET
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Exit < CLI::Command
2
+ class Command
3
+ class Exit < Command::Base
4
4
  def handle
5
5
  CLI.shutdown
6
6
  end
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Identity < CLI::Command
2
+ class Command
3
+ class Identity < Command::Base
4
4
  def handle
5
5
  Display.success Settings.identity
6
6
  end
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Import < CLI::Command
2
+ class Command
3
+ class Import < Command::Base
4
4
  def handle
5
5
  if command_valid?
6
6
  node = Models::Entry.import_from_file(filename)
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Init < CLI::Command
2
+ class Command
3
+ class Init < Command::Base
4
4
  def handle
5
5
  if Settings.uid_exists?
6
6
  if confirm? 'uid exists, are you sure you want a new identity?'
@@ -1,8 +1,8 @@
1
1
  module MeshChat
2
- class CLI
2
+ class Command
3
3
  # TODO: only include this and awesome_print when booted with
4
4
  # debug=true in the config
5
- class IRB < CLI::Command
5
+ class IRB < Command::Base
6
6
  def handle
7
7
  begin
8
8
  code = command_args[1..command_args.length].join(' ')
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Listen < CLI::Command
2
+ class Command
3
+ class Listen < Command::Base
4
4
  def handle
5
5
  CLI.start_server
6
6
  end
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Ping < CLI::Command
2
+ class Command
3
+ class Ping < Command::Base
4
4
  def handle
5
5
  if command_valid?
6
6
  msg = Message::Ping.new
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class PingAll < CLI::Command
2
+ class Command
3
+ class PingAll < Command::Base
4
4
  def handle
5
5
  Node.all.each do |n|
6
6
  Net::Client.send(node: n, message: Message::Ping.new)
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Server < CLI::Command
2
+ class Command
3
+ class Server < Command::Base
4
4
  ONLINE = 'online'
5
5
 
6
6
  def handle
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Share < CLI::Command
2
+ class Command
3
+ class Share < Command::Base
4
4
  def handle
5
5
  Settings.share
6
6
  end
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class StopListening < CLI::Command
2
+ class Command
3
+ class StopListening < Command::Base
4
4
  def handle
5
5
  CLI.close_server
6
6
  end
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Whisper < CLI::Command
2
+ class Command
3
+ class Whisper < Command::Base
4
4
  def target
5
5
  # get first arg
6
6
  command
@@ -1,6 +1,6 @@
1
1
  module MeshChat
2
- class CLI
3
- class Who < CLI::Command
2
+ class Command
3
+ class Who < Command::Base
4
4
  def handle
5
5
  Display.info Node.online.map(&:as_info) || 'no one is online'
6
6
  end
@@ -9,6 +9,7 @@ module MeshChat
9
9
  def start(options)
10
10
  # calling instance to get things going
11
11
  @instance = new(options)
12
+ @instance.start_input_device(options[:input])
12
13
  @instance.start_ui(options[:display], options[:on_display_start])
13
14
  end
14
15
 
@@ -22,7 +23,7 @@ module MeshChat
22
23
  self.client_version = options[:client_version] || MeshChat::VERSION
23
24
  end
24
25
 
25
- # @param [class] klass should be something that implements Display::Base
26
+ # @param [Class] klass should be something that implements Display::Base
26
27
  # @param [Proc] proc what to do when starting the UI
27
28
  def start_ui(klass, on_display_start)
28
29
  self.display = Display::Manager.new(klass)
@@ -30,5 +31,10 @@ module MeshChat
30
31
  on_display_start.call if on_display_start
31
32
  end
32
33
  end
34
+
35
+ def start_input_device(klass)
36
+ # The CLI is a singleton that takes a method of input
37
+ MeshChat::CLI.create(klass)
38
+ end
33
39
  end
34
40
  end
@@ -1,3 +1,3 @@
1
1
  module MeshChat
2
- VERSION = '0.5.0'
2
+ VERSION = '0.6.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: meshchat
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - L. Preston Sego III
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-21 00:00:00.000000000 Z
11
+ date: 2015-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sqlite3
@@ -216,22 +216,23 @@ files:
216
216
  - README.md
217
217
  - lib/meshchat.rb
218
218
  - lib/meshchat/cli.rb
219
- - lib/meshchat/cli/command.rb
220
- - lib/meshchat/cli/config.rb
221
- - lib/meshchat/cli/exit.rb
222
- - lib/meshchat/cli/identity.rb
223
- - lib/meshchat/cli/import.rb
224
- - lib/meshchat/cli/init.rb
219
+ - lib/meshchat/cli/base.rb
225
220
  - lib/meshchat/cli/input.rb
226
- - lib/meshchat/cli/irb.rb
227
- - lib/meshchat/cli/listen.rb
228
- - lib/meshchat/cli/ping.rb
229
- - lib/meshchat/cli/ping_all.rb
230
- - lib/meshchat/cli/server.rb
231
- - lib/meshchat/cli/share.rb
232
- - lib/meshchat/cli/stop_listening.rb
233
- - lib/meshchat/cli/whisper.rb
234
- - lib/meshchat/cli/who.rb
221
+ - lib/meshchat/command/base.rb
222
+ - lib/meshchat/command/config.rb
223
+ - lib/meshchat/command/exit.rb
224
+ - lib/meshchat/command/identity.rb
225
+ - lib/meshchat/command/import.rb
226
+ - lib/meshchat/command/init.rb
227
+ - lib/meshchat/command/irb.rb
228
+ - lib/meshchat/command/listen.rb
229
+ - lib/meshchat/command/ping.rb
230
+ - lib/meshchat/command/ping_all.rb
231
+ - lib/meshchat/command/server.rb
232
+ - lib/meshchat/command/share.rb
233
+ - lib/meshchat/command/stop_listening.rb
234
+ - lib/meshchat/command/whisper.rb
235
+ - lib/meshchat/command/who.rb
235
236
  - lib/meshchat/config/hash_file.rb
236
237
  - lib/meshchat/config/settings.rb
237
238
  - lib/meshchat/database.rb
@@ -284,5 +285,6 @@ rubyforge_project:
284
285
  rubygems_version: 2.4.7
285
286
  signing_key:
286
287
  specification_version: 4
287
- summary: MeshChat-0.5.0
288
+ summary: MeshChat-0.6.0
288
289
  test_files: []
290
+ has_rdoc: