curses-extension 1.1.4 → 1.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: 20ace1645f195ea2d92bbf0cb9b84955194bfc10d1eaee5f9d535a0dd8c18668
4
- data.tar.gz: 9b2b5cc6e581753260fd16c9a474f0bdf19fc108a050d1e64671212009eb42f4
3
+ metadata.gz: a7498f40bb4872284aeb236f6a5d585e57ec07f221c932170b33a07c4dd356ae
4
+ data.tar.gz: b9cd6a36554a25fd3b8c2c7de39a48f74496b04700d017e90cfdc0c9833095d4
5
5
  SHA512:
6
- metadata.gz: 49d8d315491a99d4c3cb343d10d2d0c8f1bdce3d988458e9fdea17a38b213822accc77e49ac5f517c329a987131e13fc8cb761d12f64259f7bed05e683a7dd6a
7
- data.tar.gz: 2a1de1c02140013d55fd8ae130ab55267ba80a5ba3374727aac41ad1d9652031a1a853127a5d67fdea1799287237457b55217cac3891df3861747e67fe2d4aed
6
+ metadata.gz: 5e6222c8fe2dd03a9746693722cafa3a3faf875c76cf1acdaaad62d7d4d7d4601e60d8c6dc134bdfbdcb52e06d074923b3243c614306b2e258aecdbd7f183221
7
+ data.tar.gz: 8afba7364535e4f10b1a670908c45c5d94ae1b6ee025aa3b1ebc0c8947e23ce34343745378f7d3136b828d70b886ea87f747623e918770598a41f37447810b55
data/lib/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Ruby-Curses-Class-Extension
2
+ Extending the Ruby Curses module with some obvious functionality
3
+
4
+ ## Attributes
5
+ Attribute | Description
6
+ --------------------|--------------------------------------------------------
7
+ color | Set the window's color to an already initiated color pair (with `init_pair(index, forground, backround`)
8
+ fg | Foreground color for window (0-255)
9
+ bg | Background color for window (0-255)
10
+ attr | Attributes for window (such as Curses::A_BOLD) - string with "\|" (such as Curses::A_BOLD \| Curses::A_UNDERLINE)
11
+ update | Whether to update the window on the next refresh
12
+
13
+ ## Functions
14
+ Function | Description
15
+ ------------------------------------|--------------------------------------------------------
16
+ clr | Clears window without flicker (win.clear flickers)
17
+ clr_to_cur_pos | Clears the window up to the current line
18
+ clr_from_cur_pos | Clears the rest of the window after the current line
19
+ fill | Fill window with color as set by :color ( or :bg if not :color is set)
20
+ fill_to_cur_pos | Fill the window up to the current line
21
+ fill_from_cur_pos | Fill the rest of the window after the current line
22
+ p(text) | Write text to window with color or fg/bg and attributes (will handle the exceptions if no colors are set)
23
+ pclr(text) | As `p(text)` but also clears the rest of the window
24
+ pa(fg, bg, attr, text) | Write text to window with specified fg, bg and attribute(s)
25
+ paclr(text) | As `pa(text)` but also clears the rest of the window
26
+ print(text, fg=255, bg=0, attr=0) | Print text (from current position) with optional attributes
27
+ puts(text, fg=255, bg=0, attr=0) | Clears window and puts text with optional attributes
28
+ format_text(text) | Format text so that it linebreaks neatly inside window
29
+
30
+ ## Curses template
31
+ The `curses_template.rb` includes the class extension and serves as the basis for my curses applications.
@@ -88,4 +88,18 @@ class Curses::Window # CLASS EXTENSION
88
88
  self.attron(color_pair(self.fg) | self.attr) { self << text }
89
89
  self.refresh
90
90
  end
91
+ def puts(text, fg=255, bg=0, attr=0) # Clears window and puts text with optional attributes
92
+ self.clr
93
+ self.refresh
94
+ self.setpos(0, 0)
95
+ self.print(text, fg, bg, attr)
96
+ end
97
+ def print(text, fg=255, bg=0, attr=0) # Print text (from current position) with optional attributes
98
+ init_pair(fg, fg, bg)
99
+ self.attron(color_pair(fg) | attr) { self << text }
100
+ self.refresh
101
+ end
102
+ def format_text(text) # Format text so that it linebreaks neatly inside window
103
+ return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
104
+ end
91
105
  end
@@ -117,6 +117,20 @@ class Curses::Window # CLASS EXTENSION
117
117
  self.attron(color_pair(self.fg) | self.attr) { self << text }
118
118
  self.refresh
119
119
  end
120
+ def puts(text, fg=255, bg=0, attr=0) # Clears window and puts text with optional attributes
121
+ self.clr
122
+ self.refresh
123
+ self.setpos(0, 0)
124
+ self.print(text, fg, bg, attr)
125
+ end
126
+ def print(text, fg=255, bg=0, attr=0) # Print text (from current position) with optional attributes
127
+ init_pair(fg, fg, bg)
128
+ self.attron(color_pair(fg) | attr) { self << text }
129
+ self.refresh
130
+ end
131
+ def format_text(text) # Format text so that it linebreaks neatly inside window
132
+ return "\n" + text.gsub(/(.{1,#{self.maxx}})( +|$\n?)|(.{1,#{self.maxx}})/, "\\1\\3\n")
133
+ end
120
134
  end
121
135
 
122
136
  def getchr # PROCESS KEY PRESSES
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curses-extension
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: '1.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: 2021-12-18 00:00:00.000000000 Z
11
+ date: 2023-01-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses
@@ -35,13 +35,14 @@ description: 'The Ruby curses library is sorely lacking some important features.
35
35
  terminal curses applications in Ruby. See the Github page for information on what
36
36
  properties and functions are included: https://github.com/isene/Ruby-Curses-Class-Extension.
37
37
  The curses_template.rb is also installed in the lib directory and serves as the
38
- basis for my own curses applications. New in 1.1.4: In the template, also catch
39
- Control+Key sequence'
38
+ basis for my own curses applications. New in 1.2: Added functions `print`, `puts`and
39
+ `format`.'
40
40
  email: g@isene.com
41
41
  executables: []
42
42
  extensions: []
43
43
  extra_rdoc_files: []
44
44
  files:
45
+ - lib/README.md
45
46
  - lib/curses-extension.rb
46
47
  - lib/curses-template.rb
47
48
  homepage: https://isene.com/
@@ -64,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
64
65
  - !ruby/object:Gem::Version
65
66
  version: '0'
66
67
  requirements: []
67
- rubygems_version: 3.1.2
68
+ rubygems_version: 3.3.5
68
69
  signing_key:
69
70
  specification_version: 4
70
71
  summary: Extending the Ruby Curses module with some obvious functionality