-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
require_relative "rspec_tmux_tui" | ||
|
||
describe "Menu Item" do | ||
bug = "1177760" | ||
around(:each) do |ex| | ||
@base = "menu_hotkeys_#{bug}" | ||
|
||
yast_ncurses = "#{__dir__}/yast_ncurses" | ||
example_dir = "/usr/share/doc/packages/yast2-ycp-ui-bindings/examples" | ||
@tui = TmuxTui.new_session "#{yast_ncurses} #{example_dir}/MenuBar1.rb" | ||
|
||
ex.run | ||
|
||
if @tui.has_session? | ||
@tui.kill_session | ||
end | ||
end | ||
|
||
it "has hotkeys in menu items, boo##{bug}" do | ||
@tui.await(/File.*Edit.*View/) | ||
@tui.capture_pane_to("#{@base}-1-initial") | ||
|
||
@tui.send_keys "M-V" # &View | ||
@tui.capture_pane_to("#{@base}-2-view-menu-activated") | ||
|
||
@tui.send_keys "M-N" # &Normal | ||
@tui.capture_pane_to("#{@base}-3-normal-menu-item-activated") | ||
|
||
# the label | ||
expect(@tui.capture_pane).to include("Last Event") | ||
# the output | ||
expect(@tui.capture_pane).to include("view_normal") | ||
|
||
@tui.send_keys "M-Q" # &Quit | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
require "shellwords" | ||
|
||
class TmuxTui | ||
class Error < RuntimeError | ||
end | ||
|
||
def self.new_session(*args) | ||
new(*args) | ||
end | ||
|
||
attr_reader :session_name | ||
|
||
def initialize(shell_command, x: 80, y: 24, detach: true, session_name: nil) | ||
@shell_command = shell_command | ||
@x = x | ||
@y = y | ||
@detach = detach | ||
@session_name = session_name || new_session_name | ||
|
||
system "tmux", "new-session", | ||
"-s", @session_name, | ||
"-x", @x.to_s, | ||
"-y", @y.to_s, | ||
*(@detach ? ["-d"] : [] ), | ||
"sh", "-c", "#{@shell_command}; sleep 9999" | ||
end | ||
|
||
def new_session_name | ||
"tmux-tui-#{rand 10000}" | ||
end | ||
|
||
# @return [String] | ||
def capture_pane(color: false) | ||
esc = color ? "-e" : "" | ||
# FIXME: failure of the command? | ||
`tmux capture-pane -t #{session_name.shellescape} -p #{esc}` | ||
end | ||
|
||
def capture_pane_to(filename) | ||
txt = capture_pane(color: false) | ||
esc = capture_pane(color: true) | ||
File.write("#{filename}.txt", txt) | ||
File.write("#{filename}.esc", esc) | ||
end | ||
|
||
def await(pattern) | ||
sleeps = [0.1, 0.2, 0.2, 0.5, 1, 2, 2, 5] | ||
txt = "" | ||
sleeps.each do |sl| | ||
txt = capture_pane | ||
case txt | ||
when pattern | ||
sleep 0.1 # draw the rest of the screen | ||
return | ||
else | ||
sleep sl | ||
end | ||
end | ||
raise Error, "Timed out waiting for #{pattern.inspect}. Seen:\n#{txt}" | ||
end | ||
|
||
# @param keys [String] "C-X" for Ctrl-X, "M-X" for Alt-X, think "Meta"; | ||
# for details see: | ||
# man tmux | less +/"^KEY BINDINGS" | ||
def send_keys(keys) | ||
system "tmux", "send-keys", "-t", session_name, keys | ||
end | ||
|
||
def has_session? | ||
system "tmux", "has-session", "-t", session_name | ||
end | ||
|
||
def kill_session | ||
system "tmux", "kill-session", "-t", session_name | ||
end | ||
end |