Loading ...
Sorry, an error occurred while loading the content.

Fun with ruby: warp-fortune

Expand Messages
  • Zakaria
    Assalamu alaikum wr. wb. Daripada bengong mendingan ngoprek script berikut ini. Fungsinya adalah membuat supaya fortune bisa di word-wrap pada column tertentu.
    Message 1 of 1 , Jul 2, 2001
    • 0 Attachment
      Assalamu'alaikum wr. wb.

      Daripada bengong mendingan ngoprek script berikut ini.
      Fungsinya adalah membuat supaya fortune bisa di word-wrap
      pada column tertentu. Ini saya gunakan untuk Phosphor Xscreensaver.

      ===============/usr/bin/warp-fortune===============
      #!/usr/bin/ruby
      COLUMN = 31
      POET_COLUMN = 60

      class String
      def ltrim!
      self.sub! /^\s+/, ''
      return self
      end
      end

      result = []

      def result.add_lines(s)
      if s.length > 0 then
      self.push s + "\n"
      end
      end

      oldprefix = ''
      output = ''
      lines = []
      if ARGV.length >= 1
      File.open(ARGV[0]) {|i| lines = i.readlines}
      else
      IO.popen('fortune') {|i| lines = i.readlines}
      end

      # Uncomment this for testing
      #puts lines
      #puts '=' * COLUMN

      lines.each {|line|
      line.chomp!.gsub! "\t", ' '

      prefix = ''
      if line =~ /^\s*$/
      result.add_lines output
      result << "\n"
      output = ''
      oldprefix = ''
      next
      end
      line_length = line.length
      if line =~ /^[\s-]+/
      prefix = ' ' * $&.length
      end
      if oldprefix != prefix
      result.add_lines output
      output = ''
      else
      line.ltrim!
      output << ' ' if output.length > 0
      end
      line.scan(/\S+|\s+/) { |match|
      if match =~ /^\s+$/
      len = output.length + match.length - 1
      else
      len = output.length + match.length
      end
      if len > COLUMN
      result << output + "\n"
      output = prefix.dup
      end
      output << match
      }
      if line_length <= POET_COLUMN
      result.add_lines output
      output = ''
      prefix = ''
      end
      oldprefix = prefix
      }
      result.add_lines output

      puts result
      ===============/usr/bin/warp-fortune===============

      Berikut File pendukung setting di GNOME perhatikan baris TryExec.

      ==========/usr/share/control-center/.data/Phosphor.desktop==========
      [Desktop Entry]
      Name=Phosphor
      Comment=Draws a simulation of an old terminal, with large pixels and
      long-sustain phosphor.
      Exec=xscreensaver-command -activate
      TryExec=phosphor -scale 4 -program warp-fortune
      Terminal=0
      Type=Application

      [Screensaver Data]
      WindowIdCommand=-window-id
      RootCommand=-root
      Icon=Phosphor.png
      Author=Jamie Zawinski <jwz@...>
      ExtendedComment=
      Demo=phosphor -delay 2
      ==========/usr/share/control-center/.data/Phosphor.desktop==========

      Silakah di perbaiki karena masih ada beberapa kelemahan misalnya
      belum bisa mengerti indentend paragraph. seperti

      ... This striving for excellence extends into people's personal
      lives as well. When '80s people buy something, they buy the best one, as
      determined by (1) price and (2) lack of availability. Eighties people buy
      imported dental floss. They buy gourmet baking soda. If an '80s couple
      goes to a restaurant where they have made a reservation three weeks in
      advance, and they are informed that their table is available, they stalk
      out immediately, because they know it is not an excellent restaurant. If
      it were, it would have an enormous crowd of excellence-oriented people
      like themselves waiting, their beepers going off like crickets in the
      night. An excellent restaurant wouldn't have a table ready immediately
      for anybody below the rank of Liza Minnelli.
      -- Dave Barry, "In Search of Excellence"
      ===============================
      ... This striving for
      excellence extends into
      people's personal
      lives as well. When '80s
      people buy something, they buy
      the best one, as determined by
      (1) price and (2) lack of
      availability. Eighties people
      buy imported dental floss.
      They buy gourmet baking soda.
      If an '80s couple goes to a
      restaurant where they have made
      a reservation three weeks in
      advance, and they are informed
      that their table is available,
      they stalk out immediately,
      because they know it is not an
      excellent restaurant. If it
      were, it would have an enormous
      crowd of excellence-oriented
      people like themselves waiting,
      their beepers going off like
      crickets in the night. An
      excellent restaurant wouldn't
      have a table ready immediately
      for anybody below the rank of
      Liza Minnelli.
      -- Dave Barry, "In Search
      of Excellence"



      Wassallam,


      -- Zakaria
      Work: zakaria@..., http://asia-karsa.com
      Private: z4k4ri4@... Yahoo!: z4k4ri4
      http://pemula.linux.or.id
    Your message has been successfully submitted and would be delivered to recipients shortly.