bovem 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bovem (1.0.1)
4
+ bovem (1.1.0)
5
5
  lazier (~> 1.0)
6
6
  open4 (~> 1.3.0)
7
7
 
@@ -32,8 +32,8 @@ GEM
32
32
  hike (1.2.1)
33
33
  i18n (0.6.0)
34
34
  journey (1.0.4)
35
- json (1.7.4)
36
- lazier (1.0.2)
35
+ json (1.7.5)
36
+ lazier (1.0.3)
37
37
  actionpack (~> 3.0)
38
38
  json (~> 1.7.0)
39
39
  tzinfo (~> 0.3.0)
data/lib/bovem/console.rb CHANGED
@@ -140,7 +140,7 @@ module Bovem
140
140
 
141
141
  # Initializes a new Console.
142
142
  def initialize
143
- @line_width = 80
143
+ @line_width = self.get_screen_width
144
144
  @indentation = 0
145
145
  @indentation_string = " "
146
146
  end
@@ -149,7 +149,7 @@ module Bovem
149
149
  #
150
150
  # @return [Fixnum] The screen width.
151
151
  def get_screen_width
152
- ::Bovem::Console.execute("tput cols").to_integer
152
+ ::Bovem::Console.execute("tput cols").to_integer(80)
153
153
  end
154
154
 
155
155
  # Sets the new indentation width.
@@ -193,7 +193,7 @@ module Bovem
193
193
  if width.to_integer <= 0 then
194
194
  message
195
195
  else
196
- width = (width == true || width.to_integer < 0 ? @line_width : width.to_integer)
196
+ width = (width == true || width.to_integer < 0 ? self.get_screen_width : width.to_integer)
197
197
 
198
198
  message.split("\n").collect { |line|
199
199
  line.length > width ? line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip : line
@@ -247,10 +247,23 @@ module Bovem
247
247
  rv = message
248
248
 
249
249
  rv = self.replace_markers(rv, plain) # Replace markers
250
+
251
+ # Compute the real width available for the screen, if we both indent and wrap
252
+ if wrap == true then
253
+ wrap = @line_width
254
+
255
+ if indent == true then
256
+ wrap -= self.indentation
257
+ else
258
+ indent_i = indent.to_integer
259
+ wrap -= (indent_i > 0 ? self.indentation : 0) + indent_i
260
+ end
261
+ end
262
+
250
263
  rv = self.wrap(rv, wrap) # Wrap
251
264
  rv = self.indent(rv, indent) # Indent
252
265
 
253
- rv += suffix if suffix # Add the suffix
266
+ rv += suffix.ensure_string if suffix # Add the suffix
254
267
  rv
255
268
  end
256
269
 
data/lib/bovem/shell.rb CHANGED
@@ -29,9 +29,10 @@ module Bovem
29
29
  # @param run [Boolean] If `false`, it will just print a message with the full command that will be run.
30
30
  # @param show_exit [Boolean] If show the exit status.
31
31
  # @param show_output [Boolean] If show command output.
32
+ # @param show_command [Boolean] If show the command that will be run.
32
33
  # @param fatal [Boolean] If quit in case of fatal errors.
33
34
  # @return [Hash] An hash with `status` and `output` keys.
34
- def run(command, message = nil, run = true, show_exit = true, show_output = false, fatal = true)
35
+ def run(command, message = nil, run = true, show_exit = true, show_output = false, show_command = false, fatal = true)
35
36
  rv = {:status => 0, :output => ""}
36
37
  command = command.ensure_string
37
38
 
@@ -45,6 +46,7 @@ module Bovem
45
46
  else # Run
46
47
  output = ""
47
48
 
49
+ self.console.info("Running command: {mark=bright}\"#{command}\"{/mark}...") if show_command
48
50
  rv[:status] = ::Open4::open4(command + " 2>&1") { |pid, stdin, stdout, stderr|
49
51
  stdout.each_line do |line|
50
52
  output << line
data/lib/bovem/version.rb CHANGED
@@ -14,10 +14,10 @@ module Bovem
14
14
  MAJOR = 1
15
15
 
16
16
  # The minor version.
17
- MINOR = 0
17
+ MINOR = 1
18
18
 
19
19
  # The patch version.
20
- PATCH = 1
20
+ PATCH = 0
21
21
 
22
22
  # The current version number of Bovem.
23
23
  STRING = [MAJOR, MINOR, PATCH].compact.join(".")
@@ -54,14 +54,14 @@ describe Bovem::Console do
54
54
  describe "#initialize" do
55
55
  it "should correctly set defaults" do
56
56
  expect(console.indentation).to eq(0)
57
- expect(console.line_width).to eq(80)
57
+ expect(console.line_width).to eq(`tput cols`.to_integer)
58
58
  expect(console.indentation_string).to eq(" ")
59
59
  end
60
60
  end
61
61
 
62
62
  describe "#get_screen_width" do
63
63
  it "should execute tput cols" do
64
- ::Bovem::Console.should_receive(:execute).with("tput cols")
64
+ ::Bovem::Console.should_receive(:execute).with("tput cols").at_least(1)
65
65
  console.get_screen_width
66
66
  end
67
67
 
@@ -372,6 +372,7 @@ describe Bovem::Console do
372
372
  Kernel.stub(:gets).and_return("VALUE\n")
373
373
  stty = %x{which stty}.strip
374
374
 
375
+ ::Bovem::Console.should_receive(:execute).with("tput cols").and_return(80)
375
376
  ::Bovem::Console.should_receive(:execute).with("which stty").and_return(stty)
376
377
  ::Bovem::Console.should_receive(:execute).with(stty).and_return("speed 9600 baud;\nlflags: echoe echoke echoctl pendin\niflags: iutf8\noflags: -oxtabs\ncflags: cs8 -parenb")
377
378
  ::Bovem::Console.should_receive(:execute).with("#{stty} -echo")
@@ -39,7 +39,12 @@ describe Bovem::Shell do
39
39
  shell.run("echo OK", nil, true, false)
40
40
  end
41
41
 
42
- it "should only print the command" do
42
+ it "should print the command line" do
43
+ shell.console.should_receive("info").with("Running command: {mark=bright}\"echo OK\"{/mark}...")
44
+ shell.run("echo OK", nil, true, false, false, true)
45
+ end
46
+
47
+ it "should only print the command if requested to" do
43
48
  shell.console.should_receive("warn").with("Will run command: {mark=bright}\"echo OK\"{/mark}...")
44
49
  ::Open4.should_not_receive("open4")
45
50
  shell.run("echo OK", nil, false, false)
@@ -55,7 +60,7 @@ describe Bovem::Shell do
55
60
  shell.console.should_receive(:status).with(:ok)
56
61
  shell.run("echo OK", nil, true, true)
57
62
  shell.console.should_receive(:status).with(:fail)
58
- shell.run("echo1 OK", nil, true, true, false, false)
63
+ shell.run("echo1 OK", nil, true, true, false, false, false)
59
64
  end
60
65
 
61
66
  it "should print output" do
@@ -64,7 +69,7 @@ describe Bovem::Shell do
64
69
  end
65
70
 
66
71
  it "should raise a exception for failures" do
67
- expect { shell.run("echo1 OK", nil, true, false, false, false) }.to_not raise_error(SystemExit)
72
+ expect { shell.run("echo1 OK", nil, true, false, false, false, false) }.to_not raise_error(SystemExit)
68
73
  expect { shell.run("echo1 OK", nil, true, false, false) }.to raise_error(SystemExit)
69
74
  end
70
75
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bovem
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 0
9
8
  - 1
10
- version: 1.0.1
9
+ - 0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Shogun
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-19 00:00:00 Z
18
+ date: 2012-08-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  version_requirements: &id001 !ruby/object:Gem::Requirement