rcurses 4.6 → 4.8

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -15
  3. data/lib/rcurses/pane.rb +6 -5
  4. data/lib/rcurses.rb +42 -1
  5. metadata +3 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 240aec267dd4c5e8377ffba6844848463a8d4a0c5291f159f354e9c600e6a264
4
- data.tar.gz: 3d3534900f41903901758496d0ed0494c400c6ca45dfbd9eb3265b1b924fd108
3
+ metadata.gz: 3315a5ab0bf9cc3f4db94b09c87de6f06319f34138e3ed5d6b71410202ccecdf
4
+ data.tar.gz: 6e7ef74687339050e3eb2f8e74ccfc42c90d9d1c9aa2a5cdb3d24554d3e8e1d4
5
5
  SHA512:
6
- metadata.gz: 92a3f431d49eb85bd4c2a25429acfe87acb2cb1a553c4ebad78614f3e34c3f9bcd23037b725b72a117404fa22397a8d5e8a6ba0d1b6193b227c126bcb4f87e80
7
- data.tar.gz: 07e0d869aa2025be468a98d359ef2f1894751b301c5ec37965fe75b6bb97bec452b01bcd67c6ddb3fa6a08fe7f7289d85082eaf0153ac6b487d70d417759e1eb
6
+ metadata.gz: 20d838d608ac34060d0bb9a8a39f791ec02a302745dbed150bd0cd65ef1ed008803b4c6bb5ea41dbb7da25782ea4f7c6115eb9a6ee4d887208db38c419ee214c
7
+ data.tar.gz: 1dffaed1371b88950bb579dc2173f076b4646cdd69dd9690d6e89ad8d3da954a532c929ce91f1dccada6fa8f670912066364b32b11c8395962d4305d3e6e8196
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,9 +116,9 @@ 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
- ansi_clean | Strip seemingly uncolored strings of ansi code (those that are enclosed in "\e[0m"
121
+ clean_ansi | 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
122
123
  inject("chars",pos) | Inject "chars" at position 'pos' in the pure version of the string (if 'pos' is '-1', then append at end). Preserves any ANSI code
123
124
 
@@ -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
 
@@ -176,8 +176,9 @@ module Rcurses
176
176
 
177
177
  o_row, o_col = pos
178
178
 
179
- # Hide cursor and disable auto-wrap (minimal fix)
180
- STDOUT.print "\e[?25l\e[?7l"
179
+ # Hide cursor, disable auto-wrap, reset all SGR and scroll margins
180
+ # (so stray underline, scroll regions, etc. can’t leak out)
181
+ STDOUT.print "\e[?25l\e[?7l\e[0m\e[r"
181
182
 
182
183
  fmt = [@fg.to_s, @bg.to_s].join(',')
183
184
 
@@ -242,8 +243,8 @@ module Rcurses
242
243
  end
243
244
  end
244
245
 
245
- # Re-enable wrap just before printing the final buffer
246
- diff_buf << "\e[#{o_row};#{o_col}H\e[?7h"
246
+ # restore wrap, then also reset SGR and scroll-region one more time
247
+ diff_buf << "\e[#{o_row};#{o_col}H\e[?7h\e[0m\e[r"
247
248
  print diff_buf
248
249
  @prev_frame = new_frame
249
250
 
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.8: Bugfix: Removed stray ansi codes
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\:\ :
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.6'
4
+ version: '4.8'
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-06 00:00:00.000000000 Z
11
+ date: 2025-06-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -30,8 +30,7 @@ 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.6: Fixed a broken pane.edit. Fixed ANSI termination bug
34
- in RGB support.'
33
+ upon utf-8 characters. 4.8: Bugfix: Removed stray ansi codes.'
35
34
  email: g@isene.com
36
35
  executables: []
37
36
  extensions: []