rcurses 4.5 → 4.7

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: 494b705528b9bb3e5040c9ecf8c1ff31c7cf0db13e04736140f35298d49b48b0
4
- data.tar.gz: 6f74dc4880397c55461c6ff0f5a6371edec67edfdfb3eb3d65d7dafdc5ac6295
3
+ metadata.gz: 5bd13b6d8edf4884599788ea2ab4ee0cd74e19c76dd5d8816fee9a8c39af2ed7
4
+ data.tar.gz: 710c11b21962f2c833b109dd1991a4e61994db67609ffa41f85ceca7d8f08aaf
5
5
  SHA512:
6
- metadata.gz: 0cbed1ef8307fd124d035dce74501d58f648668884ae50190d82460d33b3825557ccd1f07b4c0a64d7b69c81a0c1ef240cf1828adc769e96ffd9bfb47d3e7f08
7
- data.tar.gz: 0f7747ce65c0f8103759b8df5e64bceee0bf7593d137380a08b6002ec6cbaeb3540236f9ebc65b1f28f293ed009b76565fe4e0fd63cdcb2bf597dd32430107cc
6
+ metadata.gz: 6ba8e09362dd518bf485d0e5d725fe421fe1fa70d03827878581d75c9296645b7edef9450881ae4403fd9fe9fa64208c58d3b196b194d27dd8021bf990bb5e13
7
+ data.tar.gz: b1bd57631466afd0da235ee5c4e34e9124c6fd15a40bb2db44bb4ddcf9c8a54d8809c593ed580d64200fab02a4bed315723bb5ad48731f165ed9867453810a3e
data/README.md CHANGED
@@ -73,7 +73,8 @@ bg | Background color for the Pane
73
73
  border | Draw border around the Pane (=true) or not (=false), default being false
74
74
  scroll | Whether to indicate more text to be shown above/below the Pane, default is true
75
75
  text | The text/content of the Pane
76
- ix | "Index" - the line number at the top of the Pane, starts at 0, the first line of text in the Pane
76
+ ix | The line number at the top of the Pane, starts at 0, the first line of text in the Pane
77
+ index | An attribute that can be used to track the selected line/element in the pane
77
78
  align | Text alignment in the Pane: "l" = lefts aligned, "c" = center, "r" = right, with the default "l"
78
79
  prompt | The prompt to print at the beginning of a one-liner Pane used as an input box
79
80
  moreup | Set to true when there is more text above what is shown (top scroll bar i showing)
@@ -88,7 +89,7 @@ move(x,y) | Move the pane by `x`and `y` (`mypane.move(-4,5)` will move the
88
89
  refresh | Refreshes/redraws the Pane with content
89
90
  border_refresh | Refresh the Pane border only
90
91
  full_refresh | Refreshes/redraws the Pane with content completely (without diff rendering)
91
- edit | An editor for the Pane. When this is invoked, all existing font dressing is stripped and the user gets to edit the raw text. The user can add font effects similar to Markdown; Use an asterisk before and after text to be drawn in bold, text between forward-slashes become italic, and underline before and after text means the text will be underlined, a hash-sign before and after text makes the text reverse colored. You can also combine a whole set of dressings in this format: `<23,245,biurl|Hello World!>` - this will make "Hello World!" print in the color 23 with the background color 245 (regardless of the Pane's fg/bg setting) in bold, italic, underlined, reversed colored and blinking. Hitting `ESC` while in edit mode will disregard the edits, while `Ctrl-S` will save the edits
92
+ edit | An editor for the Pane. When this is invoked, all existing font dressing is stripped and the user gets to edit the raw text. The user can add font effects similar to Markdown; Use an asterisk before and after text to be drawn in bold, text between forward-slashes become italic, and underline before and after text means the text will be underlined, a hash-sign before and after text makes the text reverse colored. You can also combine a whole set of dressings in this format: `<23,245,biurl\|Hello World!>` - this will make "Hello World!" print in the color 23 with the background color 245 (regardless of the Pane's fg/bg setting) in bold, italic, underlined, reversed colored and blinking. Hitting `ESC` while in edit mode will disregard the edits, while `Ctrl-S` will save the edits
92
93
  editline | Used for one-line Panes. It will print the content of the property `prompt` and then the property `text` that can then be edited by the user. Hitting `ESC` will disregard the edits, while `ENTER` will save the edited text
93
94
  clear | Clears the pane
94
95
  say(text) | Short form for setting panel.text, then doing a refresh of that panel
@@ -115,7 +116,7 @@ i | Set text to be printed in italic (example: `"TEST".i`)
115
116
  u | Set text to be printed underlined (example: `"TEST".u`)
116
117
  l | Set text to be printed blinking (example: `"TEST".l`)
117
118
  r | Set text to be printed in reverse colors (example: `"TEST".r`)
118
- c(code) | Use coded format like "TEST".c("204,45,bui") to print "TEST" in bold, underline italic, fg=204 and bg=45 (the format is `.c("fg,bg,biulr"))
119
+ c(code) | Use coded format like "TEST".c("204,45,bui") to print "TEST" in bold, underline italic, fg=204 and bg=45 (the format is `.c("fg,bg,biulr")`)
119
120
  pure | Strip text of any "dressing" (example: with `text = "TEST".b`, you will have bold text in the variable `text`, then with `text.pure` it will show "uncoded" or pure text)
120
121
  ansi_clean | Strip seemingly uncolored strings of ansi code (those that are enclosed in "\e[0m"
121
122
  shorten(n) | Shorten the pure version of the string to 'n' characters, preserving any ANSI coding
@@ -249,17 +250,6 @@ mypane.edit
249
250
 
250
251
  And - try running the example file `rcurses_example.rb`.
251
252
 
252
- # Clean exit for your application
253
- To restore the terminal fully after you exit your application, add this:
254
- ```
255
- at_exit do # Always restore terminal state on quit (or fatal)
256
- $stdin.cooked!
257
- $stdin.echo = true
258
- Rcurses.clear_screen
259
- Cursor.show
260
- end
261
- ```
262
-
263
253
  # Not yet implemented
264
254
  Let me know what other features you like to see.
265
255
 
data/lib/rcurses/pane.rb CHANGED
@@ -33,7 +33,7 @@ module Rcurses
33
33
  include Cursor
34
34
  include Input
35
35
  attr_accessor :x, :y, :w, :h, :fg, :bg
36
- attr_accessor :border, :scroll, :text, :ix, :align, :prompt
36
+ attr_accessor :border, :scroll, :text, :ix, :index, :align, :prompt
37
37
  attr_accessor :moreup, :moredown
38
38
  attr_accessor :record, :history
39
39
 
@@ -186,7 +186,7 @@ module Rcurses
186
186
  @raw_txt = cont.split("\n")
187
187
  @lazy_txt = [] # This will hold the processed (wrapped) lines as needed.
188
188
  @lazy_index = 0 # Pointer to the next raw line to process.
189
- @cached_text = cont
189
+ @cached_text = cont.dup
190
190
  @cached_w = @w
191
191
  end
192
192
 
@@ -365,15 +365,19 @@ module Rcurses
365
365
  begin
366
366
  STDIN.cooked! rescue nil
367
367
  STDIN.echo = true rescue nil
368
- Rcurses::Cursor.show
368
+ # Prepare content with visible newline markers
369
369
  content = @text.pure.gsub("\n", "¬\n")
370
- @ix = 0
371
- @line = 0
372
- @pos = 0
373
- @txt = refresh(content)
370
+ # Reset editing cursor state
371
+ @ix = 0
372
+ @line = 0
373
+ @pos = 0
374
+ # Initial render sets @txt internally for display and cursor math
375
+ refresh(content)
376
+ Rcurses::Cursor.show
374
377
  input_char = ''
375
378
 
376
379
  while input_char != 'ESC'
380
+ # Move the terminal cursor to the logical text cursor
377
381
  row(@y + @line)
378
382
  col(@x + @pos)
379
383
  input_char = getchr(flush: false)
@@ -424,9 +428,7 @@ module Rcurses
424
428
  current_line_length = @txt[@ix + @line]&.length || 0
425
429
  @pos = current_line_length
426
430
  when 'C-HOME'
427
- @ix = 0
428
- @line = 0
429
- @pos = 0
431
+ @ix = 0; @line = 0; @pos = 0
430
432
  when 'C-END'
431
433
  total_lines = @txt.length
432
434
  @ix = [total_lines - @h, 0].max
@@ -443,6 +445,7 @@ module Rcurses
443
445
  right
444
446
  end
445
447
 
448
+ # Handle any buffered input
446
449
  while IO.select([$stdin], nil, nil, 0)
447
450
  input_char = $stdin.read_nonblock(1) rescue nil
448
451
  break unless input_char
@@ -451,7 +454,9 @@ module Rcurses
451
454
  right
452
455
  end
453
456
 
454
- @txt = refresh(content)
457
+ # Re-render without overwriting the internal @txt
458
+ refresh(content)
459
+ Rcurses::Cursor.show
455
460
  end
456
461
  ensure
457
462
  STDIN.raw! rescue nil
data/lib/rcurses.rb CHANGED
@@ -5,7 +5,7 @@
5
5
  # Web_site: http://isene.com/
6
6
  # Github: https://github.com/isene/rcurses
7
7
  # License: Public domain
8
- # Version: 4.5: Full RGB support in addition to 256-colors
8
+ # Version: 4.7: Removed the need for user templates on startup/exit. Added attr 'index' to pane
9
9
 
10
10
  require 'io/console' # Basic gem for rcurses
11
11
  require 'io/wait' # stdin handling
@@ -17,4 +17,45 @@ require_relative 'rcurses/cursor'
17
17
  require_relative 'rcurses/input'
18
18
  require_relative 'rcurses/pane'
19
19
 
20
+ module Rcurses
21
+ class << self
22
+ # Public: Initialize Rcurses. Switches terminal into raw/no-echo
23
+ # and registers cleanup handlers. Idempotent.
24
+ def init!
25
+ return if @initialized
26
+ return unless $stdin.tty?
27
+
28
+ # enter raw mode, disable echo
29
+ $stdin.raw!
30
+ $stdin.echo = false
31
+
32
+ # ensure cleanup on normal exit
33
+ at_exit { cleanup! }
34
+
35
+ # ensure cleanup on signals
36
+ %w[INT TERM].each do |sig|
37
+ trap(sig) { cleanup!; exit }
38
+ end
39
+
40
+ @initialized = true
41
+ end
42
+
43
+ # Public: Restore terminal to normal mode, clear screen, show cursor.
44
+ # Idempotent: subsequent calls do nothing.
45
+ def cleanup!
46
+ return if @cleaned_up
47
+
48
+ $stdin.cooked!
49
+ $stdin.echo = true
50
+ Rcurses.clear_screen
51
+ Cursor.show
52
+
53
+ @cleaned_up = true
54
+ end
55
+ end
56
+
57
+ # Kick off initialization as soon as the library is required.
58
+ init!
59
+ end
60
+
20
61
  # vim: set sw=2 sts=2 et filetype=ruby fdn=2 fcs=fold\:\ :
@@ -1,25 +1,25 @@
1
1
  # string_extensions.rb
2
2
 
3
3
  class String
4
- # 256-color or truecolor RGB foreground
4
+ # 256-color or truecolor RGB foregroundbreset only the fg (SGR 39)
5
5
  def fg(color)
6
6
  sp, ep = if color.to_s =~ /\A[0-9A-Fa-f]{6}\z/
7
- r, g, b = color.scan(/../).map { |c| c.to_i(16) }
8
- ["\e[38;2;#{r};#{g};#{b}m", "\e[0m"]
9
- else
10
- ["\e[38;5;#{color}m", "\e[0m"]
11
- end
7
+ r, g, b = color.scan(/../).map { |c| c.to_i(16) }
8
+ ["\e[38;2;#{r};#{g};#{b}m", "\e[39m"]
9
+ else
10
+ ["\e[38;5;#{color}m", "\e[39m"]
11
+ end
12
12
  color(self, sp, ep)
13
13
  end
14
14
 
15
- # 256-color or truecolor RGB background
15
+ # 256-color or truecolor RGB backgroundbreset only the bg (SGR 49)
16
16
  def bg(color)
17
17
  sp, ep = if color.to_s =~ /\A[0-9A-Fa-f]{6}\z/
18
- r, g, b = color.scan(/../).map { |c| c.to_i(16) }
19
- ["\e[48;2;#{r};#{g};#{b}m", "\e[0m"]
20
- else
21
- ["\e[48;5;#{color}m", "\e[0m"]
22
- end
18
+ r, g, b = color.scan(/../).map { |c| c.to_i(16) }
19
+ ["\e[48;2;#{r};#{g};#{b}m", "\e[49m"]
20
+ else
21
+ ["\e[48;5;#{color}m", "\e[49m"]
22
+ end
23
23
  color(self, sp, ep)
24
24
  end
25
25
 
@@ -41,7 +41,7 @@ class String
41
41
  end
42
42
 
43
43
  sp = "\e[#{parts.join(';')}m"
44
- color(self, sp, "\e[0m")
44
+ color(self, sp, "\e[39;49m")
45
45
  end
46
46
 
47
47
  # bold, italic, underline, blink, reverse
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcurses
3
3
  version: !ruby/object:Gem::Version
4
- version: '4.5'
4
+ version: '4.7'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-05-03 00:00:00.000000000 Z
11
+ date: 2025-05-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -30,7 +30,8 @@ description: 'Create curses applications for the terminal easier than ever. Crea
30
30
  color, blink and in any 256 terminal colors for foreground and background. Use a
31
31
  simple editor to let users edit text in panes. Left, right or center align text
32
32
  in panes. Cursor movement around the terminal. New in 3.8: Fixed border fragments
33
- upon utf-8 characters. 4.5: Full RGB support in addition to 256-colors.'
33
+ upon utf-8 characters. 4.7: Removed the need for user templates on startup/exit.
34
+ Added attr ''index'' to pane.'
34
35
  email: g@isene.com
35
36
  executables: []
36
37
  extensions: []