termplot 0.2.1 → 0.3.0

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.
Files changed (61) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/README.md +124 -54
  4. data/Rakefile +27 -14
  5. data/doc/dash.png +0 -0
  6. data/doc/demo.png +0 -0
  7. data/doc/file.png +0 -0
  8. data/doc/memory.png +0 -0
  9. data/doc/ping.png +0 -0
  10. data/doc/sin.png +0 -0
  11. data/doc/tcp.png +0 -0
  12. data/examples/sample.rb +17 -0
  13. data/lib/termplot/character_map.rb +15 -4
  14. data/lib/termplot/cli.rb +16 -3
  15. data/lib/termplot/colors.rb +7 -0
  16. data/lib/termplot/commands.rb +27 -0
  17. data/lib/termplot/consumers.rb +12 -0
  18. data/lib/termplot/consumers/base_consumer.rb +132 -0
  19. data/lib/termplot/consumers/command_consumer.rb +14 -0
  20. data/lib/termplot/consumers/multi_source_consumer.rb +33 -0
  21. data/lib/termplot/consumers/single_source_consumer.rb +36 -0
  22. data/lib/termplot/consumers/stdin_consumer.rb +11 -0
  23. data/lib/termplot/cursors/buffered_console_cursor.rb +1 -1
  24. data/lib/termplot/cursors/virtual_cursor.rb +4 -0
  25. data/lib/termplot/dsl/panels.rb +80 -0
  26. data/lib/termplot/dsl/widgets.rb +128 -0
  27. data/lib/termplot/file_config.rb +37 -0
  28. data/lib/termplot/message_broker.rb +108 -0
  29. data/lib/termplot/options.rb +100 -20
  30. data/lib/termplot/positioned_widget.rb +8 -0
  31. data/lib/termplot/producer_options.rb +3 -0
  32. data/lib/termplot/producers.rb +3 -3
  33. data/lib/termplot/producers/base_producer.rb +12 -15
  34. data/lib/termplot/producers/command_producer.rb +25 -9
  35. data/lib/termplot/producers/stdin_producer.rb +1 -4
  36. data/lib/termplot/renderable.rb +35 -0
  37. data/lib/termplot/renderer.rb +16 -257
  38. data/lib/termplot/renderers.rb +6 -0
  39. data/lib/termplot/renderers/border_renderer.rb +48 -0
  40. data/lib/termplot/renderers/text_renderer.rb +73 -0
  41. data/lib/termplot/shell.rb +13 -9
  42. data/lib/termplot/utils/ansi_safe_string.rb +68 -0
  43. data/lib/termplot/version.rb +1 -1
  44. data/lib/termplot/widget_dsl.rb +130 -0
  45. data/lib/termplot/widgets.rb +8 -0
  46. data/lib/termplot/widgets/base_widget.rb +79 -0
  47. data/lib/termplot/widgets/border.rb +6 -0
  48. data/lib/termplot/widgets/dataset.rb +50 -0
  49. data/lib/termplot/widgets/histogram_widget.rb +196 -0
  50. data/lib/termplot/widgets/statistics.rb +21 -0
  51. data/lib/termplot/widgets/statistics_widget.rb +104 -0
  52. data/lib/termplot/widgets/time_series_widget.rb +248 -0
  53. data/lib/termplot/window.rb +25 -5
  54. data/termplot.gemspec +1 -6
  55. metadata +36 -24
  56. data/doc/MSFT.png +0 -0
  57. data/doc/cpu.png +0 -0
  58. data/doc/demo.cast +0 -638
  59. data/lib/termplot/consumer.rb +0 -75
  60. data/lib/termplot/cursors/console_cursor.rb +0 -57
  61. data/lib/termplot/series.rb +0 -37
@@ -1,75 +0,0 @@
1
- require "termplot/series"
2
- require "termplot/renderer"
3
- require "termplot/shell"
4
- require "termplot/producers"
5
-
6
- module Termplot
7
- class Consumer
8
- attr_reader :options, :series, :renderer
9
-
10
- def initialize(options)
11
- @options = options
12
- @renderer = Renderer.new(
13
- cols: options.cols,
14
- rows: options.rows,
15
- debug: options.debug
16
- )
17
- @series = Series.new(
18
- title: options.title,
19
- max_data_points: renderer.inner_width,
20
- line_style: options.line_style,
21
- color: options.color,
22
- )
23
- end
24
-
25
- def run
26
- Shell.init
27
- queue = Queue.new
28
-
29
- # Consumer thread will process and render any available input in the
30
- # queue. If samples are available faster than it can render, multiple
31
- # samples will be shifted from the queue so they can be rendered at once.
32
- # If no samples are available but the queue is open, it will sleep until
33
- # woken to render new input.
34
- consumer = Thread.new do
35
- while !queue.closed?
36
- num_samples = queue.size
37
- if num_samples == 0
38
- Thread.stop
39
- else
40
- num_samples.times do
41
- series.add_point(queue.shift)
42
- end
43
-
44
- renderer.render(series)
45
- series.max_data_points = renderer.inner_width
46
- end
47
- end
48
- end
49
-
50
- # Producer will run in the main thread and will block while producing
51
- # samples from some source (which depends on the type of producer).
52
- # Samples will be added to the queue as they are available, and the
53
- # consumer will be woken to check the queue
54
- producer = build_producer(queue)
55
- producer.register_consumer(consumer)
56
- producer.run
57
-
58
- # As soon as producer continues, and we first give the consumer a chance
59
- # to finish rendering the queue, then close the queue.
60
- consumer.run
61
- producer.close
62
- consumer.join
63
- end
64
-
65
- private
66
-
67
- def build_producer(queue)
68
- producer_class = {
69
- command: "Termplot::Producers::CommandProducer",
70
- stdin: "Termplot::Producers::StdinProducer"
71
- }.fetch(options.mode)
72
- Object.const_get(producer_class).new(queue, options)
73
- end
74
- end
75
- end
@@ -1,57 +0,0 @@
1
- require "termplot/control_chars"
2
-
3
- module Termplot
4
- module Cursors
5
- class ConsoleCursor < VirtualCursor
6
- include Termplot::ControlChars
7
-
8
- def write(char)
9
- if writeable?
10
- print(char)
11
- super(char)
12
- end
13
- end
14
-
15
- def forward(n = 1)
16
- moved = super(n)
17
- moved.times { print FORWARD }
18
- end
19
-
20
- def back(n = 1)
21
- moved = super(n)
22
- moved.times { print BACK }
23
- end
24
-
25
- def up(n=1)
26
- moved = super(n)
27
- moved.times { print UP }
28
- end
29
-
30
- def down(n=1)
31
- moved = super(n)
32
- moved.times { print DOWN }
33
- end
34
-
35
- def beginning_of_line
36
- super
37
- print CR
38
- end
39
-
40
- def new_line
41
- print NEWLINE
42
- end
43
-
44
- def position=()
45
- raise "Cannot set cursor position directly"
46
- end
47
-
48
- def row=()
49
- raise "Cannot set cursor position directly"
50
- end
51
-
52
- def col=()
53
- raise "Cannot set cursor position directly"
54
- end
55
- end
56
- end
57
- end
@@ -1,37 +0,0 @@
1
- module Termplot
2
- class Series
3
- attr_reader :title, :data, :min, :max, :range, :color, :line_style
4
- attr_accessor :max_data_points
5
-
6
- DEFAULT_COLOR = "red"
7
- DEFAULT_LINE_STYLE = "line"
8
-
9
- def initialize(max_data_points:, title: "Series", color: DEFAULT_COLOR, line_style: DEFAULT_LINE_STYLE)
10
- @data = []
11
- @max_data_points = max_data_points
12
- @min = 0
13
- @max = 0
14
- @range = 0
15
-
16
- @title = title
17
- @color = Termplot::Colors.fetch(color, DEFAULT_COLOR)
18
- @line_style = Termplot::CharacterMap::LINE_STYLES.fetch(
19
- line_style,
20
- Termplot::CharacterMap::LINE_STYLES[DEFAULT_LINE_STYLE]
21
- )
22
- end
23
-
24
- def add_point(point)
25
- @data.push(point)
26
-
27
- while @data.length > max_data_points do
28
- @data.shift
29
- end
30
-
31
- @min = data.min
32
- @max = data.max
33
- @range = (max - min).abs
34
- @range = 1 if range.zero?
35
- end
36
- end
37
- end