Skip to content

Commit 1c06ed5

Browse files
committed
refactor: restructure project to use src layout and improve navigation UI
Add proper package structure with src/tokdu directory and configure setuptools in pyproject.toml to use this layout. Enhance TUI navigation with informative messages when users try to navigate above root directory and add flash cooldown to prevent excessive visual feedback.
1 parent 27dd97a commit 1c06ed5

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
requires = ["setuptools>=42", "wheel"]
33
build-backend = "setuptools.build_meta"
44

5+
[tool.setuptools]
6+
package-dir = { "" = "src" }
7+
58
[project]
69
name = "tokdu"
710
version = "0.1.1"

src/tokdu/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .tokdu import main

tokdu.py renamed to src/tokdu/tokdu.py

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,9 @@ def tui(stdscr, start_path, encoding_name, model_name):
240240

241241
selected_idx = 0
242242
offset = 0
243+
last_flash_time = 0
244+
flash_cooldown = 1.0 # Seconds to wait before flashing again
245+
root_message = "" # Message to display when at root boundary
243246

244247
while True:
245248
items = cached_scan_directory(current_path, encoder, git_spec, repo_root)
@@ -249,6 +252,15 @@ def tui(stdscr, start_path, encoding_name, model_name):
249252
max_items = height - 2
250253
offset = draw_menu(stdscr, items, selected_idx, current_path, offset, scanning)
251254

255+
# Display root boundary message if present
256+
if root_message:
257+
message_y = height - 1 if height > 2 else 0
258+
stdscr.addstr(message_y, 0, root_message[:width-1], curses.A_BOLD)
259+
stdscr.refresh()
260+
# Auto-clear message after a brief period
261+
if time.time() - last_flash_time > 2.0:
262+
root_message = ""
263+
252264
key = stdscr.getch()
253265
if key == -1:
254266
time.sleep(0.1)
@@ -257,17 +269,22 @@ def tui(stdscr, start_path, encoding_name, model_name):
257269
if key in (ord('q'), ord('Q')):
258270
break
259271
elif key in (curses.KEY_UP, ord('k')):
272+
root_message = "" # Clear message on navigation
260273
if selected_idx > 0:
261274
selected_idx -= 1
262275
elif key in (curses.KEY_DOWN, ord('j')):
276+
root_message = ""
263277
if items and selected_idx < len(items) - 1:
264278
selected_idx += 1
265279
elif key == curses.KEY_NPAGE: # Page Down
280+
root_message = ""
266281
if items:
267282
selected_idx = min(len(items) - 1, selected_idx + max_items)
268283
elif key == curses.KEY_PPAGE: # Page Up
284+
root_message = ""
269285
selected_idx = max(0, selected_idx - max_items)
270286
elif key in (curses.KEY_ENTER, 10, 13): # Enter key
287+
root_message = ""
271288
if items:
272289
chosen = items[selected_idx]
273290
if chosen['is_dir']:
@@ -276,14 +293,22 @@ def tui(stdscr, start_path, encoding_name, model_name):
276293
selected_idx = 0
277294
offset = 0
278295
elif key in (curses.KEY_BACKSPACE, 127, 8):
296+
current_time = time.time()
279297
# Prevent navigating above the starting directory.
280298
if current_path == root_dir:
281-
curses.flash()
299+
if current_time - last_flash_time > flash_cooldown:
300+
curses.flash()
301+
root_message = "Root directory reached. Cannot navigate further up."
302+
last_flash_time = current_time
282303
else:
283304
parent = os.path.dirname(current_path)
284305
if os.path.commonpath([root_dir, parent]) != root_dir:
285-
curses.flash()
306+
if current_time - last_flash_time > flash_cooldown:
307+
curses.flash()
308+
root_message = "Root directory reached. Cannot navigate further up."
309+
last_flash_time = current_time
286310
else:
311+
root_message = ""
287312
history.append(current_path)
288313
current_path = parent
289314
selected_idx = 0

0 commit comments

Comments
 (0)