Module: Drakkon::Run::Commands

Defined in:
lib/drakkon/run/commands/log.rb,
lib/drakkon/run/commands/images.rb,
lib/drakkon/run/commands/restart.rb

Overview

Runnable Terminal Commands

Class Method Summary collapse

Class Method Details

.cmd_images(_args) ⇒ Object



6
7
8
# File 'lib/drakkon/run/commands/images.rb', line 6

def self.cmd_images(_args)
  Images::Index.run!(force: true, dir: Run.context)
end

.cmd_logs(_args) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/drakkon/run/commands/log.rb', line 6

def self.cmd_logs(_args)
  TTY::Pager.page(command: 'less +G') do |pager|
    Run.logs.each do |line|
      pager.write line
    end
  end
end

.cmd_restart(_args) ⇒ Object



6
7
8
# File 'lib/drakkon/run/commands/restart.rb', line 6

def self.cmd_restart(_args)
  Run.restart
end

.cmd_tail(_args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/drakkon/run/commands/log.rb', line 14

def self.cmd_tail(_args)
  loop do
    if Run.dragonruby.ready?
      $stdin.cooked!
      line = Run.dragonruby.readline
      Run.logs.push line # Store
      puts line
    elsif key_pressed?
      key = $stdin.readchar
      if key.ord >= 32 && key.ord <= 126
        break
      else
        break if key == "\u0003" # 'CTRL C'
        break if key == "\u0004" # 'CTRL D'

        $stdin.cooked!
        puts "any key to stop following: #{key.inspect}".pastel(:green)
      end

    else
      $stdin.raw!
      sleep 0.1
    end
  end

  # Restore the previous raw mode
  $stdin.cooked!
rescue EOFError
  :ignore
end

.key_pressed?Boolean

Returns:

  • (Boolean)


45
46
47
48
49
50
51
# File 'lib/drakkon/run/commands/log.rb', line 45

def self.key_pressed?
  # Set raw mode to ensure immediate input
  $stdin.raw(&:ready?)
ensure
  # Restore the previous raw mode
  $stdin.cooked!
end