Class: Hiiro::Tmux::Buffer
- Inherits:
-
Object
- Object
- Hiiro::Tmux::Buffer
- Defined in:
- lib/hiiro/tmux/buffer.rb
Constant Summary collapse
- FORMAT =
'#{buffer_name}|#{buffer_size}|#{buffer_created}|#{buffer_sample}'
Instance Attribute Summary collapse
-
#created ⇒ Object
readonly
Returns the value of attribute created.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sample ⇒ Object
readonly
Returns the value of attribute sample.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
Class Method Summary collapse
Instance Method Summary collapse
- #content ⇒ Object
- #delete ⇒ Object
-
#initialize(name:, size: 0, created: 0, sample: nil) ⇒ Buffer
constructor
A new instance of Buffer.
- #paste(target: nil) ⇒ Object
- #save(path) ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name:, size: 0, created: 0, sample: nil) ⇒ Buffer
Returns a new instance of Buffer.
24 25 26 27 28 29 |
# File 'lib/hiiro/tmux/buffer.rb', line 24 def initialize(name:, size: 0, created: 0, sample: nil) @name = name @size = size @created = created @sample = sample end |
Instance Attribute Details
#created ⇒ Object (readonly)
Returns the value of attribute created.
6 7 8 |
# File 'lib/hiiro/tmux/buffer.rb', line 6 def created @created end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/hiiro/tmux/buffer.rb', line 6 def name @name end |
#sample ⇒ Object (readonly)
Returns the value of attribute sample.
6 7 8 |
# File 'lib/hiiro/tmux/buffer.rb', line 6 def sample @sample end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
6 7 8 |
# File 'lib/hiiro/tmux/buffer.rb', line 6 def size @size end |
Class Method Details
.from_format_line(line) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hiiro/tmux/buffer.rb', line 8 def self.from_format_line(line) return nil if line.nil? || line.strip.empty? parts = line.strip.split('|', 4) return nil if parts.size < 3 name, size, created, sample = parts new( name: name, size: size.to_i, created: created.to_i, sample: sample ) end |
Instance Method Details
#content ⇒ Object
31 32 33 |
# File 'lib/hiiro/tmux/buffer.rb', line 31 def content `tmux show-buffer -b #{name.shellescape} 2>/dev/null` end |
#delete ⇒ Object
35 36 37 |
# File 'lib/hiiro/tmux/buffer.rb', line 35 def delete system('tmux', 'delete-buffer', '-b', name) end |
#paste(target: nil) ⇒ Object
39 40 41 42 43 |
# File 'lib/hiiro/tmux/buffer.rb', line 39 def paste(target: nil) args = ['tmux', 'paste-buffer', '-b', name] args += ['-t', target] if target system(*args) end |
#save(path) ⇒ Object
45 46 47 |
# File 'lib/hiiro/tmux/buffer.rb', line 45 def save(path) system('tmux', 'save-buffer', '-b', name, path) end |
#to_h ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/hiiro/tmux/buffer.rb', line 49 def to_h { name: name, size: size, created: created, sample: sample }.compact end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/hiiro/tmux/buffer.rb', line 58 def to_s "#{name}: #{sample}" end |