readline-ng 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/.rvmrc +71 -0
  2. data/README +4 -0
  3. data/lib/readline-ng.rb +99 -0
  4. data/readline-ng.gemspec +17 -0
  5. metadata +49 -0
data/.rvmrc ADDED
@@ -0,0 +1,71 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.3-p0"
8
+
9
+ #
10
+ # Uncomment following line if you want options to be set only for given project.
11
+ #
12
+ # PROJECT_JRUBY_OPTS=( --1.9 )
13
+ #
14
+ # The variable PROJECT_JRUBY_OPTS requires the following to be run in shell:
15
+ #
16
+ # chmod +x ${rvm_path}/hooks/after_use_jruby_opts
17
+ #
18
+
19
+ #
20
+ # First we attempt to load the desired environment directly from the environment
21
+ # file. This is very fast and efficient compared to running through the entire
22
+ # CLI and selector. If you want feedback on which environment was used then
23
+ # insert the word 'use' after --create as this triggers verbose mode.
24
+ #
25
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
26
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
27
+ then
28
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
29
+
30
+ if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
31
+ then
32
+ . "${rvm_path:-$HOME/.rvm}/hooks/after_use"
33
+ fi
34
+ else
35
+ # If the environment file has not yet been created, use the RVM CLI to select.
36
+ if ! rvm --create use "$environment_id"
37
+ then
38
+ echo "Failed to create RVM environment '${environment_id}'."
39
+ return 1
40
+ fi
41
+ fi
42
+
43
+ #
44
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
45
+ # it be automatically loaded. Uncomment the following and adjust the filename if
46
+ # necessary.
47
+ #
48
+ # filename=".gems"
49
+ # if [[ -s "$filename" ]]
50
+ # then
51
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
52
+ # fi
53
+
54
+ # If you use bundler, this might be useful to you:
55
+ # if [[ -s Gemfile ]] && ! command -v bundle >/dev/null
56
+ # then
57
+ # printf "The rubygem 'bundler' is not installed. Installing it now.\n"
58
+ # gem install bundler
59
+ # fi
60
+ # if [[ -s Gemfile ]] && command -v bundle
61
+ # then
62
+ # bundle install
63
+ # fi
64
+
65
+ if [[ $- == *i* ]] # check for interactive shells
66
+ then
67
+ echo "Using: $(tput setaf 2)$GEM_HOME$(tput sgr0)" # show the user the ruby and gemset they are using in green
68
+ else
69
+ echo "Using: $GEM_HOME" # don't use colors in interactive shells
70
+ fi
71
+
data/README ADDED
@@ -0,0 +1,4 @@
1
+ Readline-NG is /not/ a drop in replacement for readline.
2
+
3
+ It addresses a very specific need I had inside a twitter client, but
4
+ hopefully it's of use to someone else, too.
@@ -0,0 +1,99 @@
1
+ module ReadlineNG
2
+
3
+ VERSION_MAJOR = 0
4
+ VERSION_MINOR = 0
5
+ VERSION_PATCH = 1
6
+ VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_PATCH}"
7
+
8
+ CONTROL_BS = "\x08"
9
+ CONTROL_INT = "\x03"
10
+ CONTROL_LF = "\x0a"
11
+ CONTROL_CR = "\x0d"
12
+
13
+ KB_BS = "\x7F"
14
+
15
+ BLANK = " "
16
+
17
+ class Reader
18
+
19
+ # TODO Arrange for the terminal to be in raw mode etc.
20
+ # XXX This probably needs to be a singleton, having more than one doesn't
21
+ # make a whole lot of sense, although potentially giving out rope is not a
22
+ # terrible idea here
23
+
24
+ attr_accessor :lines, :visible
25
+
26
+ def filter
27
+ end
28
+
29
+ def initialize
30
+ @buf = ""
31
+ @visible = true
32
+ @lines = []
33
+ end
34
+
35
+ def puts_above(string)
36
+ if visible
37
+ @buf.length.times do
38
+ # Backspace to beginning of line
39
+ _print CONTROL_BS
40
+ end
41
+ _print string
42
+ _puts CONTROL_CR
43
+ _print @buf
44
+ end
45
+ end
46
+
47
+ def tick
48
+ t = STDIN.read_nonblock(128)
49
+ process(t)
50
+ filter # Expect a 3rd party dev to override this
51
+
52
+ raise Interrupt if @buf.include?(CONTROL_INT)
53
+
54
+ a = @buf.split("\r")
55
+ return if a.empty? && @buf.empty?
56
+ @buf = @buf[-1] == "\r" ? "" : a.pop
57
+
58
+ @lines += a
59
+ rescue Errno::EAGAIN
60
+ nil
61
+ end
62
+
63
+ def line
64
+ @lines.shift
65
+ end
66
+
67
+ def each_line
68
+ yield @lines.shift while @lines.any?
69
+ end
70
+
71
+ private
72
+
73
+ def process(c)
74
+ case c
75
+ when KB_BS
76
+ @buf.chop!
77
+ backspace
78
+ else
79
+ @buf += c
80
+ _print c
81
+ end
82
+ end
83
+
84
+ def backspace
85
+ print CONTROL_BS,BLANK,CONTROL_BS
86
+ end
87
+
88
+ def _print(c)
89
+ print c if visible
90
+ end
91
+
92
+ def _puts(c)
93
+ puts c if visible
94
+ end
95
+
96
+
97
+ end
98
+ end
99
+
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "readline-ng"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "readline-ng"
7
+ s.version = ReadlineNG::VERSION
8
+ s.authors = ["Rich Healey"]
9
+ s.email = ["richo@psych0tik.net"]
10
+ s.homepage = "http://github.com/richoH/readline-ng"
11
+ s.summary = "Essentially, readline++"
12
+ s.description = s.summary
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
+ s.require_paths = ["lib"]
17
+ end
metadata ADDED
@@ -0,0 +1,49 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: readline-ng
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rich Healey
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-11 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Essentially, readline++
15
+ email:
16
+ - richo@psych0tik.net
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .rvmrc
22
+ - README
23
+ - lib/readline-ng.rb
24
+ - readline-ng.gemspec
25
+ homepage: http://github.com/richoH/readline-ng
26
+ licenses: []
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ! '>='
35
+ - !ruby/object:Gem::Version
36
+ version: '0'
37
+ required_rubygems_version: !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ! '>='
41
+ - !ruby/object:Gem::Version
42
+ version: '0'
43
+ requirements: []
44
+ rubyforge_project:
45
+ rubygems_version: 1.8.10
46
+ signing_key:
47
+ specification_version: 3
48
+ summary: Essentially, readline++
49
+ test_files: []