vedeu 0.5.13 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (83) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +6 -0
  3. data/bin/vedeu_drb_server +1 -0
  4. data/config/rubocop_enabled.yml +2 -2
  5. data/docs/events.md +2 -0
  6. data/docs/getting_started.md +1 -1
  7. data/examples/drb_app.rb +1 -0
  8. data/examples/editor_app.rb +76 -0
  9. data/lib/vedeu/all.rb +13 -7
  10. data/lib/vedeu/{bindings.rb → bindings/bindings.rb} +2 -0
  11. data/lib/vedeu/bindings/focus.rb +66 -0
  12. data/lib/vedeu/bindings/refresh.rb +77 -0
  13. data/lib/vedeu/bindings/system.rb +19 -88
  14. data/lib/vedeu/buffers/buffer.rb +8 -8
  15. data/lib/vedeu/configuration/api.rb +32 -11
  16. data/lib/vedeu/configuration/cli.rb +8 -0
  17. data/lib/vedeu/cursor/move.rb +1 -0
  18. data/lib/vedeu/distributed/templates/default_configuration.vedeu +1 -0
  19. data/lib/vedeu/{dsl.rb → dsl/dsl.rb} +0 -0
  20. data/lib/vedeu/exceptions.rb +1 -1
  21. data/lib/vedeu/geometry/position.rb +28 -0
  22. data/lib/vedeu/input/capture.rb +76 -0
  23. data/lib/vedeu/input/editor/all.rb +19 -0
  24. data/lib/vedeu/input/editor/cropper.rb +74 -0
  25. data/lib/vedeu/input/editor/document.rb +254 -0
  26. data/lib/vedeu/input/editor/documents.rb +18 -0
  27. data/lib/vedeu/input/editor/editor.rb +100 -0
  28. data/lib/vedeu/input/editor/line.rb +143 -0
  29. data/lib/vedeu/input/editor/lines.rb +199 -0
  30. data/lib/vedeu/input/editor/virtual_cursor.rb +167 -0
  31. data/lib/vedeu/input/input.rb +9 -93
  32. data/lib/vedeu/input/input_translator.rb +155 -0
  33. data/lib/vedeu/internal_api.rb +9 -0
  34. data/lib/vedeu/log/lockless_log_device.rb +1 -1
  35. data/lib/vedeu/models/escape.rb +7 -8
  36. data/lib/vedeu/output/direct.rb +59 -0
  37. data/lib/vedeu/output/renderers/terminal.rb +8 -0
  38. data/lib/vedeu/output/viewport.rb +2 -3
  39. data/lib/vedeu/{plugins.rb → plugins/plugins.rb} +0 -0
  40. data/lib/vedeu/refresh/refresh_cursor.rb +1 -0
  41. data/lib/vedeu/{repositories.rb → repositories/repositories.rb} +0 -0
  42. data/lib/vedeu/terminal/content.rb +88 -0
  43. data/lib/vedeu/terminal/mode.rb +79 -0
  44. data/lib/vedeu/{terminal.rb → terminal/terminal.rb} +9 -25
  45. data/lib/vedeu/version.rb +1 -1
  46. data/test/lib/vedeu/{bindings_test.rb → bindings/bindings_test.rb} +0 -0
  47. data/test/lib/vedeu/bindings/focus_test.rb +19 -0
  48. data/test/lib/vedeu/bindings/refresh_test.rb +19 -0
  49. data/test/lib/vedeu/bindings/system_test.rb +1 -6
  50. data/test/lib/vedeu/borders/render_border_test.rb +43 -10
  51. data/test/lib/vedeu/buffers/buffer_test.rb +18 -0
  52. data/test/lib/vedeu/buffers/virtual_buffer_test.rb +15 -0
  53. data/test/lib/vedeu/configuration/api_test.rb +18 -2
  54. data/test/lib/vedeu/configuration/cli_test.rb +5 -0
  55. data/test/lib/vedeu/cursor/move_test.rb +1 -1
  56. data/test/lib/vedeu/dsl/dsl_test.rb +8 -0
  57. data/test/lib/vedeu/dsl/shared_test.rb +12 -0
  58. data/test/lib/vedeu/{output → esc}/esc_test.rb +0 -0
  59. data/test/lib/vedeu/geometry/position_test.rb +56 -0
  60. data/test/lib/vedeu/input/capture_test.rb +63 -0
  61. data/test/lib/vedeu/input/editor/cropper_test.rb +82 -0
  62. data/test/lib/vedeu/input/editor/document_test.rb +190 -0
  63. data/test/lib/vedeu/input/editor/documents_test.rb +17 -0
  64. data/test/lib/vedeu/input/editor/editor_test.rb +170 -0
  65. data/test/lib/vedeu/input/editor/line_test.rb +333 -0
  66. data/test/lib/vedeu/input/editor/lines_test.rb +561 -0
  67. data/test/lib/vedeu/input/editor/virtual_cursor_test.rb +184 -0
  68. data/test/lib/vedeu/input/input_test.rb +20 -4
  69. data/test/lib/vedeu/input/input_translator_test.rb +32 -0
  70. data/test/lib/vedeu/internal_api_test.rb +1 -0
  71. data/test/lib/vedeu/models/escape_test.rb +6 -6
  72. data/test/lib/vedeu/models/views/view_test.rb +15 -2
  73. data/test/lib/vedeu/null/null_test.rb +8 -0
  74. data/test/lib/vedeu/output/direct_test.rb +70 -0
  75. data/test/lib/vedeu/{plugins_test.rb → plugins/plugins_test.rb} +0 -0
  76. data/test/lib/vedeu/{repositories_test.rb → repositories/repositories_test.rb} +0 -0
  77. data/test/lib/vedeu/terminal/content_test.rb +100 -0
  78. data/test/lib/vedeu/terminal/mode_test.rb +95 -0
  79. data/test/lib/vedeu/{terminal_test.rb → terminal/terminal_test.rb} +23 -23
  80. data/test/test_helper.rb +1 -0
  81. metadata +67 -20
  82. data/lib/vedeu/terminal_mode.rb +0 -59
  83. data/test/lib/vedeu/terminal_mode_test.rb +0 -72
@@ -42,7 +42,7 @@ module Vedeu
42
42
 
43
43
  private
44
44
 
45
- # @param filename [String]
45
+ # @param log [String]
46
46
  # @return [void]
47
47
  def open_logfile(log)
48
48
  if FileTest.exist?(log)
@@ -20,10 +20,14 @@ module Vedeu
20
20
  @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
21
21
  end
22
22
 
23
- # @return [String]
24
- def colour
25
- ''
23
+ # @return [NilClass]
24
+ def null
25
+ nil
26
26
  end
27
+ alias_method :background, :null
28
+ alias_method :colour, :null
29
+ alias_method :foreground, :null
30
+ alias_method :style, :null
27
31
 
28
32
  # An object is equal when its values are the same.
29
33
  #
@@ -39,11 +43,6 @@ module Vedeu
39
43
  Vedeu::Position.coerce(@position)
40
44
  end
41
45
 
42
- # @return [String]
43
- def style
44
- ''
45
- end
46
-
47
46
  # @return [String]
48
47
  def to_s
49
48
  "#{position}#{value}"
@@ -0,0 +1,59 @@
1
+ module Vedeu
2
+
3
+ # Write a string directly to the terminal at defined coordinates.
4
+ #
5
+ class Direct
6
+
7
+ # @param value [String]
8
+ # @param x [Fixnum]
9
+ # @param y [Fixnum]
10
+ # @return [void]
11
+ def self.write(value:, x:, y:)
12
+ new(value: value, x: x, y: y).write
13
+ end
14
+
15
+ # @param value [String]
16
+ # @param x [Fixnum]
17
+ # @param y [Fixnum]
18
+ def initialize(value:, x:, y:)
19
+ @value = value || ''
20
+ @x = x || 1
21
+ @y = y || 1
22
+ end
23
+
24
+ # @return [void]
25
+ def write
26
+ Vedeu::Terminal.output(output)
27
+
28
+ output
29
+ end
30
+
31
+ protected
32
+
33
+ # @attribute [r] value
34
+ # @return [String]
35
+ attr_reader :value
36
+
37
+ # @attribute [r] x
38
+ # @return [Fixnum]
39
+ attr_reader :x
40
+
41
+ # @attribute [r] y
42
+ # @return [Fixnum]
43
+ attr_reader :y
44
+
45
+ private
46
+
47
+ # @return [String]
48
+ def output
49
+ (Array(position) + Array(value)).join
50
+ end
51
+
52
+ # @return [String]
53
+ def position
54
+ Vedeu::Position.new(y, x).to_s
55
+ end
56
+
57
+ end # Direct
58
+
59
+ end # Vedeu
@@ -28,11 +28,19 @@ module Vedeu
28
28
  # @param output [Array<Array<Vedeu::Views::Char>>]
29
29
  # @return [Array<Array<Vedeu::Views::Char>>]
30
30
  def parsed(output)
31
+ store!(output)
32
+
31
33
  Vedeu.timer('Compression') do
32
34
  Vedeu::Compressor.render(output)
33
35
  end
34
36
  end
35
37
 
38
+ # @param output [Array<Array<Vedeu::Views::Char>>]
39
+ # @return [Array<Vedeu::Views::Char>]
40
+ def store!(output)
41
+ Vedeu::Terminal::Content.stores(output)
42
+ end
43
+
36
44
  end # Terminal
37
45
 
38
46
  end # Renderers
@@ -155,9 +155,8 @@ module Vedeu
155
155
  @by ||= border.by
156
156
  end
157
157
 
158
- # Fetch the cursor associated with the interface/view we are drawing.
159
- #
160
- # @return (see Vedeu::Cursors#by_name)
158
+ # @return [Vedeu::Cursor]
159
+ # @see Vedeu::Cursors#by_name
161
160
  def cursor
162
161
  @cursor ||= Vedeu.cursors.by_name(name)
163
162
  end
File without changes
@@ -68,6 +68,7 @@ module Vedeu
68
68
  end
69
69
 
70
70
  # @return [Vedeu::Cursor]
71
+ # @see Vedeu::Cursors#by_name
71
72
  def cursor
72
73
  @cursor ||= Vedeu.cursors.by_name(name)
73
74
  end
@@ -0,0 +1,88 @@
1
+ module Vedeu
2
+
3
+ module Terminal
4
+
5
+ # A permanent copy of the terminal output.
6
+ #
7
+ module Content
8
+
9
+ include Vedeu::Common
10
+ extend self
11
+
12
+ # @param char [Vedeu::Views::Char]
13
+ # @return [Boolean]
14
+ def valid?(char)
15
+ char.respond_to?(:position) &&
16
+ present?(char.position.y) &&
17
+ present?(char.position.x)
18
+ end
19
+
20
+ # @param char [Vedeu::Views::Char]
21
+ # @return [Vedeu::Views::Char]
22
+ def store(char)
23
+ # value = {}
24
+ # value[:background] = char.background.to_s if char.background
25
+ # value[:foreground] = char.foreground.to_s if char.foreground
26
+ # value[:style] = char.style.to_s if char.style
27
+ # value[:value] = char.value if char.value
28
+ # value[:x] = char.position.x if char.position.x
29
+ # value[:y] = char.position.y if char.position.y
30
+
31
+ storage[char.position.y][char.position.x] = char.value if valid?(char)
32
+
33
+ char
34
+ end
35
+
36
+ # @param chars [Array<Vedeu::Views::Char>]
37
+ # @return [Array<Vedeu::Views::Char>]
38
+ def stores(chars)
39
+ Array(chars).flatten.map { |char| store(char) }
40
+ end
41
+
42
+ # @return [Hash<String => String>|NilClass]
43
+ def write
44
+ filename = "/tmp/vedeu/content_#{Time.now.to_f}"
45
+
46
+ File.write(filename, storage.inspect) if Vedeu::Configuration.log?
47
+ end
48
+
49
+ # @return [Array<String>]
50
+ def reprocess
51
+ out = []
52
+ storage.each do |y, line|
53
+ line.each do |x, value|
54
+ out << Vedeu::Views::Char.new(position: [y, x], value: value).to_s
55
+ end
56
+ end
57
+
58
+ Vedeu::Terminal.clear
59
+
60
+ Vedeu::Terminal.output(out.join)
61
+ end
62
+
63
+ # @return [Hash]
64
+ def reset
65
+ @storage = in_memory
66
+ end
67
+
68
+ private
69
+
70
+ # Returns an empty collection ready for the storing terminal content.
71
+ #
72
+ # @return [Hash]
73
+ def in_memory
74
+ Hash.new { |h, k| h[k] = {} }
75
+ end
76
+
77
+ # Access to the storage for this repository.
78
+ #
79
+ # @return [Array]
80
+ def storage
81
+ @storage ||= in_memory
82
+ end
83
+
84
+ end # Content
85
+
86
+ end # Terminal
87
+
88
+ end # Vedeu
@@ -0,0 +1,79 @@
1
+ module Vedeu
2
+
3
+ module Terminal
4
+
5
+ # Store the current mode of the terminal.
6
+ #
7
+ module Mode
8
+
9
+ extend self
10
+
11
+ # Returns a boolean indicating whether the terminal is currently in
12
+ # `cooked` mode.
13
+ #
14
+ # @return [Boolean]
15
+ def cooked_mode?
16
+ mode == :cooked
17
+ end
18
+
19
+ # Sets the terminal in to `cooked` mode.
20
+ #
21
+ # @return [Symbol]
22
+ def cooked_mode!
23
+ @mode = :cooked
24
+ end
25
+
26
+ # Returns a boolean indicating whether the terminal is currently in `fake`
27
+ # mode.
28
+ #
29
+ # @return [Boolean]
30
+ def fake_mode?
31
+ mode == :fake
32
+ end
33
+
34
+ # Sets the terminal in to `fake` mode.
35
+ #
36
+ # @return [Symbol]
37
+ def fake_mode!
38
+ @mode = :fake
39
+ end
40
+
41
+ # Returns a boolean indicating whether the terminal is currently in `raw`
42
+ # mode.
43
+ #
44
+ # @return [Boolean]
45
+ def raw_mode?
46
+ mode == :raw
47
+ end
48
+
49
+ # Sets the terminal in to `raw` mode.
50
+ #
51
+ # @return [Symbol]
52
+ def raw_mode!
53
+ @mode = :raw
54
+ end
55
+
56
+ # Toggles the terminal's mode between `cooked`, `fake` and `raw`,
57
+ # depending on its current mode.
58
+ #
59
+ # @return [Symbol]
60
+ def switch_mode!
61
+ return fake_mode! if raw_mode?
62
+ return cooked_mode! if fake_mode?
63
+
64
+ raw_mode!
65
+ end
66
+
67
+ # Returns the mode of the terminal, either `:cooked`, `:fake` or `:raw`.
68
+ # Can change throughout the lifespan of the client application.
69
+ #
70
+ # @return [Symbol]
71
+ def mode
72
+ @mode ||= Vedeu::Configuration.terminal_mode
73
+ end
74
+
75
+ end # Mode
76
+
77
+ end # Terminal
78
+
79
+ end # Vedeu
@@ -5,7 +5,7 @@ module Vedeu
5
5
  #
6
6
  module Terminal
7
7
 
8
- include Vedeu::TerminalMode
8
+ include Vedeu::Terminal::Mode
9
9
  extend self
10
10
 
11
11
  # Opens a terminal screen in either `raw` or `cooked` mode. On exit,
@@ -16,7 +16,7 @@ module Vedeu
16
16
  def open
17
17
  fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
18
18
 
19
- if raw_mode?
19
+ if raw_mode? || fake_mode?
20
20
  console.raw { initialize_screen(mode) { yield } }
21
21
 
22
22
  else
@@ -34,29 +34,13 @@ module Vedeu
34
34
  def input
35
35
  Vedeu.log(type: :input, message: 'Waiting for user input...')
36
36
 
37
- keys_or_cmd = if raw_mode?
38
- keys = console.getch
39
-
40
- if keys.ord == 27 # \e
41
- begin
42
- keys << console.read_nonblock(5)
43
- rescue
44
- nil
45
- end
46
- begin
47
- keys << console.read_nonblock(4)
48
- rescue
49
- nil
50
- end
51
- end
52
- keys
53
-
54
- else
55
- console.gets.chomp
56
-
57
- end
58
-
59
- keys_or_cmd
37
+ if raw_mode? || fake_mode?
38
+ Vedeu::Editor::Capture.read(console)
39
+
40
+ else
41
+ console.gets.chomp
42
+
43
+ end
60
44
  end
61
45
  alias_method :read, :input
62
46
 
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.5.13'
4
+ VERSION = '0.6.0'
5
5
 
6
6
  end
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Bindings
6
+
7
+ describe Focus do
8
+
9
+ context 'the system events needed by Vedeu to run are defined' do
10
+ it { Vedeu.bound?(:_focus_by_name_).must_equal(true) }
11
+ it { Vedeu.bound?(:_focus_next_).must_equal(true) }
12
+ it { Vedeu.bound?(:_focus_prev_).must_equal(true) }
13
+ end
14
+
15
+ end # Focus
16
+
17
+ end # Bindings
18
+
19
+ end # Vedeu
@@ -0,0 +1,19 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Bindings
6
+
7
+ describe Refresh do
8
+
9
+ context 'the system events needed by Vedeu to run are defined' do
10
+ it { Vedeu.bound?(:_refresh_).must_equal(true) }
11
+ it { Vedeu.bound?(:_refresh_cursor_).must_equal(true) }
12
+ it { Vedeu.bound?(:_refresh_group_).must_equal(true) }
13
+ end
14
+
15
+ end # Refresh
16
+
17
+ end # Bindings
18
+
19
+ end # Vedeu
@@ -10,18 +10,13 @@ module Vedeu
10
10
  it { Vedeu.bound?(:_cleanup_).must_equal(true) }
11
11
  it { Vedeu.bound?(:_clear_).must_equal(true) }
12
12
  it { Vedeu.bound?(:_command_).must_equal(true) }
13
+ it { Vedeu.bound?(:_editor_).must_equal(true) }
13
14
  it { Vedeu.bound?(:_exit_).must_equal(true) }
14
- it { Vedeu.bound?(:_focus_by_name_).must_equal(true) }
15
- it { Vedeu.bound?(:_focus_next_).must_equal(true) }
16
- it { Vedeu.bound?(:_focus_prev_).must_equal(true) }
17
15
  it { Vedeu.bound?(:_initialize_).must_equal(true) }
18
16
  it { Vedeu.bound?(:_keypress_).must_equal(true) }
19
17
  it { Vedeu.bound?(:_log_).must_equal(true) }
20
18
  it { Vedeu.bound?(:_maximise_).must_equal(true) }
21
19
  it { Vedeu.bound?(:_mode_switch_).must_equal(true) }
22
- it { Vedeu.bound?(:_refresh_).must_equal(true) }
23
- it { Vedeu.bound?(:_refresh_cursor_).must_equal(true) }
24
- it { Vedeu.bound?(:_refresh_group_).must_equal(true) }
25
20
  it { Vedeu.bound?(:_resize_).must_equal(true) }
26
21
  it { Vedeu.bound?(:_unmaximise_).must_equal(true) }
27
22
  end