Commits

seydar committed 3192ca8 Draft

added last_elapsed_formatted

  • Participants
  • Parent commits 4cf9037

Comments (0)

Files changed (3)

 *   tab complete ruby/shell things
 *   post_processing for shell commands
     -> make it asynchronous and use pipes
+*   ability to 'neuter' a command, so that it won't automatically be run
 
 QUIRKS:
 *   menu doesn't erase itself sometimes
 *   does not play nice with GDB if it is called within the bash profile file
 
 FAILURES:
-*   ^C on running ruby programs kills the whole interpreter... womp.
 *   slashes in filenames
 *   `include Math; sin(5)` fails
-*   get the tops of multiline prompts to persist
 
 Questions:
 *   Why do you have to do @line = '' in Coolline in order to not affect the

lib/chitin/commands/builtins.rb

 # Things are contained in modules or functions so that they play well with
 # code folding.
+# Picked up that trick from Sinatra
 
 require 'etc'
 ENV['USER'] ||= Etc.getlogin
         SESSION.last_elapsed || 0.0
       end
 
+      def last_elapsed_formatted
+        hours = (last_elapsed / 3600).floor
+        min   = ((last_elapsed - 3600 * hours) / 60).floor
+        sec   = last_elapsed - 3600 * hours - 60 * min
+
+        if hours > 0
+          "%02d:%02d:%f" % [hours, min, sec]
+        elsif min > 0
+          "%02d:%f" % [min, sec]
+        else
+          "%f" % sec
+        end
+      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 + "last => " + "#{last_elapsed_formatted}".cyan + ") ".purple +
           "(".purple + short_pwd.yellow + ")\n".purple +
           '.'.red + '.'.yellow + '.'.cyan + ' '
       end
           end
         end
 
-        # i know puts returns nil, but this is to emphasize
-        # the fact that we want it to return nil
+        # i know puts returns nil and p returns the object, but this is to
+        # emphasize the fact that we want it to return nil. also, so that
+        # we don't accidentally run a Runnable while inspecting it
         nil 
       end
     end
     include Aliases
     
     # Fixnum math is now floating-point math
+    # hashtag gitonmahlevel
     class ::Fixnum
       alias_method :old_div, :/
       

lib/chitin/session.rb

       @config  = config
       @out     = STDOUT
       @sandbox = Sandbox.new # give it its own private space to work
-      (class << @sandbox; self; end).send :include, @config # include the config and builtins
+
+      # include the config and builtins
+      (class << @sandbox; self; end).send :include, @config
 
       @editor  = Coolline.new do |c|
         # Remove the default of '-' and add support for strings