Add history cycling widgets

This commit is contained in:
Marcelo Lima 2018-11-04 19:38:51 +01:00
commit 09b6c1659f
8 changed files with 244 additions and 40 deletions

48
spec/widgets/next_spec.rb Normal file
View file

@ -0,0 +1,48 @@
describe 'the `autosuggest-next` widget' do
context 'when suggestions are disabled' do
before do
session.
run_command('bindkey ^B autosuggest-disable').
run_command('bindkey ^K autosuggest-next').
send_keys('C-b')
end
it 'will fetch and display a suggestion' do
with_history('echo hello', 'echo world', 'echo joe') do
session.send_string('echo h')
sleep 1
expect(session.content).to eq('echo h')
session.send_keys('C-k')
wait_for { session.content }.to eq('echo hello')
session.send_string('e')
wait_for { session.content }.to eq('echo hello')
end
end
end
context 'invoked on a populated history' do
before do
session.
run_command('bindkey ^K autosuggest-next')
end
it 'will cycle, fetch, and display a suggestion' do
with_history('echo hello', 'echo world', 'echo joe') do
session.send_string('echo')
sleep 1
expect(session.content).to eq('echo joe')
session.send_keys('C-k')
wait_for { session.content }.to eq('echo world')
session.send_keys('C-k')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-k')
wait_for { session.content }.to eq('echo hello')
end
end
end
end

View file

@ -0,0 +1,58 @@
describe 'the `autosuggest-previous` widget' do
context 'when suggestions are disabled' do
before do
session.
run_command('bindkey ^B autosuggest-disable').
run_command('bindkey ^J autosuggest-previous').
send_keys('C-b')
end
it 'will fetch and display a suggestion' do
with_history('echo hello', 'echo world', 'echo joe') do
session.send_string('echo h')
sleep 1
expect(session.content).to eq('echo h')
session.send_keys('C-j')
wait_for { session.content }.to eq('echo hello')
session.send_string('e')
wait_for { session.content }.to eq('echo hello')
end
end
end
context 'invoked on a populated history' do
before do
session.
run_command('bindkey ^K autosuggest-next').
run_command('bindkey ^J autosuggest-previous')
end
it 'will cycle, fetch, and display a suggestion' do
with_history('echo hello', 'echo world', 'echo joe') do
session.send_string('echo')
sleep 1
expect(session.content).to eq('echo joe')
session.send_keys('C-k')
wait_for { session.content }.to eq('echo world')
session.send_keys('C-k')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-k')
wait_for { session.content }.to eq('echo hello')
session.send_keys('C-j')
wait_for { session.content }.to eq('echo world')
session.send_keys('C-j')
wait_for { session.content }.to eq('echo joe')
session.send_keys('C-j')
wait_for { session.content }.to eq('echo joe')
end
end
end
end