rcurses 2.1 → 2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c193555f436c0c4c0b2b3f41c8ba4045987ac9f35bdbc8258c0018584ef79f8a
4
- data.tar.gz: e704f5c7356ebc779a23092de1b50c54b6aea1b50703578b3614fe82dd04e3bc
3
+ metadata.gz: df1c1a4900f937e9e6b6b8ff3ca39d830d548c2e5a2627d57cdc058939b9aa02
4
+ data.tar.gz: 8098dc2b5bb4dca9a33a33d17dc6b91ecf496da7a18f6766990abcf036b6d7ff
5
5
  SHA512:
6
- metadata.gz: 4cb46397b2629300cb28caec54f0fcf2679f51a8e1417f8f4f89be7e7fde4da6245c532af54a8a53d98eb71e4a17ddb9a8cee3727f452e6d94f08997c6d87e3b
7
- data.tar.gz: d90157ceb59ddafd9679d5f164339d3fe0a540a2fc3d25f5abfb825aadcfb35b49f704c5589caaf1b8fac07a7fca23521cb495f31f4ac327f663399cb0599e0e
6
+ metadata.gz: 9f6edc61f223b29c81c268f0141c75d0a7ea6b1a176da81dbd2fe8efadf3c9ddda6d0be90d69b170771a56b2e947c5422d720d676e6697ffc909f988e9de2123
7
+ data.tar.gz: a3dd0151452e7f910d2a1e2d9032a1b98c99df77d91bf7e3e9d3024391755d759625064d1d11404496f69b73d1bf08681a4286b82b058538cf45d32d80eeba44
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rcurses'
4
+ include Rcurses::Input
5
+ include Rcurses::Cursor
6
+
7
+ @max_h, @max_w = IO.console.winsize
8
+ @pane = []
9
+ @focused = 3 # Start with pane 3 so that the first keypress focuses back to Pane 0
10
+ hide_cursor
11
+
12
+ # Start by creating the panes; Format:
13
+ # pane = Rcurses::Pane.new( startx, starty, width, height, fg, bg)
14
+ pane_back = Rcurses::Pane.new( 1, 1, @max_w, @max_h, 255, 236)
15
+ @pane[0] = Rcurses::Pane.new( 4, 4, 20, 10, 236, 254)
16
+ @pane[1] = Rcurses::Pane.new( 30, 10, 16, 12, 232, 132)
17
+ @pane[2] = Rcurses::Pane.new( 8, 20, 30, 20, 136, 54)
18
+ @pane[3] = Rcurses::Pane.new( 50, 30, 24, 10, 206, 24)
19
+
20
+ pane_back.text = "PRESS ANY KEY TO SHIFT FOCUS. PRESS 'ESC' TO QUIT."
21
+ @pane.each_index { |i| @pane[i].text = "This is pane " + i.to_s }
22
+ pane_back.refresh
23
+ @pane.each_index { |i| @pane[i].refresh }
24
+
25
+ input = ''
26
+ while input != 'ESC'
27
+ input = getchr
28
+ @pane[@focused].border = false
29
+ @focused += 1
30
+ @focused = 0 if @focused == @pane.size
31
+ @pane[@focused].border = true
32
+ pane_back.refresh
33
+ @pane.each_index { |i| @pane[i].refresh }
34
+ @pane[@focused].refresh
35
+ end
36
+ col(1)
37
+ row(1)
38
+ clear_screen_down
39
+ show_cursor
@@ -4,12 +4,8 @@ module Rcurses
4
4
  module_function
5
5
  ESC = "\e".freeze
6
6
  CSI = "\e[".freeze
7
- def save # Save current position
8
- print(Gem.win_platform? ? CSI + 's' : ESC + '7')
9
- end
10
- def restore # Restore cursor position
11
- print(Gem.win_platform? ? CSI + 'u' : ESC + '8')
12
- end
7
+ def save; print(Gem.win_platform? ? CSI + 's' : ESC + '7'); end # Save current position
8
+ def restore; print(Gem.win_platform? ? CSI + 'u' : ESC + '8'); end # Restore cursor position
13
9
  def pos # Query cursor current position
14
10
  res = ''
15
11
  $stdin.raw do |stdin|
@@ -30,50 +26,22 @@ module Rcurses
30
26
  _row, col = pos
31
27
  col
32
28
  end
33
- def up(n = 1) # Move cursor up by n
34
- print(CSI + "#{(n || 1)}A")
35
- end
36
- def down(n = 1) # Move the cursor down by n
37
- print(CSI + "#{(n || 1)}B")
38
- end
39
- def left(n = 1) # Move the cursor backward by n
40
- print(CSI + "#{n || 1}D")
41
- end
42
- def right(n = 1) # Move the cursor forward by n
43
- print(CSI + "#{n || 1}C")
44
- end
45
- def col(n = 1) # Cursor moves to nth position horizontally in the current line
46
- print(CSI + "#{n || 1}G")
47
- end
48
- def row(n = 1) # Cursor moves to the nth position vertically in the current column
49
- print(CSI + "#{n || 1}d")
50
- end
51
- def next_line # Move cursor down to beginning of next line
52
- print(CSI + 'E' + CSI + "1G")
53
- end
54
- def prev_line # Move cursor up to beginning of previous line
55
- print(CSI + 'A' + CSI + "1G")
56
- end
57
- def clear_char(n = 1) # Erase n characters from the current cursor position
58
- print(CSI + "#{n}X")
59
- end
60
- def clear_line # Erase the entire current line and return to beginning of the line
61
- print(CSI + '2K' + CSI + "1G")
62
- end
63
- def clear_line_before # Erase from the beginning of the line up to and including the current cursor position.
64
- print(CSI + '1K')
65
- end
66
- def clear_line_after # Erase from the current position (inclusive) to the end of the line
67
- print(CSI + '0K')
68
- end
69
- def clear_screen_down # Clear screen down from current row
70
- print(CSI + 'J')
71
- end
72
- def scroll_up # Scroll display up one line
73
- print(ESC + 'M')
74
- end
75
- def scroll_down # Scroll display down one line
76
- print(ESC + 'D')
77
- end
29
+ def up(n = 1); print(CSI + "#{(n)}A"); end # Move cursor up by n
30
+ def down(n = 1); print(CSI + "#{(n)}B"); end # Move the cursor down by n
31
+ def left(n = 1); print(CSI + "#{n}D"); end # Move the cursor backward by n
32
+ def right(n = 1); print(CSI + "#{n}C"); end # Move the cursor forward by n
33
+ def col(n = 1); print(CSI + "#{n}G"); end # Cursor moves to nth position horizontally in the current line
34
+ def row(n = 1); print(CSI + "#{n}d"); end # Cursor moves to the nth position vertically in the current column
35
+ def next_line; print(CSI + 'E' + CSI + "1G"); end # Move cursor down to beginning of next line
36
+ def prev_line; print(CSI + 'A' + CSI + "1G"); end # Move cursor up to beginning of previous line
37
+ def clear_char(n = 1); print(CSI + "#{n}X"); end # Erase n characters from the current cursor position
38
+ def clear_line; print(CSI + '2K' + CSI + "1G"); end # Erase the entire current line and return to beginning of the line
39
+ def clear_line_before; print(CSI + '1K'); end # Erase from the beginning of the line up to and including the current cursor position.
40
+ def clear_line_after; print(CSI + '0K'); end # Erase from the current position (inclusive) to the end of the line
41
+ def clear_screen_down; print(CSI + 'J'); end # Clear screen down from current row
42
+ def scroll_up; print(ESC + 'M'); end # Scroll display up one line
43
+ def scroll_down; print(ESC + 'D'); end # Scroll display down one line
44
+ def hide_cursor; print(CSI + '?25l'); end # Scroll display down one line
45
+ def show_cursor; print(CSI + '?25h'); end # Scroll display down one line
78
46
  end
79
47
  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: 2.1: New gem structure
8
+ # Version: 2.2: Added example focus_panes.rb and hide_cursor/show_cursor as Cursor functions
9
9
 
10
10
  require 'io/console' # Basic gem for rcurses
11
11
  require 'io/wait' # stdin handling
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rcurses
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.1'
4
+ version: '2.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Geir Isene
@@ -28,8 +28,8 @@ description: 'Create panes (with the colors and(or border), manipulate the panes
28
28
  add content. Dress up text (in panes or anywhere in the terminal) in bold, italic,
29
29
  underline, reverse color, blink and in any 256 terminal colors for foreground and
30
30
  background. Use a simple editor to let users edit text in panes. Left, right or
31
- center align text in panes. Cursor movement around the terminal. New in 2.1: New
32
- gem structure.'
31
+ center align text in panes. Cursor movement around the terminal. New in 2.2: Added
32
+ example focus_panes.rb and hide_cursor/show_cursor as Cursor functions.'
33
33
  email: g@isene.com
34
34
  executables: []
35
35
  extensions: []
@@ -38,6 +38,7 @@ files:
38
38
  - LICENSE
39
39
  - README.md
40
40
  - examples/basic_panes.rb
41
+ - examples/focus_panes.rb
41
42
  - lib/rcurses.rb
42
43
  - lib/rcurses/cursor.rb
43
44
  - lib/rcurses/input.rb