Class: Tmux::Buffer

Inherits:
Object
  • Object
show all
Defined in:
lib/tmux/buffer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number, session) ⇒ Filesize



11
12
13
14
15
16
17
18
# File 'lib/tmux/buffer.rb', line 11

def initialize(number, session)
  @number, @session, @size = number, session
  unless server.version >= "1.3"
    # we do not need a temporary file for tmux versions that can
    # directly load/save from/to stdin/stdout
    @file = Tempfile.new("buffer")
  end
end

Instance Attribute Details

#data(force_reload = false) ⇒ String

Parameters:

  • force_reload (Boolean) (defaults to: false)

    Ignore frozen state if true

Returns:

  • (String)


34
35
36
# File 'lib/tmux/buffer.rb', line 34

def data
  @data
end

#numberNumber (readonly)

Returns:

  • (Number)


7
8
9
# File 'lib/tmux/buffer.rb', line 7

def number
  @number
end

#serverServer (readonly)

Returns:



81
82
83
# File 'lib/tmux/buffer.rb', line 81

def server
  @server
end

#sessionSession (readonly)

Returns:



9
10
11
# File 'lib/tmux/buffer.rb', line 9

def session
  @session
end

#size(force_reload = false) ⇒ Filesize (readonly)

Parameters:

  • force_reload (Boolean) (defaults to: false)

    Ignore frozen state if true

Returns:

  • (Filesize)


22
23
24
# File 'lib/tmux/buffer.rb', line 22

def size
  @size
end

Instance Method Details

#delete

This method returns an undefined value.

Deletes a buffer.

tmux command:

  • delete-buffer



91
92
93
94
# File 'lib/tmux/buffer.rb', line 91

def delete
  freeze! # so we can still access its old value
  server.invoke_command "delete-buffer -b #@number -t #{@session.identifier}"
end

#freeze!

This method returns an undefined value.

By default, Buffer will not cache its data but instead query it each time. By calling this method, the data will be cached and not updated anymore.



74
75
76
77
78
# File 'lib/tmux/buffer.rb', line 74

def freeze!
  @frozen = true
  @data = data
  @size = size
end

#paste(target = nil, pop = false, translate = true, separator = nil)

This method returns an undefined value.

Pastes the content of a buffer into a window or pane.

Parameters:

  • target (Window) (defaults to: nil)

    The pane or window to paste the buffer into. Note: Panes as as target are only supported since tmux version 1.3.

  • pop (Boolean) (defaults to: false)

    If true, delete the buffer from the stack

  • translate (Boolean) (defaults to: true)

    If true, any linefeed (LF) characters in the paste buffer are replaced with carriage returns (CR)

  • separator (String) (defaults to: nil)

    Replace any linefeed (LF) in the buffer with this separator. +translate+ must be false.

See Also:

tmux command:

  • paste-buffer

Required tmux version:

  • >=1.3 for pasting to panes



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/tmux/buffer.rb', line 117

def paste(target = nil, pop = false, translate = true, separator = nil)
  if server.version < "1.3"
    if separator || target.is_a?(Pane)
      raise Exception::UnsupportedVersion, "1.3"
    end
  end

  flag_pop       = pop ? "-d" : ""
  flag_translate = translate ? "" : "-r"
  flag_separator = separator ? "" : "-s \"#{separator}\"" # FIXME escape
  window_param   = target ? "-t #{target.identifier}" : ""
  server.invoke_command "paste-buffer #{flag_pop} #{flag_translate} #{flag_separator} #{window_param}"
end

#save(file, append = false) Also known as: write

This method returns an undefined value.

Saves the contents of a buffer.

Parameters:

  • file (String)

    The file to write to

  • append (Boolean) (defaults to: false)

    Append to instead of overwriting the file

tmux command:

  • save-buffer



64
65
66
67
# File 'lib/tmux/buffer.rb', line 64

def save(file, append = false)
  flag = append ? "-a" : ""
  server.invoke_command "save-buffer #{flag} -b #@number -t #{@session.identifier} #{file}"
end

#to_sString

Returns The content of a buffer.

Returns:

  • (String)

    The content of a buffer



97
98
99
# File 'lib/tmux/buffer.rb', line 97

def to_s
  text
end