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 +4 -4
- data/.github/workflows/tests.yml +21 -6
- data/Gemfile +4 -0
- data/README.md +4 -0
- data/lib/process/terminal/device.rb +24 -8
- data/lib/process/terminal/version.rb +1 -1
- data/process-terminal.gemspec +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76eeb0c369d4ae4c5654639581523d17abb56b381ccc1ee9bf2f73fcf626efa2
|
4
|
+
data.tar.gz: 1a06952b321e9b0dd30f293667e1ed5a597d40f27c0d8d1faa4c6ab91a757521
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cafafc50d5ba75c1fd1eacb391d1e67e8aa8a6ad553824c756c8a2e2fd5c8ebd0189719d98a4b8c0d9ce1bd3d0b52a855a496f5ebd01535271fa2a57097e2228
|
7
|
+
data.tar.gz: 88f4e17b0f8e83453598db2176c1b4fb8b3b1aad7098611ae7e7e282587f65dfbca202312a654041c842fb1c7a4fc18952c5738ced6f70b208a4ec34c5fb936f
|
data/.github/workflows/tests.yml
CHANGED
@@ -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
|
-
|
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
|
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
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
|
-
|
29
|
+
if File.readable?(path)
|
30
|
+
self.new(File.open(path, mode))
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
|
-
|
31
|
-
|
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
|
35
|
-
@io
|
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
|
data/process-terminal.gemspec
CHANGED
@@ -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"
|
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.
|
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-
|
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: '
|
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: '
|
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.
|
120
|
+
rubygems_version: 3.0.6
|
121
121
|
signing_key:
|
122
122
|
specification_version: 4
|
123
123
|
summary: Provide access to libc terminal funtions.
|