Sha256: 31be18a003c2806ea78a01ace1c99d6fd78df68c1dbaad8281d5bca50269b031

Contents?: true

Size: 736 Bytes

Versions: 18

Compression:

Stored size: 736 Bytes

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))

require 'tty-reader'
require 'paint'

Class.new do
  attr_reader :reader

  def initialize
    @reader = TTY::Reader.new(interrupt: :exit)
    shell
  end

  def quit_cmd?(cmd)
    cmd =~ /quit|exit/
  end

  def ignored_cmd?(cmd)
    cmd =~ /shell/ ||
    cmd.strip == ''
  end

  def command
    reader.read_line(Paint['coltrane ', '#FF5A00'])
  end

  def shell
    command
    .tap        { |cmd| exit if quit_cmd?(cmd) }
    .tap        { |cmd| shell and return if ignored_cmd?(cmd) }
    .yield_self { |cmd| %x{coltrane #{cmd}} }
    .yield_self { |response| puts ["\n", response, "\n"].join }
    shell
  end
end.new

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
coltrane-4.1.2 bin/coltrane-interactive
coltrane-4.1.1 bin/coltrane-interactive
coltrane-4.1.0 bin/coltrane-interactive
coltrane-4.0.6 bin/coltrane-interactive
coltrane-4.0.5 bin/coltrane-interactive
coltrane-4.0.4 bin/coltrane-interactive
coltrane-4.0.3 bin/coltrane-interactive
coltrane-3.4.2 bin/coltrane-interactive
coltrane-3.4.1 bin/coltrane-interactive
coltrane-3.4.0 bin/coltrane-interactive
coltrane-3.3.3 bin/coltrane-interactive
coltrane-3.3.2 bin/coltrane-interactive
coltrane-3.3.1 bin/coltrane-interactive
coltrane-3.3.0 bin/coltrane-interactive
coltrane-3.2.0 bin/coltrane-interactive
coltrane-3.1.3 bin/coltrane-interactive
coltrane-3.1.2 bin/coltrane-interactive
coltrane-3.1.1 bin/coltrane-interactive