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.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/README.md +134 -58
- data/Rakefile +28 -13
- data/doc/dash.png +0 -0
- data/doc/demo.png +0 -0
- data/doc/file.png +0 -0
- data/doc/memory.png +0 -0
- data/doc/ping.png +0 -0
- data/doc/sin.png +0 -0
- data/doc/tcp.png +0 -0
- data/examples/sample.rb +17 -0
- data/lib/termplot/character_map.rb +15 -4
- data/lib/termplot/cli.rb +14 -48
- data/lib/termplot/colors.rb +36 -29
- data/lib/termplot/commands.rb +27 -0
- data/lib/termplot/consumers/base_consumer.rb +132 -0
- data/lib/termplot/consumers/command_consumer.rb +14 -0
- data/lib/termplot/consumers/multi_source_consumer.rb +33 -0
- data/lib/termplot/consumers/single_source_consumer.rb +36 -0
- data/lib/termplot/consumers/stdin_consumer.rb +11 -0
- data/lib/termplot/consumers.rb +12 -0
- data/lib/termplot/{cursors/control_chars.rb → control_chars.rb} +0 -0
- data/lib/termplot/cursors/buffered_console_cursor.rb +51 -52
- data/lib/termplot/cursors/virtual_cursor.rb +64 -58
- data/lib/termplot/cursors.rb +7 -0
- data/lib/termplot/dsl/panels.rb +80 -0
- data/lib/termplot/dsl/widgets.rb +128 -0
- data/lib/termplot/file_config.rb +37 -0
- data/lib/termplot/message_broker.rb +111 -0
- data/lib/termplot/options.rb +211 -0
- data/lib/termplot/positioned_widget.rb +8 -0
- data/lib/termplot/producer_options.rb +3 -0
- data/lib/termplot/producers/base_producer.rb +32 -0
- data/lib/termplot/producers/command_producer.rb +42 -0
- data/lib/termplot/producers/stdin_producer.rb +11 -0
- data/lib/termplot/producers.rb +7 -0
- data/lib/termplot/renderable.rb +35 -0
- data/lib/termplot/renderer.rb +16 -257
- data/lib/termplot/renderers/border_renderer.rb +48 -0
- data/lib/termplot/renderers/text_renderer.rb +73 -0
- data/lib/termplot/renderers.rb +6 -0
- data/lib/termplot/shell.rb +13 -9
- data/lib/termplot/utils/ansi_safe_string.rb +68 -0
- data/lib/termplot/version.rb +1 -1
- data/lib/termplot/widgets/base_widget.rb +79 -0
- data/lib/termplot/widgets/border.rb +6 -0
- data/lib/termplot/widgets/dataset.rb +50 -0
- data/lib/termplot/widgets/histogram_widget.rb +196 -0
- data/lib/termplot/widgets/statistics.rb +21 -0
- data/lib/termplot/widgets/statistics_widget.rb +104 -0
- data/lib/termplot/widgets/time_series_widget.rb +248 -0
- data/lib/termplot/widgets.rb +8 -0
- data/lib/termplot/window.rb +29 -9
- data/termplot.gemspec +1 -6
- metadata +46 -30
- data/doc/cpu.png +0 -0
- data/doc/demo.cast +0 -638
- data/doc/demo.gif +0 -0
- data/lib/termplot/consumer.rb +0 -71
- data/lib/termplot/cursors/console_cursor.rb +0 -56
- data/lib/termplot/series.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '068a1b08253b8e5993572546e7b73409b0ff5750a1aaa671d3d6c907b621128f'
|
4
|
+
data.tar.gz: a6ce340dac417d5999e7fd6018efd931731ecabcc2d894ff8430a5bd6c9d6bb3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe102cf42e2e1017ca2f3327c65847dbece92aeeea5de3c05b72e384bf3cfc6eb0dd602c7fa03585282ea747e88c167e8259e724ecbd30b64618c4dbce9ddc53
|
7
|
+
data.tar.gz: 13967f3be92508cc0fcc8dcc65eb9f0625ac359e30853ceaeed30e778863a7298eef38b55efe64d615ca61e9e37bcd781247c98b5e64967a46af9208deacf80c
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
# Termplot
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/termplot)
|
4
4
|
|
5
|
-
|
5
|
+
Termplot is a simple terminal plotting tool for visualising streaming data.
|
6
6
|
|
7
|
-
|
7
|
+

|
8
8
|
|
9
9
|
## Overview
|
10
10
|
|
11
|
-
Termplot draws
|
12
|
-
|
13
|
-
|
11
|
+
Termplot draws live plots of data in your terminal. It's handy for quickly
|
12
|
+
visualising streaming data and works with any numeric data you can pipe into
|
13
|
+
stdin or otherwise obtain by running a shell command.
|
14
14
|
|
15
15
|
## Installation
|
16
16
|
|
@@ -20,83 +20,158 @@ The tool is a ruby gem and can be installed with:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
There are 3 ways to provide input to termplot:
|
24
|
+
- **Stdin:** Pipe data into standard input
|
25
|
+
- **Command:** Specify a command to be ran at an interval
|
26
|
+
- **Configuration file:** Read a multi-chart configuration from a file
|
27
|
+
|
28
|
+
### Pipe data into standard input
|
29
|
+
```
|
30
|
+
COMMAND | termplot [OPTIONS]
|
31
|
+
```
|
32
|
+
|
33
|
+
`COMMAND` is any command that will periodically output numbers to standard out
|
34
|
+
delimited by a newline. These will be consumed by termplot and drawn to a chart.
|
24
35
|
|
36
|
+
You can specify the following options (all are optional):
|
25
37
|
```
|
26
|
-
|
38
|
+
-r, --rows ROWS Number of rows in the chart window (default: 19)
|
39
|
+
-c, --cols COLS Number of cols in the chart window (default: 100)
|
40
|
+
--full-screen Render to the full available terminal size
|
41
|
+
|
42
|
+
--type TYPE The type of chart to render.
|
43
|
+
Options are: timeseries (default), stats, hist
|
44
|
+
|
45
|
+
--timeseries Shorthand for --type timeseries
|
46
|
+
--stats Shorthand for --type stats
|
47
|
+
--hist Shorthand for --type hist
|
48
|
+
|
49
|
+
-t, --title TITLE Title of the series (default: 'Series')
|
50
|
+
--color COLOR Series color, specified as ansi 16-bit color name:
|
51
|
+
(i.e. black, light_black, red, light_red,
|
52
|
+
green (default), light_green, yellow,
|
53
|
+
light_yellow, blue, light_blue, magenta,
|
54
|
+
light_magenta, cyan, light_cyan, white,
|
55
|
+
light_white, default)
|
56
|
+
|
57
|
+
--line-style STYLE Line style.
|
58
|
+
Options are: line, heavy-line (default), dot, star, x, bar
|
27
59
|
```
|
28
60
|
|
29
|
-
|
30
|
-
delimited by a newline. Options and examples are given below. All command line
|
31
|
-
options are optional.
|
61
|
+
#### Examples
|
32
62
|
|
33
|
-
|
63
|
+
##### Plot a sine wave from standard in:
|
34
64
|
|
35
65
|
```
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
66
|
+
for i in $(seq 500); do \
|
67
|
+
echo $i | awk '{ print sin($0/10) }'; \
|
68
|
+
sleep 0.5; \
|
69
|
+
done | termplot -t "Sin(x)" --color red
|
70
|
+
```
|
71
|
+

|
40
72
|
|
41
|
-
|
42
|
-
|
73
|
+
##### Plot histogram of network times as reported by `ping`:
|
74
|
+
```
|
75
|
+
ping example.com |
|
76
|
+
awk '{ split($8,arr,"="); print arr[2]; fflush("/dev/stdout") }' |
|
77
|
+
termplot -t "Ping Response Times (ms)" --hist
|
78
|
+
```
|
79
|
+

|
80
|
+
|
81
|
+
##### Plot histogram of data from column 33 of a CSV file:
|
82
|
+
```
|
83
|
+
cat file.csv | cut -d, -f33 | tail -n +2 |
|
84
|
+
termplot -- --hist -r30 -t "Data" --color light_black
|
85
|
+
```
|
86
|
+

|
43
87
|
|
44
|
-
--color COLOR Series color, specified as ansi 16-bit color name:
|
45
|
-
(i.e. black, red [default], green, yellow, blue,
|
46
|
-
magenta, cyan, white). Light versions are specified
|
47
|
-
as light_{color}
|
48
88
|
|
49
|
-
|
89
|
+
### Run command at an interval
|
90
|
+
To run a command at an interval, specify `--command`, and optionally
|
91
|
+
`--interval` to termplot:
|
92
|
+
```
|
93
|
+
termplot --command 'COMMAND' --interval INTERVAL [OPTIONS]
|
50
94
|
```
|
51
95
|
|
52
|
-
|
96
|
+
`COMMAND` will be invoked at the specified interval in milliseconds (default:
|
97
|
+
1000) and its output will be used as the data for the chart. You can specify all
|
98
|
+
the same additional options as in stdin mode above.
|
53
99
|
|
54
|
-
|
100
|
+
#### Examples
|
101
|
+
##### Plot number of TCP connections over time:
|
55
102
|
|
56
103
|
```
|
57
|
-
|
58
|
-
|
59
|
-
sleep 0.5; \
|
60
|
-
done | termplot -t "Sin(x)"
|
104
|
+
termplot --command 'ss -s | head -n1 | cut -d" " -f2' \
|
105
|
+
--interval 500 -t "TCP Connections"
|
61
106
|
```
|
62
|
-

|
108
|
+
|
109
|
+
##### Plot memory usage of process with PID 4396:
|
63
110
|
|
64
|
-
Total % memory usage:
|
65
111
|
```
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
112
|
+
termplot --command "ps -q 4396 -o rss= | awk '{ print (\$0/1024.0) }'" \
|
113
|
+
-t "Process 4396 Memory (MB)" --color light_magenta
|
114
|
+
```
|
115
|
+

|
116
|
+
|
117
|
+
### Specify a multi-chart configuration
|
118
|
+
You can configure termplot to set up a multi-chart dashboard using a ruby
|
119
|
+
configuration file:
|
120
|
+
|
121
|
+
```
|
122
|
+
termplot [--file/-f] FILE
|
70
123
|
```
|
71
|
-

|
72
124
|
|
73
|
-
|
125
|
+
The configuration file uses a simple ruby DSL to arrange charts into rows and
|
126
|
+
columns. Each chart will take a command and optionally an interval as well as
|
127
|
+
formatting options. Termplot will then run the command at the specified interval
|
128
|
+
and render the resulting data into the charts.
|
129
|
+
|
130
|
+
#### Example
|
131
|
+
|
132
|
+
File (sample.rb):
|
133
|
+
```ruby
|
134
|
+
col do
|
135
|
+
row do
|
136
|
+
cpu_command =
|
137
|
+
"top -b -n 1 | awk -F',' 'NR==3{ split($4, arr, \" \"); print 100.0 - arr[1] }'"
|
138
|
+
|
139
|
+
histogram title: "CPU (%)", command: cpu_command, color: "light_cyan"
|
140
|
+
timeseries title: "CPU (%)", command: cpu_command, color: "light_cyan"
|
141
|
+
statistics title: "CPU (%)", command: cpu_command
|
142
|
+
end
|
143
|
+
|
144
|
+
row do
|
145
|
+
memory_command = "free | awk 'NR==2 { print ($3/$2) * 100 }'"
|
146
|
+
|
147
|
+
histogram title: "Memory (%)", command: memory_command, color: "light_magenta"
|
148
|
+
timeseries title: "Memory (%)", command: memory_command, color: "light_magenta"
|
149
|
+
statistics title: "Memory (%)", command: memory_command
|
150
|
+
end
|
151
|
+
end
|
74
152
|
```
|
75
|
-
|
76
|
-
ps au | grep puma | awk 'NR==1{ print $3 }'; \
|
77
|
-
sleep 0.5; \
|
78
|
-
done | termplot -t "Ruby CPU(%)" --color yellow --line-style dot -r10 -c 120
|
153
|
+
Run it with:
|
79
154
|
```
|
80
|
-
|
155
|
+
termplot -f sample.rb --cols 150 --rows 20
|
156
|
+
```
|
157
|
+
|
158
|
+
Result:
|
159
|
+

|
81
160
|
|
82
161
|
|
83
162
|
## Notes
|
84
163
|
|
85
|
-
-
|
164
|
+
- Termplot should work just fine if you have a monospaced unicode font.
|
86
165
|
Tested on linux, and should work on MacOS too. Not too sure about windows.
|
87
|
-
-
|
88
|
-
temporal spacing. So even if the time between samples is
|
89
|
-
will be plotted with the same amount of space between them.
|
90
|
-
- The `while true; do {...}; sleep INTERVAL` is pretty typical, I would like to
|
91
|
-
sometime soon implement a `--command "{...}" --interval INTERVAL` which would
|
92
|
-
reduce some of the boilerplate of calling some command at an interval and make
|
93
|
-
it easy to watch and plot.
|
166
|
+
- On timeseries plots, samples received are plotted in sequence order, and there
|
167
|
+
is no notion of temporal spacing. So even if the time between samples is
|
168
|
+
inconsistent, they will be plotted with the same amount of space between them.
|
94
169
|
|
95
|
-
## Background
|
170
|
+
## Background
|
96
171
|
|
97
|
-
I
|
98
|
-
linux machine. I could get the data I needed from `ss` with some text
|
99
|
-
but I didn't have a quick and easy way to eyeball the overall trend.
|
172
|
+
A while back I needed to be able to monitor the number of open TCP connections
|
173
|
+
on my linux machine. I could get the data I needed from `ss` with some text
|
174
|
+
processing but I didn't have a quick and easy way to eyeball the overall trend.
|
100
175
|
|
101
176
|
I mainly work with ruby, so taking
|
102
177
|
inspiration from fantastic libraries like [Unicode Plots
|
@@ -107,12 +182,13 @@ ruby.
|
|
107
182
|
Now with termplot, it's as easy as:
|
108
183
|
|
109
184
|
```
|
110
|
-
|
111
|
-
ss -s | head -n1 | cut -d ' ' -f2; sleep 1; \
|
112
|
-
done | termplot -t "TCP Connections"
|
185
|
+
termplot --command 'ss -s | head -n1 | cut -d" " -f2' --interval 500 -t "TCP Connections"
|
113
186
|
```
|
114
187
|
|
115
|
-

|
189
|
+
|
190
|
+
In the end termplot turned out to be useful for all sorts of command line
|
191
|
+
visualisation tasks.
|
116
192
|
|
117
193
|
## Development
|
118
194
|
|
data/Rakefile
CHANGED
@@ -1,18 +1,33 @@
|
|
1
|
+
require_relative "./lib/termplot/commands"
|
1
2
|
require "bundler/gem_tasks"
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
exec "bin/termplot", *ARGV[2..-1]
|
6
|
-
end
|
4
|
+
extend Termplot::Commands
|
5
|
+
extend Termplot::StdinCommands
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
do
|
12
|
-
echo $i | awk '{ print sin($0/10)* 10; fflush("/dev/stdout") }';
|
13
|
-
sleep 0.1;
|
14
|
-
done | ruby -Ilib bin/termplot -- -t 'sin(x)'
|
15
|
-
CMD
|
16
|
-
exec cmd
|
7
|
+
SAMPLE_FILES_PATH = "examples"
|
8
|
+
def termplot_binary
|
9
|
+
"ruby -Ilib bin/termplot"
|
17
10
|
end
|
18
11
|
|
12
|
+
namespace :test do
|
13
|
+
task :bin do
|
14
|
+
exec "ruby", "-Ilib", "bin/termplot", *ARGV[2..-1]
|
15
|
+
end
|
16
|
+
|
17
|
+
task :file do
|
18
|
+
cmd = %( #{termplot_binary} -f #{File.join(SAMPLE_FILES_PATH, ARGV[2])} #{ARGV[3..-1].join(" ")})
|
19
|
+
exec cmd
|
20
|
+
end
|
21
|
+
|
22
|
+
namespace :timeseries do
|
23
|
+
task :sin do
|
24
|
+
cmd = "#{sin(500)} | #{termplot_binary} -t 'sin(x)'"
|
25
|
+
exec cmd
|
26
|
+
end
|
27
|
+
|
28
|
+
task :random do
|
29
|
+
cmd = %( #{termplot_binary} --command '#{random}' --interval 900% )
|
30
|
+
exec cmd
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/doc/dash.png
ADDED
Binary file
|
data/doc/demo.png
ADDED
Binary file
|
data/doc/file.png
ADDED
Binary file
|
data/doc/memory.png
CHANGED
Binary file
|
data/doc/ping.png
ADDED
Binary file
|
data/doc/sin.png
CHANGED
Binary file
|
data/doc/tcp.png
CHANGED
Binary file
|
data/examples/sample.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
col do
|
2
|
+
row do
|
3
|
+
cpu_command = "top -b -n 1 | awk -F',' 'NR==3{ split($4, arr, \" \"); print 100.0 - arr[1] }'"
|
4
|
+
|
5
|
+
histogram title: "CPU (%)", command: cpu_command, color: "light_cyan"
|
6
|
+
timeseries title: "CPU (%)", command: cpu_command, color: "light_cyan"
|
7
|
+
statistics title: "CPU (%)", command: cpu_command
|
8
|
+
end
|
9
|
+
|
10
|
+
row do
|
11
|
+
memory_command = "free | awk 'NR==2 { print ($3/$2) * 100 }'"
|
12
|
+
|
13
|
+
histogram title: "Memory (%)", command: memory_command, color: "light_magenta"
|
14
|
+
timeseries title: "Memory (%)", command: memory_command, color: "light_magenta"
|
15
|
+
statistics title: "Memory (%)", command: memory_command
|
16
|
+
end
|
17
|
+
end
|
@@ -12,7 +12,9 @@ module Termplot
|
|
12
12
|
top_left: "┌",
|
13
13
|
bot_right: "┘",
|
14
14
|
tick_right: "┤",
|
15
|
-
|
15
|
+
tick_left: "├",
|
16
|
+
extended: true,
|
17
|
+
filled: false
|
16
18
|
}
|
17
19
|
DEFAULT = LINE
|
18
20
|
|
@@ -26,13 +28,15 @@ module Termplot
|
|
26
28
|
top_right: "┓",
|
27
29
|
top_left: "┏",
|
28
30
|
bot_right: "┛",
|
29
|
-
tick_right: "┫"
|
31
|
+
tick_right: "┫",
|
32
|
+
tick_left: "┣",
|
30
33
|
)
|
31
34
|
|
32
35
|
BASIC = {
|
33
36
|
empty: " ",
|
34
37
|
point: "•",
|
35
|
-
extended: false
|
38
|
+
extended: false,
|
39
|
+
filled: false
|
36
40
|
}
|
37
41
|
DOTS = BASIC
|
38
42
|
|
@@ -44,12 +48,19 @@ module Termplot
|
|
44
48
|
point: "*"
|
45
49
|
)
|
46
50
|
|
51
|
+
BAR = LINE.merge(
|
52
|
+
point: "▄",
|
53
|
+
extended: false,
|
54
|
+
filled: true
|
55
|
+
)
|
56
|
+
|
47
57
|
LINE_STYLES = {
|
48
58
|
"line" => LINE,
|
49
59
|
"heavy-line" => HEAVY_LINE,
|
50
60
|
"dot" => DOTS,
|
51
61
|
"star" => STAR,
|
52
|
-
"x" => X
|
62
|
+
"x" => X,
|
63
|
+
"bar" => BAR,
|
53
64
|
}
|
54
65
|
end
|
55
66
|
end
|
data/lib/termplot/cli.rb
CHANGED
@@ -1,59 +1,25 @@
|
|
1
|
-
|
2
|
-
require "termplot/
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require "termplot/options"
|
3
|
+
require "termplot/consumers"
|
3
4
|
|
4
5
|
module Termplot
|
5
6
|
class CLI
|
6
7
|
def self.run
|
7
|
-
|
8
|
-
|
8
|
+
options = Termplot::Options.new
|
9
|
+
options.parse_options!
|
10
|
+
run_consumer(options)
|
9
11
|
end
|
10
12
|
|
11
13
|
private
|
12
|
-
def self.parse_options
|
13
|
-
options = {
|
14
|
-
rows: 19,
|
15
|
-
cols: 80,
|
16
|
-
title: "Series",
|
17
|
-
line_style: "line",
|
18
|
-
color: "red",
|
19
|
-
debug: false
|
20
|
-
}
|
21
|
-
OptionParser.new do |opts|
|
22
|
-
opts.banner = "Usage: termplot [OPTIONS]"
|
23
14
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
opts.on("-tTITLE", "--title TITLE", "Title of the series (default: Series)") do |v|
|
33
|
-
options[:title] = v
|
34
|
-
end
|
35
|
-
|
36
|
-
opts.on("--line-style STYLE", "Line style. Options are: line [default], heavy-line, dot, star, x") do |v|
|
37
|
-
options[:line_style] = v.downcase
|
38
|
-
end
|
39
|
-
|
40
|
-
opts.on("--color COLOR", "Series color, specified as ansi 16-bit color name",
|
41
|
-
"(i.e. black, red [default], green, yellow, blue, magenta, cyan, white)",
|
42
|
-
"with light versions specified as light_{color}") do |v|
|
43
|
-
options[:color] = v.downcase
|
44
|
-
end
|
45
|
-
|
46
|
-
opts.on("-d", "--debug", "Enable debug mode, Logs window data to stdout instead of rendering") do |v|
|
47
|
-
options[:debug] = v
|
48
|
-
end
|
49
|
-
|
50
|
-
opts.on("-h", "--help", "Display this help message") do
|
51
|
-
puts opts
|
52
|
-
exit(0)
|
53
|
-
end
|
54
|
-
|
55
|
-
end.parse!
|
56
|
-
options
|
15
|
+
CONSUMERS = {
|
16
|
+
file: "Termplot::Consumers::MultiSourceConsumer",
|
17
|
+
command: "Termplot::Consumers::CommandConsumer",
|
18
|
+
stdin: "Termplot::Consumers::StdinConsumer",
|
19
|
+
}
|
20
|
+
def self.run_consumer(options)
|
21
|
+
consumer = Object.const_get(CONSUMERS[options.input_mode])
|
22
|
+
consumer.new(options).run
|
57
23
|
end
|
58
24
|
end
|
59
25
|
end
|
data/lib/termplot/colors.rb
CHANGED
@@ -1,40 +1,43 @@
|
|
1
1
|
module Termplot
|
2
2
|
class Colors
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
}
|
3
|
+
COLORS = {
|
4
|
+
black: 0,
|
5
|
+
light_black: 60,
|
6
|
+
red: 1,
|
7
|
+
light_red: 61,
|
8
|
+
green: 2,
|
9
|
+
light_green: 62,
|
10
|
+
yellow: 3,
|
11
|
+
light_yellow: 63,
|
12
|
+
blue: 4,
|
13
|
+
light_blue: 64,
|
14
|
+
magenta: 5,
|
15
|
+
light_magenta: 65,
|
16
|
+
cyan: 6,
|
17
|
+
light_cyan: 66,
|
18
|
+
white: 7,
|
19
|
+
light_white: 67,
|
20
|
+
default: 9
|
21
|
+
}
|
23
22
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
23
|
+
MODES = {
|
24
|
+
default: 0,
|
25
|
+
bold: 1,
|
26
|
+
italic: 3,
|
27
|
+
underline: 4,
|
28
|
+
blink: 5,
|
29
|
+
swap: 7,
|
30
|
+
hide: 8
|
31
|
+
}
|
33
32
|
|
33
|
+
class << self
|
34
34
|
COLORS.each do |(color, code)|
|
35
35
|
define_method(color) do |str|
|
36
36
|
escape_color(color) + str + escape_mode(:default)
|
37
37
|
end
|
38
|
+
define_method("#{color}_bg") do |str|
|
39
|
+
escape_bg_color(color) + str + escape_mode(:default)
|
40
|
+
end
|
38
41
|
end
|
39
42
|
|
40
43
|
def fetch(color, default)
|
@@ -47,6 +50,10 @@ module Termplot
|
|
47
50
|
"\e[#{COLORS[color] + 30}m"
|
48
51
|
end
|
49
52
|
|
53
|
+
def escape_bg_color(color)
|
54
|
+
"\e[#{COLORS[color] + 40}m"
|
55
|
+
end
|
56
|
+
|
50
57
|
def escape_mode(mode)
|
51
58
|
"\e[#{MODES[mode]}m"
|
52
59
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Termplot
|
2
|
+
module Commands
|
3
|
+
def random
|
4
|
+
"echo $RANDOM"
|
5
|
+
end
|
6
|
+
|
7
|
+
def memory
|
8
|
+
"free | awk 'NR==2 { print ($3/$2) * 100 }'"
|
9
|
+
end
|
10
|
+
|
11
|
+
def cpu
|
12
|
+
"top -b -n 1 | awk -F',' 'NR==3{ split($4, arr, \" \"); print 100.0 - arr[1] }'"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module StdinCommands
|
17
|
+
def sin(n)
|
18
|
+
<<-CMD.chomp
|
19
|
+
for i in $(seq #{n});
|
20
|
+
do
|
21
|
+
echo $i | awk '{ print sin($0/10)* 10; fflush("/dev/stdout") }';
|
22
|
+
sleep 0.1;
|
23
|
+
done
|
24
|
+
CMD
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|