Commits

seydar committed 04088dd Draft

split part of lib/chitin/file.rb to lib/.../kernel.rb. added new class called PVC which just takes the raw input. added new prompts to builtins

Comments (0)

Files changed (4)

lib/chitin/commands/builtins.rb

       def last_elapsed
         SESSION.last_elapsed || 0.0
       end
+
+      # My personal fancy shell.
+      # On the first line it has the time, elapsed time of the last
+      # run command, and the shortened working directory.
+      # On the second line, it has three colored dots.
+      def time_elapsed_working_multiline_prompt
+        "(".purple + Time.now.to_s + ") ".purple +
+          "(".purple + "last => " + "#{last_elapsed}".cyan + ") ".purple +
+          "(".purple + short_pwd.yellow + ")\n".purple +
+          '.'.red + '.'.yellow + '.'.cyan + ' '
+      end
+
+      # Minimalist.
+      def minimalist_prompt
+        '.'.red + '.'.yellow + '.'.cyan + ' '
+      end
     end
     include Prompts
   

lib/chitin/commands/ruby.rb

 module Chitin
-  class StringMethod
+  class PVC
     __sweep__ :[]
 
     include Runnable
 
     private
 
+    # prepare the initial input to be sent down through `@chains`
+    def prepare
+      self[:in]
+    end
+
     def result
-      val = self[:in].read
+      val = prepare
       @chains.each do |arr|
         val = if Proc === arr.last
                 val.send *arr[0..-2], &arr[-1]
     end
   
     def inspect
+      "#<PVC #{to_s}>"
+    end
+  end
+
+  class StringMethod < PVC
+    private
+
+    # the only difference is that we have `self[:in]`
+    # instead of just `self[:in].read`
+    def prepare
+      self[:in].read
+    end
+
+    def inspect
       "#<StringMethod #{to_s}>"
     end
   end

lib/chitin/core_ext/kernel.rb

+module Kernel
+  def D(path); Chitin::Directory.new path; end
+  def F(path); Chitin::FileObject.new path; end
+  def S(path); Chitin::Symlink.new path; end
+
+  alias_method :d, :D
+  alias_method :f, :F
+  alias_method :s, :S
+
+  # L for Lambda. Creates a proc as a RubyMethod
+  def L(&block)
+    Chitin::StringMethod.new :bottle, &block
+  end
+
+  def P(&block)
+    Chitin::PVC.new :bottle, &block
+  end
+
+  NULLIN = NULLOUT = NULLERR = File.open(File::NULL, 'w+')
+end
+

lib/chitin/file.rb

   end
 end
 
-module Kernel
-  def D(path); Chitin::Directory.new path; end
-  def F(path); Chitin::FileObject.new path; end
-  def S(path); Chitin::Symlink.new path; end
-
-  alias_method :d, :D
-  alias_method :f, :F
-  alias_method :s, :S
-
-  # L for Lambda. Creates a proc as a RubyMethod
-  def L(&block)
-    Chitin::StringMethod.new :bottle, &block
-  end
-
-  NULLIN = NULLOUT = NULLERR = File.open(File::NULL, 'w+')
-end
-