Module: XorgBuffer

Defined in:
lib/xorg_buffer/module.rb,
lib/xorg_buffer/version/version.rb,
lib/xorg_buffer/constants/constants.rb

Overview

#

require ‘xorg_buffer/constants/constants.rb’

#

Constant Summary collapse

VERSION =
#

VERSION

#
'1.2.5'
LAST_UPDATE =
#

LAST_UPDATE

#
'09.10.2022'
USE_THIS_XORG_COMMAND =
#

USE_THIS_XORG_COMMAND

We need to keep in mind that xsel may be unavailable on a user’s machine.

#
'xsel --input'

Class Method Summary collapse

Class Method Details

.set_xorg_buffer(data = nil) ⇒ Object

#

XorgBuffer.set_xorg_buffer

Use this method to set to the Xorg Buffer, on Linux.

Complete usage example for this method here:

require 'xorg_buffer/module'; XorgBuffer.set_xorg_buffer('test')

Now, the xorg buffer contains the word ‘test’.

#


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/xorg_buffer/module.rb', line 25

def self.set_xorg_buffer(
    data = nil
  )
  if data
    data = data.join('|') if data.is_a? Array
    # ===================================================================== #
    # We must get rid of '""' because this may confuse the xsel command.
    # ===================================================================== #
    if data.include? '"'
      data = data.delete('"')
    end
    # ===================================================================== #
    # We must use 2>&1 in the event that "xsel" is not installed.
    # ===================================================================== #
    cmd = 'echo "'+data+'" | '+USE_THIS_XORG_COMMAND+' 2>&1'
    system cmd
  end
end