Module: Showterm

Extended by:
Showterm
Included in:
Showterm
Defined in:
lib/showterm.rb

Instance Method Summary collapse

Instance Method Details

#delete!(url, secret = shared_secret) ⇒ Object

Delete from showterm.io

Parameters:

  • url (String)

    The URL of the showterm to delete

  • secret (String) (defaults to: shared_secret)

    The secret with which it was uploaded.



67
68
69
70
71
72
73
74
75
# File 'lib/showterm.rb', line 67

def delete!(url, secret=shared_secret)

  request = Net::HTTP::Delete.new(URI(url).path)
  request.set_form_data(:secret => secret)
  response = http(request)

  raise response.body unless Net::HTTPSuccess === response
  response.body
end

#record!(*cmd) ⇒ scriptfile, timingfile

Record a terminal session.

If a command is given, use that command; otherwise the current user’s login shell will be used.

Parameters:

  • cmd (*String)

Returns:

  • (scriptfile, timingfile)

    the two halves of a termshow



16
17
18
19
20
21
22
23
# File 'lib/showterm.rb', line 16

def record!(*cmd)
  ret = if use_script?
    record_with_script(*cmd)
  else
    record_with_ttyrec(*cmd)
  end
  ret
end

#terminal_heightInteger

Get the current height of the terminal

Returns:

  • (Integer)

    number of lines



37
38
39
40
# File 'lib/showterm.rb', line 37

def terminal_height
  guess = `tput lines`.to_i
  guess == 0 ? 25 : guess
end

#terminal_widthInteger

Get the current width of the terminal

Returns:

  • (Integer)

    number of columns



28
29
30
31
# File 'lib/showterm.rb', line 28

def terminal_width
  guess = `tput cols`.to_i
  guess == 0 ? 80 : guess
end

#upload!(scriptfile, timingfile, cols = terminal_width, lines = terminal_height, secret = shared_secret) ⇒ Object

Upload the termshow to showterm.io

Parameters:

  • scriptfile (String)

    The ANSI dump of the terminal

  • timingfile (String)

    The timings

  • cols (Integer) (defaults to: terminal_width)

    The width of the terminal

  • secret (String) (defaults to: shared_secret)

    The shared secret that will allow deleting this showterm.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/showterm.rb', line 48

def upload!(scriptfile, timingfile, cols=terminal_width, lines=terminal_height, secret=shared_secret)
  with_retry do
    request = Net::HTTP::Post.new("/scripts")
    request.set_form_data(:scriptfile => scriptfile,
                          :timingfile => timingfile,
                          :cols => cols,
                          :lines => lines,
                          :secret => secret)

    response = http(request)
    raise response.body unless Net::HTTPSuccess === response
    response.body
  end
end