Sha256: c8f7c1743b84bfeb1be6444bd6c39afec6e6c1f8cf88f3c0913d3776b8b07cf7

Contents?: true

Size: 1.17 KB

Versions: 2

Compression:

Stored size: 1.17 KB

Contents

require 'erb'

module Space
  class View
    autoload :Dashboard, 'space/view/dashboard'
    autoload :Helpers,   'space/view/helpers'
    autoload :Progress,  'space/view/progress'
    autoload :Template,  'space/view/template'

    attr_reader :project

    def initialize(project)
      @project = project
    end

    def notify(event)
      send(:"on_#{event}")
    end

    private

      def render_header
        print "Project #{project.name}\n\n", :at => [0, 0]
        render_prompt
        move 0, 5
      end

      def render_prompt
        print prompt, :at => [0, 3]
        print "\e[0K", :at => [prompt.size + 1, 3]
      end

      def render_template(name, assigns)
        path = "#{project.config.template_dir}/#{name}.erb"
        print Template.new(path).render(assigns)
      end

      def clear
        print "\e[2J" # clear entire screen
      end

      def print(string, options = {})
        move(*options[:at]) if options.key?(:at)
        super(string)
      end

      def move(x, y)
        print "\e[#{y};#{x}H"
      end

      def prompt
        "#{project.repos.scoped? ? project.repos.scope.map(&:name).join(', ') : project.name} > "
      end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
space-0.0.9 lib/space/view.rb
space-0.0.8 lib/space/view.rb