fancy_irb 0.6.0 → 0.6.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,8 +2,8 @@ FancyIrb patches your IRB to create a smooth output experience.
2
2
 
3
3
  == Features
4
4
  * Use fancy colors! You can colorize the prompts, irb errors, +stderr+ and +stdout+
5
- * Output results as Ruby comment
6
- * Enhance your output value, using procs
5
+ * Output evaluation results as Ruby comments
6
+ * Enhance your output value using procs
7
7
 
8
8
  == Motivation
9
9
  I really like the {irb_rocket}[https://github.com/genki/irb_rocket] gem, which outputs the evaluation result as comment and colorizes errors. Unfortunately, the implementation leads to bugs, because it tries to run the whole command before printing anything to +stdout+. For this reason, I've rewritten (and extended) it.
@@ -37,7 +37,7 @@ You can pass an options hash. These are the default values:
37
37
 
38
38
  === Rocket mode
39
39
 
40
- Rocket mode means: Output result as comment if there is enough space left on the terminal line.
40
+ Rocket mode means: Output result as comment if there is enough space left on the terminal line and +stdout+ does not output more than the current terminal height.
41
41
 
42
42
  === Available colors
43
43
  >> Wirble::Colorize::Color::COLORS.keys
@@ -93,14 +93,13 @@ You can modify how to get and display the input. The <tt>result_proc</tt> is a p
93
93
 
94
94
  == TODO
95
95
  === Known bugs
96
- * If stdout of the current command scrolls, the rocket is displayed not higher than the first terminal line
97
96
  * Something is wrong with input-newline when colorizing input
98
97
  * Not all input methods are patched properly (to work with the rocket) --> focusing on the often used ones
99
98
 
100
99
  === Features, maybe
101
100
  * Count string lengths without ansi escape sequences (would be more flexible than remembering)
102
101
  * "Always rocket"-mode
103
- * Allow custom ansi escape strings
102
+ * Allow custom ansi escape strings instead of wirble's colors
104
103
  * Refactor some code duplications
105
104
 
106
105
  Feel free to fix a bug or implement a todo ;)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.0
1
+ 0.6.1
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{fancy_irb}
8
- s.version = "0.6.0"
8
+ s.version = "0.6.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jan Lelis"]
@@ -17,12 +17,12 @@ Gem::Specification.new do |s|
17
17
  s.email = %q{mail@janlelis.de}
18
18
  s.extra_rdoc_files = [
19
19
  "LICENSE",
20
- "README"
20
+ "README.rdoc"
21
21
  ]
22
22
  s.files = [
23
23
  ".gitignore",
24
24
  "LICENSE",
25
- "README",
25
+ "README.rdoc",
26
26
  "Rakefile",
27
27
  "VERSION",
28
28
  "fancy_irb.gemspec",
@@ -19,13 +19,15 @@ class << FancyIrb
19
19
  attr_accessor :original_stdout
20
20
  attr_accessor :capture_irb_errors
21
21
  attr_accessor :real_lengths
22
+ attr_accessor :continue
22
23
  attr_accessor :stdout_colorful
23
24
 
24
25
  def start(user_options = {})
25
26
  # track some irb stuff
26
- @height_counter = []
27
- @real_lengths = { :output => 1, :input_prompt => 9999 } # or whatever
27
+ @height_counter = []
28
+ @real_lengths = { :output => 1, :input_prompt => 9999 } # or whatever
28
29
  @stdout_colorful = false
30
+ @continue = false
29
31
 
30
32
  # set defaults and parse user options
31
33
  default_result_proc = proc{ |context|
@@ -35,12 +35,15 @@ module IRB
35
35
  last_line_without_prompt = last_input.split("\n").last
36
36
  offset = last_line_without_prompt.size + FancyIrb.real_lengths[:input_prompt] + 1
37
37
  screen_length = `tput cols`.to_i
38
+ screen_lines = `tput lines`.to_i
38
39
  output_length = FancyIrb.real_lengths[:output]
39
40
  rocket_length = FancyIrb[:rocket_prompt].size
40
41
  stdout_lines = FancyIrb.get_height
41
42
 
42
43
  # auto rocket mode
43
- if FancyIrb[:rocket_mode] && screen_length > offset + rocket_length + output_length
44
+ if FancyIrb[:rocket_mode] &&
45
+ screen_length > offset + rocket_length + output_length &&
46
+ stdout_lines < screen_lines
44
47
  print `tput sc` + # save current cursor position
45
48
  `tput cuu1`*stdout_lines + # move cursor upwards to the original input line
46
49
  `tput cuf1`*offset + # move cursor rightwards to the original input offset
@@ -58,9 +61,14 @@ module IRB
58
61
  alias prompt_non_fancy prompt
59
62
  def prompt(*args, &block)
60
63
  print Wirble::Colorize::Color.escape(:nothing)
61
-
62
64
  prompt = prompt_non_fancy(*args, &block)
63
- FancyIrb.real_lengths[:input_prompt] = prompt.size
65
+
66
+ # this is kinda hacky... but that's irb °_°
67
+ indents = @scanner.indent*2
68
+ FancyIrb.continue = true if args[0] == IRB.conf[:PROMPT][IRB.conf[:PROMPT_MODE]][:PROMPT_C]
69
+ indents += 2 if FancyIrb.continue
70
+ FancyIrb.real_lengths[:input_prompt] = prompt.size + indents
71
+
64
72
  colorized_prompt = colorize prompt, FancyIrb[:colorize, :input_prompt]
65
73
  if input_color = FancyIrb[:colorize, :input]
66
74
  colorized_prompt + Wirble::Colorize::Color.escape( input_color ) # NOTE: No reset, relies on next one
@@ -73,6 +81,7 @@ module IRB
73
81
  # track height and capture irb errors (part 2)
74
82
  alias signal_status_non_fancy signal_status
75
83
  def signal_status(name, *args, &block)
84
+ FancyIrb.continue = false
76
85
  FancyIrb.reset_height
77
86
  signal_status_non_fancy(name, *args, &block)
78
87
  ensure
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fancy_irb
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 5
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 6
8
- - 0
9
- version: 0.6.0
9
+ - 1
10
+ version: 0.6.1
10
11
  platform: ruby
11
12
  authors:
12
13
  - Jan Lelis
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 3
28
30
  segments:
29
31
  - 0
30
32
  version: "0"
@@ -42,11 +44,11 @@ extensions: []
42
44
 
43
45
  extra_rdoc_files:
44
46
  - LICENSE
45
- - README
47
+ - README.rdoc
46
48
  files:
47
49
  - .gitignore
48
50
  - LICENSE
49
- - README
51
+ - README.rdoc
50
52
  - Rakefile
51
53
  - VERSION
52
54
  - fancy_irb.gemspec
@@ -66,6 +68,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
68
  requirements:
67
69
  - - ">="
68
70
  - !ruby/object:Gem::Version
71
+ hash: 3
69
72
  segments:
70
73
  - 0
71
74
  version: "0"
@@ -74,6 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
77
  requirements:
75
78
  - - ">="
76
79
  - !ruby/object:Gem::Version
80
+ hash: 3
77
81
  segments:
78
82
  - 0
79
83
  version: "0"