Closed ZaxonXP closed 7 months ago
I did not check it, but I guess you do not need lua for this. See macros #196.
I tried to get the latest code using git clone command and I defined the keyboard bind like this:
bind "main" "Ctrl-R" = "macro-0" "reload" "macro-1"
or like this
bind "main" "Ctrl-R" = "macro-0"; "reload"; "macro-1"
But elinks complains that this is not correct command. Did I get the correct version or should I use another command to get some specific branch with this feature which is described in #196 ?
Also I do not know what the macro can contain. I put in the macros following:
## macro.0 <str> - this should make mark a
set macro.0 = "ma"
## macro.1 <str> - this should go to the mark a
set macro.1 = "\'a"
Is this how it should be used? I could not find much of elinks macro exmples.
I tested it. It does not work yet. I thought about something like: set macro.0 = 'mark-set a; reload; mark-goto a'
I tried also to define konsole's macros, but also without success.
Not lua, but python:
import fcntl
import termios
def pre_format_html_hook(url, html):
with open('/dev/stdin', 'w') as fd:
for char in "Ma":
fcntl.ioctl(fd, termios.TIOCSTI, char)
# normal code of preformat hook follow
def try_to_reload():
"""Try to reload."""
with open('/dev/stdin', 'w') as fd:
for char in "maR":
fcntl.ioctl(fd, termios.TIOCSTI, char)
elinks.bind_key("F8", try_to_reload)
F8 is bound to this function. These are not standard: m is bound to mark-set a is key R is bound to reload M is bound to mark-goto
Normally if open stdin to write, it writes to stdout, so this trick with fcntl. With curses you can even read from keyboard, so you do not have to hardcode 'a' here. pre_format_hook is similar as javascript's onload. Scrolled to top without.
I managed to enable Perl support, but I have a problem to compile it with the Python support (I use --with-python, but this does not find it). What should I have/do?
Are libpython3-dev and python3-dev installed? Any errors in config.log ?
Looks like it was my bad. I was changing the my configure script in another directory and compiling in the other.
I put the code you posted in hooks.py
in the elinks config folder and restarted elinks. I scrolled bit down and pressed F8, but nothing happen. Should I use compete hooks.py from contrib folder and add your code? Or just your code should be enough?
I noticed that the first pre_format_html_hook
code should be added to the current method definition. I added it to standard hooks.py. However still do not work.
I have such keybindings in elinks.conf:
##################################
# Automatically saved keybindings
#
bind "main" "m" = "mark-set"
bind "main" "M" = "mark-goto"
bind "main" "R" = "reload"
Do you have similar? Could you show beginning of hooks.py and modified code?
I have the same mappings to match your code. Here is also the hooks.py file. hooks.py.txt
Did page reload after CTRL-R or not?
I tried with your settings for F8 and it did not work. I changed to Ctrl-r and it also does not (page is not reloading). However when using Shift-r it does (so the binding works). Did it worked for you?
Should I send you also my config?
I noticed you have backtick at the end of line with elinks.bind('Ctrl-r') There was bug in code I pasted. Remove it. And try again.
Remove backtick, not code.
looks like I do not have the elinks Python library installed and I have some issues installing it. I discovered it when I wanted to run hooks.py with Python.
F9 -> Help -> About Is there Python? If not, install python3-distutils and recompile
Well, stupid me. I recompiled the elinks with Python support, checked locally and forgot to install it. :\ After installation it works.
Thanks a lot for patience and your help!
The solution is working when there is only one elinks instance. However I open more than one in a separate tmux windows. In such case when I do reload, then it reloads on the first instance and not in the current. Is there a solution for that?
I have no idea how to fix it. You can use tabs (keys t,<,>,c) instead of new elinks instances. Or start new elinkses with --no-connect.
OK. I managed to use tabs. So now everything works. Thanks for your help.
@rkd77:
Recently I am starting getting following errors when executing the Python code: The Pyhon code is following:
import elinks
import fcntl
import termios
import os
def pre_format_html_hook(url, html):
with open('/dev/stdin', 'w') as fd:
for char in "Ma":
fcntl.ioctl(fd, termios.TIOCSTI, char)
def try_to_reload():
"""Try to reload."""
with open('/dev/stdin', 'w') as fd:
for char in "maR":
fcntl.ioctl(fd, termios.TIOCSTI, char)
def copy_url():
""" Copy current url """
os.system('clear')
print(elinks.current_url())
elinks.bind_key("F7", copy_url)
elinks.bind_key("Ctrl-r", try_to_reload)
What could be the reason for this?
What changed in system since April 2023? I read somewhere that TIOCSTI requires root or at least CAP_SYS_ADMIN capability.
Is there some workaround for this?
Is it an Android device or plain Linux?
Plain Linux. Debian 12.
https://stackoverflow.com/questions/75675261/alternatives-to-tiocsti-now-that-is-disable-on-default-for-kernels-6-2 dev.tty.legacy_tiocsti=1 in /etc/sysctl.conf You can try first as root: echo 1 > /proc/sys/dev/tty/legacy_tiocsti
When I do this:
echo 1 > /proc/sys/dev/tty/legacy_tiocsti
ten afterwards reloading page in Elinks does not display the error anymore. But what are the drawbacks of using it?
Does it work? Not only not display error, but also scrolls as before? I guess that paranoid security was reason of changes related to TIOCSTI, but with this legacy_tiocsti you can restore pre 6.2 kernel behaviour which worked for years. Some programs, for example viruses, can modify your input on some devices. It is a guess. But it you have viruses, they find out other ways to spread.
Yes, it reloads the page and scroll to the previous position. So it acts as before. Now I recall that this issue started to appear after I updated kernel to version 6.5. Before I had no such issue. Thanks for your help.
I use
elinks
on some site which does not keep the page position when I reload it (it scroll to top). My workaround is to set a mark, reload the page and jump to mark. I wonder if this can be also done by Lua script and assign to some keyboard shortcut?Kind regards, Zaxon