4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Googleのプログレスバー作ってみた

Last updated at Posted at 2012-03-16

シェルで実行するとググったときに出るアレがプログレスバーとして表示されます.

google_progress.rb
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

class GoogleProgress

    def initialize m
        @max = m
        @tic = 0
    end

    def +@
        return if @tic >= @max
        @tic += 1
        draw_progress_bar
        puts if @tic == @max
    end

    def reset
        @tic = 0
    end

private

    Default = "\e[0m"
    Blue = "\e[34m"
    Red = "\e[31m"
    Green = "\e[32m"
    Yellow = "\e[33m"

    def google count
        ooo = "o" * count
        "#{Blue}G#{Red}o#{Yellow}o#{ooo}#{Blue}g#{Green}l#{Red}e#{Default}"
    end

    def draw_progress_bar
        oo = @tic*20/@max
        print "\r#{google(oo)} [#{Float(@tic*100)/@max}]"
    end
end

#
# main
#
if __FILE__ == $0 then
    google_progress = GoogleProgress.new 100
    100.times do 
        +google_progress
        sleep 0.1
    end
end
4
4
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?