dynamic_curses_input 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -2
- data/Gemfile +5 -5
- data/Gemfile.lock +3 -3
- data/README.md +7 -14
- data/Rakefile +3 -3
- data/buildgem.sh +3 -2
- data/dynamic_curses_input.gemspec +12 -7
- data/lib/dynamic_curses_input/color_window.rb +3 -3
- data/lib/dynamic_curses_input/input_handler.rb +23 -1
- data/lib/dynamic_curses_input/version.rb +1 -1
- data/lib/dynamic_curses_input.rb +3 -3
- data/tester.rb +20 -0
- metadata +12 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94be33a37c50fb5c028854b16e18ec655ee6a9b20c0caa0007f3939b2f4d73a8
|
4
|
+
data.tar.gz: a5f98c86a14da07791b4cc3c5950a08bb5635d5f55bbb7beef7ef873bd07d07e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 492b393474c5e309a2003cadba1049fd7bed476ba39f7c5e6592f78fcc89345000e5c70eb7e02c143d3c3362b7ffabcd5d8e3953627ec46f3771b33bdbc44d19
|
7
|
+
data.tar.gz: c9a3249fd853c5b22e457274c61f80da3c80391d0bdec16b05328196fc6db60c5d8a6657c7221af15aa6cbef2a2cdb916382e64a121f2086be4ee6d56fb565f8
|
data/CHANGELOG.md
CHANGED
@@ -4,8 +4,6 @@
|
|
4
4
|
|
5
5
|
- Initial release
|
6
6
|
|
7
|
-
## [Release]
|
8
|
-
|
9
7
|
## [1.1.0] - 2023-07-26
|
10
8
|
|
11
9
|
- Features and Enhancements:
|
@@ -28,3 +26,13 @@
|
|
28
26
|
- Other Changes:
|
29
27
|
|
30
28
|
- Removed redundant and unused code snippets to improve code cleanliness and maintainability.
|
29
|
+
|
30
|
+
## [1.2.0] - 2023-07-31
|
31
|
+
|
32
|
+
- Features Added
|
33
|
+
|
34
|
+
- Added automatic handling for the up and down arrow keys to behave more like the user would expect.
|
35
|
+
|
36
|
+
- The Up arrow will bring the cursor to the beginning of the line by setting the cursor position to 0 after checking if the cursor is already there
|
37
|
+
|
38
|
+
- The Down arrow will bring the cursor to the end of the line by setting the cursor to the position equal to the length of the input line plus 1
|
data/Gemfile
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source "https://rubygems.org"
|
4
4
|
|
5
5
|
# Specify your gem's dependencies in dynamic_curses_input.gemspec
|
6
6
|
gemspec
|
7
7
|
|
8
|
-
gem
|
8
|
+
gem "rake"
|
9
9
|
|
10
|
-
gem
|
10
|
+
gem "rubocop"
|
11
11
|
|
12
|
-
gem
|
12
|
+
gem "curses"
|
13
13
|
|
14
|
-
gem
|
14
|
+
gem "reline"
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dynamic_curses_input (1.
|
4
|
+
dynamic_curses_input (1.1.0)
|
5
5
|
curses
|
6
6
|
reline
|
7
7
|
|
@@ -21,9 +21,9 @@ GEM
|
|
21
21
|
rainbow (3.1.1)
|
22
22
|
rake (13.0.6)
|
23
23
|
regexp_parser (2.8.1)
|
24
|
-
reline (0.3.
|
24
|
+
reline (0.3.7)
|
25
25
|
io-console (~> 0.5)
|
26
|
-
rexml (3.2.
|
26
|
+
rexml (3.2.6)
|
27
27
|
rubocop (1.55.0)
|
28
28
|
json (~> 2.3)
|
29
29
|
language_server-protocol (>= 3.17.0)
|
data/README.md
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# Dynamic Curses Input
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
## Table of Contents
|
3
|
+
Dynamic Curses Input is a Ruby gem that provides a simple and intuitive way to handle user input in a Curses-based terminal user interface (TUI). It allows for dynamic input handling, including cursor movement and inline character addition and deletion.
|
6
4
|
|
7
5
|
- [Installation](#installation)
|
8
6
|
- [Usage](#usage)
|
@@ -15,7 +13,7 @@ DynamicCursesInput is a Ruby gem that provides a simple and intuitive way to han
|
|
15
13
|
|
16
14
|
## Installation
|
17
15
|
|
18
|
-
To install
|
16
|
+
To install Dynamic Curses Input, add the following line to your application's Gemfile:
|
19
17
|
|
20
18
|
```ruby
|
21
19
|
gem 'dynamic_curses_input'
|
@@ -35,7 +33,7 @@ $ gem install dynamic_curses_input
|
|
35
33
|
|
36
34
|
## Usage
|
37
35
|
|
38
|
-
Here's a simple example of how to use
|
36
|
+
Here's a simple example of how to use Dynamic Curses Input:
|
39
37
|
|
40
38
|
```ruby
|
41
39
|
require "curses"
|
@@ -61,20 +59,15 @@ In this example, `DCI.catch_input(true)` will capture user input until the Enter
|
|
61
59
|
|
62
60
|
## Documentation
|
63
61
|
|
64
|
-
Detailed documentation for each function is available in the [wiki](https://
|
62
|
+
Detailed documentation for each function is available in the [wiki](https://git.pixelridgesoftworks.com/PixelRidge-Softworks/dynamic_curses_input/wiki).
|
65
63
|
|
66
64
|
## Dependencies
|
67
65
|
|
68
66
|
DynamicCursesInput depends on the [Curses](https://github.com/ruby/curses) gem.
|
69
67
|
|
70
|
-
## FAQs
|
71
|
-
|
72
|
-
- **Q: How do I handle special keys like arrow keys?**
|
73
|
-
- A: Special keys like arrow keys are automatically handled by DynamicCursesInput.
|
74
|
-
|
75
68
|
## Troubleshooting
|
76
69
|
|
77
|
-
If you encounter any issues while using DynamicCursesInput, please check the [issues](https://
|
70
|
+
If you encounter any issues while using DynamicCursesInput, please check the [issues](https://git.pixelridgesoftworks.com/PixelRidge-Softworks/dynamic_curses_input/issues) page. If your issue isn't listed, feel free to open a new issue.
|
78
71
|
|
79
72
|
## Contribution Guidelines
|
80
73
|
|
@@ -86,6 +79,6 @@ DynamicCursesInput is available under the [MIT License](LICENSE.txt).
|
|
86
79
|
|
87
80
|
---
|
88
81
|
|
89
|
-
### Note from the Developer:
|
82
|
+
### Note from the Developer:
|
90
83
|
|
91
84
|
There is a function in this gem that is not finished yet, it's for making asking questions in a Curses TUI easier from within the gem. This method shouldn't be used yet.
|
data/Rakefile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'rspec/core/rake_task'
|
5
5
|
|
6
6
|
RSpec::Core::RakeTask.new(:spec)
|
7
7
|
|
8
|
-
require
|
8
|
+
require 'rubocop/rake_task'
|
9
9
|
|
10
10
|
RuboCop::RakeTask.new
|
11
11
|
|
data/buildgem.sh
CHANGED
@@ -8,6 +8,7 @@ sleep 1
|
|
8
8
|
echo "Cleaning up old files..."
|
9
9
|
sleep 1
|
10
10
|
gem cleanup dynamic_curses_input
|
11
|
+
rm -f dynamic_curses_input-1.2.0.gem
|
11
12
|
sleep 1
|
12
13
|
echo "Building DCI..."
|
13
14
|
sleep 1
|
@@ -16,7 +17,7 @@ echo "built!"
|
|
16
17
|
sleep 1
|
17
18
|
echo "Installing new version of DCI..."
|
18
19
|
sleep 1
|
19
|
-
gem install dynamic_curses_input-1.0.
|
20
|
+
gem install dynamic_curses_input-1.2.0.gem
|
20
21
|
echo "Installed!"
|
21
22
|
echo "press any key to exit..."
|
22
|
-
read
|
23
|
+
read ""
|
@@ -5,8 +5,8 @@ require_relative 'lib/dynamic_curses_input/version'
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
6
|
spec.name = 'dynamic_curses_input'
|
7
7
|
spec.version = DynamicCursesInput::VERSION
|
8
|
-
spec.authors = ['
|
9
|
-
spec.email = ['
|
8
|
+
spec.authors = ['PixelRidge-Softworks']
|
9
|
+
spec.email = ['connorc@pixelridgesoftworks.com']
|
10
10
|
|
11
11
|
spec.summary = 'A simple library for making Curses TUI input more dynamic and user-friendly'
|
12
12
|
spec.description = "Dynamic Curses Input is a highly simple, yet powerful gem that allows simple implementation of
|
@@ -16,17 +16,22 @@ Gem::Specification.new do |spec|
|
|
16
16
|
that code, by providing simple to use methods that allow developers to capture user input, while
|
17
17
|
allowing the special keys to work as the average user would expect.
|
18
18
|
IE: When you press the left arrow key, the cursor moves to the left and allows you to delete a
|
19
|
-
character you entered that isn't the last character you entered.
|
20
|
-
|
19
|
+
character you entered that isn't the last character you entered.
|
20
|
+
|
21
|
+
KNOWN BUG: X & Y coords for placing windows appear to be broken right now. Will fix with
|
22
|
+
next update"
|
23
|
+
spec.homepage = 'https://git.pixelridgesoftworks.com/PixelRidge-Softworks/dynamic_curses_input'
|
21
24
|
spec.license = 'MIT'
|
22
25
|
spec.required_ruby_version = '3.2.2'
|
23
26
|
|
24
27
|
spec.metadata['homepage_uri'] = spec.homepage
|
25
|
-
spec.metadata['source_code_uri'] = 'https://
|
26
|
-
spec.metadata['changelog_uri'] = 'https://
|
28
|
+
spec.metadata['source_code_uri'] = 'https://git.pixelridgesoftworks.com/PixelRidge-Softworks/dynamic_curses_input'
|
29
|
+
spec.metadata['changelog_uri'] = 'https://git.pixelridgesoftworks.com/PixelRidge-Softworks/dynamic_curses_input/src/branch/main/CHANGELOG.md'
|
27
30
|
|
28
31
|
# Specify which files should be added to the gem when it is released.
|
29
|
-
spec.files = Dir.glob('{bin,lib,sig}/**/*') + Dir.glob('*').reject
|
32
|
+
spec.files = Dir.glob('{bin,lib,sig}/**/*') + Dir.glob('*').reject do |f|
|
33
|
+
f.start_with?('spec', '.rspec', 'dynamic_curses_input.gemspec')
|
34
|
+
end
|
30
35
|
spec.files << 'LICENSE.txt'
|
31
36
|
spec.files << 'README.md'
|
32
37
|
spec.files << 'dynamic_curses_input.gemspec'
|
@@ -9,7 +9,7 @@ module DynamicCursesInput
|
|
9
9
|
# Class for creating a colored window
|
10
10
|
class ColorWindow
|
11
11
|
# Initialize instance variables and setup curses
|
12
|
-
def initialize(echo, x, y)
|
12
|
+
def initialize(echo, x, y) # rubocop:disable Metrics/MethodLength, Naming/MethodParameterName
|
13
13
|
@echo = echo # Determines whether input should be echoed to the screen
|
14
14
|
setup_curses_color # Setup curses
|
15
15
|
@x = x
|
@@ -26,7 +26,7 @@ module DynamicCursesInput
|
|
26
26
|
end
|
27
27
|
|
28
28
|
# Method that adds colored text to the window
|
29
|
-
def add_color_window(color, text, x, y, input: nil, echo: true)
|
29
|
+
def add_color_window(color, text, x, y, input: nil, echo: true) # rubocop:disable Metrics/MethodLength, Metrics/ParameterLists, Naming/MethodParameterName
|
30
30
|
# Map color names to color pair numbers
|
31
31
|
color_map = {
|
32
32
|
'black' => 1,
|
@@ -70,7 +70,7 @@ module DynamicCursesInput
|
|
70
70
|
end
|
71
71
|
|
72
72
|
# Set cursor position manually on the X and Y axis
|
73
|
-
def set_position(y, x)
|
73
|
+
def set_position(y, x) # rubocop:disable Naming/MethodParameterName
|
74
74
|
Curses.setpos(y, x)
|
75
75
|
end
|
76
76
|
end
|
@@ -47,6 +47,8 @@ module DynamicCursesInput
|
|
47
47
|
case chk
|
48
48
|
when Curses::KEY_LEFT then handle_left_key # Move cursor left
|
49
49
|
when Curses::KEY_RIGHT then handle_right_key # Move cursor right
|
50
|
+
when Curses::KEY_UP then handle_up_key
|
51
|
+
when Curses::KEY_DOWN then handle_down_key
|
50
52
|
when Curses::KEY_BACKSPACE, 127 then handle_backspace_key # Delete character
|
51
53
|
when 10, 13 then handle_enter_key # Break loop if enter key is pressed
|
52
54
|
else handle_default_key(chk) # Add character to input string
|
@@ -63,6 +65,16 @@ module DynamicCursesInput
|
|
63
65
|
@cursor_pos = CursorMover.right(@cursor_pos, @input.length)
|
64
66
|
end
|
65
67
|
|
68
|
+
# Move cursor down
|
69
|
+
def handle_down_key
|
70
|
+
@cursor_pos = CursorMover.down(@cursor_pos, @input.length)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Move cursor up
|
74
|
+
def handle_up_key
|
75
|
+
@cursor_pos = CursorMover.up(@cursor_pos, @input.length)
|
76
|
+
end
|
77
|
+
|
66
78
|
# Delete character
|
67
79
|
def handle_backspace_key
|
68
80
|
@input, @cursor_pos = CharacterDeleter.delete(@input, @cursor_pos)
|
@@ -103,8 +115,18 @@ module DynamicCursesInput
|
|
103
115
|
cursor_pos == length ? cursor_pos : cursor_pos + 1
|
104
116
|
end
|
105
117
|
|
118
|
+
# Handle down arrow key
|
119
|
+
def self.down(_, length)
|
120
|
+
length # Move to the end of the line
|
121
|
+
end
|
122
|
+
|
123
|
+
# Handle up arrow key
|
124
|
+
def self.up(_, _length)
|
125
|
+
0 # Move to the beginning of the line (position 0)
|
126
|
+
end
|
127
|
+
|
106
128
|
# Set cursor position
|
107
|
-
def self.set_position(y, x)
|
129
|
+
def self.set_position(y, x) # rubocop:disable Naming/MethodParameterName
|
108
130
|
Curses.setpos(y, x)
|
109
131
|
end
|
110
132
|
end
|
data/lib/dynamic_curses_input.rb
CHANGED
@@ -15,12 +15,12 @@ module DynamicCursesInput
|
|
15
15
|
InputHandler.catch_input(echo)
|
16
16
|
end
|
17
17
|
|
18
|
-
def self.ask_question(color = 'white', question, x: 'center', input: true, echo: nil)
|
18
|
+
def self.ask_question(color = 'white', question, x: 'center', input: true, echo: nil) # rubocop:disable Naming/MethodParameterName
|
19
19
|
Curses.clear
|
20
20
|
ColorWindow.add_color_window(color, question, y:, x:, input:, echo:)
|
21
21
|
end
|
22
22
|
|
23
|
-
def self.print_color_window(color, text, y_value: nil, x: 'center', input: nil, echo: true)
|
23
|
+
def self.print_color_window(color, text, y_value: nil, x: 'center', input: nil, echo: true) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/ParameterLists, Naming/MethodParameterName
|
24
24
|
case x
|
25
25
|
when 'center'
|
26
26
|
terminal_size = `stty size`.split.map(&:to_i)
|
@@ -59,7 +59,7 @@ module DynamicCursesInput
|
|
59
59
|
class << self
|
60
60
|
private
|
61
61
|
|
62
|
-
def process_print_color_window_args(args)
|
62
|
+
def process_print_color_window_args(args) # rubocop:disable Metrics/MethodLength
|
63
63
|
case args.size
|
64
64
|
when 2
|
65
65
|
['white', args[0], args[1], 'center', nil, true]
|
data/tester.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'dynamic_curses_input'
|
4
|
+
|
5
|
+
# Create and display a red window at the center of the screen
|
6
|
+
DCI.print_color_window('red', 'test', y_value: 60, x: '40')
|
7
|
+
|
8
|
+
# Create and display a magenta window at a specific position
|
9
|
+
DCI.print_color_window('magenta', 'testy-test', y_value: 30, x: '20')
|
10
|
+
|
11
|
+
# Initialize Curses
|
12
|
+
Curses.init_screen
|
13
|
+
Curses.cbreak
|
14
|
+
Curses.noecho
|
15
|
+
|
16
|
+
# Wait for the Enter key to be pressed
|
17
|
+
Curses.stdscr.getch until Curses.stdscr.getch == 10
|
18
|
+
|
19
|
+
# Clean up and close Curses
|
20
|
+
Curses.close_screen
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_curses_input
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- PixelRidge-Softworks
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -61,8 +61,11 @@ description: |-
|
|
61
61
|
allowing the special keys to work as the average user would expect.
|
62
62
|
IE: When you press the left arrow key, the cursor moves to the left and allows you to delete a
|
63
63
|
character you entered that isn't the last character you entered.
|
64
|
+
|
65
|
+
KNOWN BUG: X & Y coords for placing windows appear to be broken right now. Will fix with
|
66
|
+
next update
|
64
67
|
email:
|
65
|
-
-
|
68
|
+
- connorc@pixelridgesoftworks.com
|
66
69
|
executables: []
|
67
70
|
extensions: []
|
68
71
|
extra_rdoc_files: []
|
@@ -83,13 +86,14 @@ files:
|
|
83
86
|
- lib/dynamic_curses_input/input_handler.rb
|
84
87
|
- lib/dynamic_curses_input/version.rb
|
85
88
|
- sig/dynamic_curses_input.rbs
|
86
|
-
|
89
|
+
- tester.rb
|
90
|
+
homepage: https://git.pixelridgesoftworks.com/PixelRidge-Softworks/dynamic_curses_input
|
87
91
|
licenses:
|
88
92
|
- MIT
|
89
93
|
metadata:
|
90
|
-
homepage_uri: https://
|
91
|
-
source_code_uri: https://
|
92
|
-
changelog_uri: https://
|
94
|
+
homepage_uri: https://git.pixelridgesoftworks.com/PixelRidge-Softworks/dynamic_curses_input
|
95
|
+
source_code_uri: https://git.pixelridgesoftworks.com/PixelRidge-Softworks/dynamic_curses_input
|
96
|
+
changelog_uri: https://git.pixelridgesoftworks.com/PixelRidge-Softworks/dynamic_curses_input/src/branch/main/CHANGELOG.md
|
93
97
|
post_install_message:
|
94
98
|
rdoc_options: []
|
95
99
|
require_paths:
|