keybox 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,125 @@
1
+ #!/usr/local/bin/ruby -w
2
+
3
+ # system_extensions.rb
4
+ #
5
+ # Created by James Edward Gray II on 2006-06-14.
6
+ # Copyright 2006 Gray Productions. All rights reserved.
7
+ #
8
+ # This is Free Software. See LICENSE and COPYING for details.
9
+
10
+ class HighLine
11
+ module SystemExtensions
12
+ module_function
13
+
14
+ #
15
+ # This section builds character reading and terminal size functions
16
+ # to suit the proper platform we're running on. Be warned: Here be
17
+ # dragons!
18
+ #
19
+ begin
20
+ # Cygwin will look like Windows, but we want to treat it like a Posix OS:
21
+ raise LoadError, "Cygwin is a Posix OS." if RUBY_PLATFORM =~ /\bcygwin\b/i
22
+
23
+ require "Win32API" # See if we're on Windows.
24
+
25
+ CHARACTER_MODE = "Win32API" # For Debugging purposes only.
26
+
27
+ #
28
+ # Windows savvy getc().
29
+ #
30
+ # *WARNING*: This method ignores <tt>input</tt> and reads one
31
+ # character from +STDIN+!
32
+ #
33
+ def get_character( input = STDIN )
34
+ Win32API.new("crtdll", "_getch", [ ], "L").Call
35
+ end
36
+
37
+ # A Windows savvy method to fetch the console columns, and rows.
38
+ def terminal_size
39
+ m_GetStdHandle = Win32API.new( 'kernel32',
40
+ 'GetStdHandle',
41
+ ['L'],
42
+ 'L' )
43
+ m_GetConsoleScreenBufferInfo = Win32API.new(
44
+ 'kernel32', 'GetConsoleScreenBufferInfo', ['L', 'P'], 'L'
45
+ )
46
+
47
+ format = 'SSSSSssssSS'
48
+ buf = ([0] * format.size).pack(format)
49
+ stdout_handle = m_GetStdHandle.call(0xFFFFFFF5)
50
+
51
+ m_GetConsoleScreenBufferInfo.call(stdout_handle, buf)
52
+ bufx, bufy, curx, cury, wattr,
53
+ left, top, right, bottom, maxx, maxy = buf.unpack(format)
54
+ return right - left + 1, bottom - top + 1
55
+ end
56
+ rescue LoadError # If we're not on Windows try...
57
+ begin
58
+ require "termios" # Unix, first choice.
59
+
60
+ CHARACTER_MODE = "termios" # For Debugging purposes only.
61
+
62
+ #
63
+ # Unix savvy getc(). (First choice.)
64
+ #
65
+ # *WARNING*: This method requires the "termios" library!
66
+ #
67
+ def get_character( input = STDIN )
68
+ old_settings = Termios.getattr(input)
69
+
70
+ new_settings = old_settings.dup
71
+ new_settings.c_lflag &= ~(Termios::ECHO | Termios::ICANON)
72
+ new_settings.c_cc[Termios::VMIN] = 1
73
+
74
+ begin
75
+ Termios.setattr(input, Termios::TCSANOW, new_settings)
76
+ input.getc
77
+ ensure
78
+ Termios.setattr(input, Termios::TCSANOW, old_settings)
79
+ end
80
+ end
81
+ rescue LoadError # If our first choice fails, default.
82
+ CHARACTER_MODE = "stty" # For Debugging purposes only.
83
+
84
+ #
85
+ # Unix savvy getc(). (Second choice.)
86
+ #
87
+ # *WARNING*: This method requires the external "stty" program!
88
+ #
89
+ def get_character( input = STDIN )
90
+ raw_no_echo_mode
91
+
92
+ begin
93
+ input.getc
94
+ ensure
95
+ restore_mode
96
+ end
97
+ end
98
+
99
+ #
100
+ # Switched the input mode to raw and disables echo.
101
+ #
102
+ # *WARNING*: This method requires the external "stty" program!
103
+ #
104
+ def raw_no_echo_mode
105
+ @state = `stty -g`
106
+ system "stty raw -echo cbreak"
107
+ end
108
+
109
+ #
110
+ # Restores a previously saved input mode.
111
+ #
112
+ # *WARNING*: This method requires the external "stty" program!
113
+ #
114
+ def restore_mode
115
+ system "stty #{@state}"
116
+ end
117
+ end
118
+
119
+ # A Unix savvy method to fetch the console columns, and rows.
120
+ def terminal_size
121
+ `stty size`.split.map { |x| x.to_i }.reverse
122
+ end
123
+ end
124
+ end
125
+ end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.1
3
3
  specification_version: 1
4
4
  name: keybox
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.0
7
- date: 2007-01-14 00:00:00 -07:00
6
+ version: 1.1.0
7
+ date: 2007-01-27 00:00:00 -07:00
8
8
  summary: Keybox is a set of command line applications and ruby libraries for secure password storage and password generation.
9
9
  require_paths:
10
10
  - lib
@@ -26,11 +26,19 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
26
26
  platform: ruby
27
27
  signing_key:
28
28
  cert_chain:
29
- post_install_message: Try `keybox --help` for more information
29
+ post_install_message: "\e[1m\e[31m\e[40mTry `keybox --help` for more information\e[0m"
30
30
  authors:
31
31
  - Jeremy Hinegardner
32
32
  files:
33
+ - data/dark_bg.color_scheme.yaml
33
34
  - data/chargrams.txt
35
+ - data/light_bg.color_scheme.yaml
36
+ - vendor/highline/highline.rb
37
+ - vendor/highline/highline/system_extensions.rb
38
+ - vendor/highline/highline/question.rb
39
+ - vendor/highline/highline/color_scheme.rb
40
+ - vendor/highline/highline/menu.rb
41
+ - vendor/highline/highline/import.rb
34
42
  - spec/kpg_app_spec.rb
35
43
  - spec/convert_csv_spec.rb
36
44
  - spec/storage_record_spec.rb
@@ -42,12 +50,9 @@ files:
42
50
  - spec/string_generator_spec.rb
43
51
  - spec/password_hash_spec.rb
44
52
  - spec/randomizer_spec.rb
45
- - README
46
- - CHANGES
47
- - COPYING
48
53
  - lib/keybox.rb
54
+ - lib/keybox/highline_util.rb
49
55
  - lib/keybox/cipher.rb
50
- - lib/keybox/term_io.rb
51
56
  - lib/keybox/error.rb
52
57
  - lib/keybox/randomizer.rb
53
58
  - lib/keybox/uuid.rb
@@ -65,13 +70,22 @@ files:
65
70
  - lib/keybox/application/password_safe.rb
66
71
  - bin/keybox
67
72
  - bin/kpg
73
+ - README
74
+ - CHANGES
75
+ - COPYING
68
76
  test_files: []
69
77
 
70
78
  rdoc_options:
71
79
  - --line-numbers
72
80
  - --inline-source
73
- extra_rdoc_files: []
74
-
81
+ - --title
82
+ - keybox - 1.1.0
83
+ - --main
84
+ - README
85
+ extra_rdoc_files:
86
+ - README
87
+ - CHANGES
88
+ - COPYING
75
89
  executables:
76
90
  - keybox
77
91
  - kpg
@@ -79,5 +93,13 @@ extensions: []
79
93
 
80
94
  requirements: []
81
95
 
82
- dependencies: []
83
-
96
+ dependencies:
97
+ - !ruby/object:Gem::Dependency
98
+ name: highline
99
+ version_requirement:
100
+ version_requirements: !ruby/object:Gem::Version::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 1.2.6
105
+ version:
@@ -1,163 +0,0 @@
1
- module Keybox
2
- # including this module assumes that the class included has
3
- # @stdout and @stdin member variables.
4
- #
5
- # This module also assumes that stty is available
6
- module TermIO
7
-
8
- # http://pueblo.sourceforge.net/doc/manual/ansi_color_codes.html
9
- #
10
- ESCAPE = "\e"
11
- BOLD_ON = "[1m"
12
- RESET = "[0m"
13
-
14
- FG_BLACK = "[30m"
15
- FG_RED = "[31m"
16
- FG_GREEN = "[32m"
17
- FG_YELLOW = "[33m"
18
- FG_BLUE = "[34m"
19
- FG_MAGENTA = "[35m"
20
- FG_CYAN = "[36m"
21
- FG_WHITE = "[37m"
22
-
23
- COLORS = {
24
- :black => FG_BLACK,
25
- :red => FG_RED,
26
- :green => FG_GREEN,
27
- :yellow => FG_YELLOW,
28
- :blue => FG_BLUE,
29
- :magenta => FG_MAGENTA,
30
- :cyan => FG_CYAN,
31
- :white => FG_WHITE,
32
- }
33
-
34
- VALID_COLORS = COLORS.keys()
35
-
36
-
37
- STTY = "stty"
38
- STTY_SAVE_CMD = "#{STTY} -g"
39
- STTY_RAW_CMD = "#{STTY} raw -echo isig"
40
-
41
- EOL_CHARS = [10, # '\n'
42
- 13, # '\r'
43
- ]
44
- #
45
- # prompt for input, returning what was typed. If echo is false,
46
- # then '*' is printed out for each character typed in. If it is
47
- # any other character then that is output instead.
48
- #
49
- # If validate is set to true, then it will prompt twice and make
50
- # sure that the two values match
51
- #
52
- def prompt(p,echo = true, validate = false, width = 20)
53
- validated = false
54
- line = ""
55
- extra_prompt = " (again)"
56
- original_prompt = p
57
- validation_prompt = original_prompt + extra_prompt
58
- width += extra_prompt.length
59
-
60
- until validated do
61
- line = prompt_and_return(original_prompt.rjust(width),echo)
62
-
63
- # if we are validating then prompt again to validate
64
- if validate then
65
- v = prompt_and_return(validation_prompt.rjust(width),echo)
66
- if v != line then
67
- color_puts "Entries do not match, try again.", :red
68
- else
69
- validated = true
70
- end
71
- else
72
- validated = true
73
- end
74
- end
75
- return line
76
- end
77
-
78
- def prompt_y_n(p)
79
- response = prompt(p)
80
- if response.size > 0 and response.downcase[0].chr == 'y' then
81
- true
82
- else
83
- false
84
- end
85
- end
86
-
87
- def get_one_char
88
- stty_original = %x{#{STTY_SAVE_CMD}}
89
- char = nil
90
- begin
91
- system STTY_RAW_CMD
92
- char = @stdin.getc
93
- ensure
94
- system "#{STTY} #{stty_original}"
95
- end
96
-
97
- return char
98
- end
99
-
100
- def prompt_and_return(the_prompt,echo)
101
- line = ""
102
- color_print "#{the_prompt} : ", :white
103
- if echo != true then
104
-
105
- echo_char = echo || '*'
106
-
107
- if has_stty? then
108
- stty_original = %x{#{STTY_SAVE_CMD}}
109
-
110
- begin
111
- system STTY_RAW_CMD
112
- while char = @stdin.getc
113
- line << char
114
- break if EOL_CHARS.include? char
115
- @stdout.putc echo_char
116
- end
117
- ensure
118
- system "#{STTY} #{stty_original}"
119
- end
120
- @stdout.puts
121
- end
122
- else
123
- line = @stdin.gets
124
- end
125
-
126
- # if we got end of file or some other input resulting in
127
- # line becoming nil then set it to the empty string
128
- line = line || ""
129
-
130
- return line.rstrip
131
- end
132
-
133
- def has_stty?
134
- system "which stty > /dev/null 2>&1"
135
- end
136
-
137
- def colorize(text,color,bold=true)
138
- before = ""
139
- after = ""
140
- if VALID_COLORS.include?(color) then
141
- before = ESCAPE + COLORS[color]
142
- before = ESCAPE + BOLD_ON + before if bold
143
- after = ESCAPE + RESET
144
- end
145
- "#{before}#{text}#{after}"
146
- end
147
-
148
- def colorize_if_io_isatty(io,text,color,bold)
149
- if io.tty? then
150
- text = colorize(text,color,bold)
151
- end
152
- text
153
- end
154
-
155
- def color_puts(text, color, bold = true)
156
- @stdout.puts colorize_if_io_isatty(@stdout,text,color,bold)
157
- end
158
-
159
- def color_print(text,color, bold = true)
160
- @stdout.print colorize_if_io_isatty(@stdout,text,color,bold)
161
- end
162
- end
163
- end