Skip to content

Commit

Permalink
Merge pull request #234 from gavinlaking/twerks
Browse files Browse the repository at this point in the history
Various improvements;
  • Loading branch information
gavinlaking committed Sep 27, 2015
2 parents 2ebbccf + 3f3e16d commit 041cfa4
Show file tree
Hide file tree
Showing 40 changed files with 315 additions and 106 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
2 changes: 1 addition & 1 deletion docs/events/system.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions lib/vedeu/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
5 changes: 2 additions & 3 deletions lib/vedeu/dsl/text.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/vedeu/events/aliases.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
44 changes: 12 additions & 32 deletions lib/vedeu/geometry/geometry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,31 +135,21 @@ 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.
#
# 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.
Expand All @@ -179,31 +169,21 @@ 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.
#
# 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
Expand Down
4 changes: 2 additions & 2 deletions lib/vedeu/input/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ module Input

end # Vedeu

require 'vedeu/input/input'
require 'vedeu/input/capture'
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'
8 changes: 4 additions & 4 deletions lib/vedeu/input/input.rb → lib/vedeu/input/capture.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions lib/vedeu/input/key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down
13 changes: 0 additions & 13 deletions lib/vedeu/input/keys.rb

This file was deleted.

71 changes: 71 additions & 0 deletions lib/vedeu/input/store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module Vedeu

module Input

# Stores each keypress or command to be retrieved later.
#
class Store

def initialize
end

# @return [Hash<Symbol => Array<Symbol|String>>]
def add_command(command)
all_commands << command
end

# @return [Hash<Symbol => Array<Symbol|String>>]
def add_keypress(keypress)
all_keypresses << keypress
end

# @return [Hash<Symbol => Array<Symbol|String>>]
def all
storage
end

# @return [Array<Symbol|String>]
def all_commands
storage[:commands]
end

# @return [Array<Symbol|String>]
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<Symbol => Array<Symbol|String>>]
def reset
@storage = in_memory
end

private

# @return [Hash<Symbol => Array<Symbol|String>>]
def storage
@storage ||= in_memory
end

# @return [Hash<Symbol => Array<Symbol|String>>]
def in_memory
{
commands: [],
keypresses: [],
}
end

end # Store

end # Input

end # Vedeu
4 changes: 1 addition & 3 deletions lib/vedeu/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 4 additions & 10 deletions lib/vedeu/output/wordwrap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/vedeu/runtime/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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_)
Expand Down
4 changes: 4 additions & 0 deletions test/lib/vedeu/bindings/drb_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
6 changes: 5 additions & 1 deletion test/lib/vedeu/buffers/buffer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }

Expand Down
1 change: 1 addition & 0 deletions test/lib/vedeu/cursors/refresh_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module Cursors

describe '.by_name' do
before do
Vedeu.stubs(:log)
Vedeu.geometry 'refresh_cursor' do
x 1
xn 3
Expand Down
1 change: 1 addition & 0 deletions test/lib/vedeu/distributed/client_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Distributed
let(:server) {}

before do
Vedeu.stubs(:log)
$stdout.stubs(:puts)
DRbObject.stubs(:new_with_uri).returns(server)
end
Expand Down
1 change: 1 addition & 0 deletions test/lib/vedeu/distributed/server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/lib/vedeu/events/aliases_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/lib/vedeu/events/event_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down Expand Up @@ -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 } }

Expand Down
Loading

0 comments on commit 041cfa4

Please sign in to comment.