Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shortcut "ctrl+e > exit with cd" (non rooted) & command yd, not working #121

Closed
cargilcm opened this issue Nov 9, 2024 · 14 comments
Closed
Labels
bug Something isn't working Partially Solved Termux

Comments

@cargilcm
Copy link

cargilcm commented Nov 9, 2024

Specifications

  • OS: Android 12 aarch
  • Terminal: termux
  • TUIFI Version: v.5.0.0

Describe the bug

The top most call in the execution stack is logged below:
File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/TUIFIManager/TUItilities.py", line 49, in put_text_back_into_terminal_input_buffer for c in text: ioctl(1, TIOCSTI, c) ^^^^^^^^^^^^^^^^^^^^ PermissionError: [Errno 13] Permission denied

Additional context

I found a SO post that says the process must have root privileges for ioctl tiocsti operations to succeed. It would be nice if the cd path could be assigned to an variable that bash could call ie: bash -c cd $cdpath manually after tuifi exits if ioctl permissions are prohibitive. The error that is thrown by python crashes the terminal tab also so no further text can be displayed when typed after this type of exit. Let me know if you desire to see the whole stack trace from stderr.

Thank you

@cargilcm
Copy link
Author

cargilcm commented Nov 10, 2024

without putting on my code inspector goggles my first guess is that the yd command calls a function that uses tiocsti like the exit with CD operation does

This is a pretty large-size screenshot image, but termux-clipboard-set could be a potential workaround for such a function call in the termux environment depending on what other packages are used and how. I'm glad if I can write some code to this end to help out

Screenshot_20241109-193857

@cargilcm cargilcm changed the title Shortcut cntl+e: exit with CD not working on non rooted termux environment Shortcut cntl+e: "exit with CD" and shortcut command "yd" not working on non rooted termux environment Nov 10, 2024
@GiorgosXou GiorgosXou changed the title Shortcut cntl+e: "exit with CD" and shortcut command "yd" not working on non rooted termux environment Shortcut ctrl+e > exit with cd (on non rooted termux environment) & command yd, not working Nov 10, 2024
@GiorgosXou GiorgosXou changed the title Shortcut ctrl+e > exit with cd (on non rooted termux environment) & command yd, not working Shortcut ctrl+e > "exit with cd" (non rooted) & command yd, not working Nov 10, 2024
@GiorgosXou GiorgosXou changed the title Shortcut ctrl+e > "exit with cd" (non rooted) & command yd, not working Shortcut "ctrl+e > exit with cd" (non rooted) & command yd, not working Nov 10, 2024
@GiorgosXou GiorgosXou added Termux bug Something isn't working Partially Solved labels Nov 10, 2024
@GiorgosXou
Copy link
Owner

Thanks for the catch! I forgot to add that, here's the fix: a4f7992

(Additional info for anyone coming across this issue, you do also need to install this and pkg install termux-api)

@GiorgosXou
Copy link
Owner

GiorgosXou commented Nov 10, 2024

The top most call in the execution stack is logged below:
File "/data/data/com.termux/files/usr/lib/python3.12/site-packages/TUIFIManager/TUItilities.py", line 49, in put_text_back_into_terminal_input_buffer for c in text: ioctl(1, TIOCSTI, c) ^^^^^^^^^^^^^^^^^^^^ PermissionError: [Errno 13] Permission denied

Yes, that's a trick only available for root devices, but I just found that it might be possible via this way gokcehan/lf#140 (comment), too. Once I find the time I'll see what I can do, but...

I'm glad if I can write some code to this end to help out

... feel free to do so, if you like.

@cargilcm
Copy link
Author

Awesome, I love tuifi and I especially love your passion for programming and keeping others on the up with your attention to their input etc

Thank you, Giorgios, really..as to the lf program's scripts I think this is what can be hoped for alternative to iocntl because I learned to you can't set environment variables that persist beyond the life of the process(& subprocesses) in Python so yes you have to do some bash scripting (and to tweak possibly main.py so that after endwin it prints os.getcwd() or maybe the selected file? I'll upload some code and share what I use for "-last-directory" with the autojump program.

Thank You, Giorgos

@GiorgosXou
Copy link
Owner

Instaed of tweaking main.py I guess you could replace:

if not IS_WINDOWS and not self.directory == INIT_DIRECTORY:
self.cd(self.directory)

from:
def exit_to_self_directory(self):
if not IS_WINDOWS and not self.directory == INIT_DIRECTORY:
self.cd(self.directory)
print(END_MOUSE)
unicurses.endwin()
self.__handle_garbage()
exit()

with what you are trying to do.

@GiorgosXou
Copy link
Owner

GiorgosXou commented Nov 12, 2024

crossreff: #85

@cargilcm
Copy link
Author

cargilcm commented Nov 16, 2024

Exit with CD function output messes up the terminal prompt display when cntl+e is executed without root privileges.

It WOULD BE great if there was/is a way to test whether the tuifi program is being executed under root privilege. If you cntl+e without su'ing before the program or without sudo'ing I would think you should see the behavior I'm describing. Screenshot available if not lol

I have no sysadmin experience but from an article on stack exchange I'd be curious if you can determine whether the process has root privileges by executing subprocess in Python with the command logname and testing for equality to "root"?

@GiorgosXou
Copy link
Owner

GiorgosXou commented Nov 16, 2024

Exit with CD function output messes up the terminal prompt display when cntl+e is executed without root privileges.

I know.

It WOULD BE great if there was/is a way to test whether the tuifi program is being executed under root privilege.

There's no need for such a thing. if simply this works gokcehan/lf#140 (comment), I'll ditch the root-trick completly. I just don't have the time to work on it, right now.

@cargilcm
Copy link
Author

cargilcm commented Nov 16, 2024

Lf's exit with CD directs the session location to the relevant directory but lf is written in go which I had wondered was there something special in the go binaries different from pythons that allowed their program to achieve this. I have some other quirks that are not meeting my needs with the documented behavior or tuifi not playing out as described (non rooted termux issues again I think) but I'll file those under different support tickets, appropriately. I had noticed other tui file managers writing the files to a file and currently that's my only way of knowing how to solve the issue and I had just finished my commit solving that way when I broke my termux by a faulty alias in bashrc back to coding at base level zero lol

Edit: tuifi inside termux when navigating from TERMUX_HOME to shared storage will only get you back to TERMUX_HOME via a previously set marker if you're not rooted ie backspace does not do it

Thanks Giorgos!

Edit: I was feeling frustrated with tuifi not functioning as I thought it would and was able to address some of those eccentricities by fixing a mistake I'd made by reinstalling termux and running pkg up before python setup.py install

@cargilcm cargilcm reopened this Nov 30, 2024
@GiorgosXou
Copy link
Owner

when navigating from TERMUX_HOME to shared storage will only get you back to TERMUX_HOME via a previously set marker...

You don't need a marker, just use the HOME button:
Screenshot_2024-12-01-12-01-49-012_com termux_1

@cargilcm cargilcm closed this as completed Dec 2, 2024
@cargilcm cargilcm reopened this Dec 2, 2024
@cargilcm
Copy link
Author

cargilcm commented Dec 2, 2024

Seeing how your are the author of unicurses I would feel mostly certain that it doesn't remain unknown yet that piping the output of a python curses program will most likely include control séquences and escape characters that are hard to filter out but to use the tuifi program's command line output "you" could (read: I am) use endwin() followed by a custom escape sequence (//) at the end of the control flow of TUIFIManager and assign that value from AWK to a bash variable ie CD_dir after which your bash function executes cd $CD_dir like the lfcd function / lf -last-dir-path does. I am happy to pass along my .bashrc with this functionality and or init.py and main.py files I used if you'd like.

Can I submit via pull request? For my research, I'm giving this an"issue closed" tag. Fwiw if newterm -juggling were possible like here I would like that.

Reiteration, TUIFIManager and ecosystem for my learning about curses gets a double thumbs up

@cargilcm cargilcm closed this as completed Dec 2, 2024
@GiorgosXou
Copy link
Owner

Seeing how your are the author of unicurses

Not the author, just a maintainer.

Can I submit via pull request?

Feel free to do so. Or simply link me to your fork changes and I'll do the the rest by my own (while ensuring to co-author you), as I'm concerned of few things that may need to be changed.

@cargilcm
Copy link
Author

I think I have committed a working tuifi-cd if you will command. In my bash I have named it tuify and if you use setup.py to install with my init you still need to click escape after cntl+e since exit() is not called after handle_garbage () . Should I have moved the end win and print statements to just under "if not Windows" to replace self.cd like you mentioned?

How does this attempt look to you?

@GiorgosXou
Copy link
Owner

Looks ok.

Don't worry, I'll fix what's needed once I have the time, right now I'm working on another project and that's why I'm not active on the issue.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Partially Solved Termux
Projects
None yet
Development

No branches or pull requests

2 participants