termline 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: e8a666432b2c154e47a5a7eab4bf5000b82f757505ae7dc8d3e666f6d5e3348e
4
+ data.tar.gz: 474673368a2be027c630918b5e063c65d0439adf222ec541b1ecfd546c9475c1
5
+ SHA512:
6
+ metadata.gz: 5498fedb4fc8b12a28da46e142a188ff0251667704e3df0b02143932ebc14f95afb91df155715a5e93208fc59fd149cf301450428e6a84c2783e69845fe77bc8
7
+ data.tar.gz: 8365ae2a44b6857315d9d3006d4362747094a71c8375bb32745d1a70523354bd1173d06e8fcce30779c6264c4f4503a8be356cb46749f7d3de71752bc26211bd
@@ -0,0 +1,50 @@
1
+
2
+ module Termline
3
+ module Banner
4
+ def self.title title
5
+ width = WIDTH - title.length - 4
6
+ self.line(WIDTH/8)
7
+ puts title.rjust(width / 2)
8
+ self.line(WIDTH/8)
9
+ end
10
+
11
+ def self.infob *messages
12
+ puts(separator_pretty(:blue))
13
+ messages.each { |message| puts(pretty("INFO: #{ message }", :white, :blue)) }
14
+ puts(separator_pretty(:blue))
15
+ end
16
+
17
+ def self.successb *messages
18
+ puts(separator_pretty(:green))
19
+ messages.each { |message| puts(pretty("SUCCESS: #{ message }", :black, :green)) }
20
+ puts(separator_pretty(:green))
21
+ end
22
+
23
+ def self.warningb *messages
24
+ puts(separator_pretty(:yellow))
25
+ messages.each { |message| puts(pretty("WARNING: #{ message }", :black, :yellow)) }
26
+ puts(separator_pretty(:yellow))
27
+ end
28
+
29
+ def self.dangerb *messages
30
+ puts(separator_pretty(:red))
31
+ messages.each { |message| puts(pretty("ERROR: #{ message }", :yellow, :red)) }
32
+ puts(pretty("PATH: #{ caller[0] }", :yellow, :red))
33
+ puts(separator_pretty(:red))
34
+ end
35
+
36
+ def self.fatal *messages
37
+ puts(separator_pretty(:red))
38
+ messages.each { |message| puts("\e[5m#{pretty(message, :white, :red)}\e[0m") }
39
+ puts(pretty("PATH: #{ caller[0] }", :white, :red))
40
+ puts(separator_pretty(:red))
41
+ end
42
+
43
+
44
+ def self.deprecation message
45
+ puts(separator_pretty(:red))
46
+ puts(pretty("DEPRECATED METHOD: #{ caller[0] }, #{ message }", :white, :red))
47
+ puts(separator_pretty(:red))
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,64 @@
1
+
2
+
3
+ module Termline
4
+ module Config
5
+
6
+ ICONS = {
7
+ checkmark: "✓",
8
+ bullet: "•",
9
+ star: "★"
10
+ }.freeze
11
+
12
+ # standard color palette for texts
13
+ COLORS = {
14
+ skyblue: '96',
15
+ default: '38',
16
+ yellow: '1;33',
17
+ white: '1;37',
18
+ green: '32',
19
+ black: '30',
20
+ blue: '36',
21
+ red: '31'
22
+ }.freeze
23
+
24
+ # standard color palette for backgrounds
25
+ BG_COLORS = {
26
+ default: '0',
27
+ yellow: '103',
28
+ white: '107',
29
+ green: '42',
30
+ black: '40',
31
+ blue: '44',
32
+ red: '41'
33
+ }.freeze
34
+
35
+
36
+ # calculate the console width
37
+ # tputcols is not available on windows
38
+ #WIDTH = `tput cols`.to_i rescue WIDTH = 1;
39
+ WIDTH = begin
40
+ term = ENV['TERM']
41
+ term ? `tput cols`.to_i : 1
42
+ rescue
43
+ 1
44
+ end
45
+
46
+ def self.colorize(text, colour = :default, bg_colour = :default)
47
+ colour_code = COLORS[colour]
48
+ bg_colour_code = BG_COLORS[bg_colour]
49
+ return "\e[#{bg_colour_code};#{colour_code}m#{text}\e[0m".squeeze(';')
50
+ end
51
+
52
+
53
+ def self.pretty(message, colour = :default, bg_colour = :default)
54
+ width = 1
55
+
56
+ unless bg_colour == :default
57
+ width = WIDTH - message.length - 4
58
+ width = 1 if width.negative?
59
+ end
60
+
61
+ return colorize("\ \ #{ message } #{"\ " * width}", colour, bg_colour)
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,17 @@
1
+
2
+ module Termline
3
+ module List
4
+
5
+ def self.bullet *items
6
+ items.each { |item| puts(" #{Config::ICONS[:bullet]} #{ item }" )}
7
+ end
8
+
9
+ def self.check *items
10
+ items.each { |item| puts(" #{Config::ICONS[:checkmark]} #{ item }" )}
11
+ end
12
+
13
+ def self.star *items
14
+ items.each { |item| puts(" #{Config::ICONS[:star]} #{ item }" )}
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,32 @@
1
+
2
+ module Termline
3
+ module Msg
4
+ def self.msg messages
5
+ puts(message)
6
+ end
7
+
8
+ def self.builder message, tag: 'MSG', color: :default
9
+ puts(Config.pretty("#{tag} #{ message }", color))
10
+ end
11
+
12
+ def self.info message
13
+ builder(message, tag:'INFO:', color: :blue)
14
+ end
15
+
16
+ def self.success message
17
+ builder(message, tag:'SUCCESS:', color: :green)
18
+ end
19
+
20
+ def self.warning messages
21
+ messages.each { |message| puts(Config.pretty("WARNING: #{ message }", :yellow)) }
22
+ end
23
+
24
+ def self.danger messages
25
+ messages.each { |message| puts(Config.pretty("ERROR: #{ message }", :red)) }
26
+ end
27
+
28
+ def self.alert messages
29
+ messages.each { |message| puts("\e[5m#{message}\e[0m") }
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,17 @@
1
+
2
+ module Termline
3
+ module Space
4
+
5
+ def self.br count=1
6
+ puts("\n" * count);
7
+ end
8
+
9
+ def self.line count=8
10
+ puts('-·- ' * count)
11
+ end
12
+
13
+ def self.color color
14
+ Config.pretty("", :black, color)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,61 @@
1
+
2
+ module Termline
3
+ module Table
4
+ def self.simple data, header:true
5
+
6
+ return if Gem.win_platform?
7
+ return unless data.size > 0
8
+
9
+ if data.class.name == "ActiveRecord::Relation"
10
+ data = data.to_a.map(&:serializable_hash)
11
+ end
12
+
13
+ # get the available characters in terminal width
14
+ #terminal_width = `tput cols`.to_i
15
+ terminal_width = Config::WIDTH
16
+
17
+ # get the number of columns to print base on the data hash
18
+
19
+ pp "--------------------------"
20
+ pp "--------------------------"
21
+ header = false if data.first.class == Array
22
+ pp "--------------------------"
23
+ pp "--------------------------"
24
+
25
+ cols = data.first.length + 1
26
+
27
+ # get the available space for every column
28
+ col_width = (terminal_width / cols) - 1
29
+
30
+ # validate that we have minimum space to render the table
31
+ return if col_width <= 0
32
+
33
+ # separator for every column and row
34
+ separator = ('| ' << ('- ' * (col_width / 2)))
35
+
36
+ # add extra blank spaces to adjust the col_width only if col_width not a even number
37
+ separator += (' ') if (col_width - separator.size).odd?
38
+
39
+ # print data as table :)
40
+ data.each_with_index do |row, index|
41
+
42
+ # only for table header
43
+ if index == 0 && header
44
+
45
+ # print table titles
46
+ puts '| ' << row.keys.map { |key| key.to_s.upcase.ljust(col_width) }.join('| ')
47
+
48
+ # print header separators, only for visible columns
49
+ puts separator * (cols - 1)
50
+
51
+ end
52
+
53
+ # join hash values as a line and justify every value to print value
54
+ # in its own column
55
+ puts '| ' << row.values.map { |value| value.to_s.ljust(col_width) }.join('| ')
56
+ #puts '| ' << row.map { |value| value.to_s.ljust(col_width) }.join('| ')
57
+
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,35 @@
1
+ =begin
2
+
3
+ Copyright (c) 2022, Lesli Technologies, S. A.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ Lesli Ruby Messages - Message utilities for the Ruby console
19
+
20
+ Powered by https://www.lesli.tech
21
+ Building a better future, one line of code at a time.
22
+
23
+ @contact <hello@lesli.tech>
24
+ @website <https://www.lesli.tech>
25
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
26
+ @author The Lesli Development Team
27
+
28
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
29
+ // ·
30
+ =end
31
+
32
+ module Termline
33
+ VERSION = "0.1.0"
34
+ BUILD = "1774159419"
35
+ end
data/lib/termline.rb ADDED
@@ -0,0 +1,112 @@
1
+ =begin
2
+
3
+ Copyright (c) 2022, Lesli Technologies, S. A.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ Lesli Ruby Messages - Message utilities for the Ruby console
19
+
20
+ Powered by https://www.lesli.tech
21
+ Building a better future, one line of code at a time.
22
+
23
+ @contact <hello@lesli.tech>
24
+ @website <https://www.lesli.tech>
25
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
26
+ @author The Lesli Development Team
27
+
28
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
29
+ // ·
30
+ =end
31
+
32
+ require "termline/config"
33
+ require "termline/table"
34
+ require "termline/space"
35
+ require "termline/list"
36
+ require "termline/msg"
37
+ require "termline/banner"
38
+
39
+
40
+ # ·
41
+ module Termline
42
+
43
+ def self.m *messages
44
+ messages.each { |message| Termline::Msg.msg(message) }
45
+ end
46
+
47
+ def self.msg (*messages)
48
+ messages.each { |message| Termline::Msg.builder(message) }
49
+ end
50
+
51
+ def self.info *messages
52
+ messages.each { |message| Termline::Msg.info(message) }
53
+ end
54
+
55
+ def self.success *messages
56
+ messages.each { |message| Termline::Msg.success(message) }
57
+ end
58
+
59
+ def self.warning *messages
60
+ Termline::Msg.warning(messages)
61
+ end
62
+
63
+ def self.danger *messages
64
+ Termline::Msg.danger(messages)
65
+ end
66
+
67
+ def self.alert *messages
68
+ Termline::Msg.alert(messages)
69
+ end
70
+
71
+ def self.warn *messages
72
+ warning(messages)
73
+ end
74
+
75
+ def self.error *messages
76
+ Termline::Msg.danger(messages)
77
+ end
78
+
79
+
80
+ def self.list *items
81
+ Termline::List.bullet(items)
82
+ end
83
+
84
+ def self.list_check *items
85
+ Termline::List.check(items)
86
+ end
87
+
88
+ def self.list_star *items
89
+ Termline::List.star(items)
90
+ end
91
+
92
+
93
+ def self.table data, header:true
94
+ Termline::Table.simple(data, header:header)
95
+ end
96
+
97
+ def self.br count=1
98
+ Termline::Space.br(count)
99
+ end
100
+
101
+ def self.line count=8
102
+ Termline::Space.line(count)
103
+ end
104
+
105
+ def self.color color
106
+ Termline::Space.color(count)
107
+ end
108
+
109
+
110
+ def self.deprecation message
111
+ end
112
+ end
data/readme.md ADDED
@@ -0,0 +1,145 @@
1
+ <p align="center">
2
+ <a href="https://www.lesli.dev" target="_blank">
3
+ <img alt="Lesli Ruby Message logo" width="200px" src="./docs/l2-logo.svg" />
4
+ </a>
5
+ </p>
6
+ <h3 align="center">Message utilities for the Ruby console</h3>
7
+
8
+ Version 0.5.2
9
+
10
+ ## Installation
11
+
12
+ Install the gem and add to the application's Gemfile by executing:
13
+
14
+ $ bundle add l2
15
+
16
+ If bundler is not being used to manage dependencies, install the gem by executing:
17
+
18
+ $ gem install l2
19
+
20
+ Rails apps
21
+
22
+ $ gem "L2", "~> 0.4.0"
23
+
24
+ ## Usage
25
+
26
+
27
+ **Simple message:**
28
+
29
+ ```ruby
30
+ L2.m("hola")
31
+ L2.m("hola", "hello", "hallo", 1, [2], {"a":"b"})
32
+ ```
33
+
34
+
35
+ **Simple message with dividing line:**
36
+
37
+ ```ruby
38
+ L2.msg("hola")
39
+ L2.msg("hola", "hello", "hallo", 1, [2], {"a":"b"})
40
+ ```
41
+
42
+
43
+ **Informative message:**
44
+
45
+ ```ruby
46
+ L2.info("hola")
47
+ L2.info("hola", "hello", "hallo", 1, [2], {"a":"b"})
48
+ ```
49
+
50
+
51
+ **Sucessful message:**
52
+
53
+ ```ruby
54
+ L2.success("hola")
55
+ L2.success("hola", "hello", "hallo", 1, [2], {"a":"b"})
56
+ ```
57
+
58
+
59
+ **Simple message:**
60
+
61
+ ```ruby
62
+ L2.warning("hola")
63
+ L2.warning("hola", "hello", "hallo", 1, [2], {"a":"b"})
64
+ ```
65
+
66
+
67
+ **Error message:**
68
+
69
+ ```ruby
70
+ L2.danger("hola")
71
+ L2.danger("hola", "hello", "hallo", 1, [2], {"a":"b"})
72
+ ```
73
+
74
+
75
+ **Error with flashing message:**
76
+
77
+ ```ruby
78
+ L2.fatal("hola")
79
+ L2.fatal("hola", "hello", "hallo", 1, [2], {"a":"b"})
80
+ ```
81
+
82
+
83
+ **Flashing message:**
84
+
85
+ ```ruby
86
+ L2.alert("hola")
87
+ L2.alert("hola", "hello", "hallo", 1, [2], {"a":"b"})
88
+ ```
89
+
90
+
91
+ **Useful to give instructions in deprecated methods or code:**
92
+
93
+ ```ruby
94
+ L2.deprecation("hola")
95
+ ```
96
+
97
+
98
+ **Print a simple list:**
99
+
100
+ ```ruby
101
+ L2.list("hola", "hello", "hallo", 1, [2], {"a":"b"})
102
+ ```
103
+
104
+
105
+ **Show data as table:**
106
+
107
+ ```ruby
108
+ L2.table([
109
+ { español: "hola", english: "hello", deutsch: "hallo" },
110
+ { español: "hola", english: "hello", deutsch: "hallo" },
111
+ { español: "hola", english: "hello", deutsch: "hallo" }
112
+ ])
113
+ ```
114
+
115
+
116
+ **Display a cow message:**
117
+
118
+ ```ruby
119
+ L2.cow("Hello little cow!")
120
+ ```
121
+
122
+
123
+ ### Development
124
+ ------
125
+
126
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
127
+
128
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
129
+
130
+ ### Contributing
131
+ ------
132
+
133
+ Bug reports and pull requests are welcome on GitHub at https://github.com/LesliTech/l2.
134
+
135
+
136
+ ### License
137
+ ------
138
+
139
+ Software developed in [Guatemala](http://visitguatemala.com/) distributed under the *General Public License v 3.0* you can read the full license [here](http://www.gnu.org/licenses/gpl-3.0.html)
140
+
141
+ <p align="center">
142
+ <a href="https://www.lesli.tech" target="_blank">
143
+ <img alt="LesliTech logo" width="150" src="https://cdn.lesli.tech/leslitech/brand/leslitech-logo.svg" />
144
+ </a>
145
+ </p>
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: termline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - The Lesli Development Team
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: "Termline is a lightweight Ruby gem for printing terminal messages with
13
+ \ncolors, icons, and semantic log levels.\n"
14
+ email:
15
+ - hello@lesli.tech
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/termline.rb
21
+ - lib/termline/banner.rb
22
+ - lib/termline/config.rb
23
+ - lib/termline/list.rb
24
+ - lib/termline/msg.rb
25
+ - lib/termline/space.rb
26
+ - lib/termline/table.rb
27
+ - lib/termline/version.rb
28
+ - readme.md
29
+ homepage: https://www.lesli.dev/
30
+ licenses:
31
+ - GPL-3.0-or-later
32
+ metadata:
33
+ homepage_uri: https://www.lesli.dev/
34
+ changelog_uri: https://github.com/LesliTech/Termline/releases
35
+ source_code_uri: https://github.com/LesliTech/Termline
36
+ bug_tracker_uri: https://github.com/LesliTech/Termline/issues
37
+ documentation_uri: https://www.lesli.dev/gems/termline/
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.7.1
53
+ specification_version: 4
54
+ summary: Human-friendly terminal logs for the Lesli Platform.
55
+ test_files: []