process-terminal 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6df8e6e077ce8e3aff50a36351eba10632633c5a22217e28de7d47ba43508b13
4
- data.tar.gz: 4f9ee77e46d446741ffff42b27cdee5a322d5139b9e7f4eed6e49e9063b51f4c
3
+ metadata.gz: 76eeb0c369d4ae4c5654639581523d17abb56b381ccc1ee9bf2f73fcf626efa2
4
+ data.tar.gz: 1a06952b321e9b0dd30f293667e1ed5a597d40f27c0d8d1faa4c6ab91a757521
5
5
  SHA512:
6
- metadata.gz: fbcb8dba4df1fe0e0a6350f69a71e993f43ca8b9d7313ace820ff8b7e89a42e361393f8ea72be7ad03eb3a47593e933f9556d079037fe6da659865497d6e0273
7
- data.tar.gz: 538bfa1c9ec9102ac61f2a2980c624ecbec1b1c9045d18d2144aef72ae935cd5698553a762b533de1a93ce707b88bf0f2ffdfba41f5fa8c47cacc773caedc6a8
6
+ metadata.gz: cafafc50d5ba75c1fd1eacb391d1e67e8aa8a6ad553824c756c8a2e2fd5c8ebd0189719d98a4b8c0d9ce1bd3d0b52a855a496f5ebd01535271fa2a57097e2228
7
+ data.tar.gz: 88f4e17b0f8e83453598db2176c1b4fb8b3b1aad7098611ae7e7e282587f65dfbca202312a654041c842fb1c7a4fc18952c5738ced6f70b208a4ec34c5fb936f
@@ -4,17 +4,32 @@ on: [push]
4
4
 
5
5
  jobs:
6
6
  build:
7
-
8
- runs-on: ubuntu-latest
9
-
10
7
  strategy:
11
8
  matrix:
12
- ruby-version: ['2.3', '2.4', '2.5', '2.6']
9
+ os:
10
+ - ubuntu
11
+ - macos
12
+
13
+ ruby:
14
+ - 2.4
15
+ - 2.5
16
+ - 2.6
17
+
18
+ include:
19
+ - os: 'ubuntu'
20
+ ruby: '2.6'
21
+ env: COVERAGE=PartialSummary,Coveralls
22
+
23
+ runs-on: ${{matrix.os}}-latest
13
24
 
14
25
  steps:
15
26
  - uses: actions/checkout@v1
16
27
  - uses: actions/setup-ruby@v1
17
28
  with:
18
- ruby-version: ${{matrix.ruby-version}}
29
+ ruby-version: ${{matrix.ruby}}
30
+ - name: Install dependencies
31
+ run: |
32
+ command -v bundler || gem install bundler
33
+ bundle install
19
34
  - name: Run tests
20
- run: bundle exec rspec
35
+ run: ${{matrix.env}} bundle exec rspec
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in process-terminal.gemspec
4
4
  gemspec
5
+
6
+ group :test do
7
+ gem 'irb'
8
+ end
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Provides access to the POSIX terminal functions, e.g. `tcgetpgrp` and `tcsetpgrp`.
4
4
 
5
+ [![Actions Status](https://github.com/socketry/process-terminal/workflows/Tests/badge.svg)](https://github.com/socketry/process-terminal/actions?workflow=Tests)
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -20,6 +22,8 @@ Or install it yourself as:
20
22
 
21
23
  ## Usage
22
24
 
25
+ You can change the current foreground process for the current terminal:
26
+
23
27
  ```ruby
24
28
  device = Process::Terminal::Device.open
25
29
 
@@ -23,17 +23,23 @@ require_relative 'unistd'
23
23
  module Process
24
24
  module Terminal
25
25
  class Device
26
+ # Attempts to open the current TTY. Prefer `.new?` if possible.
27
+ # @returns [Device | nil] the terminal device if the file was readable.
26
28
  def self.open(path = "/dev/tty", mode = "r+")
27
- self.new(File.open(path, mode))
29
+ if File.readable?(path)
30
+ self.new(File.open(path, mode))
31
+ end
28
32
  end
29
33
 
30
- def initialize(io)
31
- @io = io
34
+ # Create a new device instance, but only if the supplied IO is a TTY.
35
+ def self.new?(io = STDIN)
36
+ if io.tty?
37
+ self.new(io)
38
+ end
32
39
  end
33
40
 
34
- def close
35
- @io.close
36
- @io = nil
41
+ def initialize(io = STDIN)
42
+ @io = io
37
43
  end
38
44
 
39
45
  # Make the specified pid the foreground processs in the current terminal.
@@ -41,14 +47,24 @@ module Process
41
47
  def foreground=(pid)
42
48
  current = Signal.trap(:SIGTTOU, :IGNORE)
43
49
 
44
- Unistd.tcsetpgrp(@io.fileno, pid)
50
+ result = Unistd.tcsetpgrp(@io.fileno, pid)
51
+
52
+ if result == -1
53
+ raise SystemCallError.new('tcsetpgrp', FFI.errno)
54
+ end
45
55
  ensure
46
56
  Signal.trap(:SIGTTOU, current) if current
47
57
  end
48
58
 
49
59
  # @return [Integer] the foreground process group.
50
60
  def foreground
51
- Unistd.tcgetpgrp(@io.fileno)
61
+ result = Unistd.tcgetpgrp(@io.fileno)
62
+
63
+ if result == -1
64
+ raise SystemCallError.new('tcgetpgrp', FFI.errno)
65
+ end
66
+
67
+ return result
52
68
  end
53
69
  end
54
70
  end
@@ -20,6 +20,6 @@
20
20
 
21
21
  module Process
22
22
  module Terminal
23
- VERSION = "0.1.0"
23
+ VERSION = "0.2.0"
24
24
  end
25
25
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_dependency "ffi"
24
24
 
25
25
  spec.add_development_dependency "covered"
26
- spec.add_development_dependency "bundler", "~> 2.0"
26
+ spec.add_development_dependency "bundler"
27
27
  spec.add_development_dependency "rake", "~> 10.0"
28
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process-terminal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-08 00:00:00.000000000 Z
11
+ date: 2019-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '2.0'
47
+ version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '2.0'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -117,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
117
  - !ruby/object:Gem::Version
118
118
  version: '0'
119
119
  requirements: []
120
- rubygems_version: 3.0.4
120
+ rubygems_version: 3.0.6
121
121
  signing_key:
122
122
  specification_version: 4
123
123
  summary: Provide access to libc terminal funtions.