Class: Repla::Logger

Inherits:
Object
  • Object
show all
Defined in:
lib/repla/logger.rb

Overview

Logger

Constant Summary collapse

MESSAGE_PREFIX =
'MESSAGE '.freeze
ERROR_PREFIX =
'ERROR '.freeze
LOG_PLUGIN_NAME =
'Log'.freeze
SHOW_LOG_SCRIPT =

Toggle

File.join(APPLESCRIPT_DIRECTORY, 'show_log.scpt')
HIDE_LOG_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, 'hide_log.scpt')
TOGGLE_LOG_SCRIPT =
File.join(APPLESCRIPT_DIRECTORY, 'toggle_log.scpt')

Instance Method Summary collapse

Instance Method Details

#error(message) ⇒ Object



37
38
39
40
41
# File 'lib/repla/logger.rb', line 37

def error(message)
  message = message.dup
  message.gsub!(/^/, ERROR_PREFIX)
  log_message(message)
end

#hideObject



18
19
20
# File 'lib/repla/logger.rb', line 18

def hide
  Repla.run_applescript(HIDE_LOG_SCRIPT, [window_id])
end

#info(message) ⇒ Object

Messages



29
30
31
32
33
34
35
# File 'lib/repla/logger.rb', line 29

def info(message)
  message = message.dup
  message.gsub!(/^/, MESSAGE_PREFIX) # Prefix all lines
  # Strip trailing white space
  # Add a line break
  log_message(message)
end

#showObject



13
14
15
# File 'lib/repla/logger.rb', line 13

def show
  Repla.run_applescript(SHOW_LOG_SCRIPT, [window_id])
end

#toggleObject



23
24
25
# File 'lib/repla/logger.rb', line 23

def toggle
  Repla.run_applescript(TOGGLE_LOG_SCRIPT, [window_id])
end

#view_idObject



50
51
52
53
54
55
56
57
# File 'lib/repla/logger.rb', line 50

def view_id
  @view_id ||= Repla.split_id_in_window(window_id, LOG_PLUGIN_NAME)
  return @view_id unless @view_id.nil?

  @view_id = Repla.split_id_in_window_last(window_id)
  Repla.run_plugin_in_split(LOG_PLUGIN_NAME, window_id, @view_id)
  @view_id
end

#window_idObject

Properties



45
46
47
48
# File 'lib/repla/logger.rb', line 45

def window_id
  key = WINDOW_ID_KEY
  @window_id ||= ENV.key?(key) ? ENV[key] : Repla.create_window
end