chitin 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,9 +9,13 @@ Hai everybahdy
9
9
 
10
10
  == So what IS Chitin?
11
11
 
12
+ Everything you type has to be valid Ruby.
13
+
12
14
  * Chitin is a Ruby interpreter
13
15
  * Turned into a shell.
14
16
 
17
+ Everything you type has to be valid Ruby.
18
+
15
19
  I hope you all get the joke. I made it myself. The joke and the shell.
16
20
 
17
21
  Everything you type is Ruby -- remember that. So let's look at it in action.
@@ -42,6 +46,10 @@ even need closing quotes if they're the final character in a line:
42
46
  % ll | split("\n").map {|l| l.size }
43
47
  => [9, 57, 51, 49, 48, 61, 59, 53, 48, 55]
44
48
 
49
+ Everything you type has to be valid Ruby. I am repeating this because in
50
+ test cases, this is the one thing that everybody forgot. You can use the
51
+ text preprocessor to change this, of course, but it's up to you.
52
+
45
53
  == Why use it?
46
54
 
47
55
  Because it's written in Ruby and supadupes easy to modify. Also:
data/README CHANGED
@@ -399,16 +399,8 @@ Did you know?
399
399
 
400
400
  * A FULL RUBY INTERPRETER!
401
401
  * Tab completion that respects spaces in strings!
402
- * Bashes' ESC-. to place the last argument!
402
+ * Bash's ESC-. to place the last argument!
403
403
  * Syntax highlighting as you type!
404
404
  * ^q quotes the word just behind your cursor
405
405
  * I think this train might ACTUALLY get to Chicago on time!
406
406
 
407
- == Bugs
408
-
409
- Coolline deletes and reprints the line with every character you type. This is
410
- great! We like this because it means we get syntax highlighting as we type.
411
- We don't like this, however, because it means that if a program prints output
412
- without a trailing newline, the last line of the output will be cut off by
413
- chitin as soon as you start typing :(
414
-
@@ -50,6 +50,10 @@ module Chitin
50
50
  StringMethod.new :bottle, &block
51
51
  end
52
52
 
53
+ # ruby's backtick doesn't chomp off the newline, which makes it more
54
+ # or less useless for piping into other commands
55
+ def `(args); super(args).chomp; end
56
+
53
57
  # Place the last argument on the line
54
58
  # This is a total hack. It would need proper parsing to accomodate for
55
59
  # strings with spaces in them.
@@ -20,7 +20,6 @@ module Chitin
20
20
  end
21
21
 
22
22
  def method_missing(*arr, &block)
23
- puts caller[0]
24
23
  latest = [*arr]
25
24
  latest << block if block
26
25
  @chains << latest
@@ -1,12 +1,27 @@
1
1
  module Chitin
2
2
  module Runnable
3
3
 
4
+ def <(io)
5
+ case io
6
+ when IO, File
7
+ self[:set_in, io]
8
+ when String, FileObject
9
+ f = File.open io.to_s, 'r'
10
+ self[:set_in, f]
11
+ f.close
12
+ else
13
+ raise "Unknown piping type: #{io.class}"
14
+ end
15
+
16
+ self
17
+ end
18
+
4
19
  def >(io)
5
20
  case io
6
21
  when IO, File
7
22
  self[:set_out, io]
8
23
  when String, FileObject
9
- f = File.open io, 'w'
24
+ f = File.open io.to_s, 'w'
10
25
  self[:set_out, f]
11
26
  f.close
12
27
  else
@@ -17,11 +32,26 @@ module Chitin
17
32
  end
18
33
 
19
34
  def >>(io)
35
+ case io
36
+ when IO, File
37
+ self[:set_out, io]
38
+ when String, FileObject
39
+ f = File.open io.to_s, 'a'
40
+ self[:set_out, f]
41
+ f.close
42
+ else
43
+ raise "Unknown piping type: #{io.class}"
44
+ end
45
+
46
+ self
47
+ end
48
+
49
+ def ^(io)
20
50
  case io
21
51
  when IO, File
22
52
  self[:set_err, io]
23
53
  when String, FileObject
24
- f = File.open io, 'w'
54
+ f = File.open io.to_s, 'w'
25
55
  self[:set_err, f]
26
56
  f.close
27
57
  else
@@ -46,17 +46,24 @@ class Coolline
46
46
  end
47
47
  end
48
48
 
49
- # This is to comment out `reset_line`.
50
- # Now why would we do that, you ask?
51
- # Because otherwise it overwrites the entire line when printing the prompt.
52
- # And what's wrong with that?
53
- # This is undesirable behavior if the previous program run prints output
54
- # that does NOT have a trailing newline.
55
- # This was the source of a "bug" for a few days now.
56
- #
57
- # NB: This preserves any input on the line for ONLY the initial printing of
58
- # the prompt. After that, the render call in the #getch loop will overwrite
59
- # it. This needs some work, obviously.
49
+ # In tests, this reads the first character of buffered input.
50
+ # In practice, this does not do anything differently than `@input.getch`
51
+ # C'est la vie.
52
+ def read_char
53
+ @input.raw { @input.getc }
54
+ end
55
+
56
+ # This is here because the line:
57
+ # until (char = @input.getch) == "\r"
58
+ # was replaced with:
59
+ # until (char = read_char) == "\r"
60
+ # because I'm trying and failing to fix it so that Coolline
61
+ # will read buffered characters from STDIN. For example:
62
+ # def test; sleep 2; STDIN.getch; end
63
+ # if you run that and type a bunch of characters, it will only
64
+ # return the first character you typed AFTER STDIN.getch got a chance
65
+ # to run. Ideally, with `read_char` it will read the first character that
66
+ # you typed regardless.
60
67
  def readline(prompt = ">> ")
61
68
  @prompt = prompt
62
69
 
@@ -76,7 +83,7 @@ class Coolline
76
83
  @history.index = @history.size - 1
77
84
  @history << @line
78
85
 
79
- until (char = @input.getch) == "\r"
86
+ until (char = read_char) == "\r"
80
87
  @menu.erase
81
88
 
82
89
  handle(char)
@@ -98,7 +105,6 @@ class Coolline
98
105
 
99
106
  @history.save_line
100
107
 
101
- @menu.erase
102
108
  @line
103
109
  end
104
110
  end
@@ -57,6 +57,10 @@ module Chitin
57
57
  def to_s
58
58
  path
59
59
  end
60
+
61
+ def symlink?
62
+ false
63
+ end
60
64
  end
61
65
 
62
66
  class FileObject < FSObject
@@ -89,10 +93,6 @@ module Chitin
89
93
  def inspect
90
94
  "#<Chitin::FileObject #{path.inspect}>"
91
95
  end
92
-
93
- def symlink?
94
- false
95
- end
96
96
  end
97
97
 
98
98
  class Symlink < FileObject
@@ -132,10 +132,6 @@ module Chitin
132
132
  def inspect
133
133
  "#<Chitin::Directory #{path.inspect}>"
134
134
  end
135
-
136
- def symlink?
137
- false
138
- end
139
135
  end
140
136
  end
141
137
 
@@ -1,5 +1,7 @@
1
1
  module Chitin
2
2
  class Sandbox
3
+ attr_reader :previous
4
+
3
5
  def initialize
4
6
  @binding = binding
5
7
  @previous = nil
@@ -10,7 +12,11 @@ module Chitin
10
12
  end
11
13
 
12
14
  def evaluate(code)
13
- @previous = eval code, @binding
15
+ self.previous = eval code, @binding
16
+ end
17
+
18
+ def previous=(val)
19
+ @previous = val
14
20
  eval "_ = @previous", @binding
15
21
  end
16
22
  end
@@ -160,6 +160,13 @@ module Chitin
160
160
  else
161
161
  val = res
162
162
  end
163
+
164
+ # if the input is ruby, then this is redundant
165
+ # if the input is a pipe that returns ruby,
166
+ # then this is needed because while the expression
167
+ # returns a pipe, when we run it it returns a ruby
168
+ # value. we want to remember the ruby value.
169
+ @sandbox.previous = val
163
170
 
164
171
  txt = @config.post_processing[:color].call val.inspect
165
172
  puts " => #{txt}"
@@ -1,4 +1,4 @@
1
1
  module Chitin
2
- VERSION = '1.0.2'
2
+ VERSION = '1.0.3'
3
3
  end
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chitin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-01 00:00:00.000000000 Z
12
+ date: 2012-12-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: wirble