hawktui 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: 07fe25870ab381af56a2690f6b7befd22933dea333cb63f2d4d9e96b6801af5e
4
- data.tar.gz: 8d7e1ce5dc90cfcc1d07e7adcb2b9f0c99949f612616c5ab64b7a3e34529f7c3
3
+ metadata.gz: 56702f773b1ff7da828d1a7e9dfc838b83e1167036ed707ad72525b34c8f0738
4
+ data.tar.gz: 7d056d53a33107647ffaa5164c9d6d7b1d6013a3d3c4263ef338e7ef014108e6
5
5
  SHA512:
6
- metadata.gz: 25ead068f0039099acabceba170d120aaa8c674cae0b607df496a7de60fdc9a722c827376bf2bb6929522d5405861e515e4e8b3713d9b4bcce964bd855d51061
7
- data.tar.gz: 5c6b1112d3519712730b7c84dccd153d0ae6062afd5c325beea6ad70cd13f6da8d6bed61f5f94ce9b0c20a0d03325117416326413b76301994cdf3698becb297
6
+ metadata.gz: 0df227c1bfb4eb2c31baf4ce2e60c486c657b4d567c16a1384b878f94bef021d5c827fde1c20d9300cae91400e9a13eb204490be2c2875f387479564620fdcf5
7
+ data.tar.gz: 7f6086a30a2df0cb42da9ab8097ac662994593492f30dbaae42f2d8ccc1bea0f7fac41ade120a10a3ee65897a38accfd0149084b7a88a83f5f154aafe17d2671
data/README.md CHANGED
@@ -3,3 +3,42 @@
3
3
  Hawktui is a simple and easy to use TUI (Terminal User Interface) library for Ruby. It is built on the [curses](https://github.com/ruby/curses) library.
4
4
 
5
5
  ![hawktui](https://github.com/jonmagic/hawktui/blob/main/hawktui.jpeg)
6
+
7
+ So far it includes a `StreamingTable` API and more APIs are planned.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem "hawktui"
15
+ ```
16
+
17
+ Run the following command to install it:
18
+
19
+ ```bash
20
+ bundle install
21
+ ```
22
+
23
+ ## StreamingTable
24
+
25
+ The `Hawktui::StreamingTable` API can be used to create a full screen table in your terminal that can be updated in real time. This is useful for displaying data that is constantly changing.
26
+
27
+ ```bash
28
+ git clone https://github.com/jonmagic/hawktui
29
+ cd hawktui
30
+ bin/setup
31
+ bin/demo
32
+ ```
33
+
34
+ https://github.com/user-attachments/assets/9085352f-9f6a-47ae-90c7-cc23946f2d30
35
+
36
+ See [bin/demo](https://github.com/jonmagic/hawktui/blob/main/bin/demo) for an example of how to use `Hawktui::StreamingTable` and the implementation in [lib/hawktui/streaming_table.rb](https://github.com/jonmagic/hawktui/blob/main/lib/hawktui/streaming_table.rb) for documentation.
37
+
38
+ ## Roadmap
39
+
40
+ - Add functionality to StreamingTable for selecting and acting on rows.
41
+
42
+ ## Contributors
43
+
44
+ - [@jonmagic](https://github.com/jonmagic)
@@ -7,11 +7,11 @@ module Hawktui
7
7
  #
8
8
  # Examples
9
9
  #
10
- # cell = Tui::Cell.new("Hello")
10
+ # cell = Hawktui::StreamingTable::Cell.new("Hello")
11
11
  # cell.value # => "Hello"
12
12
  # cell.color # => nil
13
13
  #
14
- # colored_cell = Tui::Cell.new(value: "Error", color: :red)
14
+ # colored_cell = Hawktui::StreamingTable::Cell.new(value: "Error", color: :red)
15
15
  # colored_cell.value # => "Error"
16
16
  # colored_cell.color # => :red
17
17
  #
@@ -7,7 +7,7 @@ module Hawktui
7
7
  #
8
8
  # Examples
9
9
  #
10
- # column = Tui::Column.new(name: :message, width: 50)
10
+ # column = Hawktui::StreamingTable::Column.new(name: :message, width: 50)
11
11
  #
12
12
  class Column
13
13
  attr_reader :name, :width
@@ -19,7 +19,7 @@ module Hawktui
19
19
  #
20
20
  # Examples
21
21
  #
22
- # column = Tui::Column.new(name: :message, width: 50)
22
+ # column = Hawktui::StreamingTable::Column.new(name: :message, width: 50)
23
23
  #
24
24
  # Returns a new Column instance.
25
25
  def initialize(name:, width:)
@@ -31,11 +31,11 @@ module Hawktui
31
31
  # If the text is longer than `width`, it will be truncated with an ellipsis ("…").
32
32
  # Otherwise, it’s left-padded with spaces to fill the width.
33
33
  #
34
- # cell - A Tui::Cell containing the raw value and color.
34
+ # cell - A Hawktui::StreamingTable::Cell containing the raw value and color.
35
35
  #
36
36
  # Examples
37
37
  #
38
- # cell = Tui::Cell.new("Some message")
38
+ # cell = Hawktui::StreamingTable::Cell.new("Some message")
39
39
  # column.format_cell(cell)
40
40
  # # => ["Some message ", nil] # => example if width is bigger
41
41
  #
@@ -12,7 +12,7 @@ module Hawktui
12
12
  # { name: :timestamp, width: 20 },
13
13
  # { name: :message, width: 50 },
14
14
  # ]
15
- # layout = Tui::TableLayout.new(columns: columns, header_color: :white)
15
+ # layout = Hawktui::StreamingTable::Layout.new(columns: columns, header_color: :white)
16
16
  #
17
17
  # header_cells = layout.build_header_row # => [Cell(...), Cell(...)]
18
18
  #
@@ -21,13 +21,13 @@ module Hawktui
21
21
 
22
22
  # Public: Create a new TableLayout.
23
23
  #
24
- # columns - An Array of Hashes or Tui::Column objects. Each element must
24
+ # columns - An Array of Hashes or Hawktui::StreamingTable::Column objects. Each element must
25
25
  # have a `:name` and `:width`.
26
26
  # header_color - A Symbol representing the color used in the header (defaults to :white).
27
27
  #
28
28
  # Examples
29
29
  #
30
- # layout = Tui::TableLayout.new(
30
+ # layout = Hawktui::StreamingTable::Layout.new(
31
31
  # columns: [
32
32
  # { name: :time, width: 10 },
33
33
  # { name: :level, width: 5 },
@@ -52,7 +52,7 @@ module Hawktui
52
52
  # layout.build_header_row
53
53
  # # => [Cell(value="time", color=:white), Cell(value="level", color=:white)]
54
54
  #
55
- # Returns an Array of Tui::Cell objects.
55
+ # Returns an Array of Hawktui::StreamingTable::Cell objects.
56
56
  def build_header_row
57
57
  columns.map do |col|
58
58
  # Use the stored @header_color for all headers
@@ -71,7 +71,7 @@ module Hawktui
71
71
  # layout.build_cells_for_row(row_hash)
72
72
  # # => [Cell(value="12:00", color=nil), Cell(value="INFO", color=:green)]
73
73
  #
74
- # Returns an Array of Tui::Cell objects.
74
+ # Returns an Array of Hawktui::StreamingTable::Cell objects.
75
75
  def build_cells_for_row(row_hash)
76
76
  columns.map do |col|
77
77
  value_or_hash = row_hash[col.name] || ""
@@ -17,7 +17,7 @@ module Hawktui
17
17
  # { name: :timestamp, width: 20 },
18
18
  # { name: :message, width: 50 },
19
19
  # ]
20
- # table = Tui::StreamingTable.new(columns: columns, max_rows: 1000)
20
+ # table = Hawktui::StreamingTable.new(columns: columns, max_rows: 1000)
21
21
  # table.start
22
22
  #
23
23
  # # In a separate thread or async process:
@@ -31,16 +31,16 @@ module Hawktui
31
31
  class StreamingTable
32
32
  # Public: Create a new StreamingTable.
33
33
  #
34
- # columns - An Array of Hashes or Tui::Column objects that define the table’s
34
+ # columns - An Array of Hashes or Hawktui::StreamingTable::Column objects that define the table’s
35
35
  # columns. Each element should at least contain `:name` and `:width`.
36
36
  # max_rows - The maximum number of rows to keep in the table. Defaults to 100000.
37
37
  #
38
38
  # Examples
39
39
  #
40
- # table = Tui::StreamingTable.new(columns: [{ name: :time, width: 10 }], max_rows: 500)
40
+ # table = Hawktui::StreamingTable.new(columns: [{ name: :time, width: 10 }], max_rows: 500)
41
41
  #
42
42
  # Returns a new StreamingTable instance.
43
- def initialize(columns:, max_rows: 100_000)
43
+ def initialize(columns: {}, max_rows: 100_000)
44
44
  @layout = Layout.new(columns: columns)
45
45
  @max_rows = max_rows
46
46
  @rows = [] # Store rows newest-first
@@ -53,6 +53,21 @@ module Hawktui
53
53
  attr_reader :layout, :max_rows, :rows, :paused, :should_exit
54
54
  attr_accessor :win
55
55
 
56
+ # Public: Set the layout for the table. This will redraw the table with the new layout.
57
+ #
58
+ # new_layout - A Hawktui::StreamingTable::Layout object.
59
+ #
60
+ # Examples
61
+ #
62
+ # new_layout = Hawktui::StreamingTable::Layout.new(columns: [{ name: :id, width: 10 }])
63
+ # table.layout = new_layout
64
+ #
65
+ # Returns nothing.
66
+ def layout=(new_layout)
67
+ @layout = new_layout
68
+ draw if win # Ensure the window is initialized before attempting to draw
69
+ end
70
+
56
71
  # Public: Start the table UI. Initializes curses, sets up input handling,
57
72
  # and draws the initial screen.
58
73
  #
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hawktui
4
- VERSION = "0.1.0"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hawktui
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
  - Jonathan Hoyt
@@ -69,6 +69,6 @@ requirements: []
69
69
  rubygems_version: 3.5.16
70
70
  signing_key:
71
71
  specification_version: 4
72
- summary: HawkTui is a simple and easy to use TUI (Terminal User Interface) library
72
+ summary: Hawktui is a simple and easy to use TUI (Terminal User Interface) library
73
73
  for Ruby.
74
74
  test_files: []