mirror of
https://github.com/junegunn/fzf.git
synced 2025-11-14 22:33:47 -05:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3101120fd | ||
|
|
30f9651f99 | ||
|
|
4dcc0f10b8 | ||
|
|
3d39ab5ded | ||
|
|
c3a198d0c7 | ||
|
|
be5c17612a | ||
|
|
fe89ac8a89 | ||
|
|
4c3ae847b6 | ||
|
|
5c0dc79ffa | ||
|
|
0a83705d21 | ||
|
|
ea22292d2c | ||
|
|
1990f3c992 | ||
|
|
c0b432f7b4 | ||
|
|
ae3180f919 | ||
|
|
62acb9adc4 | ||
|
|
0b5fa56444 | ||
|
|
789f26b1a5 |
27
.travis.yml
27
.travis.yml
@@ -1,10 +1,23 @@
|
||||
language: ruby
|
||||
sudo: false
|
||||
rvm:
|
||||
- "1.8.7"
|
||||
- "1.9.3"
|
||||
- "2.0.0"
|
||||
- "2.1.1"
|
||||
|
||||
install: gem install curses minitest
|
||||
install:
|
||||
- sudo apt-get install -y libncurses-dev lib32ncurses5-dev
|
||||
- sudo add-apt-repository -y ppa:pi-rho/dev
|
||||
- sudo apt-get update
|
||||
- sudo apt-get install -y tmux=1.9a-1~ppa1~p
|
||||
|
||||
script: |
|
||||
export GOROOT=~/go1.4
|
||||
export GOPATH=~/go
|
||||
export FZF_BASE=~/go/src/github.com/junegunn/fzf
|
||||
|
||||
mkdir -p ~/go/src/github.com/junegunn
|
||||
ln -s $(pwd) $FZF_BASE
|
||||
|
||||
curl https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz | tar -xz
|
||||
mv go $GOROOT
|
||||
|
||||
cd $FZF_BASE/src && make test fzf/fzf-linux_amd64 install &&
|
||||
cd $FZF_BASE/bin && ln -sf fzf-linux_amd64 fzf-$(./fzf --version)-linux_amd64 &&
|
||||
cd $FZF_BASE && yes | ./install &&
|
||||
tmux new "rake test > out && touch ok" && cat out && [ -e ok ]
|
||||
|
||||
7
Rakefile
7
Rakefile
@@ -2,8 +2,11 @@ require "bundler/gem_tasks"
|
||||
require 'rake/testtask'
|
||||
|
||||
Rake::TestTask.new(:test) do |test|
|
||||
test.pattern = 'test/**/test_*.rb'
|
||||
test.verbose = true
|
||||
test.pattern = 'test/test_go.rb'
|
||||
end
|
||||
|
||||
Rake::TestTask.new(:testall) do |test|
|
||||
test.pattern = 'test/test_*.rb'
|
||||
end
|
||||
|
||||
task :default => :test
|
||||
|
||||
14
install
14
install
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
version=0.9.0
|
||||
version=0.9.1
|
||||
|
||||
cd $(dirname $BASH_SOURCE)
|
||||
fzf_base=$(pwd)
|
||||
@@ -16,6 +16,7 @@ check_binary() {
|
||||
local output=$("$fzf_base"/bin/fzf --version 2>&1)
|
||||
if [ "$version" = "$output" ]; then
|
||||
echo "$output"
|
||||
binary_error=""
|
||||
else
|
||||
echo "$output != $version"
|
||||
rm -f "$fzf_base"/bin/fzf
|
||||
@@ -27,18 +28,21 @@ check_binary() {
|
||||
symlink() {
|
||||
echo " - Creating symlink: bin/$1 -> bin/fzf"
|
||||
(cd "$fzf_base"/bin &&
|
||||
rm -f fzf
|
||||
rm -f fzf &&
|
||||
ln -sf $1 fzf)
|
||||
if [ $? -ne 0 ]; then
|
||||
binary_error="Failed to create symlink"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
download() {
|
||||
echo "Downloading bin/fzf ..."
|
||||
if [ -x "$fzf_base"/bin/fzf ]; then
|
||||
if [[ ! $1 =~ dev && -x "$fzf_base"/bin/fzf ]]; then
|
||||
echo " - Already exists"
|
||||
check_binary && return
|
||||
elif [ -x "$fzf_base"/bin/$1 ]; then
|
||||
symlink $1
|
||||
check_binary && return
|
||||
symlink $1 && check_binary && return
|
||||
fi
|
||||
mkdir -p "$fzf_base"/bin && cd "$fzf_base"/bin
|
||||
if [ $? -ne 0 ]; then
|
||||
|
||||
@@ -6,7 +6,7 @@ RUN pacman-db-upgrade && pacman -Syu --noconfirm base-devel git
|
||||
|
||||
# Install Go 1.4
|
||||
RUN cd / && curl \
|
||||
https://storage.googleapis.com/golang/go1.4.linux-amd64.tar.gz | \
|
||||
https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz | \
|
||||
tar -xz && mv go go1.4
|
||||
|
||||
ENV GOPATH /go
|
||||
|
||||
@@ -6,7 +6,7 @@ RUN yum install -y git gcc make tar ncurses-devel
|
||||
|
||||
# Install Go 1.4
|
||||
RUN cd / && curl \
|
||||
https://storage.googleapis.com/golang/go1.4.linux-amd64.tar.gz | \
|
||||
https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz | \
|
||||
tar -xz && mv go go1.4
|
||||
|
||||
ENV GOPATH /go
|
||||
|
||||
@@ -7,7 +7,7 @@ RUN apt-get update && apt-get -y upgrade && \
|
||||
|
||||
# Install Go 1.4
|
||||
RUN cd / && curl \
|
||||
https://storage.googleapis.com/golang/go1.4.linux-amd64.tar.gz | \
|
||||
https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz | \
|
||||
tar -xz && mv go go1.4
|
||||
|
||||
ENV GOPATH /go
|
||||
|
||||
25
src/Makefile
25
src/Makefile
@@ -21,31 +21,16 @@ BINARY64 := fzf-$(GOOS)_amd64
|
||||
VERSION = $(shell fzf/$(BINARY64) --version)
|
||||
RELEASE32 = fzf-$(VERSION)-$(GOOS)_386
|
||||
RELEASE64 = fzf-$(VERSION)-$(GOOS)_amd64
|
||||
BREW = fzf-$(VERSION)-homebrew.tgz
|
||||
|
||||
all: test release
|
||||
|
||||
brew: ../$(BREW)
|
||||
|
||||
../$(BREW): release
|
||||
ifneq ($(UNAME_S),Darwin)
|
||||
$(error brew package must be built on OS X)
|
||||
endif
|
||||
mkdir -p ../bin && \
|
||||
cp fzf/$(RELEASE64) fzf/$(RELEASE32) ../bin && \
|
||||
cd .. && ln -sf . fzf-$(VERSION) && \
|
||||
tar -cvzf $(BREW) \
|
||||
fzf-$(VERSION)/{{,un}install,fzf-completion.{ba,z}sh,LICENSE} \
|
||||
fzf-$(VERSION)/{plugin/fzf.vim,bin/{$(RELEASE64),$(RELEASE32)}} && \
|
||||
rm fzf-$(VERSION) && \
|
||||
openssl sha1 $(notdir $@)
|
||||
all: release
|
||||
|
||||
release: build
|
||||
cd fzf && \
|
||||
cp $(BINARY32) $(RELEASE32) && tar -czf $(RELEASE32).tgz $(RELEASE32) && \
|
||||
cp $(BINARY64) $(RELEASE64) && tar -czf $(RELEASE64).tgz $(RELEASE64)
|
||||
cp $(BINARY64) $(RELEASE64) && tar -czf $(RELEASE64).tgz $(RELEASE64) && \
|
||||
rm $(RELEASE32) $(RELEASE64)
|
||||
|
||||
build: fzf/$(BINARY32) fzf/$(BINARY64)
|
||||
build: test fzf/$(BINARY32) fzf/$(BINARY64)
|
||||
|
||||
test:
|
||||
go get
|
||||
@@ -86,4 +71,4 @@ $(DISTRO): docker
|
||||
docker run -i -t -v $(GOPATH):/go junegunn/$(DISTRO)-sandbox \
|
||||
sh -c 'cd /go/src/github.com/junegunn/fzf/src; /bin/bash'
|
||||
|
||||
.PHONY: all brew build release test install uninstall clean docker linux $(DISTRO)
|
||||
.PHONY: all build release test install uninstall clean docker linux $(DISTRO)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
fzf in Go
|
||||
=========
|
||||
|
||||
<img src="https://cloud.githubusercontent.com/assets/700826/5725028/028ea834-9b93-11e4-9198-43088c3f295d.gif" height="463" alt="fzf in go">
|
||||
|
||||
This directory contains the source code for the new fzf implementation in
|
||||
[Go][go].
|
||||
|
||||
@@ -81,9 +83,6 @@ make install
|
||||
|
||||
# Build executables and tarballs for Linux using Docker
|
||||
make linux
|
||||
|
||||
# Build tarball for Homebrew release
|
||||
make brew
|
||||
```
|
||||
|
||||
Contribution
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
// Current version
|
||||
const Version = "0.9.0"
|
||||
const Version = "0.9.1"
|
||||
|
||||
// fzf events
|
||||
const (
|
||||
|
||||
@@ -30,7 +30,7 @@ type Terminal struct {
|
||||
progress int
|
||||
reading bool
|
||||
merger *Merger
|
||||
selected map[*string]*string
|
||||
selected map[*string]selectedItem
|
||||
reqBox *util.EventBox
|
||||
eventBox *util.EventBox
|
||||
mutex sync.Mutex
|
||||
@@ -38,6 +38,25 @@ type Terminal struct {
|
||||
suppress bool
|
||||
}
|
||||
|
||||
type selectedItem struct {
|
||||
at time.Time
|
||||
text *string
|
||||
}
|
||||
|
||||
type ByTimeOrder []selectedItem
|
||||
|
||||
func (a ByTimeOrder) Len() int {
|
||||
return len(a)
|
||||
}
|
||||
|
||||
func (a ByTimeOrder) Swap(i, j int) {
|
||||
a[i], a[j] = a[j], a[i]
|
||||
}
|
||||
|
||||
func (a ByTimeOrder) Less(i, j int) bool {
|
||||
return a[i].at.Before(a[j].at)
|
||||
}
|
||||
|
||||
var _spinner = []string{`-`, `\`, `|`, `/`, `-`, `\`, `|`, `/`}
|
||||
|
||||
const (
|
||||
@@ -70,7 +89,7 @@ func NewTerminal(opts *Options, eventBox *util.EventBox) *Terminal {
|
||||
multi: opts.Multi,
|
||||
printQuery: opts.PrintQuery,
|
||||
merger: EmptyMerger,
|
||||
selected: make(map[*string]*string),
|
||||
selected: make(map[*string]selectedItem),
|
||||
reqBox: util.NewEventBox(),
|
||||
eventBox: eventBox,
|
||||
mutex: sync.Mutex{},
|
||||
@@ -134,16 +153,18 @@ func (t *Terminal) output() {
|
||||
fmt.Println(string(t.input))
|
||||
}
|
||||
if len(t.selected) == 0 {
|
||||
if t.merger.Length() > t.cy {
|
||||
cnt := t.merger.Length()
|
||||
if cnt > 0 && cnt > t.cy {
|
||||
fmt.Println(t.merger.Get(t.listIndex(t.cy)).AsString())
|
||||
}
|
||||
} else {
|
||||
for ptr, orig := range t.selected {
|
||||
if orig != nil {
|
||||
fmt.Println(*orig)
|
||||
} else {
|
||||
fmt.Println(*ptr)
|
||||
}
|
||||
sels := make([]selectedItem, 0, len(t.selected))
|
||||
for _, sel := range t.selected {
|
||||
sels = append(sels, sel)
|
||||
}
|
||||
sort.Sort(ByTimeOrder(sels))
|
||||
for _, sel := range sels {
|
||||
fmt.Println(*sel.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -443,7 +464,13 @@ func (t *Terminal) Loop() {
|
||||
if idx < t.merger.Length() {
|
||||
item := t.merger.Get(idx)
|
||||
if _, found := t.selected[item.text]; !found {
|
||||
t.selected[item.text] = item.origText
|
||||
var strptr *string
|
||||
if item.origText != nil {
|
||||
strptr = item.origText
|
||||
} else {
|
||||
strptr = item.text
|
||||
}
|
||||
t.selected[item.text] = selectedItem{time.Now(), strptr}
|
||||
} else {
|
||||
delete(t.selected, item.text)
|
||||
}
|
||||
@@ -514,7 +541,8 @@ func (t *Terminal) Loop() {
|
||||
t.rubout("[^[:alnum:]][[:alnum:]]")
|
||||
}
|
||||
case C.CtrlY:
|
||||
t.input = append(append(t.input[:t.cx], t.yanked...), t.input[t.cx:]...)
|
||||
suffix := copySlice(t.input[t.cx:])
|
||||
t.input = append(append(t.input[:t.cx], t.yanked...), suffix...)
|
||||
t.cx += len(t.yanked)
|
||||
case C.Del:
|
||||
t.delChar()
|
||||
|
||||
41
src/update_assets.rb
Executable file
41
src/update_assets.rb
Executable file
@@ -0,0 +1,41 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# http://www.rubydoc.info/github/rest-client/rest-client/RestClient
|
||||
require 'rest_client'
|
||||
|
||||
if ARGV.length < 3
|
||||
puts "usage: #$0 <token> <version> <files...>"
|
||||
end
|
||||
|
||||
token, version, *files = ARGV
|
||||
base = "https://api.github.com/repos/junegunn/fzf-bin/releases"
|
||||
|
||||
# List releases
|
||||
rels = JSON.parse(RestClient.get(base, :authorization => "token #{token}"))
|
||||
rel = rels.find { |r| r['tag_name'] == version }
|
||||
unless rel
|
||||
puts "#{version} not found"
|
||||
exit 1
|
||||
end
|
||||
|
||||
# List assets
|
||||
assets = Hash[rel['assets'].map { |a| a.values_at *%w[name id] }]
|
||||
|
||||
files.select { |f| File.exists? f }.each do |file|
|
||||
name = File.basename file
|
||||
|
||||
if asset_id = assets[name]
|
||||
puts "#{name} found. Deleting asset id #{asset_id}."
|
||||
RestClient.delete "#{base}/assets/#{asset_id}",
|
||||
:authorization => "token #{token}"
|
||||
else
|
||||
puts "#{name} not found"
|
||||
end
|
||||
|
||||
puts "Uploading #{name}"
|
||||
RestClient.post(
|
||||
"#{base.sub 'api', 'uploads'}/#{rel['id']}/assets?name=#{name}",
|
||||
File.read(file),
|
||||
:authorization => "token #{token}",
|
||||
:content_type => "application/octet-stream")
|
||||
end
|
||||
278
test/test_go.rb
Normal file
278
test/test_go.rb
Normal file
@@ -0,0 +1,278 @@
|
||||
#!/usr/bin/env ruby
|
||||
# encoding: utf-8
|
||||
|
||||
require 'minitest/autorun'
|
||||
|
||||
class NilClass
|
||||
def include? str
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
class Tmux
|
||||
TEMPNAME = '/tmp/fzf-test.txt'
|
||||
|
||||
attr_reader :win
|
||||
|
||||
def initialize shell = 'bash'
|
||||
@win = go("new-window -d -P -F '#I' 'PS1= bash --rcfile ~/.fzf.#{shell}'").first
|
||||
@lines = `tput lines`.chomp.to_i
|
||||
end
|
||||
|
||||
def closed?
|
||||
!go("list-window -F '#I'").include?(win)
|
||||
end
|
||||
|
||||
def close timeout = 1
|
||||
send_keys 'C-c', 'C-u', 'exit', :Enter
|
||||
wait(timeout) { closed? }
|
||||
end
|
||||
|
||||
def kill
|
||||
go("kill-window -t #{win} 2> /dev/null")
|
||||
end
|
||||
|
||||
def send_keys *args
|
||||
args = args.map { |a| %{"#{a}"} }.join ' '
|
||||
go("send-keys -t #{win} #{args}")
|
||||
end
|
||||
|
||||
def capture
|
||||
go("capture-pane -t #{win} \\; save-buffer #{TEMPNAME}")
|
||||
raise "Window not found" if $?.exitstatus != 0
|
||||
File.read(TEMPNAME).split($/)[0, @lines].reverse.drop_while(&:empty?).reverse
|
||||
end
|
||||
|
||||
def until timeout = 1
|
||||
wait(timeout) { yield capture }
|
||||
end
|
||||
|
||||
private
|
||||
def wait timeout = 1
|
||||
waited = 0
|
||||
until yield
|
||||
waited += 0.1
|
||||
sleep 0.1
|
||||
if waited > timeout
|
||||
hl = '=' * 10
|
||||
puts hl
|
||||
capture.each_with_index do |line, idx|
|
||||
puts [idx.to_s.rjust(2), line].join(': ')
|
||||
end
|
||||
puts hl
|
||||
raise "timeout"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def go *args
|
||||
%x[tmux #{args.join ' '}].split($/)
|
||||
end
|
||||
end
|
||||
|
||||
class TestGoFZF < MiniTest::Unit::TestCase
|
||||
attr_reader :tmux
|
||||
|
||||
def tempname
|
||||
'/tmp/output'
|
||||
end
|
||||
|
||||
def rmtemp
|
||||
while File.exists? tempname
|
||||
File.unlink tempname rescue nil
|
||||
end
|
||||
end
|
||||
|
||||
def readtemp
|
||||
waited = 0
|
||||
while waited < 5
|
||||
begin
|
||||
return File.read(tempname)
|
||||
rescue
|
||||
sleep 0.1
|
||||
waited += 0.1
|
||||
end
|
||||
end
|
||||
raise "failed to read tempfile"
|
||||
end
|
||||
|
||||
def setup
|
||||
ENV.delete 'FZF_DEFAULT_OPTS'
|
||||
ENV.delete 'FZF_DEFAULT_COMMAND'
|
||||
@tmux = Tmux.new
|
||||
rmtemp
|
||||
end
|
||||
|
||||
def teardown
|
||||
@tmux.kill
|
||||
end
|
||||
|
||||
def test_vanilla
|
||||
tmux.send_keys "seq 1 100000 | fzf > #{tempname}", :Enter
|
||||
tmux.until(10) { |lines| lines.last =~ /^>/ && lines[-2] =~ /^ 100000/ }
|
||||
lines = tmux.capture
|
||||
assert_equal ' 2', lines[-4]
|
||||
assert_equal '> 1', lines[-3]
|
||||
assert_equal ' 100000/100000', lines[-2]
|
||||
assert_equal '>', lines[-1]
|
||||
|
||||
# Testing basic key bindings
|
||||
tmux.send_keys '99', 'C-a', '1', 'C-f', '3', 'C-b', 'C-h', 'C-u', 'C-e', 'C-y', 'C-k', 'Tab', 'BTab'
|
||||
tmux.until { |lines| lines[-2] == ' 856/100000' }
|
||||
lines = tmux.capture
|
||||
assert_equal '> 1391', lines[-4]
|
||||
assert_equal ' 391', lines[-3]
|
||||
assert_equal ' 856/100000', lines[-2]
|
||||
assert_equal '> 391', lines[-1]
|
||||
|
||||
tmux.send_keys :Enter
|
||||
tmux.close
|
||||
assert_equal '1391', readtemp.chomp
|
||||
end
|
||||
|
||||
def test_fzf_default_command
|
||||
tmux.send_keys "FZF_DEFAULT_COMMAND='echo hello' fzf > #{tempname}", :Enter
|
||||
tmux.until { |lines| lines.last =~ /^>/ }
|
||||
|
||||
tmux.send_keys :Enter
|
||||
tmux.close
|
||||
assert_equal 'hello', readtemp.chomp
|
||||
end
|
||||
|
||||
def test_key_bindings
|
||||
tmux.send_keys "fzf -q 'foo bar foo-bar'", :Enter
|
||||
tmux.until { |lines| lines.last =~ /^>/ }
|
||||
|
||||
# CTRL-A
|
||||
tmux.send_keys "C-A", "("
|
||||
tmux.until { |lines| lines.last == '> (foo bar foo-bar' }
|
||||
|
||||
# META-F
|
||||
tmux.send_keys :Escape, :f, ")"
|
||||
tmux.until { |lines| lines.last == '> (foo) bar foo-bar' }
|
||||
|
||||
# CTRL-B
|
||||
tmux.send_keys "C-B", "var"
|
||||
tmux.until { |lines| lines.last == '> (foovar) bar foo-bar' }
|
||||
|
||||
# Left, CTRL-D
|
||||
tmux.send_keys :Left, :Left, "C-D"
|
||||
tmux.until { |lines| lines.last == '> (foovr) bar foo-bar' }
|
||||
|
||||
# META-BS
|
||||
tmux.send_keys :Escape, :BSpace
|
||||
tmux.until { |lines| lines.last == '> (r) bar foo-bar' }
|
||||
|
||||
# CTRL-Y
|
||||
tmux.send_keys "C-Y", "C-Y"
|
||||
tmux.until { |lines| lines.last == '> (foovfoovr) bar foo-bar' }
|
||||
|
||||
# META-B
|
||||
tmux.send_keys :Escape, :b, :Space, :Space
|
||||
tmux.until { |lines| lines.last == '> ( foovfoovr) bar foo-bar' }
|
||||
|
||||
# CTRL-F / Right
|
||||
tmux.send_keys 'C-F', :Right, '/'
|
||||
tmux.until { |lines| lines.last == '> ( fo/ovfoovr) bar foo-bar' }
|
||||
|
||||
# CTRL-H / BS
|
||||
tmux.send_keys 'C-H', :BSpace
|
||||
tmux.until { |lines| lines.last == '> ( fovfoovr) bar foo-bar' }
|
||||
|
||||
# CTRL-E
|
||||
tmux.send_keys "C-E", 'baz'
|
||||
tmux.until { |lines| lines.last == '> ( fovfoovr) bar foo-barbaz' }
|
||||
|
||||
# CTRL-U
|
||||
tmux.send_keys "C-U"
|
||||
tmux.until { |lines| lines.last == '>' }
|
||||
|
||||
# CTRL-Y
|
||||
tmux.send_keys "C-Y"
|
||||
tmux.until { |lines| lines.last == '> ( fovfoovr) bar foo-barbaz' }
|
||||
|
||||
# CTRL-W
|
||||
tmux.send_keys "C-W", "bar-foo"
|
||||
tmux.until { |lines| lines.last == '> ( fovfoovr) bar bar-foo' }
|
||||
|
||||
# META-D
|
||||
tmux.send_keys :Escape, :b, :Escape, :b, :Escape, :d, "C-A", "C-Y"
|
||||
tmux.until { |lines| lines.last == '> bar( fovfoovr) bar -foo' }
|
||||
|
||||
# CTRL-M
|
||||
tmux.send_keys "C-M"
|
||||
tmux.until { |lines| lines.last !~ /^>/ }
|
||||
tmux.close
|
||||
end
|
||||
|
||||
def test_multi_order
|
||||
tmux.send_keys "seq 1 10 | fzf --multi > #{tempname} && echo -n done", :Enter
|
||||
tmux.until { |lines| lines.last =~ /^>/ }
|
||||
|
||||
tmux.send_keys :Tab, :Up, :Up, :Tab, :Tab, :Tab, # 3, 2
|
||||
'C-K', 'C-K', 'C-K', 'C-K', :BTab, :BTab, # 5, 6
|
||||
:PgUp, 'C-J', :Down, :Tab, :Tab # 8, 7
|
||||
tmux.until { |lines| lines[-2].include? '(6)' }
|
||||
tmux.send_keys "C-M"
|
||||
tmux.until { |lines| lines[-1].include?('done') }
|
||||
assert_equal %w[3 2 5 6 8 7], readtemp.split($/)
|
||||
tmux.close
|
||||
end
|
||||
|
||||
def test_with_nth
|
||||
[true, false].each do |multi|
|
||||
rmtemp
|
||||
|
||||
tmux.send_keys "(echo ' 1st 2nd 3rd/';
|
||||
echo ' first second third/') |
|
||||
fzf #{"--multi" if multi} -x --nth 2 --with-nth 2,-1,1 > #{tempname} && echo -n done",
|
||||
:Enter
|
||||
tmux.until { |lines| lines[-2].include?('2/2') }
|
||||
|
||||
# Transformed list
|
||||
lines = tmux.capture
|
||||
assert_equal ' second third/first', lines[-4]
|
||||
assert_equal '> 2nd 3rd/1st', lines[-3]
|
||||
|
||||
# However, the output must not be transformed
|
||||
if multi
|
||||
tmux.send_keys :BTab, :BTab, :Enter
|
||||
tmux.until { |lines| lines[-1].include?('done') }
|
||||
assert_equal [' 1st 2nd 3rd/', ' first second third/'], readtemp.split($/)
|
||||
else
|
||||
tmux.send_keys '^', '3'
|
||||
tmux.until { |lines| lines[-2].include?('1/2') }
|
||||
tmux.send_keys :Enter
|
||||
tmux.until { |lines| lines[-1].include?('done') }
|
||||
assert_equal [' 1st 2nd 3rd/'], readtemp.split($/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_scroll
|
||||
[true, false].each do |rev|
|
||||
rmtemp
|
||||
|
||||
tmux.send_keys "seq 1 100 | fzf #{'--reverse' if rev} > #{tempname} && echo -n done", :Enter
|
||||
tmux.until { |lines| rev ? lines.first == '>' : lines.last == '>' }
|
||||
tmux.send_keys *110.times.map { rev ? :Down : :Up }
|
||||
tmux.until { |lines| lines.include? '> 100' }
|
||||
tmux.send_keys :Enter
|
||||
tmux.until { |lines| lines[-1].include?('done') }
|
||||
assert_equal '100', readtemp.chomp
|
||||
end
|
||||
end
|
||||
|
||||
def test_select_1
|
||||
tmux.send_keys "seq 1 100 | fzf --with-nth ..,.. --print-query -q 5555 -1 > #{tempname} && echo -n done", :Enter
|
||||
tmux.until { |lines| lines[-1].include?('done') }
|
||||
assert_equal ['5555', '55'], readtemp.split($/)
|
||||
end
|
||||
|
||||
def test_exit_0
|
||||
tmux.send_keys "seq 1 100 | fzf --with-nth ..,.. --print-query -q 555555 -0 > #{tempname} && echo -n done", :Enter
|
||||
tmux.until { |lines| lines[-1].include?('done') }
|
||||
assert_equal ['555555'], readtemp.split($/)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -54,7 +54,7 @@ class MockTTY
|
||||
end
|
||||
end
|
||||
|
||||
class TestFZF < MiniTest::Unit::TestCase
|
||||
class TestRubyFZF < MiniTest::Unit::TestCase
|
||||
def setup
|
||||
ENV.delete 'FZF_DEFAULT_SORT'
|
||||
ENV.delete 'FZF_DEFAULT_OPTS'
|
||||
Reference in New Issue
Block a user