From 85aea692359c82ce845464f64a00a2c2ccaab233 Mon Sep 17 00:00:00 2001 From: Jeff Mandell Date: Tue, 28 Mar 2017 18:01:50 -0400 Subject: [PATCH] Press b to go back in preview history II --- README.md | 3 ++- tools/preview.rb | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e0efaf5..679f51c 100644 --- a/README.md +++ b/README.md @@ -1042,7 +1042,8 @@ the linked page, it doesn't run on tmux or screen. tools/preview.rb schemes/AdventureTime.itermcolors # Apply the schemes in turn. -# - Press any key to advance; hit CTRL-C or ESC to stop +# - Press (almost) any key to advance; hit CTRL-C or ESC to stop +# - Press the delete key to go back tools/preview.rb schemes/* ``` diff --git a/tools/preview.rb b/tools/preview.rb index 963b4be..387dc08 100755 --- a/tools/preview.rb +++ b/tools/preview.rb @@ -21,6 +21,7 @@ if ENV.has_key? 'TMUX' end preview = files.length > 1 +history = [] until files.empty? file = files.shift print "[#{File.basename file, '.*'}] " if preview @@ -59,7 +60,14 @@ until files.empty? 'cursor text' => 'm', }.fetch(type, '%x' % type.to_i) << rgb << "\e\\" end - break if files.empty? || [3.chr, "\e"].include?(IO.console.getch) + case IO.console.getch.ord + when 127 # backspace + files.unshift *[history.pop, file].compact + when 3, 27 # ctrl-c, esc + break + else + history << file + end rescue Exception print '(X) ' end