termline 0.1.0 → 1.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8a666432b2c154e47a5a7eab4bf5000b82f757505ae7dc8d3e666f6d5e3348e
4
- data.tar.gz: 474673368a2be027c630918b5e063c65d0439adf222ec541b1ecfd546c9475c1
3
+ metadata.gz: 9ffa74e98e74cd4e79135aab3703a664301edad3c1a68789547876b5ed523a25
4
+ data.tar.gz: e194b805ec6fee33f52cde37d15af6005bd27d0c876fabe6978a7f585e584e0d
5
5
  SHA512:
6
- metadata.gz: 5498fedb4fc8b12a28da46e142a188ff0251667704e3df0b02143932ebc14f95afb91df155715a5e93208fc59fd149cf301450428e6a84c2783e69845fe77bc8
7
- data.tar.gz: 8365ae2a44b6857315d9d3006d4362747094a71c8375bb32745d1a70523354bd1173d06e8fcce30779c6264c4f4503a8be356cb46749f7d3de71752bc26211bd
6
+ metadata.gz: 8336beddc055905e84ad0cd98c77192d890990daac52cdfeb3f861c33b7cee177f85db496b293e5fd74dfcf934bb0e81a3314e583afeaee65cec58df389dea19
7
+ data.tar.gz: 91ab1b950cb4585c8fe257c92b12e06bc27b4b81ec191684f7b5865a0dc4feebdfcfd120f44cd75dad410b875a7322e06aaafff509db99f8bb927adb11ec54af
data/lib/termline/list.rb CHANGED
@@ -1,17 +1,8 @@
1
1
 
2
2
  module Termline
3
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 }" )}
4
+ def self.builder(items, icon:, color:)
5
+ items.each { |item| puts(" #{Style.colorize(Style.icon(icon), color)} #{ item }" )}
15
6
  end
16
7
  end
17
8
  end
data/lib/termline/msg.rb CHANGED
@@ -1,32 +1,46 @@
1
1
 
2
2
  module Termline
3
3
  module Msg
4
- def self.msg messages
5
- puts(message)
6
- end
4
+ class << self
7
5
 
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
6
+ def builder(
7
+ message,
8
+ tag: nil,
9
+ icon: nil,
10
+ color: :default,
11
+ bgcolor: :default,
12
+ timestamp: Time.now.strftime('%H:%M:%S:%L'), data:nil)
15
13
 
16
- def self.success message
17
- builder(message, tag:'SUCCESS:', color: :green)
18
- end
14
+ parts = []
15
+ parts << "[#{timestamp}]" if timestamp
16
+ parts << Style.colorize(Style.icon(icon), color) if icon
17
+ parts << Style.colorize(tag, color) if tag
18
+ parts << message
19
+ parts << data_text(data, color) if data
19
20
 
20
- def self.warning messages
21
- messages.each { |message| puts(Config.pretty("WARNING: #{ message }", :yellow)) }
22
- end
21
+ puts(parts.compact.map(&:to_s).reject(&:empty?).join(" ").strip)
22
+ end
23
23
 
24
- def self.danger messages
25
- messages.each { |message| puts(Config.pretty("ERROR: #{ message }", :red)) }
26
- end
24
+ def alert message
25
+ puts("\e[5m#{message}\e[0m")
26
+ puts("\e[5m#{Style.colorize(message,:red)}\e[0m")
27
+ end
28
+
29
+ private
30
+
31
+ def format_value(value)
32
+ case value
33
+ when String
34
+ value.include?(" ") ? value.inspect : value
35
+ else
36
+ value.inspect
37
+ end
38
+ end
27
39
 
28
- def self.alert messages
29
- messages.each { |message| puts("\e[5m#{message}\e[0m") }
40
+ def data_text(data, color)
41
+ return nil if data.nil? || data.empty?
42
+ data.map { |key, value| "#{key}#{Style.colorize('=>', color)}#{format_value(value)}" }.join(" ")
43
+ end
30
44
  end
31
45
  end
32
46
  end
@@ -1,11 +1,15 @@
1
1
 
2
2
 
3
3
  module Termline
4
- module Config
4
+ module Style
5
5
 
6
+ # Available icons
6
7
  ICONS = {
7
- checkmark: "",
8
- bullet: "",
8
+ warning: "",
9
+ success: "",
10
+ debug: "•",
11
+ error: "✖",
12
+ info: "ℹ",
9
13
  star: "★"
10
14
  }.freeze
11
15
 
@@ -17,6 +21,7 @@ module Termline
17
21
  white: '1;37',
18
22
  green: '32',
19
23
  black: '30',
24
+ gray: '90',
20
25
  blue: '36',
21
26
  red: '31'
22
27
  }.freeze
@@ -35,7 +40,6 @@ module Termline
35
40
 
36
41
  # calculate the console width
37
42
  # tputcols is not available on windows
38
- #WIDTH = `tput cols`.to_i rescue WIDTH = 1;
39
43
  WIDTH = begin
40
44
  term = ENV['TERM']
41
45
  term ? `tput cols`.to_i : 1
@@ -43,6 +47,11 @@ module Termline
43
47
  1
44
48
  end
45
49
 
50
+ def self.icon icon
51
+ ICONS[icon]
52
+ end
53
+
54
+ # Concat color to text
46
55
  def self.colorize(text, colour = :default, bg_colour = :default)
47
56
  colour_code = COLORS[colour]
48
57
  bg_colour_code = BG_COLORS[bg_colour]
@@ -58,7 +67,7 @@ module Termline
58
67
  width = 1 if width.negative?
59
68
  end
60
69
 
61
- return colorize("\ \ #{ message } #{"\ " * width}", colour, bg_colour)
70
+ return colorize("#{ message } #{"\ " * width}", colour, bg_colour)
62
71
  end
63
72
  end
64
73
  end
@@ -6,22 +6,18 @@ module Termline
6
6
  return if Gem.win_platform?
7
7
  return unless data.size > 0
8
8
 
9
+ table_from_array = true if data.first.class == Array
10
+ header = false if table_from_array
11
+
9
12
  if data.class.name == "ActiveRecord::Relation"
10
13
  data = data.to_a.map(&:serializable_hash)
11
14
  end
12
15
 
13
16
  # get the available characters in terminal width
14
17
  #terminal_width = `tput cols`.to_i
15
- terminal_width = Config::WIDTH
18
+ terminal_width = Style::WIDTH
16
19
 
17
20
  # 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
21
  cols = data.first.length + 1
26
22
 
27
23
  # get the available space for every column
@@ -35,27 +31,28 @@ module Termline
35
31
 
36
32
  # add extra blank spaces to adjust the col_width only if col_width not a even number
37
33
  separator += (' ') if (col_width - separator.size).odd?
38
-
39
- # print data as table :)
40
- data.each_with_index do |row, index|
41
34
 
42
- # only for table header
43
- if index == 0 && header
35
+ # only for table header
36
+ if header
44
37
 
45
- # print table titles
46
- puts '| ' << row.keys.map { |key| key.to_s.upcase.ljust(col_width) }.join('| ')
38
+ # print table titles
39
+ puts '| ' << data.first.keys.map { |key| key.to_s.upcase.ljust(col_width) }.join('| ')
40
+ end
47
41
 
48
- # print header separators, only for visible columns
49
- puts separator * (cols - 1)
42
+ # print header separators, only for visible columns
43
+ puts separator * (cols - 1)
50
44
 
51
- end
45
+ # print data as table :)
46
+ data.each_with_index do |row, index|
52
47
 
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('| ')
48
+ # join hash values as a line and justify every value to print value in its own column
49
+ puts '| ' << row.values.map { |value| value.to_s.ljust(col_width) }.join('| ') unless table_from_array
57
50
 
51
+ # print simple value from the array data
52
+ puts '| ' << row.map { |value| value.to_s.ljust(col_width) }.join('| ') if table_from_array
58
53
  end
54
+
55
+ puts separator * (cols - 1) unless header
59
56
  end
60
57
  end
61
58
  end
@@ -30,6 +30,6 @@ Building a better future, one line of code at a time.
30
30
  =end
31
31
 
32
32
  module Termline
33
- VERSION = "0.1.0"
34
- BUILD = "1774159419"
33
+ VERSION = "1.0.0"
34
+ BUILD = "1774219112"
35
35
  end
data/lib/termline.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  =begin
2
2
 
3
- Copyright (c) 2022, Lesli Technologies, S. A.
3
+ Lesli
4
+
5
+ Copyright (c) 2026, Lesli Technologies, S. A.
4
6
 
5
7
  This program is free software: you can redistribute it and/or modify
6
8
  it under the terms of the GNU General Public License as published by
@@ -13,80 +15,63 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
15
  GNU General Public License for more details.
14
16
 
15
17
  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/>.
18
+ along with this program. If not, see http://www.gnu.org/licenses/.
17
19
 
18
- Lesli Ruby Messages - Message utilities for the Ruby console
20
+ Lesli · Ruby on Rails SaaS Development Framework.
19
21
 
20
- Powered by https://www.lesli.tech
22
+ Made with ♥ by LesliTech
21
23
  Building a better future, one line of code at a time.
22
24
 
23
- @contact <hello@lesli.tech>
24
- @website <https://www.lesli.tech>
25
+ @contact hello@lesli.tech
26
+ @website https://www.lesli.tech
25
27
  @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
26
- @author The Lesli Development Team
27
28
 
28
- // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
29
30
  // ·
30
31
  =end
31
32
 
32
- require "termline/config"
33
- require "termline/table"
34
- require "termline/space"
35
- require "termline/list"
36
- require "termline/msg"
37
- require "termline/banner"
33
+ require_relative "termline/style"
34
+ require_relative "termline/table"
35
+ require_relative "termline/space"
36
+ require_relative "termline/list"
37
+ require_relative "termline/msg"
38
+ require_relative "termline/banner"
38
39
 
39
40
 
40
41
  # ·
41
42
  module Termline
42
43
 
43
44
  def self.m *messages
44
- messages.each { |message| Termline::Msg.msg(message) }
45
+ messages.each { |message| puts(message) }
45
46
  end
46
47
 
47
- def self.msg (*messages)
48
- messages.each { |message| Termline::Msg.builder(message) }
48
+ def self.msg (*messages, **data)
49
+ messages.each { |message| Termline::Msg.builder(message, data:data) }
49
50
  end
50
51
 
51
- def self.info *messages
52
- messages.each { |message| Termline::Msg.info(message) }
52
+ def self.info *messages, tag:'INFO:', icon: :info, **data
53
+ messages.each { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :blue) }
53
54
  end
54
55
 
55
- def self.success *messages
56
- messages.each { |message| Termline::Msg.success(message) }
56
+ def self.success *messages, tag:'SUCCESS:', icon: :success, **data
57
+ messages.each { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :green) }
57
58
  end
58
59
 
59
- def self.warning *messages
60
- Termline::Msg.warning(messages)
60
+ def self.warning *messages, tag:'WARNING:', icon: :warning, **data
61
+ messages.each { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :yellow) }
61
62
  end
62
63
 
63
- def self.danger *messages
64
- Termline::Msg.danger(messages)
64
+ def self.danger *messages, tag:'DANGER:', icon: :error, **data
65
+ messages.each { |message| Termline::Msg.builder(message, tag:tag, icon:icon, data:data, color: :red) }
65
66
  end
66
67
 
67
68
  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)
69
+ messages.each { |message| Termline::Msg.alert(message) }
77
70
  end
78
71
 
79
72
 
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)
73
+ def self.list *items, color: :default, icon: :debug
74
+ Termline::List.builder(items, color:color, icon:icon)
90
75
  end
91
76
 
92
77
 
data/readme.md CHANGED
@@ -1,145 +1,76 @@
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>
1
+ <div align="center" class="documentation-header">
2
+ <img width="100" alt="LesliTesting logo" src="./docs/images/termline-logo.svg" />
3
+ <h3 align="center">Human-friendly terminal logs for the Lesli Platform</h3>
4
+ </div>
7
5
 
8
- Version 0.5.2
6
+ <br />
7
+ <hr/>
8
+ <br />
9
9
 
10
- ## Installation
11
10
 
12
- Install the gem and add to the application's Gemfile by executing:
11
+ ### Quick start
13
12
 
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")
13
+ ```shell
14
+ # Add LesliAdmin engine gem
15
+ bundle add termline
95
16
  ```
96
17
 
97
-
98
- **Print a simple list:**
99
-
18
+ ### Usage
100
19
  ```ruby
101
- L2.list("hola", "hello", "hallo", 1, [2], {"a":"b"})
20
+ Termline.br
21
+ Termline.m("Simple message")
22
+ Termline.msg("Message with data:", data:{ name: "Luis", last_name: "Donis", title: "Software developer"})
23
+ Termline.info("Message with data:", data:{ name: "Luis", last_name: "Donis", title: "Software developer"})
24
+ Termline.success("Message with data:", data:{ name: "Luis", last_name: "Donis", title: "Software developer"})
25
+ Termline.warning("Message with data:", data:{ name: "Luis", last_name: "Donis", title: "Software developer"})
26
+ Termline.danger("Message with data:", data:{ name: "Luis", last_name: "Donis", title: "Software developer"})
102
27
  ```
103
28
 
29
+ **Result:**
104
30
 
105
- **Show data as table:**
31
+ <img alt="LesliTesting logo" src="./docs/images/screenshot.png" />
106
32
 
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
33
 
34
+ ### Documentation
35
+ * [website](https://www.lesli.dev/)
36
+ * [documentation](https://www.lesli.dev/gems/termline/)
115
37
 
116
- **Display a cow message:**
117
-
118
- ```ruby
119
- L2.cow("Hello little cow!")
120
- ```
121
38
 
39
+ ### Connect with Lesli
122
40
 
123
- ### Development
124
- ------
41
+ * [X: @LesliTech](https://x.com/LesliTech)
42
+ * [Email: hello@lesli.tech](hello@lesli.tech)
43
+ * [Website: https://www.lesli.tech](https://www.lesli.tech)
125
44
 
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
45
 
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).
46
+ ### License
47
+ -------
48
+ Copyright (c) 2026, Lesli Technologies, S. A.
129
49
 
130
- ### Contributing
131
- ------
50
+ This program is free software: you can redistribute it and/or modify
51
+ it under the terms of the GNU General Public License as published by
52
+ the Free Software Foundation, either version 3 of the License, or
53
+ (at your option) any later version.
132
54
 
133
- Bug reports and pull requests are welcome on GitHub at https://github.com/LesliTech/l2.
55
+ This program is distributed in the hope that it will be useful,
56
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
57
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58
+ GNU General Public License for more details.
134
59
 
60
+ You should have received a copy of the GNU General Public License
61
+ along with this program. If not, see http://www.gnu.org/licenses/.
135
62
 
136
- ### License
137
- ------
63
+ <br />
64
+ <hr />
65
+ <br />
66
+ <br />
138
67
 
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)
68
+ <div align="center" class="has-text-centered">
69
+ <img width="200" alt="Lesli logo" src="https://cdn.lesli.tech/lesli/brand/app-logo.svg" />
70
+ <h3 align="center" class="mt-0">
71
+ The Open-Source SaaS Development Framework for Ruby on Rails.
72
+ </h3>
73
+ </div>
140
74
 
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>
75
+ <br />
76
+ <br />
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: termline
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Lesli Development Team
@@ -19,10 +19,10 @@ extra_rdoc_files: []
19
19
  files:
20
20
  - lib/termline.rb
21
21
  - lib/termline/banner.rb
22
- - lib/termline/config.rb
23
22
  - lib/termline/list.rb
24
23
  - lib/termline/msg.rb
25
24
  - lib/termline/space.rb
25
+ - lib/termline/style.rb
26
26
  - lib/termline/table.rb
27
27
  - lib/termline/version.rb
28
28
  - readme.md