Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
leonovk committed Nov 1, 2023
1 parent 639795f commit 23f55db
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Ruby

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1
with:
ruby-version: '3.1'
- name: Install dependencies
run: bundle install
- name: Run cops
run: bundle exec rubocop
7 changes: 7 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec

gem 'rubocop'
44 changes: 44 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
PATH
remote: .
specs:
boaw (0.0.2)

GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
json (2.6.3)
language_server-protocol (3.17.0.3)
parallel (1.23.0)
parser (3.2.2.4)
ast (~> 2.4.1)
racc
racc (1.7.2)
rainbow (3.1.1)
regexp_parser (2.8.2)
rexml (3.2.6)
rubocop (1.57.2)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.4)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
ruby-progressbar (1.13.0)
unicode-display_width (2.5.0)

PLATFORMS
x86_64-linux

DEPENDENCIES
boaw!
rubocop

BUNDLED WITH
2.4.20
8 changes: 8 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'boaw'

require 'irb'
IRB.start(__FILE__)
6 changes: 6 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install
19 changes: 19 additions & 0 deletions boaw.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require_relative 'lib/boaw/version'

Gem::Specification.new do |s|
s.name = 'boaw'
s.version = Boaw::VERSION
s.summary = 'Mouse manipulation library'
s.description = 'The library will allow you to create auto-clickers for Unix systems'
s.authors = ['Kirill Leonov']
s.email = '[email protected]'
s.files = Dir.glob('lib/**/*')
s.homepage = 'https://github.com/leonovk/boaw'
s.license = 'MIT'
s.required_ruby_version = '>= 3.1.0'
s.metadata['homepage_uri'] = s.homepage
s.metadata['source_code_uri'] = s.homepage
s.metadata['documentation_uri'] = s.homepage
end
20 changes: 20 additions & 0 deletions lib/boaw.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

require_relative 'xdotool/adapter'

# Main class
class Boaw
attr_reader :adapter

def initialize
@adapter = Xdotool::Adapter.new
end

def position
adapter.position
end

def left_click(position)
adapter.left_click(position)
end
end
5 changes: 5 additions & 0 deletions lib/boaw/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class Boaw
VERSION = '0.0.2'
end
35 changes: 35 additions & 0 deletions lib/xdotool/adapter.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# frozen_string_literal: true

module Xdotool
# Xdotool adapter for mouse control
class Adapter
def position
system('xdotool getmouselocation>temp.txt')

current_position = parse_position

{
x: current_position['x'].to_i,
y: current_position['y'].to_i
}
end

def left_click(position)
system("xdotool mousemove #{position[:x]} #{position[:y]} click 1")
end

private

def parse_position
file = File.open('./temp.txt', 'r')
position = file.gets.scan(/(\w+):(\d+)/).to_h
file.close
delete_temp_file
position
end

def delete_temp_file
File.delete('./temp.txt')
end
end
end

0 comments on commit 23f55db

Please sign in to comment.