Sha256: 21a170f6ef8535a7a038cce9c9e5ad8c1a1c7697818ce72ceebe17ce61759ed9

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require "curses"
require "logger"
require "jared/version"
require "jared/pane"
require "jared/file_view"
require "jared/buffer"

module JarEd
  class << self
    def start(args)
      buffer = Buffer.new(args[0])
      pane = Pane.new
      pane.view = FileView.new buffer

      take_input do |char|
        # FIXME: This should normalize incoming escape sequences and such.
        pane.send_input char
        pane.refresh(window)
      end
    end

    def norman
      "Jared Norman"
    end

    def logger
      @logger ||=
        begin
          log_directory_path = File.join(jared_folder_path, "logs")
          FileUtils.mkdir_p log_directory_path
          log_file_path = File.join(log_directory_path, "jared.log")
          logger = Logger.new(log_file_path, 10)
          logger.level = Logger::DEBUG
          logger
        end
    end

    private

    def jared_folder_path
      @jared_folder_path ||=
        begin
          path = File.join(Dir.home, ".jared")
          FileUtils.mkdir_p(path)
          path
        end
    end

    def window
      @window ||= Curses::Window.new(0, 0, 0, 0)
    end

    def take_input
      Curses.init_screen
      begin
        Curses.crmode
        Curses.noecho
        Curses.refresh

        yield nil
        Curses.doupdate

        loop do
          begin
            yield Curses.getch.chr
          rescue RangeError
            yield nil
          end

          Curses.doupdate
        end
      ensure
        Curses.close_screen
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
jareditor-3.0.0 lib/jared.rb