Skip to content

Commit d78642d

Browse files
tobiclaude
andcommitted
fix: cursor positioning in centered dialogs, version 1.7.1
- Fix cursor offset in rename/delete dialogs by using (width - 1) - Mark red background wins over selection in delete mode - Add echo for rename cd path - Hook all tests to rake test (unit + spec) - Update tests for new highlight color and dialog design Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent a8d25b7 commit d78642d

File tree

9 files changed

+82
-18
lines changed

9 files changed

+82
-18
lines changed

.claude/settings.local.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(git add:*)",
5+
"Bash(git commit:*)",
6+
"Bash(gh issue list:*)"
7+
],
8+
"deny": [],
9+
"ask": []
10+
}
11+
}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.callgrind*

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ source "https://rubygems.org"
44

55
# gem "rails"
66

7+
gem "rake", group: :development
78
gem "ruby-prof", "~> 1.7", group: :development
89
gem "minitest", "~> 5.0", group: :development

Gemfile.lock

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
base64 (0.3.0)
5+
minitest (5.27.0)
6+
rake (13.3.1)
7+
ruby-prof (1.7.2)
8+
base64
9+
10+
PLATFORMS
11+
arm64-darwin-23
12+
ruby
13+
14+
DEPENDENCIES
15+
minitest (~> 5.0)
16+
rake
17+
ruby-prof (~> 1.7)
18+
19+
BUNDLED WITH
20+
2.6.2

Rakefile

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
desc "Run spec compliance tests"
2-
task :test do
1+
require 'rake/testtask'
2+
3+
Rake::TestTask.new(:unit) do |t|
4+
t.libs << 'lib' << 'test'
5+
t.pattern = 'test/**/*_test.rb'
6+
end
7+
8+
desc "Run shell spec compliance tests"
9+
task :spec do
310
sh "bash spec/tests/runner.sh ./try.rb"
411
end
512

13+
desc "Run all tests (unit + spec)"
14+
task test: [:unit, :spec]
15+
616
task default: :test

lib/tui.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,14 @@ def flush
415415
# Use \r to position at column 0, clear line, fill with spaces for reliability
416416
gap = body_space - body_rendered
417417
blank_line = "\r#{ANSI::CLEAR_EOL}#{' ' * (@width - 1)}\n"
418-
gap.times do
419-
@io.write(blank_line)
418+
blank_line_no_newline = "\r#{ANSI::CLEAR_EOL}#{' ' * (@width - 1)}"
419+
gap.times do |i|
420+
# Last gap line without newline if no footer follows
421+
if i == gap - 1 && @footer.lines.empty?
422+
@io.write(blank_line_no_newline)
423+
else
424+
@io.write(blank_line)
425+
end
420426
current_row += 1
421427
end
422428

spec/tests/test_31_rename.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ fi
2727

2828
# Test: Rename dialog shows pencil emoji
2929
output=$(try_run --path="$REN_TEST_DIR" --and-keys='CTRL-R,ESC' exec 2>&1)
30-
if echo "$output" | grep -q "📝"; then
30+
if echo "$output" | grep -qE "📝|✏️"; then
3131
pass
3232
else
33-
fail "Rename dialog should show pencil emoji" "📝" "$output" "rename"
33+
fail "Rename dialog should show pencil emoji" "📝 or ✏️" "$output" "rename"
3434
fi
3535

3636
# Test: Rename dialog pre-fills date prefix for dated entry
@@ -131,12 +131,12 @@ else
131131
fail "Rename dialog should have separator lines" "─ character" "$output" "rename"
132132
fi
133133

134-
# Test: Rename shows current name in dialog
134+
# Test: Rename shows current name in dialog (with folder emoji)
135135
output=$(try_run --path="$REN_TEST_DIR" --and-keys='CTRL-R,ESC' exec 2>&1)
136-
if echo "$output" | grep -q "Current:"; then
136+
if echo "$output" | grep -qE "Current:|📁.*nodate-project"; then
137137
pass
138138
else
139-
fail "Rename dialog should show Current: label" "Current:" "$output" "rename"
139+
fail "Rename dialog should show current name" "Current: or 📁 with name" "$output" "rename"
140140
fi
141141

142142
# Test: Rename shows new name field

test/tui_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def test_dim_wraps_with_palette
3737
def test_accent_and_highlight_helpers
3838
enable_colors!
3939
assert_includes Tui::Text.accent("wow"), Tui::Palette::ACCENT
40-
assert_includes Tui::Text.highlight("hit"), Tui::Palette::MATCH
40+
assert_includes Tui::Text.highlight("hit"), Tui::Palette::HIGHLIGHT
4141
end
4242
end
4343

@@ -101,7 +101,7 @@ def test_write_bold_and_highlight
101101
writer.write_highlight("H")
102102
output = writer.to_s
103103
assert_includes output, Tui::ANSI::BOLD
104-
assert_includes output, Tui::Palette::MATCH
104+
assert_includes output, Tui::Palette::HIGHLIGHT
105105
end
106106

107107
def test_fill_fills_remaining_width

try.rb

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,11 @@ def render(tries)
363363

364364
def render_entry_line(screen, entry, is_selected, width)
365365
is_marked = @marked_for_deletion.include?(entry[:path])
366-
background = if is_selected
367-
Tui::Palette::SELECTED_BG
368-
elsif is_marked
366+
# Marked items always show red; selection shows via arrow only
367+
background = if is_marked
369368
Tui::Palette::DANGER_BG
369+
elsif is_selected
370+
Tui::Palette::SELECTED_BG
370371
end
371372

372373
line = screen.body.add_line(background: background)
@@ -559,7 +560,13 @@ def render_rename_dialog(current_name, rename_buffer, rename_cursor, rename_erro
559560
prefix = "New name: "
560561
line.center.write_dim(prefix)
561562
line.center << screen.input("", value: rename_buffer, cursor: rename_cursor).to_s
562-
line.mark_has_input((screen.width - Tui::Metrics.visible_width(prefix) - rename_buffer.length) / 2 + Tui::Metrics.visible_width(prefix))
563+
# Input displays buffer + trailing space when cursor at end
564+
# Use (width - 1) to match Line.render's max_content calculation
565+
input_width = [rename_buffer.length, rename_cursor + 1].max
566+
prefix_width = Tui::Metrics.visible_width(prefix)
567+
max_content = screen.width - 1
568+
center_start = (max_content - prefix_width - input_width) / 2
569+
line.mark_has_input(center_start + prefix_width)
563570
end
564571

565572
if rename_error
@@ -710,7 +717,13 @@ def render_delete_dialog(marked_items, confirmation_buffer, confirmation_cursor)
710717
prefix = "Type YES to confirm: "
711718
line.center.write_dim(prefix)
712719
line.center << screen.input("", value: confirmation_buffer, cursor: confirmation_cursor).to_s
713-
line.mark_has_input((screen.width - Tui::Metrics.visible_width(prefix) - confirmation_buffer.length) / 2 + Tui::Metrics.visible_width(prefix))
720+
# Input displays buffer + trailing space when cursor at end
721+
# Use (width - 1) to match Line.render's max_content calculation
722+
input_width = [confirmation_buffer.length, confirmation_cursor + 1].max
723+
prefix_width = Tui::Metrics.visible_width(prefix)
724+
max_content = screen.width - 1
725+
center_start = (max_content - prefix_width - input_width) / 2
726+
line.mark_has_input(center_start + prefix_width)
714727
end
715728

716729
screen.footer.add_line { |line| line.write.write_dim(fill("─")) }
@@ -756,7 +769,7 @@ def process_delete_confirmation(marked_items, confirmation)
756769
# Main execution with OptionParser subcommands
757770
if __FILE__ == $0
758771

759-
VERSION = "1.7.0"
772+
VERSION = "1.7.1"
760773

761774
def print_global_help
762775
text = <<~HELP
@@ -1120,10 +1133,12 @@ def script_delete(paths, base_path)
11201133
end
11211134

11221135
def script_rename(base_path, old_name, new_name)
1136+
new_path = File.join(base_path, new_name)
11231137
[
11241138
"cd #{q(base_path)}",
11251139
"mv #{q(old_name)} #{q(new_name)}",
1126-
"cd #{q(File.join(base_path, new_name))}"
1140+
"echo #{q(new_path)}",
1141+
"cd #{q(new_path)}"
11271142
]
11281143
end
11291144

0 commit comments

Comments
 (0)