[Rush-developer] rush Alias.rb BufferedWindow.rb rush.rb

reynvlietstra at rubyforge.org reynvlietstra at rubyforge.org
Fri Aug 26 18:15:30 EDT 2005


Update of /var/cvs/rush/rush
In directory rubyforge.org:/tmp/cvs-serv12874

Modified Files:
	Alias.rb BufferedWindow.rb rush.rb 
Log Message:


Index: BufferedWindow.rb
===================================================================
RCS file: /var/cvs/rush/rush/BufferedWindow.rb,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** BufferedWindow.rb	26 Aug 2005 15:51:08 -0000	1.10
--- BufferedWindow.rb	26 Aug 2005 22:15:28 -0000	1.11
***************
*** 1,8 ****
  class BufferedWindow < Curses::Window
    
!   attr_accessor :cursPos,:curx,:cury,:top,:lines,:width,:height,:done
    
    def get_current_line
!     @lines[-1]
    end
    
--- 1,8 ----
  class BufferedWindow < Curses::Window
    
!   attr_accessor :curx,:cury,:top,:lines,:width,:height,:done
    
    def get_current_line
!     @lines[cury]
    end
    
***************
*** 11,26 ****
      # state
      @done = false
      # Position
      @x = x
!     @y = y
!     
      @top = @curx = @cury = 0
      # Dimensions
      @width = width
      @height = height
      # Contents
      @lines = [""]
!     @cursPos = 0
      super(@height, at width, @y, @x)
      scrollok true
      idlok true
--- 11,29 ----
      # state
      @done = false
+ 
      # Position
      @x = x
!     @y = y    
      @top = @curx = @cury = 0
+ 
      # Dimensions
      @width = width
      @height = height
+ 
      # Contents
      @lines = [""]
! 
      super(@height, at width, @y, @x)
+ 
      scrollok true
      idlok true
***************
*** 51,104 ****
    def backspace
  
!     return if @cursPos == eval($env[:prompt]).length
      
! 	if @curx == 0
! 		@curx = @width
! 		@cury -= 1
! 	end
! 	
!     if @cursPos == @lines[-1].length
!       @lines[-1] = @lines[-1][0..-2]
        @curx -= 1
- 	  @cursPos -= 1
        return
      end 
      
!     @lines[-1].slice!(@cursPos-1)
      @curx -= 1
- 	@cursPos -= 1
      
    end
  
    def deletekey
!     @lines[-1].slice!(@cursPos)
    end
  
    def type_string(s)
  
!     exit if @lines[-1] == nil
! 	cursPos = (@lines[-1].length / @width) + @curx
!     @lines[-1].insert(@cursPos,s)
! 	@cury += (@curx+s.length) / @width
! 	#@curx += s.length
!     @curx = (@curx+s.length) %  @width# if (@curx+s.length) > @width
! 	@cursPos += s.length
    
    end
  
    def display
  
- 	#clear # Flickers a bit more but at least the combobox disappears ... 
      setpos(0,0)
      theend = @top+ at height
      theend = @lines.length if theend > @lines.length
!     
!     @top.upto(theend) do |i|
!       addstr("#{@lines[i]}\n")
      end
!     
!     setpos(@cury- at top, at curx)
!     
      refresh()
    end
  
--- 54,146 ----
    def backspace
  
!     return if @curx == eval($env[:prompt]).length
      
!     if @curx == @lines[@cury].length
!       @lines[@cury] = @lines[@cury][0..-2]
        @curx -= 1
        return
      end 
      
!     @lines[@cury].slice!(@curx-1)
      @curx -= 1
      
    end
  
    def deletekey
!     @lines[@cury].slice!(@curx)
    end
  
+ 
    def type_string(s)
  
!     exit if @lines[@cury] == nil
!     @lines[@cury].insert(@curx,s)
!     @curx += s.length
    
    end
  
    def display
+     clear
  
      setpos(0,0)
      theend = @top+ at height
      theend = @lines.length if theend > @lines.length
!  
!     extralines = 0
! 
!     @top.upto(theend-1) do |i|
!       i == theend-1 ? addstr("#{@lines[i]}") : addstr("#{@lines[i]}\n") 
!       extralines += (@lines[i].length/@width) if i != theend-1
      end
! 
!     clrtoeol
!  
!     # The last line is special
!     lastliney = @lines[-1].length/@width
! 
!     # The last line is special
!     linesonscreen = @cury- at top
! 
!     # Get where x should be 
!     (@curx/@width) == 0 ? xpos = @curx : xpos = @curx - @width*lastliney
! 
!     # Check if we are at the end of the screen
!     if linesonscreen+extralines >= @height-1
!       endofscreen = true
!     else
!       endofscreen = false
!     end
! 
!     # Calculate how much the screen will scroll automatically
!     willscroll = linesonscreen+extralines+lastliney-(@height-1)
!     willscroll = 0 if willscroll < 0
! 
!     # Check what the ypos should be
!     ypos = linesonscreen+extralines+(@curx/@width)
! 
!     if ypos > @height-1 and endofscreen
!       ypos = linesonscreen-lastliney+(@curx/@width)
!     end
! 
!     setpos(ypos,xpos)    
! 
      refresh()
+ 
+     #file = File.open("log","a")
+ 	#file << "-------------------\n"
+     #file << "@top\t-\t#{@top}\n"
+     #file << "@width\t-\t#{@width}\n"
+     #file << "@height\t-\t#{@height}\n"
+     #file << "xpos\t-\t#{xpos}\n"
+     #file << "ypos\t-\t#{ypos}\n"
+     #file << "@curx\t-\t#{@curx}\n"
+     #file << "@cury\t-\t#{@cury}\n"
+     #file << "willscroll\t-\t#{willscroll.to_s}\n"
+     #file << "lastliney\t-\t#{lastliney.to_s}\n"
+     #file << "endofscreen\t-\t#{endofscreen.to_s}\n"
+     #file << "extralines\t-\t#{extralines.to_s}\n"
+     #file << "linesonscreen\t-\t#{linesonscreen.to_s}\n"
+     #file.close
+ 
    end
  
***************
*** 122,126 ****
    
    def add_line(line)
-     @cury += line.length / @width
      @lines.push(line)
    end
--- 164,167 ----

Index: Alias.rb
===================================================================
RCS file: /var/cvs/rush/rush/Alias.rb,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Alias.rb	25 Aug 2005 14:20:18 -0000	1.2
--- Alias.rb	26 Aug 2005 22:15:28 -0000	1.3
***************
*** 18,22 ****
     def self.list
       ret = ""
!      @@aliases.each_pair{|key,value| ret += "#{key}\t-\t#{value}"}
       return ret
     end
--- 18,22 ----
     def self.list
       ret = ""
!      @@aliases.each_pair{|key,value| ret += "#{key}\t-\t#{value}\n"}
       return ret
     end

Index: rush.rb
===================================================================
RCS file: /var/cvs/rush/rush/rush.rb,v
retrieving revision 1.50
retrieving revision 1.51
diff -C2 -d -r1.50 -r1.51
*** rush.rb	26 Aug 2005 15:51:08 -0000	1.50
--- rush.rb	26 Aug 2005 22:15:28 -0000	1.51
***************
*** 1,8 ****
! #!/usr/bin/env ruby -w
  $: << "commands"
  
  # Stdlib
  require "curses"
! #require "breakpoint"
  require "open4"
  
--- 1,8 ----
! #!/usr/bin/ruby
  $: << "commands"
  
  # Stdlib
  require "curses"
! require "breakpoint"
  require "open4"
  
***************
*** 138,142 ****
  
    $bw.lines[-1] = eval($env[:prompt])
!   $bw.cursPos = $bw.curx = eval($env[:prompt]).length
    $bw.display
  
--- 138,142 ----
  
    $bw.lines[-1] = eval($env[:prompt])
!   $bw.curx = eval($env[:prompt]).length
    $bw.display
  
***************
*** 146,199 ****
      case ch
      when Curses::Key::RIGHT
!       if $bw.curx == $bw.width and ($bw.lines[-1].length - $bw.cursPos) > 0
!          $bw.curx = 0
!          $bw.cury += 1
!       else
!         $bw.curx += 1
! 		$bw.cursPos += 1
! 		if $bw.cursPos > $bw[-1].length
! 	    	$bw.curx = $bw[-1].length % $bw.width
! 			$bw.cursPos = $bw[-1].length
! 		end
!       end
        $bw.display
      when Curses::Key::LEFT
!       if $bw.curx == 0
! 		  $bw.curx = $bw.width
! 		  $bw.cury -= 1
! 		  #$bw.cursPos -= 1
!       elsif $bw.cursPos < $bw.width and $bw.curx == promptString.length
! 		  $bw.curx = promptString.length
!       else
!         $bw.curx -= 1
! 		$bw.cursPos -= 1
! 	  end
        $bw.display
      when Curses::Key::HOME
!       $bw.cury -= $bw.cursPos / $bw.width
!       $bw.curx = $bw.cursPos = promptString.length
        $bw.display
      when Curses::Key::END
!       $bw.cury += ($bw[-1].length / $bw.width) - ($bw.cursPos / $bw.width)
! 	  $bw.cursPos = $bw[-1].length
! 	  $bw.curx = $bw[-1].length % $bw.width
        $bw.display
      when Curses::Key::UP
        history_line -= 1
!       history_line = 0 if history_line < 0
! 	  $bw.cury -= $bw.cursPos / $bw.width
        $bw.lines[-1] = promptString+history[history_line]
! 	  $bw.cursPos = $bw[-1].length
!       $bw.curx = $bw[-1].length % $bw.width
! 	  $bw.cury += $bw[-1].length / $bw.width
        $bw.display
      when Curses::Key::DOWN
        history_line += 1
        history_line = history.length-1 if history_line > history.length-1
- 	  $bw.cury -= $bw.cursPos / $bw.width
        $bw.lines[-1] = promptString+history[history_line]
!       $bw.cursPos = $bw.lines[-1].length
! 	  $bw.curx = $bw[-1].length % $bw.width
! 	  $bw.cury += $bw[-1].length / $bw.width
        $bw.display
      when 13 # Enter
--- 146,173 ----
      case ch
      when Curses::Key::RIGHT
!       $bw.curx += 1
! 	  $bw.curx = $bw[-1].length if $bw.curx > $bw[-1].length
        $bw.display
      when Curses::Key::LEFT
!       $bw.curx -= 1
!       $bw.curx = promptString.length if $bw.curx < promptString.length  
        $bw.display
      when Curses::Key::HOME
!       $bw.curx = promptString.length  
        $bw.display
      when Curses::Key::END
! 	  $bw.curx = $bw[-1].length
        $bw.display
      when Curses::Key::UP
        history_line -= 1
!       history_line = 0 if history_line < 0 
        $bw.lines[-1] = promptString+history[history_line]
!       $bw.curx = $bw.lines[-1].length
        $bw.display
      when Curses::Key::DOWN
        history_line += 1
        history_line = history.length-1 if history_line > history.length-1
        $bw.lines[-1] = promptString+history[history_line]
!       $bw.curx = $bw.lines[-1].length
        $bw.display
      when 13 # Enter
***************
*** 213,224 ****
        end
        
- 	  $bw.cury += ($bw[-1].length / $bw.width) - ($bw.cursPos / $bw.width)
- 	  $bw.cursPos = $bw[-1].length
- 	  $bw.curx = $bw[-1].length % $bw.width
        # Reset the prompt screen here, it might have been changed 
        promptString = eval($env[:prompt])
        ret.split("\n").map{|l| $bw.add_line(l); $bw.cury += 1} if ret != nil
        $bw.cury += 1; $bw.lines.push(promptString)
- 	  $bw.cursPos = promptString.length
        $bw.curx = promptString.length
        $bw.show_bottom
--- 187,194 ----



More information about the Rush-developer mailing list