termplot 0.1.0 → 0.3.1

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 (62) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/README.md +134 -58
  4. data/Rakefile +28 -13
  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 +14 -48
  15. data/lib/termplot/colors.rb +36 -29
  16. data/lib/termplot/commands.rb +27 -0
  17. data/lib/termplot/consumers/base_consumer.rb +132 -0
  18. data/lib/termplot/consumers/command_consumer.rb +14 -0
  19. data/lib/termplot/consumers/multi_source_consumer.rb +33 -0
  20. data/lib/termplot/consumers/single_source_consumer.rb +36 -0
  21. data/lib/termplot/consumers/stdin_consumer.rb +11 -0
  22. data/lib/termplot/consumers.rb +12 -0
  23. data/lib/termplot/{cursors/control_chars.rb → control_chars.rb} +0 -0
  24. data/lib/termplot/cursors/buffered_console_cursor.rb +51 -52
  25. data/lib/termplot/cursors/virtual_cursor.rb +64 -58
  26. data/lib/termplot/cursors.rb +7 -0
  27. data/lib/termplot/dsl/panels.rb +80 -0
  28. data/lib/termplot/dsl/widgets.rb +128 -0
  29. data/lib/termplot/file_config.rb +37 -0
  30. data/lib/termplot/message_broker.rb +111 -0
  31. data/lib/termplot/options.rb +211 -0
  32. data/lib/termplot/positioned_widget.rb +8 -0
  33. data/lib/termplot/producer_options.rb +3 -0
  34. data/lib/termplot/producers/base_producer.rb +32 -0
  35. data/lib/termplot/producers/command_producer.rb +42 -0
  36. data/lib/termplot/producers/stdin_producer.rb +11 -0
  37. data/lib/termplot/producers.rb +7 -0
  38. data/lib/termplot/renderable.rb +35 -0
  39. data/lib/termplot/renderer.rb +16 -257
  40. data/lib/termplot/renderers/border_renderer.rb +48 -0
  41. data/lib/termplot/renderers/text_renderer.rb +73 -0
  42. data/lib/termplot/renderers.rb +6 -0
  43. data/lib/termplot/shell.rb +13 -9
  44. data/lib/termplot/utils/ansi_safe_string.rb +68 -0
  45. data/lib/termplot/version.rb +1 -1
  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/widgets.rb +8 -0
  54. data/lib/termplot/window.rb +29 -9
  55. data/termplot.gemspec +1 -6
  56. metadata +46 -30
  57. data/doc/cpu.png +0 -0
  58. data/doc/demo.cast +0 -638
  59. data/doc/demo.gif +0 -0
  60. data/lib/termplot/consumer.rb +0 -71
  61. data/lib/termplot/cursors/console_cursor.rb +0 -56
  62. data/lib/termplot/series.rb +0 -37
data/doc/demo.gif DELETED
Binary file
@@ -1,71 +0,0 @@
1
- require "termplot/series"
2
- require "termplot/renderer"
3
- require "termplot/shell"
4
-
5
- module Termplot
6
- class Consumer
7
- attr_reader :series, :renderer
8
-
9
- def initialize(cols:, rows:, title:, line_style:, color:, debug:)
10
- @renderer = Renderer.new(
11
- cols: cols,
12
- rows: rows,
13
- debug: debug
14
- )
15
- @series = Series.new(
16
- title: title,
17
- max_data_points: renderer.inner_width,
18
- line_style: line_style,
19
- color: color,
20
- )
21
- end
22
-
23
- def run
24
- Shell.init
25
- queue = Queue.new
26
-
27
- # Consumer thread will process and render any available input in the
28
- # queue. If samples are available faster than it can render, multiple
29
- # samples will be shifted from the queue so they can be rendered at once.
30
- # If no samples are available but stdin is open, it will sleep until
31
- # woken to render new input.
32
- consumer = Thread.new do
33
- while !queue.closed?
34
- num_samples = queue.size
35
- if num_samples == 0
36
- Thread.stop
37
- else
38
- num_samples.times do
39
- series.add_point(queue.shift)
40
- end
41
-
42
- renderer.render(series)
43
- series.max_data_points = renderer.inner_width
44
- end
45
- end
46
- end
47
-
48
- # Main thread will accept samples as fast as they become available from stdin,
49
- # and wake the consumer thread to process them if its asleep
50
- while n = STDIN.gets&.chomp do
51
- if numeric?(n)
52
- queue << n.to_f
53
- consumer.run
54
- end
55
- end
56
-
57
- # Queue is closed as soon as stdin is closed, and we wait for the consumer
58
- # to finish rendering
59
- queue.close
60
- consumer.run
61
- consumer.join
62
- end
63
-
64
- private
65
-
66
- FLOAT_REGEXP = /^[-+]?[0-9]*\.?[0-9]+$/
67
- def numeric?(n)
68
- n =~ FLOAT_REGEXP
69
- end
70
- end
71
- end
@@ -1,56 +0,0 @@
1
- require "termplot/cursors/virtual_cursor"
2
- require "termplot/cursors/control_chars"
3
-
4
- module Termplot
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
@@ -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