graphina 0.0.0 → 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 +4 -4
- data/README.md +48 -2
- data/Rakefile +3 -0
- data/VERSION +1 -1
- data/bin/graphina +34 -26
- data/graphina.gemspec +7 -4
- data/lib/graphina/graph/display.rb +0 -3
- data/lib/graphina/graph.rb +3 -3
- data/lib/graphina/graphina_config.rb +45 -0
- data/lib/graphina/panel/chooser.rb +56 -0
- data/lib/graphina/panel.rb +212 -0
- data/lib/graphina/version.rb +1 -1
- data/lib/graphina.rb +14 -0
- metadata +55 -1
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 1f570978e09506bff882553a4c39ab03e74af7cadd008513e0167b50493343cf
         | 
| 4 | 
            +
              data.tar.gz: b2f5b74fb597d1935592f586856495189cce766c3c160003ed89632d0276dabd
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: d4c746f79af45187c5a239ac8d6907420adb9aa315fedb9b8f37a5bc1e89c4a37d523a3152597f1e48229297787fe8d49e055e54397f420159e68d050fdb320b
         | 
| 7 | 
            +
              data.tar.gz: e9a6465440a088a96e71eebd562982a91fb5641e9350345c4e0172cb474cce4be180e34ff6bd573a1b8a259f5bb241c35392629c70b66c7ac666f37343aed4e8
         | 
    
        data/README.md
    CHANGED
    
    | @@ -28,6 +28,8 @@ Complete API documentation is available at: [GitHub.io](https://flori.github.io/ | |
| 28 28 | 
             
            - **Signal Handling**: Graceful shutdown and terminal resize handling
         | 
| 29 29 | 
             
            - **String-based Color Derivation**: Automatically derive consistent colors
         | 
| 30 30 | 
             
              from titles and labels
         | 
| 31 | 
            +
            - **Panel Configuration System**: Predefined panel configurations for reuse
         | 
| 32 | 
            +
            - **Interactive Selection**: Choose from available panels with fuzzy matching
         | 
| 31 33 |  | 
| 32 34 | 
             
            ## Installation
         | 
| 33 35 |  | 
| @@ -72,7 +74,17 @@ graphina -t "CPU Usage (faked)" -f blue -b black | |
| 72 74 | 
             
            graphina -t 'CPU Usage' -n 1 -F as_percent -e "top -l 1 -n 0 | grep 'CPU usage' | awk '{print \$3+\$5}' | sed 's/%//'"
         | 
| 73 75 | 
             
            ```
         | 
| 74 76 |  | 
| 75 | 
            -
            ### 4.  | 
| 77 | 
            +
            ### 4. Using Predefined Panels
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            ```bash
         | 
| 80 | 
            +
            # Use a predefined panel configuration
         | 
| 81 | 
            +
            graphina -P cpu
         | 
| 82 | 
            +
             | 
| 83 | 
            +
            # Interactive panel selection
         | 
| 84 | 
            +
            graphina
         | 
| 85 | 
            +
            ```
         | 
| 86 | 
            +
             | 
| 87 | 
            +
            ### 5. Custom Data Source
         | 
| 76 88 |  | 
| 77 89 | 
             
            ```ruby
         | 
| 78 90 | 
             
            # Using the library directly in Ruby code
         | 
| @@ -88,7 +100,7 @@ graph = Graphina::Graph.new( | |
| 88 100 | 
             
            graph.start
         | 
| 89 101 | 
             
            ```
         | 
| 90 102 |  | 
| 91 | 
            -
            ###  | 
| 103 | 
            +
            ### 6. Custom Command with External Data
         | 
| 92 104 |  | 
| 93 105 | 
             
            ```ruby
         | 
| 94 106 | 
             
            # Using external command for data
         | 
| @@ -101,6 +113,38 @@ graph = Graphina::Graph.new( | |
| 101 113 | 
             
            graph.start
         | 
| 102 114 | 
             
            ```
         | 
| 103 115 |  | 
| 116 | 
            +
            ## Panel Configuration
         | 
| 117 | 
            +
             | 
| 118 | 
            +
            Graphina now supports predefined panel configurations. Create a `panels.yml`
         | 
| 119 | 
            +
            file in your configuration directory (`"$XDG_CONFIG_HOME/graphina"`, usually
         | 
| 120 | 
            +
            `~/.config/graphina/panels.yml`) to define reusable panel setups:
         | 
| 121 | 
            +
             | 
| 122 | 
            +
            ```yaml
         | 
| 123 | 
            +
            cpu:
         | 
| 124 | 
            +
              title: "CPU Usage (%)"
         | 
| 125 | 
            +
              interval: 1
         | 
| 126 | 
            +
              command: "top -l 1 -n 0 | awk '/^CPU usage:/ { print \$3 + \$5 }'"
         | 
| 127 | 
            +
              format_value: as_percent
         | 
| 128 | 
            +
              color: '#ff5f00'
         | 
| 129 | 
            +
            memory:
         | 
| 130 | 
            +
              title: "Memory Usage"
         | 
| 131 | 
            +
              interval: 1
         | 
| 132 | 
            +
              command: "free -b | awk '/^Mem:/ { print \$4 }'"
         | 
| 133 | 
            +
              format_value: as_bytes
         | 
| 134 | 
            +
              color: '#87d700'
         | 
| 135 | 
            +
              color_secondary: '#d7ff00'
         | 
| 136 | 
            +
            ```
         | 
| 137 | 
            +
             | 
| 138 | 
            +
            To use a specific panel:
         | 
| 139 | 
            +
            ```bash
         | 
| 140 | 
            +
            graphina -P cpu
         | 
| 141 | 
            +
            ```
         | 
| 142 | 
            +
             | 
| 143 | 
            +
            To see all available panels:
         | 
| 144 | 
            +
            ```bash
         | 
| 145 | 
            +
            graphina
         | 
| 146 | 
            +
            ```
         | 
| 147 | 
            +
             | 
| 104 148 | 
             
            ## Command Line Options
         | 
| 105 149 |  | 
| 106 150 | 
             
            ```
         | 
| @@ -116,6 +160,8 @@ Usage: graphina [OPTIONS] | |
| 116 160 | 
             
                -c COLOR      Primary color (default: derived from title)
         | 
| 117 161 | 
             
                -C COLOR      Secondary color (default: derived from primary)
         | 
| 118 162 | 
             
                -F FORMAT     Format function (:as_bytes, :as_hertz, :as_celsius, :as_percent, :as_default, default: :as_default)
         | 
| 163 | 
            +
                -e COMMAND    External command to execute for data values (default: random data)
         | 
| 164 | 
            +
                -P PANEL      Panel name to use from configuration (default: interactive selection)
         | 
| 119 165 | 
             
                -h            this help
         | 
| 120 166 | 
             
            ```
         | 
| 121 167 |  | 
    
        data/Rakefile
    CHANGED
    
    | @@ -35,6 +35,9 @@ GemHadar do | |
| 35 35 |  | 
| 36 36 | 
             
              dependency  'tins',             '~> 1.45'
         | 
| 37 37 | 
             
              dependency  'term-ansicolor',   '~> 1.11'
         | 
| 38 | 
            +
              dependency  'const_conf',       '~> 0.4', '>= 0.4.3'
         | 
| 39 | 
            +
              dependency  'amatch',           '~> 0.5'
         | 
| 40 | 
            +
              dependency  'search_ui'
         | 
| 38 41 | 
             
              development_dependency 'debug', '~> 1.0'
         | 
| 39 42 |  | 
| 40 43 | 
             
              licenses << 'MIT'
         | 
    
        data/VERSION
    CHANGED
    
    | @@ -1 +1 @@ | |
| 1 | 
            -
            0. | 
| 1 | 
            +
            0.1.0
         | 
    
        data/bin/graphina
    CHANGED
    
    | @@ -19,6 +19,8 @@ def usage | |
| 19 19 | 
             
                  -c COLOR      Primary color (default: derived from title)
         | 
| 20 20 | 
             
                  -C COLOR      Secondary color (default: derived from primary)
         | 
| 21 21 | 
             
                  -F FORMAT     Format function (:as_bytes, :as_hertz, :as_celsius, :as_percent, :as_default, default: :as_default)
         | 
| 22 | 
            +
                  -P PANEL      Use predefined panel configuration (default: interactive selection)
         | 
| 23 | 
            +
                  -e COMMAND    External command to execute for data values (default: random data)
         | 
| 22 24 | 
             
                  -h            this help
         | 
| 23 25 |  | 
| 24 26 | 
             
                Examples:
         | 
| @@ -27,41 +29,47 @@ def usage | |
| 27 29 | 
             
                  graphina -t "CPU Usage"               # Custom title
         | 
| 28 30 | 
             
                  graphina -t "Memory" -f blue -b black # Custom colors
         | 
| 29 31 | 
             
                  graphina -t "Network" -r single -n 2  # Single resolution, 2 second updates
         | 
| 30 | 
            -
                  # Full  | 
| 31 | 
            -
                  graphina -t 'CPU Usage' -n 1 -F as_percent -e "top -l 1 -n 0 |  | 
| 32 | 
            +
                  # Full examples
         | 
| 33 | 
            +
                  graphina -t 'CPU Usage (%)' -n 1 -F as_percent -e "top -l 1 -n 0 | awk '/^CPU usage:/ { print \\$3 + \\$5 }'"
         | 
| 34 | 
            +
                  graphina -t 'Memory' -n 1 -F as_bytes -e "free -b | awk '/^Mem:/ { print \\$4 }'"
         | 
| 32 35 |  | 
| 33 36 | 
             
              EOT
         | 
| 34 37 | 
             
              0
         | 
| 35 38 | 
             
            end
         | 
| 36 39 |  | 
| 37 | 
            -
            $opts = go 't:n:r:f:b:c:C:F:e:h' | 
| 38 | 
            -
              ?t => 'Data',
         | 
| 39 | 
            -
              ?n => 5,
         | 
| 40 | 
            -
              ?r => :double,
         | 
| 41 | 
            -
              ?f => :white,
         | 
| 42 | 
            -
              ?b => :black,
         | 
| 43 | 
            -
              ?F => :as_default,
         | 
| 44 | 
            -
            }
         | 
| 40 | 
            +
            $opts = go 't:n:r:f:b:c:C:F:e:P:h'
         | 
| 45 41 |  | 
| 46 42 | 
             
            $opts[?h] and exit usage
         | 
| 47 43 |  | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 44 | 
            +
            panel = Graphina::Panel.new
         | 
| 45 | 
            +
            case
         | 
| 46 | 
            +
            when panel_name = $opts[?P]
         | 
| 47 | 
            +
              if panel_config = Graphina::GraphinaConfig::PANELS[panel_name]
         | 
| 48 | 
            +
                panel.configure(panel_config)
         | 
| 49 | 
            +
              else
         | 
| 50 | 
            +
                STDERR.puts "No panel named #{panel_name.inspect} defined!"
         | 
| 51 | 
            +
                exit 1
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            when $opts[?e]
         | 
| 54 | 
            +
              panel.configure_from_opts($opts)
         | 
| 55 | 
            +
            when panels = Graphina::GraphinaConfig::PANELS
         | 
| 56 | 
            +
              unless panel = Graphina::Panel::Chooser.choose(panels) 
         | 
| 57 | 
            +
                STDERR.puts "No panel chosen."
         | 
| 58 | 
            +
                exit 0
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
            else
         | 
| 61 | 
            +
              panel.configure_from_opts($opts)
         | 
| 62 | 
            +
            end
         | 
| 55 63 | 
             
            graph = Graphina::Graph.new(
         | 
| 56 | 
            -
              title:             | 
| 57 | 
            -
              sleep:             | 
| 58 | 
            -
              value | 
| 64 | 
            +
              title:            panel.title,
         | 
| 65 | 
            +
              sleep:            panel.interval,
         | 
| 66 | 
            +
              value:            panel.value,
         | 
| 59 67 | 
             
              true_coloring:    ENV['COLORTERM'] =~ /\A(truecolor|24bit)\z/,
         | 
| 60 | 
            -
              color:             | 
| 61 | 
            -
              color_secondary:   | 
| 62 | 
            -
              foreground_color:  | 
| 63 | 
            -
              background_color:  | 
| 64 | 
            -
              resolution:        | 
| 65 | 
            -
              format_value:
         | 
| 68 | 
            +
              color:            panel.color,
         | 
| 69 | 
            +
              color_secondary:  panel.color_secondary,
         | 
| 70 | 
            +
              foreground_color: panel.foreground_color,
         | 
| 71 | 
            +
              background_color: panel.background_color,
         | 
| 72 | 
            +
              resolution:       panel.resolution,
         | 
| 73 | 
            +
              format_value:     panel.format_value,
         | 
| 66 74 | 
             
            )
         | 
| 67 75 | 
             
            graph.start
         | 
    
        data/graphina.gemspec
    CHANGED
    
    | @@ -1,9 +1,9 @@ | |
| 1 1 | 
             
            # -*- encoding: utf-8 -*-
         | 
| 2 | 
            -
            # stub: graphina 0. | 
| 2 | 
            +
            # stub: graphina 0.1.0 ruby lib
         | 
| 3 3 |  | 
| 4 4 | 
             
            Gem::Specification.new do |s|
         | 
| 5 5 | 
             
              s.name = "graphina".freeze
         | 
| 6 | 
            -
              s.version = "0. | 
| 6 | 
            +
              s.version = "0.1.0".freeze
         | 
| 7 7 |  | 
| 8 8 | 
             
              s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
         | 
| 9 9 | 
             
              s.require_paths = ["lib".freeze]
         | 
| @@ -12,8 +12,8 @@ Gem::Specification.new do |s| | |
| 12 12 | 
             
              s.description = "Gem that provides terminal-based data visualization capabilities, enabling\ndevelopers to create dynamic, real-time graphical displays of numerical data\ndirectly within terminal environments using Unicode characters and ANSI\nstyling.\n".freeze
         | 
| 13 13 | 
             
              s.email = "flori@ping.de".freeze
         | 
| 14 14 | 
             
              s.executables = ["graphina".freeze]
         | 
| 15 | 
            -
              s.extra_rdoc_files = ["README.md".freeze, "lib/graphina.rb".freeze, "lib/graphina/graph.rb".freeze, "lib/graphina/graph/display.rb".freeze, "lib/graphina/graph/display/cell.rb".freeze, "lib/graphina/graph/formatters.rb".freeze, "lib/graphina/version.rb".freeze]
         | 
| 16 | 
            -
              s.files = ["Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/graphina".freeze, "graphina.gemspec".freeze, "lib/graphina.rb".freeze, "lib/graphina/graph.rb".freeze, "lib/graphina/graph/display.rb".freeze, "lib/graphina/graph/display/cell.rb".freeze, "lib/graphina/graph/formatters.rb".freeze, "lib/graphina/version.rb".freeze]
         | 
| 15 | 
            +
              s.extra_rdoc_files = ["README.md".freeze, "lib/graphina.rb".freeze, "lib/graphina/graph.rb".freeze, "lib/graphina/graph/display.rb".freeze, "lib/graphina/graph/display/cell.rb".freeze, "lib/graphina/graph/formatters.rb".freeze, "lib/graphina/graphina_config.rb".freeze, "lib/graphina/panel.rb".freeze, "lib/graphina/panel/chooser.rb".freeze, "lib/graphina/version.rb".freeze]
         | 
| 16 | 
            +
              s.files = ["Gemfile".freeze, "LICENSE".freeze, "README.md".freeze, "Rakefile".freeze, "VERSION".freeze, "bin/graphina".freeze, "graphina.gemspec".freeze, "lib/graphina.rb".freeze, "lib/graphina/graph.rb".freeze, "lib/graphina/graph/display.rb".freeze, "lib/graphina/graph/display/cell.rb".freeze, "lib/graphina/graph/formatters.rb".freeze, "lib/graphina/graphina_config.rb".freeze, "lib/graphina/panel.rb".freeze, "lib/graphina/panel/chooser.rb".freeze, "lib/graphina/version.rb".freeze]
         | 
| 17 17 | 
             
              s.homepage = "https://github.com/flori/graphina".freeze
         | 
| 18 18 | 
             
              s.licenses = ["MIT".freeze]
         | 
| 19 19 | 
             
              s.rdoc_options = ["--title".freeze, "Graphina - Gem for creating terminal-based data visualizations with real-time\ngraphical displays using Unicode characters and ANSI styling.\n".freeze, "--main".freeze, "README.md".freeze]
         | 
| @@ -27,4 +27,7 @@ Gem::Specification.new do |s| | |
| 27 27 | 
             
              s.add_development_dependency(%q<debug>.freeze, ["~> 1.0".freeze])
         | 
| 28 28 | 
             
              s.add_runtime_dependency(%q<tins>.freeze, ["~> 1.45".freeze])
         | 
| 29 29 | 
             
              s.add_runtime_dependency(%q<term-ansicolor>.freeze, ["~> 1.11".freeze])
         | 
| 30 | 
            +
              s.add_runtime_dependency(%q<const_conf>.freeze, ["~> 0.4".freeze, ">= 0.4.3".freeze])
         | 
| 31 | 
            +
              s.add_runtime_dependency(%q<amatch>.freeze, ["~> 0.5".freeze])
         | 
| 32 | 
            +
              s.add_runtime_dependency(%q<search_ui>.freeze, [">= 0".freeze])
         | 
| 30 33 | 
             
            end
         | 
| @@ -46,9 +46,6 @@ class Graphina::Graph | |
| 46 46 | 
             
                # array of Cell objects that represent the display grid, filling each cell
         | 
| 47 47 | 
             
                # with a space character and default styling attributes
         | 
| 48 48 | 
             
                #
         | 
| 49 | 
            -
                # @param color [ Symbol ] the default text color for the display
         | 
| 50 | 
            -
                # @param on_color [ Symbol ] the default background color for the display
         | 
| 51 | 
            -
                #
         | 
| 52 49 | 
             
                # @return [ Graphina::Graph::Display ] returns the Display instance to allow
         | 
| 53 50 | 
             
                #   for method chaining
         | 
| 54 51 | 
             
                def clear
         | 
    
        data/lib/graphina/graph.rb
    CHANGED
    
    | @@ -286,8 +286,8 @@ class Graphina::Graph | |
| 286 286 | 
             
              #
         | 
| 287 287 | 
             
              # This method applies the appropriate formatting to a value based on the
         | 
| 288 288 | 
             
              # \@format_value instance variable configuration It supports different
         | 
| 289 | 
            -
              # formatting approaches including custom Proc objects,  | 
| 290 | 
            -
              # calls, and default formatting
         | 
| 289 | 
            +
              # formatting approaches including custom Proc objects, String- or
         | 
| 290 | 
            +
              # Symbol-based method calls, and default formatting
         | 
| 291 291 | 
             
              #
         | 
| 292 292 | 
             
              # @param value [ Object ] the value to be formatted according to the configured strategy
         | 
| 293 293 | 
             
              #
         | 
| @@ -296,7 +296,7 @@ class Graphina::Graph | |
| 296 296 | 
             
                case @format_value
         | 
| 297 297 | 
             
                when Proc
         | 
| 298 298 | 
             
                  @format_value.(value)
         | 
| 299 | 
            -
                when Symbol
         | 
| 299 | 
            +
                when Symbol, String
         | 
| 300 300 | 
             
                  send(@format_value, value)
         | 
| 301 301 | 
             
                else
         | 
| 302 302 | 
             
                  send(:as_default, value)
         | 
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            require 'const_conf'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # A module that provides configuration management for Graphina
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # The GraphinaConfig module handles the setup and retrieval of configuration
         | 
| 6 | 
            +
            # values for the Graphina application. It uses the ConstConf library to define
         | 
| 7 | 
            +
            # and manage constants with default values, decoding mechanisms, and environment
         | 
| 8 | 
            +
            # variable support. The module specifically manages paths for configuration
         | 
| 9 | 
            +
            # directories and panel configurations using XDG Base Directory specifications
         | 
| 10 | 
            +
            # for proper cross-platform configuration handling
         | 
| 11 | 
            +
            #
         | 
| 12 | 
            +
            # @example
         | 
| 13 | 
            +
            #   Graphina::GraphinaConfig::CONFIG_DIR
         | 
| 14 | 
            +
            #   # => Pathname object pointing to the Graphina config directory
         | 
| 15 | 
            +
            module Graphina::GraphinaConfig
         | 
| 16 | 
            +
              include ConstConf
         | 
| 17 | 
            +
             | 
| 18 | 
            +
              plugin ConstConf::YAMLPlugin
         | 
| 19 | 
            +
             | 
| 20 | 
            +
              description 'Graphina configuration module'
         | 
| 21 | 
            +
              prefix      'GRAPHINA'
         | 
| 22 | 
            +
             | 
| 23 | 
            +
              XDG_CONFIG_HOME = set do
         | 
| 24 | 
            +
                description 'XDG Configuration directory path'
         | 
| 25 | 
            +
                prefix ''
         | 
| 26 | 
            +
                default { '~/.config' }
         | 
| 27 | 
            +
                decode  { Pathname.new(_1) }
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
              CONFIG_DIR = set do
         | 
| 31 | 
            +
                description 'Graphina config directory'
         | 
| 32 | 
            +
                decode { XDG_CONFIG_HOME + 'graphina' }
         | 
| 33 | 
            +
              end
         | 
| 34 | 
            +
             | 
| 35 | 
            +
              PANELS_PATH = set do
         | 
| 36 | 
            +
                description 'Panels configuration file path'
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                default CONFIG_DIR + 'panels.yml'
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
              PANELS = set do
         | 
| 42 | 
            +
                description 'Panels configuration file'
         | 
| 43 | 
            +
                default yaml(PANELS_PATH)
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| @@ -0,0 +1,56 @@ | |
| 1 | 
            +
            require 'search_ui'
         | 
| 2 | 
            +
            require 'amatch'
         | 
| 3 | 
            +
             | 
| 4 | 
            +
            # A module that provides functionality for choosing panels from a configuration
         | 
| 5 | 
            +
            #
         | 
| 6 | 
            +
            # The Panel::Chooser module implements a search-based interface for selecting
         | 
| 7 | 
            +
            # from available panel configurations. It integrates with terminal-based user
         | 
| 8 | 
            +
            # interfaces to allow interactive selection of panels with fuzzy matching and
         | 
| 9 | 
            +
            # visual feedback during the selection process
         | 
| 10 | 
            +
            module Graphina::Panel::Chooser
         | 
| 11 | 
            +
              class << self
         | 
| 12 | 
            +
                include SearchUI
         | 
| 13 | 
            +
                include Term::ANSIColor
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                # The choose method presents an interactive selection interface for
         | 
| 16 | 
            +
                # available panels
         | 
| 17 | 
            +
                #
         | 
| 18 | 
            +
                # This method implements a search-based user interface that allows users to
         | 
| 19 | 
            +
                # select from a collection of predefined panel configurations. It utilizes
         | 
| 20 | 
            +
                # fuzzy matching to find relevant panel names and provides visual feedback
         | 
| 21 | 
            +
                # during the selection process with a colored highlight for the currently
         | 
| 22 | 
            +
                # selected option
         | 
| 23 | 
            +
                #
         | 
| 24 | 
            +
                # @param panels [ Hash ] a hash (convertible) containing panel
         | 
| 25 | 
            +
                #   configurations indexed by name
         | 
| 26 | 
            +
                #
         | 
| 27 | 
            +
                # @return [ Graphina::Panel, nil ] returns a new Panel instance configured
         | 
| 28 | 
            +
                #   with the selected panel's settings, or nil if no panel was chosen
         | 
| 29 | 
            +
                def choose(panels)
         | 
| 30 | 
            +
                  panel_names = panels.to_h.keys
         | 
| 31 | 
            +
                  panel = Search.new(
         | 
| 32 | 
            +
                    prompt: 'Choose a panel? ',
         | 
| 33 | 
            +
                    match: -> answer {
         | 
| 34 | 
            +
                      matcher = Amatch::PairDistance.new(answer.downcase)
         | 
| 35 | 
            +
                      matches = panel_names.map { |n| [ n, -matcher.similar(n.to_s.downcase) ] }.
         | 
| 36 | 
            +
                        select { |_, s| s < 0 }.sort_by(&:last).map(&:first)
         | 
| 37 | 
            +
                      matches.empty? and matches = panel_names
         | 
| 38 | 
            +
                      matches.first(Tins::Terminal.lines - 1)
         | 
| 39 | 
            +
                    },
         | 
| 40 | 
            +
                    query: -> _answer, matches, selector {
         | 
| 41 | 
            +
                      matches.each_with_index.
         | 
| 42 | 
            +
                      map { |m, i| i == selector ? on_blue { m } : m } * ?\n
         | 
| 43 | 
            +
                    },
         | 
| 44 | 
            +
                    found: -> _answer, matches, selector {
         | 
| 45 | 
            +
                      matches[selector]
         | 
| 46 | 
            +
                    },
         | 
| 47 | 
            +
                    output: STDOUT
         | 
| 48 | 
            +
                  ).start
         | 
| 49 | 
            +
                  if panel
         | 
| 50 | 
            +
                    Graphina::Panel.new(panels[panel])
         | 
| 51 | 
            +
                  else
         | 
| 52 | 
            +
                    puts
         | 
| 53 | 
            +
                  end
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
              end
         | 
| 56 | 
            +
            end
         | 
| @@ -0,0 +1,212 @@ | |
| 1 | 
            +
            # A class that represents a panel configuration for graph visualization
         | 
| 2 | 
            +
            #
         | 
| 3 | 
            +
            # The Panel class encapsulates the settings and behavior for a graph display
         | 
| 4 | 
            +
            # panel, including title, update interval, data source command, color
         | 
| 5 | 
            +
            # configuration, and formatting options. It provides methods for initializing
         | 
| 6 | 
            +
            # from configuration data or command-line options, and for generating the
         | 
| 7 | 
            +
            # appropriate data value provider proc based on the configured command or
         | 
| 8 | 
            +
            # default random data generation.
         | 
| 9 | 
            +
            class Graphina::Panel
         | 
| 10 | 
            +
              # The from_opts method creates a new Panel instance configured from
         | 
| 11 | 
            +
              # command-line options
         | 
| 12 | 
            +
              #
         | 
| 13 | 
            +
              # This method serves as a factory constructor for Panel objects, taking a
         | 
| 14 | 
            +
              # hash of command-line options and using them to initialize and configure a
         | 
| 15 | 
            +
              # new panel instance with appropriate settings
         | 
| 16 | 
            +
              #
         | 
| 17 | 
            +
              # @param opts [ Hash ] a hash containing command-line option values
         | 
| 18 | 
            +
              #
         | 
| 19 | 
            +
              # @return [ Graphina::Panel ] a new Panel instance configured with the
         | 
| 20 | 
            +
              #   provided options
         | 
| 21 | 
            +
              def self.from_opts(opts)
         | 
| 22 | 
            +
                new.configure_from_opts(opts)
         | 
| 23 | 
            +
              end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
              # The configure_from_opts method configures the panel settings based on
         | 
| 26 | 
            +
              # command-line options
         | 
| 27 | 
            +
              #
         | 
| 28 | 
            +
              # This method takes a hash of command-line options and uses them to set up
         | 
| 29 | 
            +
              # the panel's configuration values including title, update interval, data
         | 
| 30 | 
            +
              # source command, color settings, and formatting options
         | 
| 31 | 
            +
              #
         | 
| 32 | 
            +
              # @param opts [ Hash ] a hash containing command-line option values indexed
         | 
| 33 | 
            +
              #   by their short names
         | 
| 34 | 
            +
              #
         | 
| 35 | 
            +
              # @return [ Graphina::Panel ] returns the Panel instance to allow for method
         | 
| 36 | 
            +
              #   chaining
         | 
| 37 | 
            +
              def configure_from_opts(opts)
         | 
| 38 | 
            +
                configure(
         | 
| 39 | 
            +
                  title:            opts[?t],
         | 
| 40 | 
            +
                  interval:         opts[?n],
         | 
| 41 | 
            +
                  command:          opts[?e],
         | 
| 42 | 
            +
                  color:            opts[?c],
         | 
| 43 | 
            +
                  color_secondary:  opts[?C],
         | 
| 44 | 
            +
                  foreground_color: opts[?f],
         | 
| 45 | 
            +
                  background_color: opts[?b],
         | 
| 46 | 
            +
                  resolution:       opts[?r],
         | 
| 47 | 
            +
                  format_value:     opts[?F]
         | 
| 48 | 
            +
                )
         | 
| 49 | 
            +
              end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
              # The initialize method sets up a Panel instance with default configuration
         | 
| 52 | 
            +
              # values
         | 
| 53 | 
            +
              #
         | 
| 54 | 
            +
              # This method configures a new panel object with predefined default settings
         | 
| 55 | 
            +
              # for title, update interval, resolution mode, color scheme, and formatting
         | 
| 56 | 
            +
              # options before applying any custom configuration provided in the config
         | 
| 57 | 
            +
              # hash
         | 
| 58 | 
            +
              #
         | 
| 59 | 
            +
              # @param config [ Hash ] a hash containing panel configuration values to
         | 
| 60 | 
            +
              #   override defaults
         | 
| 61 | 
            +
              #
         | 
| 62 | 
            +
              # @return [ Graphina::Panel ] returns the initialized Panel instance
         | 
| 63 | 
            +
              def initialize(config = {})
         | 
| 64 | 
            +
                self.title            = 'Data'
         | 
| 65 | 
            +
                self.interval         = 10.0
         | 
| 66 | 
            +
                self.resolution       = :double
         | 
| 67 | 
            +
                self.foreground_color = :white
         | 
| 68 | 
            +
                self.background_color = :black
         | 
| 69 | 
            +
                self.format_value     = :as_default
         | 
| 70 | 
            +
                configure(config)
         | 
| 71 | 
            +
              end
         | 
| 72 | 
            +
             | 
| 73 | 
            +
              # The configure method sets panel attributes based on a configuration hash
         | 
| 74 | 
            +
              #
         | 
| 75 | 
            +
              # This method iterates over a configuration hash and dynamically assigns
         | 
| 76 | 
            +
              # values to panel attributes by calling corresponding setter methods
         | 
| 77 | 
            +
              #
         | 
| 78 | 
            +
              # @param config [ Hash ] a hash containing panel configuration values to be
         | 
| 79 | 
            +
              #   applied
         | 
| 80 | 
            +
              #
         | 
| 81 | 
            +
              # @return [ Graphina::Panel ] returns the Panel instance to allow for method
         | 
| 82 | 
            +
              #   chaining
         | 
| 83 | 
            +
              def configure(config)
         | 
| 84 | 
            +
                config.to_h.each do |name, value|
         | 
| 85 | 
            +
                  value.nil? and next
         | 
| 86 | 
            +
                  respond_to?("#{name}=") or raise ArgumentError, "invalid attribute #{name.inspect}"
         | 
| 87 | 
            +
                  send("#{name}=", value)
         | 
| 88 | 
            +
                end
         | 
| 89 | 
            +
              end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
              attr_accessor :title
         | 
| 92 | 
            +
             | 
| 93 | 
            +
              # The interval reader method provides access to the interval attribute that
         | 
| 94 | 
            +
              # was set during object initialization.
         | 
| 95 | 
            +
              #
         | 
| 96 | 
            +
              # This method returns the value of the interval instance variable, which
         | 
| 97 | 
            +
              # typically represents the update interval in seconds for the graph
         | 
| 98 | 
            +
              # visualization.
         | 
| 99 | 
            +
              #
         | 
| 100 | 
            +
              # @return [ Numeric ] the interval value stored in the instance variable
         | 
| 101 | 
            +
              attr_reader :interval
         | 
| 102 | 
            +
             | 
| 103 | 
            +
              # The interval= method sets the update interval for the graph visualization
         | 
| 104 | 
            +
              #
         | 
| 105 | 
            +
              # This method assigns a new value to the interval instance variable, ensuring
         | 
| 106 | 
            +
              # that the interval is at least 0.01 seconds to prevent excessively rapid
         | 
| 107 | 
            +
              # updates
         | 
| 108 | 
            +
              #
         | 
| 109 | 
            +
              # @param value [ Object ] the new interval value to be set
         | 
| 110 | 
            +
              #
         | 
| 111 | 
            +
              # @return [ Numeric ] the normalized interval value that is at least 0.01
         | 
| 112 | 
            +
              #   seconds
         | 
| 113 | 
            +
              def interval=(value)
         | 
| 114 | 
            +
                @interval = [ 0.01, value.to_f ].max
         | 
| 115 | 
            +
              end
         | 
| 116 | 
            +
             | 
| 117 | 
            +
              # The command accessor method provides read and write access to the command
         | 
| 118 | 
            +
              # attribute
         | 
| 119 | 
            +
              #
         | 
| 120 | 
            +
              # This method creates a public getter and setter for the command instance
         | 
| 121 | 
            +
              # variable which stores the external command string used to generate data
         | 
| 122 | 
            +
              # values for visualization
         | 
| 123 | 
            +
              #
         | 
| 124 | 
            +
              # @attr [ String, nil ] command the external command string for data generation
         | 
| 125 | 
            +
              attr_accessor :command
         | 
| 126 | 
            +
             | 
| 127 | 
            +
              # The color accessor method provides read and write access to the color
         | 
| 128 | 
            +
              # attribute
         | 
| 129 | 
            +
              #
         | 
| 130 | 
            +
              # This method creates a public getter and setter for the color instance
         | 
| 131 | 
            +
              # variable which stores the primary color value used for graph visualization
         | 
| 132 | 
            +
              #
         | 
| 133 | 
            +
              # @attr [ Object, nil ] color the primary color value for graph visualization
         | 
| 134 | 
            +
              attr_accessor :color
         | 
| 135 | 
            +
             | 
| 136 | 
            +
              # The color_secondary accessor method provides read and write access to the
         | 
| 137 | 
            +
              # color_secondary attribute
         | 
| 138 | 
            +
              #
         | 
| 139 | 
            +
              # This method creates a public getter and setter for the color_secondary
         | 
| 140 | 
            +
              # instance variable which stores the secondary color value used for enhanced
         | 
| 141 | 
            +
              # visual effects
         | 
| 142 | 
            +
              # in graph visualization
         | 
| 143 | 
            +
              #
         | 
| 144 | 
            +
              # @attr [ Object, nil ] color_secondary the secondary color value for graph
         | 
| 145 | 
            +
              #   visualization
         | 
| 146 | 
            +
              attr_accessor :color_secondary
         | 
| 147 | 
            +
             | 
| 148 | 
            +
              # The foreground_color accessor method provides read and write access to the
         | 
| 149 | 
            +
              # foreground_color attribute
         | 
| 150 | 
            +
              #
         | 
| 151 | 
            +
              # This method creates a public getter and setter for the foreground_color
         | 
| 152 | 
            +
              # instance variable which stores the text color value used for graph
         | 
| 153 | 
            +
              # visualization
         | 
| 154 | 
            +
              #
         | 
| 155 | 
            +
              # @attr [ Symbol ] foreground_color the text color value for graph
         | 
| 156 | 
            +
              #   visualization
         | 
| 157 | 
            +
              attr_accessor :foreground_color
         | 
| 158 | 
            +
             | 
| 159 | 
            +
              # The background_color accessor method provides read and write access to the
         | 
| 160 | 
            +
              # background_color attribute
         | 
| 161 | 
            +
              #
         | 
| 162 | 
            +
              # This method creates a public getter and setter for the background_color
         | 
| 163 | 
            +
              # instance variable which stores the background color value used for graph
         | 
| 164 | 
            +
              # visualization
         | 
| 165 | 
            +
              #
         | 
| 166 | 
            +
              # @attr [ Symbol ] background_color the background color value for graph
         | 
| 167 | 
            +
              #   visualization
         | 
| 168 | 
            +
              attr_accessor :background_color
         | 
| 169 | 
            +
             | 
| 170 | 
            +
              # The resolution accessor method provides read and write access to the
         | 
| 171 | 
            +
              # resolution attribute
         | 
| 172 | 
            +
              #
         | 
| 173 | 
            +
              # This method creates a public getter and setter for the resolution instance
         | 
| 174 | 
            +
              # variable which stores the display resolution mode for the graph
         | 
| 175 | 
            +
              # visualization
         | 
| 176 | 
            +
              #
         | 
| 177 | 
            +
              # @attr [ Symbol ] resolution the display resolution mode (:single or
         | 
| 178 | 
            +
              #   :double) for graph visualization
         | 
| 179 | 
            +
              attr_accessor :resolution
         | 
| 180 | 
            +
             | 
| 181 | 
            +
              # The format_value accessor method provides read and write access to the
         | 
| 182 | 
            +
              # format_value attribute
         | 
| 183 | 
            +
              #
         | 
| 184 | 
            +
              # This method creates a public getter and setter for the format_value
         | 
| 185 | 
            +
              # instance variable which stores the formatting strategy used for displaying
         | 
| 186 | 
            +
              # data values
         | 
| 187 | 
            +
              #
         | 
| 188 | 
            +
              # @attr [ Symbol, Proc, nil ] format_value the formatting strategy for
         | 
| 189 | 
            +
              #   displaying data values
         | 
| 190 | 
            +
              attr_accessor :format_value
         | 
| 191 | 
            +
             | 
| 192 | 
            +
              # The value method returns a proc that generates data values for graph
         | 
| 193 | 
            +
              # display
         | 
| 194 | 
            +
              #
         | 
| 195 | 
            +
              # This method creates and returns a proc object that serves as the data
         | 
| 196 | 
            +
              # source for the graph visualization. When the graph needs a new data point,
         | 
| 197 | 
            +
              # it invokes this proc with an index parameter. The proc either executes a
         | 
| 198 | 
            +
              # configured external command and converts its output to a float, or
         | 
| 199 | 
            +
              # generates a random float value between 0 and 100 if no command is specified
         | 
| 200 | 
            +
              #
         | 
| 201 | 
            +
              # @return [ Proc ] a proc that takes an index parameter and returns a numeric
         | 
| 202 | 
            +
              #   value for graph plotting
         | 
| 203 | 
            +
              def value
         | 
| 204 | 
            +
                if @command
         | 
| 205 | 
            +
                  -> i { `#@command`.to_f }
         | 
| 206 | 
            +
                else
         | 
| 207 | 
            +
                  -> i { rand(100).to_f }
         | 
| 208 | 
            +
                end
         | 
| 209 | 
            +
              end
         | 
| 210 | 
            +
            end
         | 
| 211 | 
            +
             | 
| 212 | 
            +
            require 'graphina/panel/chooser'
         | 
    
        data/lib/graphina/version.rb
    CHANGED
    
    
    
        data/lib/graphina.rb
    CHANGED
    
    | @@ -1,4 +1,18 @@ | |
| 1 | 
            +
            require 'tins'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # Graphina module
         | 
| 4 | 
            +
            #
         | 
| 5 | 
            +
            # The Graphina module serves as the root namespace for the Graphina gem, which
         | 
| 6 | 
            +
            # provides terminal-based data visualization capabilities. It contains the core
         | 
| 7 | 
            +
            # classes and modules responsible for creating real-time graphical displays
         | 
| 8 | 
            +
            # using Unicode characters and ANSI styling in terminal environments.
         | 
| 9 | 
            +
            #
         | 
| 10 | 
            +
            # The module organizes the various components of the gem including graph visualization
         | 
| 11 | 
            +
            # classes, panel configurations, display management, and formatting utilities into
         | 
| 12 | 
            +
            # a coherent namespace structure for easy access and usage.
         | 
| 1 13 | 
             
            module Graphina
         | 
| 2 14 | 
             
            end
         | 
| 3 15 | 
             
            require 'graphina/version'
         | 
| 16 | 
            +
            require 'graphina/graphina_config'
         | 
| 17 | 
            +
            require 'graphina/panel'
         | 
| 4 18 | 
             
            require 'graphina/graph'
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: graphina
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Florian Frank
         | 
| @@ -65,6 +65,54 @@ dependencies: | |
| 65 65 | 
             
                - - "~>"
         | 
| 66 66 | 
             
                  - !ruby/object:Gem::Version
         | 
| 67 67 | 
             
                    version: '1.11'
         | 
| 68 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 69 | 
            +
              name: const_conf
         | 
| 70 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 71 | 
            +
                requirements:
         | 
| 72 | 
            +
                - - "~>"
         | 
| 73 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 74 | 
            +
                    version: '0.4'
         | 
| 75 | 
            +
                - - ">="
         | 
| 76 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 77 | 
            +
                    version: 0.4.3
         | 
| 78 | 
            +
              type: :runtime
         | 
| 79 | 
            +
              prerelease: false
         | 
| 80 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 81 | 
            +
                requirements:
         | 
| 82 | 
            +
                - - "~>"
         | 
| 83 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 84 | 
            +
                    version: '0.4'
         | 
| 85 | 
            +
                - - ">="
         | 
| 86 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 87 | 
            +
                    version: 0.4.3
         | 
| 88 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 89 | 
            +
              name: amatch
         | 
| 90 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 91 | 
            +
                requirements:
         | 
| 92 | 
            +
                - - "~>"
         | 
| 93 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 94 | 
            +
                    version: '0.5'
         | 
| 95 | 
            +
              type: :runtime
         | 
| 96 | 
            +
              prerelease: false
         | 
| 97 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 98 | 
            +
                requirements:
         | 
| 99 | 
            +
                - - "~>"
         | 
| 100 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 101 | 
            +
                    version: '0.5'
         | 
| 102 | 
            +
            - !ruby/object:Gem::Dependency
         | 
| 103 | 
            +
              name: search_ui
         | 
| 104 | 
            +
              requirement: !ruby/object:Gem::Requirement
         | 
| 105 | 
            +
                requirements:
         | 
| 106 | 
            +
                - - ">="
         | 
| 107 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 108 | 
            +
                    version: '0'
         | 
| 109 | 
            +
              type: :runtime
         | 
| 110 | 
            +
              prerelease: false
         | 
| 111 | 
            +
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 112 | 
            +
                requirements:
         | 
| 113 | 
            +
                - - ">="
         | 
| 114 | 
            +
                  - !ruby/object:Gem::Version
         | 
| 115 | 
            +
                    version: '0'
         | 
| 68 116 | 
             
            description: |
         | 
| 69 117 | 
             
              Gem that provides terminal-based data visualization capabilities, enabling
         | 
| 70 118 | 
             
              developers to create dynamic, real-time graphical displays of numerical data
         | 
| @@ -81,6 +129,9 @@ extra_rdoc_files: | |
| 81 129 | 
             
            - lib/graphina/graph/display.rb
         | 
| 82 130 | 
             
            - lib/graphina/graph/display/cell.rb
         | 
| 83 131 | 
             
            - lib/graphina/graph/formatters.rb
         | 
| 132 | 
            +
            - lib/graphina/graphina_config.rb
         | 
| 133 | 
            +
            - lib/graphina/panel.rb
         | 
| 134 | 
            +
            - lib/graphina/panel/chooser.rb
         | 
| 84 135 | 
             
            - lib/graphina/version.rb
         | 
| 85 136 | 
             
            files:
         | 
| 86 137 | 
             
            - Gemfile
         | 
| @@ -95,6 +146,9 @@ files: | |
| 95 146 | 
             
            - lib/graphina/graph/display.rb
         | 
| 96 147 | 
             
            - lib/graphina/graph/display/cell.rb
         | 
| 97 148 | 
             
            - lib/graphina/graph/formatters.rb
         | 
| 149 | 
            +
            - lib/graphina/graphina_config.rb
         | 
| 150 | 
            +
            - lib/graphina/panel.rb
         | 
| 151 | 
            +
            - lib/graphina/panel/chooser.rb
         | 
| 98 152 | 
             
            - lib/graphina/version.rb
         | 
| 99 153 | 
             
            homepage: https://github.com/flori/graphina
         | 
| 100 154 | 
             
            licenses:
         |