rcurses 3.4 → 3.4.2

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 +2 -2
  3. data/lib/rcurses/pane.rb +57 -32
  4. data/lib/rcurses.rb +1 -1
  5. metadata +4 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '089c7b974ce66ffc1afdc8c70d6b5d354f11926894329367c4ac304fc56e7af4'
4
- data.tar.gz: 23e9d5853f8977ecc914a4cdbfce0a26570d9e3076415709a150c59b5ddc61df
3
+ metadata.gz: 1dedc4f074f0fb22d35c46607f6d6a3e9d5d9b70a41cf55f677eaec9a6074b39
4
+ data.tar.gz: 136e8e4dfaae2d416e7a681d0eb9167000e9d9c0e8214e82e90899ca78302b64
5
5
  SHA512:
6
- metadata.gz: 31a9cf284d90a1ead46acfc3f3f77c0777e6e879481e01203e2bb7219579b6d694d50c08d9af7beedcd7a355244bee5975b4f3d9b037827081430abf08363721
7
- data.tar.gz: d0f9ed3cdf1a29c10e1a732f61e62c2054ad549edb04398ea5a273c49730c7bdb567e16e59ee67ebdcc9d420499e1823f2c11b087b558bb7e3bfb71b1293b6b0
6
+ metadata.gz: 487faf40ebff1682b386db0dee77af305ddae16e396339686507b50595a7f84253cc5e497825cf8d21a10e98d3bc029220c9789f53d306725aada571300c3417
7
+ data.tar.gz: 1f49d400171fffd2a34f8da725c2910df327a97d8dc58dba7a3997c01b796a60008fe3d6ae3b97fe95a58b4abd6f550bcaef5d1cf7bfa99e645dcb5eac1a90a4
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # rcurses - An alternative curses library written in pure Ruby
2
-
2
+
3
3
  ![Ruby](https://img.shields.io/badge/language-Ruby-red) [![Gem Version](https://badge.fury.io/rb/rcurses.svg)](https://badge.fury.io/rb/rcurses) ![Unlicense](https://img.shields.io/badge/license-Unlicense-green) ![Stay Amazing](https://img.shields.io/badge/Stay-Amazing-important)
4
4
 
5
5
  <img src="img/rcurses-logo.png" width="150" height="150">
@@ -82,7 +82,7 @@ refresh | Refreshes/redraws the Pane with content
82
82
  full_refresh | Refreshes/redraws the Pane with content completely (without diff rendering)
83
83
  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
84
84
  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
85
- puts(text) | Short form for setting panel.text, then doing a refresh of that panel
85
+ say(text) | Short form for setting panel.text, then doing a refresh of that panel
86
86
  ask(prompt,text) | Short form of setting panel.prompt, then panel.text, doing a panel.editline and then returning panel.text
87
87
  pagedown | Scroll down one page height in the text (minus one line), but not longer than the length of the text
88
88
  pageup | Scroll up one page height in the text (minus one line)
data/lib/rcurses/pane.rb CHANGED
@@ -35,40 +35,50 @@ module Rcurses
35
35
  attr_accessor :x, :y, :w, :h, :fg, :bg
36
36
  attr_accessor :border, :scroll, :text, :ix, :align, :prompt
37
37
  attr_accessor :moreup, :moredown
38
+ attr_accessor :record, :history
38
39
 
39
40
  def initialize(x = 1, y = 1, w = 1, h = 1, fg = nil, bg = nil)
40
41
  @max_h, @max_w = IO.console.winsize
41
- @x = x
42
- @y = y
43
- @w = w
44
- @h = h
45
- @fg, @bg = fg, bg
46
- @text = "" # Initialize text variable
47
- @align = "l" # Default alignment
48
- @scroll = true # Enable scroll indicators
49
- @prompt = "" # Prompt for editline
50
- @ix = 0 # Starting text line index
51
- @prev_frame = nil # Holds the previously rendered frame (array of lines)
52
- @line = 0 # For cursor tracking during editing:
53
- @pos = 0 # For cursor tracking during editing:
42
+ @x = x
43
+ @y = y
44
+ @w = w
45
+ @h = h
46
+ @fg, @bg = fg, bg
47
+ @text = "" # Initialize text variable
48
+ @align = "l" # Default alignment
49
+ @scroll = true # Enable scroll indicators
50
+ @prompt = "" # Prompt for editline
51
+ @ix = 0 # Starting text line index
52
+ @prev_frame = nil # Holds the previously rendered frame (array of lines)
53
+ @line = 0 # For cursor tracking during editing:
54
+ @pos = 0 # For cursor tracking during editing:
55
+ @record = false # Don't record history unless explicitly set to true
56
+ @history = [] # History array
54
57
  end
55
58
 
56
- def move(dx, dy)
57
- @x += dx
58
- @y += dy
59
- refresh
59
+ def text=(new_text)
60
+ (@history << @text) if @record && @text
61
+ @text = new_text
60
62
  end
61
63
 
62
64
  def ask(prompt, text)
63
65
  @prompt = prompt
64
66
  @text = text
65
67
  editline
68
+ (@history << @text) if @record && !@text.empty?
66
69
  @text
67
- end
70
+ end
68
71
 
69
- def puts(text)
72
+ def say(text)
73
+ (@history << text) if @record && !text.empty?
70
74
  @text = text
71
75
  @ix = 0
76
+ refresh
77
+ end
78
+
79
+ def move(dx, dy)
80
+ @x += dx
81
+ @y += dy
72
82
  refresh
73
83
  end
74
84
 
@@ -130,7 +140,9 @@ module Rcurses
130
140
  end
131
141
 
132
142
  o_row, o_col = pos
133
- STDOUT.print "\e[?25l" # Hide cursor
143
+
144
+ # Hide cursor and disable auto-wrap (minimal fix)
145
+ STDOUT.print "\e[?25l\e[?7l"
134
146
 
135
147
  fmt = [@fg, @bg].compact.join(',')
136
148
 
@@ -149,7 +161,7 @@ module Rcurses
149
161
  while @lazy_txt.size < required_lines && @lazy_index < @raw_txt.size
150
162
  raw_line = @raw_txt[@lazy_index]
151
163
  # If the raw line is short, no wrapping is needed.
152
- if raw_line.respond_to?(:pure) && raw_line.pure.length < @w
164
+ if raw_line.respond_to?(:pure) && Rcurses.display_width(raw_line.pure) < @w
153
165
  processed = [raw_line]
154
166
  else
155
167
  processed = split_line_with_ansi(raw_line, @w)
@@ -172,7 +184,7 @@ module Rcurses
172
184
  line_str = ""
173
185
  l = @ix + i
174
186
  if @txt[l].to_s != ""
175
- pl = @w - @txt[l].pure.length
187
+ pl = @w - Rcurses.display_width(@txt[l].pure)
176
188
  pl = 0 if pl < 0
177
189
  hl = pl / 2
178
190
  case @align
@@ -209,7 +221,8 @@ module Rcurses
209
221
  end
210
222
  end
211
223
 
212
- diff_buf << "\e[#{o_row};#{o_col}H"
224
+ # Re-enable wrap just before printing the final buffer
225
+ diff_buf << "\e[#{o_row};#{o_col}H\e[?7h"
213
226
  print diff_buf
214
227
  @prev_frame = new_frame
215
228
 
@@ -247,11 +260,6 @@ module Rcurses
247
260
  result
248
261
  end
249
262
 
250
- def puts(txt)
251
- @text = txt
252
- refresh
253
- end
254
-
255
263
  def right
256
264
  if @pos < @txt[@ix + @line].length
257
265
  @pos += 1
@@ -440,6 +448,7 @@ module Rcurses
440
448
  cont = @text.pure.slice(0, content_len)
441
449
  @pos = cont.length
442
450
  chr = ''
451
+ history_index = @history.size
443
452
 
444
453
  while chr != 'ESC'
445
454
  col(@x + prompt_len)
@@ -474,6 +483,22 @@ module Rcurses
474
483
  when 'ENTER'
475
484
  @text = parse(cont)
476
485
  chr = 'ESC'
486
+ when 'UP'
487
+ if @history.any? && history_index > 0
488
+ history_index -= 1
489
+ cont = @history[history_index].pure.slice(0, content_len)
490
+ @pos = cont.length
491
+ end
492
+ when 'DOWN'
493
+ if history_index < @history.size - 1
494
+ history_index += 1
495
+ cont = @history[history_index].pure.slice(0, content_len)
496
+ @pos = cont.length
497
+ elsif history_index == @history.size - 1
498
+ history_index += 1
499
+ cont = ""
500
+ @pos = 0
501
+ end
477
502
  when /^.$/
478
503
  if @pos < content_len
479
504
  cont.insert(@pos, chr)
@@ -511,7 +536,7 @@ module Rcurses
511
536
  def calculate_posx
512
537
  total_length = 0
513
538
  (@ix + @line).times do |i|
514
- total_length += @txt[i].pure.length + 1 # +1 for newline
539
+ total_length += Rcurses.display_width(@txt[i].pure) + 1 # +1 for newline
515
540
  end
516
541
  total_length += @pos
517
542
  total_length
@@ -520,7 +545,7 @@ module Rcurses
520
545
  def calculate_line_start_pos
521
546
  total_length = 0
522
547
  (@ix + @line).times do |i|
523
- total_length += @txt[i].pure.length + 1
548
+ total_length += Rcurses.display_width(@txt[i].pure) + 1
524
549
  end
525
550
  total_length
526
551
  end
@@ -556,7 +581,7 @@ module Rcurses
556
581
  else
557
582
  words = token.scan(/\s+|\S+/)
558
583
  words.each do |word|
559
- word_length = word.gsub(ansi_regex, '').length
584
+ word_length = Rcurses.display_width(word.gsub(ansi_regex, ''))
560
585
  if current_line_length + word_length <= w
561
586
  current_line << word
562
587
  current_line_length += word_length
@@ -571,7 +596,7 @@ module Rcurses
571
596
  current_line << part
572
597
  result << current_line
573
598
  word = word[w..-1]
574
- word_length = word.gsub(ansi_regex, '').length
599
+ word_length = Rcurses.display_width(word.gsub(ansi_regex, ''))
575
600
  current_line = active_sequences.join
576
601
  current_line_length = 0
577
602
  end
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: 3.3: Faster rendering of pane content
8
+ # Version: 3.4.2: Changed method 'puts' to 'say'
9
9
 
10
10
  require 'io/console' # Basic gem for rcurses
11
11
  require 'io/wait' # stdin handling
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: '3.4'
4
+ version: 3.4.2
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-04-05 00:00:00.000000000 Z
11
+ date: 2025-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clipboard
@@ -29,8 +29,8 @@ description: 'Create curses applications for the terminal easier than ever. Crea
29
29
  up text (in panes or anywhere in the terminal) in bold, italic, underline, reverse
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
- in panes. Cursor movement around the terminal. New in 3.4: Added ansi_clean and
33
- full_refresh methods.'
32
+ in panes. Cursor movement around the terminal. New in 3.4.2: Changed method ''puts''
33
+ to ''say''.'
34
34
  email: g@isene.com
35
35
  executables: []
36
36
  extensions: []