Class: NanDoc::SpecDoc::Playback::Terminal

Inherits:
Object
  • Object
show all
Includes:
PlaybackMethods, ColorToHtml, Nanoc3::Helpers::HTMLEscape, Singleton
Defined in:
lib/nandoc/spec-doc/playback/players/terminal.rb,
lib/nandoc/spec-doc/playback/terminal/color-to-html.rb

Defined Under Namespace

Modules: ColorToHtml

Constant Summary

Constants included from ColorToHtml

ColorToHtml::Code2CssClass

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ColorToHtml

#prompt_highlight, #prompt_highlight2, #terminal_color_to_html

Methods included from PlaybackMethods

#get_tag_filter, #run_sexp_with_handlers

Constructor Details

#initializeTerminal

Returns a new instance of Terminal.



18
19
20
21
22
# File 'lib/nandoc/spec-doc/playback/players/terminal.rb', line 18

def initialize
  @ellipsis_default = '...'
  @prompt_str_default = '~ > '
  @prompt_str = nil
end

Instance Attribute Details

#ellipsis_defaultObject

Returns the value of attribute ellipsis_default.



38
39
40
# File 'lib/nandoc/spec-doc/playback/players/terminal.rb', line 38

def ellipsis_default
  @ellipsis_default
end

#prompt_str_defaultObject

Returns the value of attribute prompt_str_default.



40
41
42
# File 'lib/nandoc/spec-doc/playback/players/terminal.rb', line 40

def prompt_str_default
  @prompt_str_default
end

Instance Method Details

#fake_pwd_popObject



34
35
36
# File 'lib/nandoc/spec-doc/playback/players/terminal.rb', line 34

def fake_pwd_pop
  @prompt_str = @old_prompts.pop
end

#fake_pwd_push(new_dir) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/nandoc/spec-doc/playback/players/terminal.rb', line 24

def fake_pwd_push new_dir
  /\A(.+) > \Z/ =~ prompt_str or
    fail("can't determine cwd from #{prmpt_str.inspect}")
  new_pwd = "#{$1}/#{new_dir}"
  @old_prompts ||= []
  @old_prompts.push prompt_str
  @prompt_str = "#{new_pwd} > "
  nil
end

#prompt_strObject



42
43
44
# File 'lib/nandoc/spec-doc/playback/players/terminal.rb', line 42

def prompt_str
  @prompt_str ||= @prompt_str_default
end

#run_cd(out, scn) ⇒ Object



46
47
48
49
50
51
52
53
# File 'lib/nandoc/spec-doc/playback/players/terminal.rb', line 46

def run_cd out, scn
  node = scn.scan_assert(:cd)
  the_new_directory = node[1]
  html = prompt_highlight2(prompt_str, "cd #{the_new_directory}")
  fake_pwd_push the_new_directory
  out.push_smart 'pre', 'terminal', html
  nil
end

#run_cd_end(out, scn) ⇒ Object



55
56
57
58
59
# File 'lib/nandoc/spec-doc/playback/players/terminal.rb', line 55

def run_cd_end out, scn
  _ = scn.scan_assert(:cd_end)
  fake_pwd_pop
  nil
end

#run_command(out, scn) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/nandoc/spec-doc/playback/players/terminal.rb', line 61

def run_command out, scn
  node = scn.scan_assert(:command)
  command_content = node[1]
  html = prompt_highlight2(prompt_str, command_content)
  out.push_smart 'pre', 'terminal', html
  nil
end

#run_out(out, scn) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/nandoc/spec-doc/playback/players/terminal.rb', line 69

def run_out out, scn
  node = scn.scan_assert(:out)
  raw = node[1]
  html = terminal_color_to_html(raw) || html_escape(raw)
  out.push_smart 'pre', 'terminal', html
  nil
end

#run_out_begin(out, scn) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/nandoc/spec-doc/playback/players/terminal.rb', line 77

def run_out_begin out, scn
  node = scn.scan_assert(:out_begin)
  lines = [node[1].strip]
  if node = scn.scan(:cosmetic_ellipsis)
    lines.push node[1]
  else
    lines.push ellipsis_default
  end
  node = scn.scan_assert(:out_end)
  lines.push node[1]
  raw = lines.join("\n")
  html = terminal_color_to_html(raw) || html_escape(raw)
  out.push_smart 'pre', 'terminal', html
  nil
end