From e6998ec03c1925ae1b8391c9f5dc250a3a9eda11 Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Sat, 26 Sep 2015 18:19:24 +0100 Subject: [PATCH 01/11] Update documentation. --- docs/events/system.md | 2 +- lib/vedeu/dsl/text.rb | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/docs/events/system.md b/docs/events/system.md index 4baab3544..787b17a05 100644 --- a/docs/events/system.md +++ b/docs/events/system.md @@ -43,7 +43,7 @@ to 'do things'. If the `escape` key is pressed, then `key` is triggered with the argument `:escape`, also an internal event `_mode_switch_` is triggered. Vedeu recognises most key presses and some 'extended' keypress (eg. Ctrl+J), a list of supported keypresses can be found here: -{Vedeu::Input::Input#specials} and {Vedeu::Input::Input#f_keys}. +{Vedeu::Input::Input}. Vedeu.trigger(:_keypress_, key) diff --git a/lib/vedeu/dsl/text.rb b/lib/vedeu/dsl/text.rb index 005f966e5..6d2580930 100644 --- a/lib/vedeu/dsl/text.rb +++ b/lib/vedeu/dsl/text.rb @@ -11,9 +11,8 @@ module Text # string (or object responding to `to_s`), and add it as a Line # or to the Stream. # - # @note If using the convenience methods; {left}, {centre}, - # {center} or {right}, then a specified anchor will be - # ignored. + # @note If using the convenience methods; left, centre, center + # or right, then a specified anchor will be ignored. # # @example # lines do From c6f6ae52afb94fdbf0e4bcca08e95244df6f9b21 Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Sat, 26 Sep 2015 18:33:08 +0100 Subject: [PATCH 02/11] Use find method instead of the storage directly. --- lib/vedeu/events/aliases.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/vedeu/events/aliases.rb b/lib/vedeu/events/aliases.rb index ddb5855b3..9b2fb0e36 100644 --- a/lib/vedeu/events/aliases.rb +++ b/lib/vedeu/events/aliases.rb @@ -89,7 +89,7 @@ def storage def trigger(alias_name, *args) return [] unless registered?(alias_name) - storage[alias_name].map do |event_name| + find(alias_name).map do |event_name| Vedeu.log(type: :debug, message: "#{event_name}") Vedeu::Events::Trigger.trigger(event_name, *args) end From e1afdcab5e9db94ce5e86256c337aae8fc040d68 Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Sat, 26 Sep 2015 18:33:19 +0100 Subject: [PATCH 03/11] Stub out Vedeu.log in tests. --- test/lib/vedeu/bindings/drb_test.rb | 4 ++++ test/lib/vedeu/buffers/buffer_test.rb | 6 +++++- test/lib/vedeu/cursors/refresh_test.rb | 1 + test/lib/vedeu/distributed/client_test.rb | 1 + test/lib/vedeu/distributed/server_test.rb | 1 + test/lib/vedeu/events/aliases_test.rb | 1 + test/lib/vedeu/events/event_test.rb | 4 ++++ test/lib/vedeu/input/keymap_test.rb | 4 ++++ test/lib/vedeu/input/mapper_test.rb | 2 ++ test/lib/vedeu/models/focus_test.rb | 2 ++ test/lib/vedeu/output/renderers/all_test.rb | 5 ++++- test/lib/vedeu/plugins/plugins_test.rb | 2 ++ test/lib/vedeu/repositories/repositories_test.rb | 5 ++++- test/lib/vedeu/repositories/repository_test.rb | 4 ++++ test/lib/vedeu/repositories/store_test.rb | 2 ++ test/lib/vedeu/runtime/bootstrap_test.rb | 1 + test/lib/vedeu/runtime/launcher_test.rb | 1 + test/lib/vedeu/runtime/main_loop_test.rb | 2 ++ test/lib/vedeu/runtime/router_test.rb | 6 ++++++ test/lib/vedeu/terminal/terminal_test.rb | 2 ++ 20 files changed, 53 insertions(+), 3 deletions(-) diff --git a/test/lib/vedeu/bindings/drb_test.rb b/test/lib/vedeu/bindings/drb_test.rb index 9b9f3563f..09620b380 100644 --- a/test/lib/vedeu/bindings/drb_test.rb +++ b/test/lib/vedeu/bindings/drb_test.rb @@ -6,6 +6,10 @@ module Bindings describe DRB do + before do + Vedeu.stubs(:log) + end + context 'the drb specific events are defined' do it { Vedeu.bound?(:_drb_input_).must_equal(true) } it { Vedeu.bound?(:_drb_retrieve_output_).must_equal(true) } diff --git a/test/lib/vedeu/buffers/buffer_test.rb b/test/lib/vedeu/buffers/buffer_test.rb index 0599fae71..d5f8726e4 100644 --- a/test/lib/vedeu/buffers/buffer_test.rb +++ b/test/lib/vedeu/buffers/buffer_test.rb @@ -114,6 +114,7 @@ module Buffers describe '#show' do before do + Vedeu.stubs(:log) # Vedeu::Clear::Interface.stubs(:render) Vedeu::Output::Output.stubs(:render) end @@ -127,7 +128,10 @@ module Buffers end describe '#render' do - before { Vedeu::Output::Output.stubs(:render) } + before { + Vedeu.stubs(:log) + Vedeu::Output::Output.stubs(:render) + } subject { instance.render } diff --git a/test/lib/vedeu/cursors/refresh_test.rb b/test/lib/vedeu/cursors/refresh_test.rb index c4160c566..7cb1ecf8b 100644 --- a/test/lib/vedeu/cursors/refresh_test.rb +++ b/test/lib/vedeu/cursors/refresh_test.rb @@ -20,6 +20,7 @@ module Cursors describe '.by_name' do before do + Vedeu.stubs(:log) Vedeu.geometry 'refresh_cursor' do x 1 xn 3 diff --git a/test/lib/vedeu/distributed/client_test.rb b/test/lib/vedeu/distributed/client_test.rb index c2848d59d..7803e8d82 100644 --- a/test/lib/vedeu/distributed/client_test.rb +++ b/test/lib/vedeu/distributed/client_test.rb @@ -12,6 +12,7 @@ module Distributed let(:server) {} before do + Vedeu.stubs(:log) $stdout.stubs(:puts) DRbObject.stubs(:new_with_uri).returns(server) end diff --git a/test/lib/vedeu/distributed/server_test.rb b/test/lib/vedeu/distributed/server_test.rb index f3a0f9fb4..44b516b0b 100644 --- a/test/lib/vedeu/distributed/server_test.rb +++ b/test/lib/vedeu/distributed/server_test.rb @@ -13,6 +13,7 @@ module Distributed let(:running) { false } before do + Vedeu.stubs(:log) Vedeu::Configuration.stubs(:drb?).returns(enabled) DRb.stubs(:thread).returns(running) end diff --git a/test/lib/vedeu/events/aliases_test.rb b/test/lib/vedeu/events/aliases_test.rb index 658e6335c..a8457d06d 100644 --- a/test/lib/vedeu/events/aliases_test.rb +++ b/test/lib/vedeu/events/aliases_test.rb @@ -111,6 +111,7 @@ module Events context 'when the alias name is registered' do before do + Vedeu.stubs(:log) Vedeu::Events::Trigger.stubs(:trigger) described.add(:some_alias, :some_event) diff --git a/test/lib/vedeu/events/event_test.rb b/test/lib/vedeu/events/event_test.rb index 709c3a302..89c012c1d 100644 --- a/test/lib/vedeu/events/event_test.rb +++ b/test/lib/vedeu/events/event_test.rb @@ -13,6 +13,8 @@ module Events let(:options) { {} } describe '.bind' do + before { Vedeu.stubs(:log) } + subject { described.bind(event_name, options) { :event_triggered } } it { described.must_respond_to(:event) } @@ -95,6 +97,8 @@ module Events end describe '#unbind' do + before { Vedeu.stubs(:log) } + context 'when the event exists' do before { Vedeu.bind(:gallium) { :some_action } } diff --git a/test/lib/vedeu/input/keymap_test.rb b/test/lib/vedeu/input/keymap_test.rb index 37a119809..8f943d897 100644 --- a/test/lib/vedeu/input/keymap_test.rb +++ b/test/lib/vedeu/input/keymap_test.rb @@ -33,6 +33,8 @@ module Input end describe '#add' do + before { Vedeu.stubs(:log) } + subject { instance.add(key) } context 'when the key is already defined' do @@ -68,6 +70,8 @@ module Input describe '#use' do let(:input) { 'b' } + before { Vedeu.stubs(:log) } + subject { instance.use(input) } context 'when the input is defined' do diff --git a/test/lib/vedeu/input/mapper_test.rb b/test/lib/vedeu/input/mapper_test.rb index 665d23b36..012f3dbc3 100644 --- a/test/lib/vedeu/input/mapper_test.rb +++ b/test/lib/vedeu/input/mapper_test.rb @@ -34,6 +34,8 @@ module Input describe '.keypress' do let(:keymap) { 'test' } + before { Vedeu.stubs(:log) } + subject { described.keypress(key, keymap) } context 'when the key is not provided' do diff --git a/test/lib/vedeu/models/focus_test.rb b/test/lib/vedeu/models/focus_test.rb index ee4869bcf..0a40594f8 100644 --- a/test/lib/vedeu/models/focus_test.rb +++ b/test/lib/vedeu/models/focus_test.rb @@ -9,6 +9,8 @@ module Models let(:described) { Vedeu::Models::Focus } before do + Vedeu.stubs(:log) + Vedeu::Models::Focus.reset Vedeu.interfaces.reset diff --git a/test/lib/vedeu/output/renderers/all_test.rb b/test/lib/vedeu/output/renderers/all_test.rb index 155c47941..b975f5535 100644 --- a/test/lib/vedeu/output/renderers/all_test.rb +++ b/test/lib/vedeu/output/renderers/all_test.rb @@ -19,7 +19,10 @@ def self.render(*output) let(:described) { Vedeu::Renderers } let(:output) {} - before { Vedeu::Renderers.reset } + before { + Vedeu.stubs(:log) + Vedeu::Renderers.reset + } after { Vedeu::Renderers.reset } describe '.renderers' do diff --git a/test/lib/vedeu/plugins/plugins_test.rb b/test/lib/vedeu/plugins/plugins_test.rb index 40cf4f5ea..a29470542 100644 --- a/test/lib/vedeu/plugins/plugins_test.rb +++ b/test/lib/vedeu/plugins/plugins_test.rb @@ -23,6 +23,8 @@ module Vedeu let(:_name) {} let(:plugin) { false } + before { Vedeu.stubs(:log) } + subject { instance.register(_name, plugin) } # @todo Add more tests. diff --git a/test/lib/vedeu/repositories/repositories_test.rb b/test/lib/vedeu/repositories/repositories_test.rb index 0e5acce72..0486240dd 100644 --- a/test/lib/vedeu/repositories/repositories_test.rb +++ b/test/lib/vedeu/repositories/repositories_test.rb @@ -23,7 +23,10 @@ module Vedeu end describe '.registered' do - before { described.reset! } + before { + Vedeu.stubs(:log) + described.reset! + } subject { described.registered } diff --git a/test/lib/vedeu/repositories/repository_test.rb b/test/lib/vedeu/repositories/repository_test.rb index 7879cef20..132a258bf 100644 --- a/test/lib/vedeu/repositories/repository_test.rb +++ b/test/lib/vedeu/repositories/repository_test.rb @@ -166,6 +166,8 @@ def initialize(name = nil) describe '#find_or_create' do let(:model_instance) { Vedeu::Repositories::TestModel.new('niobium') } + before { Vedeu.stubs(:log) } + subject { instance.find_or_create(model_name) } context 'when the model exists' do @@ -251,6 +253,8 @@ def initialize(name = nil) describe '#store' do subject { instance.store(model_instance) } + before { Vedeu.stubs(:log) } + it { instance.must_respond_to(:register) } context 'when a name attribute is empty or nil' do diff --git a/test/lib/vedeu/repositories/store_test.rb b/test/lib/vedeu/repositories/store_test.rb index 806b6b995..f6a3d612c 100644 --- a/test/lib/vedeu/repositories/store_test.rb +++ b/test/lib/vedeu/repositories/store_test.rb @@ -127,6 +127,8 @@ def in_memory end describe '#reset' do + before { Vedeu.stubs(:log) } + it 'returns a Hash' do instance.reset.must_be_instance_of(Hash) end diff --git a/test/lib/vedeu/runtime/bootstrap_test.rb b/test/lib/vedeu/runtime/bootstrap_test.rb index 1f07c9e4f..f187597a2 100644 --- a/test/lib/vedeu/runtime/bootstrap_test.rb +++ b/test/lib/vedeu/runtime/bootstrap_test.rb @@ -24,6 +24,7 @@ module Runtime describe '.start' do before do + Vedeu.stubs(:log) Vedeu::Configuration.stubs(:root). returns([:controller, :action, :args]) Vedeu.stubs(:trigger) diff --git a/test/lib/vedeu/runtime/launcher_test.rb b/test/lib/vedeu/runtime/launcher_test.rb index c5099c733..55d1ff712 100644 --- a/test/lib/vedeu/runtime/launcher_test.rb +++ b/test/lib/vedeu/runtime/launcher_test.rb @@ -37,6 +37,7 @@ module Vedeu describe '#execute!' do before do + Vedeu.stubs(:log_stdout) Vedeu::Runtime::Application.stubs(:start) Kernel.stubs(:exit) Kernel.stubs(:puts) diff --git a/test/lib/vedeu/runtime/main_loop_test.rb b/test/lib/vedeu/runtime/main_loop_test.rb index 50d271cda..1334d7f82 100644 --- a/test/lib/vedeu/runtime/main_loop_test.rb +++ b/test/lib/vedeu/runtime/main_loop_test.rb @@ -9,6 +9,8 @@ module Runtime let(:described) { Vedeu::Runtime::MainLoop } describe '.start!' do + before { Vedeu.stubs(:log) } + subject { described.start! { } } end diff --git a/test/lib/vedeu/runtime/router_test.rb b/test/lib/vedeu/runtime/router_test.rb index bf9b59b2a..f4ec88ece 100644 --- a/test/lib/vedeu/runtime/router_test.rb +++ b/test/lib/vedeu/runtime/router_test.rb @@ -25,6 +25,8 @@ module Runtime let(:controller) {} let(:klass) { "SomeController" } + before { Vedeu.stubs(:log) } + subject { described.add_controller(controller, klass) } context 'when a name is not given' do @@ -68,6 +70,8 @@ module Runtime let(:controller) {} let(:action) {} + before { Vedeu.stubs(:log) } + subject { described.add_action(controller, action) } context 'when the controller is not given' do @@ -125,6 +129,8 @@ module Runtime } } + before { Vedeu.stubs(:log) } + subject { described.goto(controller, action, **args) } it { described.must_respond_to(:action) } diff --git a/test/lib/vedeu/terminal/terminal_test.rb b/test/lib/vedeu/terminal/terminal_test.rb index 2e1fb77f1..2141cc5f4 100644 --- a/test/lib/vedeu/terminal/terminal_test.rb +++ b/test/lib/vedeu/terminal/terminal_test.rb @@ -41,6 +41,8 @@ module Vedeu end describe '.input' do + before { Vedeu.stubs(:log) } + subject { Vedeu::Terminal.input } it { described.must_respond_to(:read) } From 92e454b95206faae48b9b1f2f6763bbd56367afc Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Sat, 26 Sep 2015 18:36:22 +0100 Subject: [PATCH 04/11] Disable Ruby warnings when running tests. --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 4c63c3a26..b4edad103 100644 --- a/Rakefile +++ b/Rakefile @@ -8,7 +8,7 @@ Rake::TestTask.new(:test) do |task| task.libs.push 'test' task.pattern = 'test/**/*_test.rb' task.verbose = false - task.warning = true # set to true for Ruby warnings (ruby -w) + task.warning = false # set to true for Ruby warnings (ruby -w) end YARD::Rake::YardocTask.new(:yard) do |task| From 93cd1d14b508250a871e03fe114e889600e5e586 Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Sat, 26 Sep 2015 19:24:31 +0100 Subject: [PATCH 05/11] Store each command or keypress entered by the user of the client application for use later. --- lib/vedeu/input/all.rb | 1 + lib/vedeu/input/store.rb | 71 +++++++++++++++ test/lib/vedeu/input/store_test.rb | 138 +++++++++++++++++++++++++++++ 3 files changed, 210 insertions(+) create mode 100644 lib/vedeu/input/store.rb create mode 100644 test/lib/vedeu/input/store_test.rb diff --git a/lib/vedeu/input/all.rb b/lib/vedeu/input/all.rb index 94628df2a..89082f304 100644 --- a/lib/vedeu/input/all.rb +++ b/lib/vedeu/input/all.rb @@ -15,4 +15,5 @@ module Input require 'vedeu/input/keymaps' require 'vedeu/input/keys' require 'vedeu/input/mapper' +require 'vedeu/input/store' require 'vedeu/input/translator' diff --git a/lib/vedeu/input/store.rb b/lib/vedeu/input/store.rb new file mode 100644 index 000000000..cabcd3c81 --- /dev/null +++ b/lib/vedeu/input/store.rb @@ -0,0 +1,71 @@ +module Vedeu + + module Input + + # Stores each keypress or command to be retrieved later. + # + class Store + + def initialize + end + + # @return [Hash Array>] + def add_command(command) + all_commands << command + end + + # @return [Hash Array>] + def add_keypress(keypress) + all_keypresses << keypress + end + + # @return [Hash Array>] + def all + storage + end + + # @return [Array] + def all_commands + storage[:commands] + end + + # @return [Array] + def all_keypresses + storage[:keypresses] + end + + # @return [NilClass|Symbol|String] + def last_command + all_commands.last + end + + # @return [NilClass|Symbol|String] + def last_keypress + all_keypresses.last + end + + # @return [Hash Array>] + def reset + @storage = in_memory + end + + private + + # @return [Hash Array>] + def storage + @storage ||= in_memory + end + + # @return [Hash Array>] + def in_memory + { + commands: [], + keypresses: [], + } + end + + end # Store + + end # Input + +end # Vedeu diff --git a/test/lib/vedeu/input/store_test.rb b/test/lib/vedeu/input/store_test.rb new file mode 100644 index 000000000..eb96357b7 --- /dev/null +++ b/test/lib/vedeu/input/store_test.rb @@ -0,0 +1,138 @@ +require 'test_helper' + +module Vedeu + + module Input + + describe Store do + + let(:described) { Vedeu::Input::Store } + let(:instance) { described.new } + + before { instance.reset } + + describe '#add_command' do + let(:command) { 'command_1' } + + subject { instance.add_command(command) } + + it { subject.must_equal(['command_1']) } + end + + describe '#add_keypress' do + let(:keypress) { 'a' } + + subject { instance.add_keypress(keypress) } + + it { subject.must_equal(['a']) } + end + + describe '#all' do + subject { instance.all } + + context 'when empty' do + it { subject.must_equal({ commands: [], keypresses: [] }) } + end + + context 'when not empty' do + let(:expected) { + { + commands: ['command_1', 'command_2'], + keypresses: ['a', 'b'], + } + } + + before do + instance.add_command('command_1') + instance.add_command('command_2') + instance.add_keypress('a') + instance.add_keypress('b') + end + + it { subject.must_equal(expected) } + end + end + + describe '#all_commands' do + subject { instance.all_commands } + + context 'when there are no stored commands' do + it { subject.must_equal([]) } + end + + context 'when there are stored commands' do + before do + instance.add_command('command_1') + instance.add_command('command_2') + instance.add_command('command_3') + end + + it { subject.must_equal(['command_1', 'command_2', 'command_3']) } + end + end + + describe '#all_keypresses' do + subject { instance.all_keypresses } + + context 'when there are no stored keypresses' do + it { subject.must_equal([]) } + end + + context 'when there are stored keypresses' do + before do + instance.add_keypress('a') + instance.add_keypress('b') + instance.add_keypress('c') + end + + it { subject.must_equal(['a', 'b', 'c']) } + end + end + + describe '#last_command' do + subject { instance.last_command } + + context 'when there are no stored commands' do + it { subject.must_equal(nil) } + end + + context 'when there are stored commands' do + before do + instance.add_command('command_1') + instance.add_command('command_2') + instance.add_command('command_3') + end + + it { subject.must_equal('command_3') } + end + end + + describe '#last_keypress' do + subject { instance.last_keypress } + + context 'when there are no stored keypresses' do + it { subject.must_equal(nil) } + end + + context 'when there are stored keypresses' do + before do + instance.add_keypress('a') + instance.add_keypress('b') + instance.add_keypress('c') + end + + it { subject.must_equal('c') } + end + end + + describe '#reset' do + subject { instance.reset } + + it { subject.must_equal({ commands: [], keypresses: [] }) } + end + + end # Store + + end # Input + +end # Vedeu From 1fb268e1af935acc210ea86091fd56a95a7d7538 Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Sat, 26 Sep 2015 22:31:44 +0100 Subject: [PATCH 06/11] Move Input::Keys into Input::Key. --- lib/vedeu/all.rb | 2 -- lib/vedeu/input/all.rb | 1 - lib/vedeu/input/key.rb | 6 ++++++ lib/vedeu/input/keys.rb | 13 ------------- test/lib/vedeu/input/key_test.rb | 13 +++++++++++++ test/lib/vedeu/input/keys_test.rb | 22 ---------------------- 6 files changed, 19 insertions(+), 38 deletions(-) delete mode 100644 lib/vedeu/input/keys.rb delete mode 100644 test/lib/vedeu/input/keys_test.rb diff --git a/lib/vedeu/all.rb b/lib/vedeu/all.rb index 3f7ea74b4..40aeae57c 100644 --- a/lib/vedeu/all.rb +++ b/lib/vedeu/all.rb @@ -12,8 +12,6 @@ require 'vedeu/terminal/all' require 'vedeu/repositories/all' -require 'vedeu/input/keys' - require 'vedeu/models/toggleable' require 'vedeu/output/presentation/presentation' diff --git a/lib/vedeu/input/all.rb b/lib/vedeu/input/all.rb index 89082f304..70b276e88 100644 --- a/lib/vedeu/input/all.rb +++ b/lib/vedeu/input/all.rb @@ -13,7 +13,6 @@ module Input require 'vedeu/input/key' require 'vedeu/input/keymap' require 'vedeu/input/keymaps' -require 'vedeu/input/keys' require 'vedeu/input/mapper' require 'vedeu/input/store' require 'vedeu/input/translator' diff --git a/lib/vedeu/input/key.rb b/lib/vedeu/input/key.rb index a0914ed60..95a9f967e 100644 --- a/lib/vedeu/input/key.rb +++ b/lib/vedeu/input/key.rb @@ -2,6 +2,12 @@ module Vedeu module Input + # A collection of {Vedeu::Input::Key} instances. + # + class Keys < Vedeu::Repositories::Collection + + end # Keys + # A single keypress or combination of keypresses bound to a # specific action. # diff --git a/lib/vedeu/input/keys.rb b/lib/vedeu/input/keys.rb deleted file mode 100644 index 047a91db7..000000000 --- a/lib/vedeu/input/keys.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Vedeu - - module Input - - # A collection of {Vedeu::Input::Key} instances. - # - class Keys < Vedeu::Repositories::Collection - - end # Keys - - end # Input - -end # Vedeu diff --git a/test/lib/vedeu/input/key_test.rb b/test/lib/vedeu/input/key_test.rb index a1cab95dd..e0a9a0ca8 100644 --- a/test/lib/vedeu/input/key_test.rb +++ b/test/lib/vedeu/input/key_test.rb @@ -4,6 +4,19 @@ module Vedeu module Input + describe Keys do + + let(:described) { Vedeu::Input::Keys } + let(:instance) { described.new } + + it { described.superclass.must_equal(Vedeu::Repositories::Collection) } + + describe '#initialize' do + it { instance.must_be_instance_of(described) } + end + + end # Keys + describe Key do let(:described) { Vedeu::Input::Key } diff --git a/test/lib/vedeu/input/keys_test.rb b/test/lib/vedeu/input/keys_test.rb deleted file mode 100644 index d549d6490..000000000 --- a/test/lib/vedeu/input/keys_test.rb +++ /dev/null @@ -1,22 +0,0 @@ -require 'test_helper' - -module Vedeu - - module Input - - describe Keys do - - let(:described) { Vedeu::Input::Keys } - let(:instance) { described.new } - - it { described.superclass.must_equal(Vedeu::Repositories::Collection) } - - describe '#initialize' do - it { instance.must_be_instance_of(described) } - end - - end # Keys - - end # Input - -end # Vedeu From d083b40131c1d48de041000d2e1c0d7108aae4ed Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Sat, 26 Sep 2015 22:32:13 +0100 Subject: [PATCH 07/11] Simplify movement of geometry. --- lib/vedeu/geometry/geometry.rb | 44 ++++++++++------------------------ 1 file changed, 12 insertions(+), 32 deletions(-) diff --git a/lib/vedeu/geometry/geometry.rb b/lib/vedeu/geometry/geometry.rb index 389dbac8a..ad8b002f3 100644 --- a/lib/vedeu/geometry/geometry.rb +++ b/lib/vedeu/geometry/geometry.rb @@ -135,15 +135,10 @@ def maximise # TODO: Move cursor also. # @return [Vedeu::Geometry::Geometry] def move_down - if yn + 1 > Vedeu.height - dy = y - dyn = yn - else - dy = y + 1 - dyn = yn + 1 - end + return self if yn + 1 > Vedeu.height - Vedeu::Geometry::Geometry.store(move_attributes.merge!(y: dy, yn: dyn)) + Vedeu::Geometry::Geometry.store(move_attributes.merge!(y: y + 1, + yn: yn + 1)) end # Moves the geometry left by one column. @@ -151,15 +146,10 @@ def move_down # TODO: Move cursor also. # @return [Vedeu::Geometry::Geometry] def move_left - if x - 1 < 1 - dx = x - dxn = xn - else - dx = x - 1 - dxn = xn - 1 - end + return self if x - 1 < 1 - Vedeu::Geometry::Geometry.store(move_attributes.merge!(x: dx, xn: dxn)) + Vedeu::Geometry::Geometry.store(move_attributes.merge!(x: x - 1, + xn: xn - 1)) end # Moves the geometry to the top left of the terminal. @@ -179,15 +169,10 @@ def move_origin # TODO: Move cursor also. # @return [Vedeu::Geometry::Geometry] def move_right - if xn + 1 > Vedeu.width - dx = x - dxn = xn - else - dx = x + 1 - dxn = xn + 1 - end + return self if xn + 1 > Vedeu.width - Vedeu::Geometry::Geometry.store(move_attributes.merge!(x: dx, xn: dxn)) + Vedeu::Geometry::Geometry.store(move_attributes.merge!(x: x + 1, + xn: xn + 1)) end # Moves the geometry up by one column. @@ -195,15 +180,10 @@ def move_right # TODO: Move cursor also. # @return [Vedeu::Geometry::Geometry] def move_up - if y - 1 < 1 - dy = y - dyn = yn - else - dy = y - 1 - dyn = yn - 1 - end + return self if y - 1 < 1 - Vedeu::Geometry::Geometry.store(move_attributes.merge!(y: dy, yn: dyn)) + Vedeu::Geometry::Geometry.store(move_attributes.merge!(y: y - 1, + yn: yn - 1)) end # Will unmaximise the named interface geometry. Previously, when From 58aa8aa6f4a039cfbeb14d71ab5a218a6eb9b284 Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Sat, 26 Sep 2015 22:33:14 +0100 Subject: [PATCH 08/11] Move Input::Input to Input::Capture. --- lib/vedeu/input/all.rb | 2 +- lib/vedeu/input/{input.rb => capture.rb} | 8 ++++---- lib/vedeu/runtime/application.rb | 2 +- test/lib/vedeu/input/{input_test.rb => capture_test.rb} | 8 ++++---- 4 files changed, 10 insertions(+), 10 deletions(-) rename lib/vedeu/input/{input.rb => capture.rb} (94%) rename test/lib/vedeu/input/{input_test.rb => capture_test.rb} (94%) diff --git a/lib/vedeu/input/all.rb b/lib/vedeu/input/all.rb index 70b276e88..e0e3dd466 100644 --- a/lib/vedeu/input/all.rb +++ b/lib/vedeu/input/all.rb @@ -9,7 +9,7 @@ module Input end # Vedeu -require 'vedeu/input/input' +require 'vedeu/input/capture' require 'vedeu/input/key' require 'vedeu/input/keymap' require 'vedeu/input/keymaps' diff --git a/lib/vedeu/input/input.rb b/lib/vedeu/input/capture.rb similarity index 94% rename from lib/vedeu/input/input.rb rename to lib/vedeu/input/capture.rb index 853eeca7b..db04f1c1a 100644 --- a/lib/vedeu/input/input.rb +++ b/lib/vedeu/input/capture.rb @@ -5,14 +5,14 @@ module Input # Captures input from the user via {Vedeu::Terminal#input} and # translates special characters into symbols. # - class Input + class Capture # Instantiate Vedeu::Input::Input and capture keypress(es). # # @param (see #initialize) # @return [String|Symbol] - def self.capture(reader) - new(reader).capture + def self.read(reader) + new(reader).read end # Returns a new instance of Vedeu::Input::Input. @@ -29,7 +29,7 @@ def initialize(reader) # event with the key(s) pressed. # # @return [Array|String|Symbol] - def capture + def read if reader.raw_mode? Vedeu.trigger(:_keypress_, keypress) diff --git a/lib/vedeu/runtime/application.rb b/lib/vedeu/runtime/application.rb index 02b3a2fdd..657de505b 100644 --- a/lib/vedeu/runtime/application.rb +++ b/lib/vedeu/runtime/application.rb @@ -102,7 +102,7 @@ def runner # @return [void] def main_sequence if configuration.interactive? - Vedeu::Input::Input.capture(Terminal) + Vedeu::Input::Capture.read(Terminal) else Vedeu.trigger(:_standalone_) diff --git a/test/lib/vedeu/input/input_test.rb b/test/lib/vedeu/input/capture_test.rb similarity index 94% rename from test/lib/vedeu/input/input_test.rb rename to test/lib/vedeu/input/capture_test.rb index 233d8015f..c5bbb7738 100644 --- a/test/lib/vedeu/input/input_test.rb +++ b/test/lib/vedeu/input/capture_test.rb @@ -4,11 +4,11 @@ module Vedeu module Input - describe Input do + describe Capture do let(:reader) { Vedeu::Terminal } let(:keypress) { 'a' } - let(:described) { Vedeu::Input::Input } + let(:described) { Vedeu::Input::Capture } let(:instance) { described.new(reader) } let(:raw_mode) { true } @@ -17,14 +17,14 @@ module Input it { instance.instance_variable_get('@reader').must_equal(reader) } end - describe '.capture' do + describe '.read' do before do reader.stubs(:raw_mode?).returns(raw_mode) reader.stubs(:fake_mode?).returns(fake_mode) Vedeu.stubs(:trigger).returns([false]) end - subject { described.capture(reader) } + subject { described.read(reader) } context 'when in cooked mode' do let(:raw_mode) { false } From 788258ceeede4a52b13eaa92f2ca6504448d1be1 Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Sat, 26 Sep 2015 22:33:31 +0100 Subject: [PATCH 09/11] Remove unused @attributes. --- lib/vedeu/models/group.rb | 4 +--- test/lib/vedeu/models/group_test.rb | 3 --- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/vedeu/models/group.rb b/lib/vedeu/models/group.rb index d3396c412..f67b2b672 100644 --- a/lib/vedeu/models/group.rb +++ b/lib/vedeu/models/group.rb @@ -31,9 +31,7 @@ class Group # visible or not. # @return [Vedeu::Models::Group] def initialize(attributes = {}) - @attributes = defaults.merge!(attributes) - - @attributes.each do |key, value| + defaults.merge!(attributes).each do |key, value| instance_variable_set("@#{key}", value) end end diff --git a/test/lib/vedeu/models/group_test.rb b/test/lib/vedeu/models/group_test.rb index dcd402516..fee0b2808 100644 --- a/test/lib/vedeu/models/group_test.rb +++ b/test/lib/vedeu/models/group_test.rb @@ -23,9 +23,6 @@ module Models describe '#initialize' do it { instance.must_be_instance_of(described) } - it { - instance.instance_variable_get('@attributes').must_be_instance_of(Hash) - } it { instance.instance_variable_get('@members').must_equal(members) } it { instance.instance_variable_get('@name').must_equal(_name) } it { From ec784efcd1072793b12a206efbc0a20024db3ed8 Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Sun, 27 Sep 2015 14:19:36 +0100 Subject: [PATCH 10/11] Minor tidyup. --- lib/vedeu/output/wordwrap.rb | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/vedeu/output/wordwrap.rb b/lib/vedeu/output/wordwrap.rb index 851e6f850..3467a5eaa 100644 --- a/lib/vedeu/output/wordwrap.rb +++ b/lib/vedeu/output/wordwrap.rb @@ -38,19 +38,15 @@ def content def prune return text if text.size <= pruned_width - processed = [] - - if split_lines.size > 1 - processed = split_lines.reduce([]) do |acc, line| + processed = if split_lines.size > 1 + split_lines.reduce([]) do |acc, line| acc << ellipsis_string(line) end else - processed = ellipsis_string(text) + ellipsis_string(text) end - - processed end # @return [String] @@ -75,9 +71,7 @@ def wrap processed << reformatted end - processed.reduce([]) do |output, line| - output << line.join(' ') - end + processed.reduce([]) { |output, line| output << line.join(' ') } end protected From 3f3e16dfe8d6b9d7506564d5fe4c25fdf308790e Mon Sep 17 00:00:00 2001 From: Gavin Laking Date: Mon, 28 Sep 2015 00:19:32 +0100 Subject: [PATCH 11/11] Bump dependency gem versions. --- vedeu.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vedeu.gemspec b/vedeu.gemspec index 507dfd3bb..e6b49a8de 100644 --- a/vedeu.gemspec +++ b/vedeu.gemspec @@ -35,5 +35,5 @@ Gem::Specification.new do |spec| spec.add_dependency 'bundler', '~> 1.10' spec.add_dependency 'rake', '~> 10.4' - spec.add_dependency 'vedeu_cli', '0.0.5' + spec.add_dependency 'vedeu_cli', '0.0.6' end