markw-dmenu 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/dmenu.gemspec +3 -2
  3. data/lib/dmenu.rb +21 -8
  4. data/lib/test.rb +17 -0
  5. metadata +6 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ef6ca078ebbfd95bfa5054155cd8edbde1967bb
4
- data.tar.gz: 2e192a476b78fbab2fdafc98d5150aa6697e7b33
3
+ metadata.gz: c4970b9671c550168bff003f3d5abcc252d83768
4
+ data.tar.gz: 7611b44957a330b91861133914ff9d26e1756693
5
5
  SHA512:
6
- metadata.gz: f38873e2aae318b9b34fbcc76f01208fdb025c32b10e733750fcdfdd1c798aaf8deb5c45c745b892ea44cd93cdad9638eae7000a2f8db78fa1aba22c1e921c7e
7
- data.tar.gz: a226744e2cb98c5d8761e1fdae951a54853a8bba5e1f76b65ab900b8233ccdc41654b5ef5869544c114d67cc0e1402ff82f21ab9f763fbcdf88464bfcb1b7419
6
+ metadata.gz: 300bead8873d4137a9958bb88575e65809cbae196a2db1a8342666b6f8626c74b0a37deda27ec463ef3a362ceb530e1b9d7ba127f286e886d5f26bbc16d5a889
7
+ data.tar.gz: b27278737605cc1d50a98dcbf4511347a0586e74ea8cbf1edfe547e2e9297a47c37e7beba80afc86da1877d4f0204171312b769a24f711c1cc1b73720d08466d
data/dmenu.gemspec CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = "markw-dmenu"
5
- spec.version = "1.0.0"
5
+ spec.version = "1.1.0"
6
6
  spec.authors = ["Mark Watts"]
7
7
  spec.email = ["wattsmark2015@gmail.com"]
8
8
  spec.summary = %q{A set of utilites for working with the dmenu command line tool.}
9
9
  spec.homepage = "http://github.com/mwatts15/dmenu"
10
10
  spec.license = "MPL-2.0"
11
+ spec.description = """Primarily for use by other things made by markw. Use at your own risk"""
11
12
  spec.files = `git ls-files -z`.split("\x0")
12
13
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
14
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
@@ -15,5 +16,5 @@ Gem::Specification.new do |spec|
15
16
 
16
17
  spec.add_development_dependency "bundler", "~> 1.7"
17
18
  spec.add_development_dependency "rake", "~> 10.0"
18
- spec.add_runtime_dependency "markw-wcwidth", "~> 0.0.3"
19
+ spec.add_runtime_dependency "markw-wcwidth", "0.0.3"
19
20
  end
data/lib/dmenu.rb CHANGED
@@ -6,6 +6,7 @@ class String
6
6
  force_encoding("utf-8")
7
7
  end
8
8
  end
9
+
9
10
  module Dmenu
10
11
  require 'wcwidth'
11
12
  # Characters that, in the keyed fonts, are actually double width,
@@ -37,16 +38,28 @@ module Dmenu
37
38
  res = ""
38
39
  lr_separation = 4
39
40
  textwidth = 2 * width / font_width - lr_separation
40
- expr = %r{[^#{repl_chars}]+}
41
+ if !repl_chars.nil?
42
+ expr = %r{[^#{repl_chars}]+}
43
+ end
41
44
  entries.collect! do |line|
42
- line = line.each_char.reject{|char| char.ord < 32 or (char.ord >= 0x7f and char.ord < 0xa0)}.inject(:+)
43
- l, r = line.split("|||")
44
- loff = l.gsub(expr, "").length
45
- roff = r.nil? ? 0 : r.gsub(expr, "").length
46
- scrunched = scrunch(r, [textwidth - l.width - lr_separation, textwidth / 2].max)
47
- s = r ? alignr(l, scrunched, textwidth - loff - roff) : l
45
+ transformed_line = line.each_char.reject{|char| char.ord < 32 or (char.ord >= 0x7f and char.ord < 0xa0)}.inject(:+)
46
+ s = if !transformed_line.nil?
47
+ l, r = transformed_line.split("|||")
48
+ loff = 0
49
+ roff = 0
50
+ if !repl_chars.nil?
51
+ loff = l.gsub(expr, "").length
52
+ roff = r.nil? ? 0 : r.gsub(expr, "").length
53
+ end
54
+ scrunched = scrunch(r, [textwidth - l.width - lr_separation, textwidth / 2].max)
55
+ r ? alignr(l, scrunched, textwidth - loff - roff) : l
56
+ else
57
+ $stderr.puts "Couldn't list #{line.inspect}"
58
+ nil
59
+ end
48
60
  s
49
- end
61
+ end.reject! {|x| x.nil? or x.empty? or x.match(/\s+/) }
62
+
50
63
  cmdline = "dmenu -f -p \"#{prompt}\" -nf \"#{fg_color}\" \
51
64
  -nb \"#{bg_color}\" \
52
65
  -sb \"#{sel_bg_color}\" \
data/lib/test.rb ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'dmenu'
4
+ require 'test/unit'
5
+
6
+ class DmenuTest < Test::Unit::TestCase
7
+ include Dmenu
8
+ def test_1
9
+ assert_equal(10, Dmenu::scrunch("012345678901234567890", 10).width)
10
+ end
11
+ def test_2
12
+ assert(Dmenu::scrunch("患部で止まってすぐ溶ける ~ 狂気の優曇華院 (03:04)", 10).width <= 10)
13
+ end
14
+ def test_3
15
+ assert_not_nil(Dmenu::dmenu(%w<a b c>))
16
+ end
17
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markw-dmenu
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mark Watts
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-21 00:00:00.000000000 Z
11
+ date: 2017-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,17 +42,17 @@ dependencies:
42
42
  name: markw-wcwidth
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - '='
46
46
  - !ruby/object:Gem::Version
47
47
  version: 0.0.3
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - '='
53
53
  - !ruby/object:Gem::Version
54
54
  version: 0.0.3
55
- description:
55
+ description: Primarily for use by other things made by markw. Use at your own risk
56
56
  email:
57
57
  - wattsmark2015@gmail.com
58
58
  executables: []
@@ -62,6 +62,7 @@ files:
62
62
  - Gemfile
63
63
  - dmenu.gemspec
64
64
  - lib/dmenu.rb
65
+ - lib/test.rb
65
66
  homepage: http://github.com/mwatts15/dmenu
66
67
  licenses:
67
68
  - MPL-2.0