Commits

seydar  committed 0089837

fixed the coolline output bug! thanks to chris2 for helping me get the ansi response code

  • Participants
  • Parent commits a118bb2

Comments (0)

Files changed (7)

File ANNOUNCEMENT

 I hope you all get the joke. I made it myself. The joke and the shell.
 
 Everything you type is Ruby -- remember that. So let's look at it in action.
-Remember that the tab completion makes typing quotes painless:
+Remember that the tab completion makes typing quotes painless. Plus you don't
+even need closing quotes if they're the final character in a line:
 
   % hg.commit :m => 'fixed issues with procs in pipes...
   % hg.push
   pushing to https://seydar:***@bitbucket.org/seydar/chitin
-  searching for changes
-  remote: adding changesets
-  remote: adding manifests
-  remote: adding file changes
-  remote: added 1 changesets with 10 changes to 10 files
+  ...
   remote: bb/acl: seydar is allowed. accepted payload.
   % cat("ANNOUNCEMENT") | pbcopy
   % ll
   total 136
   -rw-r--r--  1 ari  staff   1.7K Nov 25 14:43 ANNOUNCEMENT
-  -rw-r--r--  1 ari  staff    14K Nov 24 20:09 README
-  -rw-r--r--  1 ari  staff   1.4K Nov 25 00:16 TODO
-  drwxr-xr-x  3 ari  staff   102B Nov 21 16:46 bin
-  -rw-r--r--  1 ari  staff    25K Nov 24 20:50 chitin-1.0.1.gem
-  -rw-r--r--  1 ari  staff   883B Nov 21 14:43 chitin.gemspec
-  -rw-r--r--  1 ari  staff   1.9K Nov 19 14:50 chitinrc
-  drwxr-xr-x  4 ari  staff   136B Nov 22 09:30 lib
+  ...
   -rw-r--r--  1 ari  staff   7.7K Nov 24 20:44 sample.txt
   % rm "chitin-1.0.1.gem"
   % gem.build "chitin.gemspec"
 
 Because it's written in Ruby and supadupes easy to modify. Also:
 
-  * No need to use closing quotes. If you need a final quote in a line, don't
-    sweat it. Chitin will take care of that.
+  * The power of Ruby in a shell
+  * The command utility of a shell in Ruby
+  * Text processing is SO. MUCH. EASIER.
+  * A much more programmatic shell
+  * Prevents against accidental `rm -rf /usr /local/bin` like that one thing
+    we all saw on Reddit.
   * Syntax highlighting while you type (thanks to Coolline!)
   * You can do simple arithmetic on the command line without having to switch
     interfaces (this was the original itch I had to scratch).
-  * The power of Ruby in a shell
-  * The command utility of a shell in Ruby
   * No underlying shell usage
-  * A much more programmatic shell
   * Sweet tab completion
+  * No need to use closing quotes. If you need a final quote in a line, don't
+    sweat it. Chitin will take care of that.
   * You can set key bindings to arbitrary keys
-  * Prevents against accidental `rm -rf /usr /local/bin` like that one thing
-    we all saw on Reddit.
   * Makes for a great Christmas present
-  * Text processing is SO. MUCH. EASIER.
   * Great library for calling executable files from your own program without
     shelling your soul or shelling out.
 
 FUTURE:
-*   add STDERR support
-*   fix it so that self.err isn't alone in the whole `if self.err` bit.
 *   set local variables in config, have them appear in shell
 *   getting the menu to NOT have leading quotes
 *   remove/edit history
     -> important for removing passwords if accidentally typed
 *   improve library usage of executables
-*   cursor display issues with the menu
-    -> it places the cursor at the location of the cursor on the input line
-       except the cursor is actually placed on the final line of the menu
-       (the input line is several lines above it)
+
+QUIRKS:
+*   menu doesn't erase itself sometimes
+    -> cat and tabcomplete a file that is empty. output is correct but confusing
 
 FAILURES:
-*   get coolline to play well with missing newlines before it
-    -> right now it preserves junk on the line up until the first character is
-       typed. once the user types something, the line is made pristine.
-    -> use ncurses. if the starting column isn't 0, automaticall add a newline
-*   how to redirect stderr?
 
 Questions:
 *   Why do you have to do @line = '' in Coolline in order to not affect the
     matter if I do @line.clear on the original.
 
 RELEASE
-*   figure out what doesn't work with STDERR
 *   failures
 

File chitin.gemspec

   # specify any dependencies here; for example:
   # s.add_development_dependency "rspec"
   s.add_runtime_dependency "wirble"
-  s.add_runtime_dependency "coolline"
+  s.add_runtime_dependency "coolline", ">= 0.4.0"
   s.add_runtime_dependency "coderay"
 end
 

File lib/chitin/commands/builtins.rb

     module Prompts
       # The standard prompt. Must return a string. Override this to provide
       # a custom prompt.
-      def big_prompt
-        "+-#{'-' * ENV['USER'].length}--#{'-' * short_pwd.length}-+\n" +
-        "| #{ENV['USER']}: #{short_pwd} |\n" +
-        "+-#{'-' * ENV['USER'].length}--#{'-' * short_pwd.length}-+ "
-      end
-  
-      def small_prompt
+      def prompt
         "#{ENV['USER']}: #{short_pwd} % "
       end
-  
-      def prompt
-        big_prompt
-      end
     end
     include Prompts
   

File lib/chitin/commands/ruby.rb

 module Chitin
   class StringMethod
+    __sweep__ :[]
+
     include Runnable
   
     attr_reader :chains
     def result
       val = self[:in].read
       @chains.each do |arr|
-        val = if arr.last.is_a? Proc
+        val = if Proc === arr.last
                 val.send *arr[0..-2], &arr[-1]
               else
                 val.send *arr
       :ruby
     end
   
+    # fix this. What if someone passes an executable as an argument?
     def to_s
       @chains.map do |arr|
         "#{arr[0]}(#{arr[1..-1].map {|a| a.is_a?(Proc) ? "&block" : a.inspect }.join ', '})"

File lib/chitin/commands/runnable.rb

       self
     end
 
+    def >>(io)
+      case io
+      when IO, File
+        self[:set_err, io]
+      when String, FileObject
+        f = File.open io, 'w'
+        self[:set_err, f]
+        f.close
+      else
+        raise "Unknown piping type: #{io.class}"
+      end
+  
+      self
+    end
+
     # access private methods
     def [](*args)
       if method(args.first)

File lib/chitin/core_ext/coolline.rb

       old_word_beginning_before(pos)
     end
   end
-
-  # This is to comment out `reset_line`.
-  # Now why would we do that, you ask?
-  # Because otherwise it overwrites the entire line when printing the prompt.
-  # And what's wrong with that?
-  # This is undesirable behavior if the previous program run prints output
-  # that does NOT have a trailing newline.
-  # This was the source of a "bug" for a few days now.
-  #
-  # NB: This preserves any input on the line for ONLY the initial printing of
-  # the prompt. After that, the render call in the #getch loop will overwrite
-  # it. This needs some work, obviously.
-  def readline(prompt = ">> ")
-    @prompt = prompt
-
-    @history.delete_empty
-
-    @line        = ""
-    @pos         = 0
-    @accumulator = nil
-
-    @history_moved = false
-
-    @should_exit = false
-
-    reset_line
-    print @prompt
-
-    @history.index = @history.size - 1
-    @history << @line
-
-    until (char = @input.getch) == "\r"
-      @menu.erase
-
-      handle(char)
-      return if @should_exit
-
-      if @history_moved
-        @history_moved = false
-      end
-
-      render
-    end
-
-    @menu.erase
-
-    print "\n"
-
-    @history[-1] = @line if @history.size != 0
-    @history.index = @history.size
-
-    @history.save_line
-
-    @line
-  end
 end