restoring last position when less-ing a page
This commit is contained in:
parent
80bf937f03
commit
75397963cf
|
@ -7,6 +7,7 @@ UPGRADE: Users who subscribed to pages before 0.4 should run once the command "l
|
||||||
- Introducing the "open" command to open current page/image/file with external handler.
|
- Introducing the "open" command to open current page/image/file with external handler.
|
||||||
- "set width XX" now works to set the max width. If smaller, terminal width is used (thanks kelbot for reporting the bug)
|
- "set width XX" now works to set the max width. If smaller, terminal width is used (thanks kelbot for reporting the bug)
|
||||||
- RSS feeds are now rendered as Gemlogs to improve consistency while browsing
|
- RSS feeds are now rendered as Gemlogs to improve consistency while browsing
|
||||||
|
- "less" will restore previous position in a page (requires less 572+)
|
||||||
- Improved syncing performances and multiple bug/crash fixes.
|
- Improved syncing performances and multiple bug/crash fixes.
|
||||||
|
|
||||||
## 0.3 - Feb 11th 2022
|
## 0.3 - Feb 11th 2022
|
||||||
|
|
30
offpunk.py
30
offpunk.py
|
@ -156,8 +156,18 @@ _MAX_CACHE_AGE_SECS = 180
|
||||||
# -M : long prompt (to have info about where you are in the file)
|
# -M : long prompt (to have info about where you are in the file)
|
||||||
# -w : hilite the new first line after a page skip (space)
|
# -w : hilite the new first line after a page skip (space)
|
||||||
# -i : ignore case in search
|
# -i : ignore case in search
|
||||||
|
_DEFAULT_LESS = "less --save-marks -XRfMwi \"+''\" %s"
|
||||||
_DEFAULT_CAT = "less --save-marks -EXFRfMwi %s"
|
_DEFAULT_CAT = "less --save-marks -EXFRfMwi %s"
|
||||||
_DEFAULT_LESS = "less --save-marks -XRfMwi %s"
|
def less_cmd(file, histfile=None,cat=False):
|
||||||
|
if histfile:
|
||||||
|
prefix = "LESSHISTFILE=%s "%histfile
|
||||||
|
else:
|
||||||
|
prefix = ""
|
||||||
|
if cat:
|
||||||
|
cmd_str = prefix + _DEFAULT_CAT % file
|
||||||
|
else:
|
||||||
|
cmd_str = prefix + _DEFAULT_LESS % file
|
||||||
|
subprocess.call(cmd_str,shell=True)
|
||||||
|
|
||||||
less_version = 0
|
less_version = 0
|
||||||
return_code = subprocess.run("less --version",shell=True, capture_output=True)
|
return_code = subprocess.run("less --version",shell=True, capture_output=True)
|
||||||
|
@ -848,6 +858,7 @@ class GeminiItem():
|
||||||
self.renderer = None
|
self.renderer = None
|
||||||
self.links = None
|
self.links = None
|
||||||
self.body = None
|
self.body = None
|
||||||
|
self.histfile = None
|
||||||
parsed = urllib.parse.urlparse(self.url)
|
parsed = urllib.parse.urlparse(self.url)
|
||||||
if "./" in url or url[0] == "/":
|
if "./" in url or url[0] == "/":
|
||||||
self.scheme = "file"
|
self.scheme = "file"
|
||||||
|
@ -903,6 +914,12 @@ class GeminiItem():
|
||||||
if len(self.path+parsed.query) < 258:
|
if len(self.path+parsed.query) < 258:
|
||||||
self.path += "/" + parsed.query
|
self.path += "/" + parsed.query
|
||||||
|
|
||||||
|
def get_histfile(self):
|
||||||
|
if not self.histfile:
|
||||||
|
tmpf = tempfile.NamedTemporaryFile("w", encoding="UTF-8", delete=False)
|
||||||
|
self.histfile = tmpf.name
|
||||||
|
return self.histfile
|
||||||
|
|
||||||
def get_cache_path(self):
|
def get_cache_path(self):
|
||||||
if self._cache_path and not os.path.isdir(self._cache_path):
|
if self._cache_path and not os.path.isdir(self._cache_path):
|
||||||
return self._cache_path
|
return self._cache_path
|
||||||
|
@ -1504,8 +1521,7 @@ class GeminiClient(cmd.Cmd):
|
||||||
self.index_index = -1
|
self.index_index = -1
|
||||||
if display:
|
if display:
|
||||||
self._temp_file(rendered_body)
|
self._temp_file(rendered_body)
|
||||||
cmd_str = _DEFAULT_CAT
|
less_cmd(self.idx_filename,histfile=gi.get_histfile(),cat=True)
|
||||||
subprocess.run(shlex.split(cmd_str % self.idx_filename))
|
|
||||||
elif display :
|
elif display :
|
||||||
cmd_str = self._get_handler_cmd(gi.get_mime())
|
cmd_str = self._get_handler_cmd(gi.get_mime())
|
||||||
try:
|
try:
|
||||||
|
@ -2618,14 +2634,14 @@ Use 'ls -l' to see URLs."""
|
||||||
|
|
||||||
@needs_gi
|
@needs_gi
|
||||||
def do_less(self, *args):
|
def do_less(self, *args):
|
||||||
"""Run most recently visited item through "less" command.
|
"""Run most recently visited item through "less" command, restoring \
|
||||||
|
previous position.
|
||||||
Use "less full" to see a complete html page instead of the article view.
|
Use "less full" to see a complete html page instead of the article view.
|
||||||
(the "full" argument has no effect on Gemtext content)."""
|
(the "full" argument has no effect on Gemtext content but doesn’t restore position)."""
|
||||||
if self.gi and args and args[0] == "full":
|
if self.gi and args and args[0] == "full":
|
||||||
self._go_to_gi(self.gi,readable=False)
|
self._go_to_gi(self.gi,readable=False)
|
||||||
elif self.gi.is_cache_valid():
|
elif self.gi.is_cache_valid():
|
||||||
cmd_str = _DEFAULT_LESS % self._get_active_tmpfile()
|
less_cmd(self._get_active_tmpfile(),histfile=self.gi.get_histfile())
|
||||||
subprocess.call(cmd_str, shell=True)
|
|
||||||
else:
|
else:
|
||||||
self.do_go(self.gi.url)
|
self.do_go(self.gi.url)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user