Sha256: 2276355e8c587561a2fe4fe8488a3b37fd4164c28b5cc67618d6254c3a42b1bb

Contents?: true

Size: 1.95 KB

Versions: 38

Compression:

Stored size: 1.95 KB

Contents

#!/usr/bin/env ruby

require 'bundler/setup'
require 'vedeu'

# An example application to demonstrate 'Hello World' and a minimum of
# interactivity.  It uses the DSL-style of vedeu (not the full-flegded
# MVC-approach).
#
# If you have cloned this repository from GitHub, you can run this example:
#
#     bundle exec ./examples/hello_worlds.rb
#
class HelloWorldsApp

  Vedeu.bind(:_initialize_) {
    Vedeu.trigger(:_show_view_, :hello)
    Vedeu.trigger(:_refresh_)
  }

  # Add specific configuration for the client application.
  #
  # Vedeu.configure do
  #   log '/tmp/hello_worlds.log'
  # end

  Vedeu.interface :hello do
    # Define all of the interface in one place.
    background '#000000'
    foreground '#00ff00'
    geometry do
      align(:middle, :centre, 24, 5)
    end
    keymap do
      key('q') { Vedeu.exit }
      key('w') { HelloWorldsApp.render_world }
    end
  end

  Vedeu.renders do
    view :hello do
      lines do
        line { centre 'Hello Worlds!', width: 24 }
        line
        line { centre "Press 'q' to exit,",     width: 24 }
        line { centre " 'w' to switch worlds.", width: 24 }
      end
    end
  end

  def self.start(argv = ARGV)
    Vedeu::Launcher.execute!(argv)
  end

  private

  def self.render_world
    # Immediately render this to screen.
    Vedeu.render do
      view :hello do
        geometry do
          align(:middle, :centre, (24 + 2), (5 + 2))
        end
        border do
          colour foreground: ["#00ff00", "#000033", "#cddc39", "#03a9f4"].sample
          title ["atlantis", "oceania", "utopia", "midgard", "middle-earth"].sample
        end
        lines do
          line { centre 'Hello Worlds!', width: 24 }
          line
          line { centre "Press 'q' to exit,",     width: 24 }
          line { centre " 'w' to switch worlds.", width: 24 }
          line { centre "#{Vedeu.trigger(:_cursor_position_, Vedeu.focus)}" }
        end
      end
    end
  end

end # HelloWorldsApp

HelloWorldsApp.start(ARGV)

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
vedeu-0.8.0 examples/dsl_hello_worlds.rb
vedeu-0.7.4 examples/dsl_hello_worlds.rb
vedeu-0.7.3 examples/dsl_hello_worlds.rb
vedeu-0.7.2 examples/dsl_hello_worlds.rb
vedeu-0.7.1 examples/dsl_hello_worlds.rb
vedeu-0.7.0 examples/dsl_hello_worlds.rb
vedeu-0.6.71 examples/dsl_hello_worlds.rb
vedeu-0.6.70 examples/dsl_hello_worlds.rb
vedeu-0.6.69 examples/dsl_hello_worlds.rb
vedeu-0.6.68 examples/dsl_hello_worlds.rb
vedeu-0.6.67 examples/dsl_hello_worlds.rb
vedeu-0.6.66 examples/dsl_hello_worlds.rb
vedeu-0.6.65 examples/dsl_hello_worlds.rb
vedeu-0.6.64 examples/dsl_hello_worlds.rb
vedeu-0.6.63 examples/dsl_hello_worlds.rb
vedeu-0.6.62 examples/dsl_hello_worlds.rb
vedeu-0.6.61 examples/dsl_hello_worlds.rb
vedeu-0.6.60 examples/dsl_hello_worlds.rb
vedeu-0.6.59 examples/dsl_hello_worlds.rb
vedeu-0.6.58 examples/dsl_hello_worlds.rb