termux-app icon indicating copy to clipboard operation
termux-app copied to clipboard

feat(view): Enable mouse cursor movement in shell readline

Open ankitkrshah30 opened this issue 3 months ago • 13 comments

This pull request adds support for moving the cursor within a long command in the shell by clicking with a mouse or tapping on the touchscreen. This makes editing multi-line commands significantly easier and faster.

How it Works The implementation works by:

Intercepting ACTION_DOWN events from both mice and touchscreens in TerminalView.

Calculating a 1D character index for both the click location and the current cursor position, correctly handling multi-line wrapping.

Sending the appropriate number of left or right arrow keypress events (KEYCODE_DPAD_LEFT/RIGHT) via the existing handleKeyCode() method to move the cursor to the target location.

This approach ensures that the cursor movement is handled by the underlying readline library, behaving exactly like physical keypresses.

https://github.com/user-attachments/assets/b6df9415-c855-4156-a661-59040b586d53

Closes #4748

ankitkrshah30 avatar Sep 22 '25 20:09 ankitkrshah30

@TomJo2000 kindly look into this PR.

ankitkrshah30 avatar Sep 22 '25 20:09 ankitkrshah30

@obfusk @fornwall @agnostic-apollo @ayoubelmhamdi Kindly look into the PR.

ankitkrshah30 avatar Sep 23 '25 15:09 ankitkrshah30

@ankitkrshah30

Recording2.mp4

from the video, i saw the experience will be more awful than i expected before, because we always make wrong presses while using touch screen, but the cursor will be moved to the first character in the first line, we should think about it, after people use this feature.

ayoubelmhamdi avatar Sep 23 '25 22:09 ayoubelmhamdi

Hi, Thank you for the excellent feedback on the user experience. I've pushed an update that adds a boundary check to the logic. The cursor now only moves when clicking directly on the command's text, and accidental taps on empty areas are safely ignored. Here is a new video demonstrating the final, improved behavior:

the improved version: https://github.com/user-attachments/assets/4527774b-80c2-449c-bddc-a8596d4ea860

the issue part: https://github.com/user-attachments/assets/56c17cf3-9e32-4635-b856-ec62054e62c0

@ayoubelmhamdi

ankitkrshah30 avatar Sep 24 '25 06:09 ankitkrshah30

Hi, just a quick follow-up to note that I've updated the PR with the requested fixes. I'm also participating in Hacktoberfest, so I'd appreciate it if this contribution could be considered when you have time. Thanks for maintaining this great project!

ankitkrshah30 avatar Sep 24 '25 06:09 ankitkrshah30

Hi, I appreciate the value of this idea and I believe it would be useful for some people, however, I have two requests:

Even though I have many years of experience with terminal emulators, I have never personally seen any terminal emulator on desktop PC that implements this feature.

Because of that, I believe it should not be the default behavior, but should be configurable to be enabled by a setting in the Termux App "Settings" menu.

If it's not inconvenient for you to do this additional work, could you please try the following steps?

  • Try to adjust this so that it is disabled by default, but can be optionally enabled by a setting toggle in the "Settings" that come from holding down long press on the screen and selecting "more" and "settings" (and it should still be possible to return to the Settings the same way and disable it again after it has been enabled!)
  • Try to find and show me a terminal emulator for laptop and desktop PC that you like which has the same feature, so that I can compare your implementation with it, especially its behavior when used on Touchscreen Ubuntu Tablets, compared to your implementation for Touchscreen Android Phones.

robertkirkman avatar Sep 24 '25 18:09 robertkirkman

Hi,

I've pushed the final updates. The feature is now controlled by an on/off switch in the settings, as requested. I've also added the boundary check to prevent the cursor from jumping on accidental taps in empty areas.

Here is a new video demonstrating the final behavior, including the settings toggle:

https://github.com/user-attachments/assets/fb9917a0-29f8-468c-87c3-0db7f5e54045

I'm also participating in Hacktoberfest, so I'd be grateful if this contribution could be considered for the event.

Thank you again for all your guidance! @robertkirkman

ankitkrshah30 avatar Sep 25 '25 19:09 ankitkrshah30

Hi @twaik and @robertkirkman,

Thanks so much for the detailed feedback!

You're right, @twaik, my calculation logic is too simple and will break. I'd love to fix it, but I'm not sure of the best way to map the screen coordinates to the shell's command buffer. If you have any suggestions on the right approach, I'd really appreciate it!

And thanks, @robertkirkman, for the testing and for the context on the settings. I'm happy to implement the setting however the team decides is best.

I'll hold off on pushing more code until I hear your thoughts on the calculation fix. Thanks again!

ankitkrshah30 avatar Sep 26 '25 05:09 ankitkrshah30

@TomJo2000 @twaik @robertkirkman any info

ankitkrshah30 avatar Oct 02 '25 17:10 ankitkrshah30

Neither of us 3 merge pull requests in this repository.

TomJo2000 avatar Oct 02 '25 17:10 TomJo2000

can you help me if to know if any changes required. or if someone who can take this serious..

ankitkrshah30 avatar Oct 02 '25 17:10 ankitkrshah30

There are many PRs waiting in order before this PR. The people who can merge PRs in this repository will be busy with all of the other ones before they reach this one.

robertkirkman avatar Oct 02 '25 19:10 robertkirkman

Hi, sorry about late reply, I am busy with termux-app rewrite and won't be merging any pulls before that, and as robert said some more important PRs will take precedence even after I finish rewrite and push. And this cannot be merged anyways before rewrite as it needs changes to properties, which conflict with my local rewrite changes. Additionally, such changes for mouse tracking in terminal will need to be looked into carefully to not break things and whether it is viable to merge, and whether issues above for ncurses can be solved. That will take time, I am also not very familiar with mouse related implementation in terminal, so will need to research first too. So I cannot give you any immediate timeline for merging this, sorry.

agnostic-apollo avatar Oct 04 '25 22:10 agnostic-apollo