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

feat: add ansi scrolling support #52

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ build:
$(MAKE) clean
python3 setup.py -q sdist bdist_wheel

.PHONY: install
install: build
pip3 install --force-reinstall dist/*.whl

.PHONY: publish
publish: build
twine check dist/*
Expand Down
33 changes: 26 additions & 7 deletions devcluster/console.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import fcntl
import time
import subprocess
import sys
Expand Down Expand Up @@ -305,28 +306,46 @@ def handle_key(self, key: str) -> None:
self.state_machine_handle.quit()
elif key == "\x04": # ctrl-d
self.state_machine_handle.dump_state()
elif key == "q":
# include escape key
elif key == "q" or key == "\033":
self.state_machine_handle.quit()
elif key == "k":
# include up arrow and scroll up
elif key == "k" or key == "\033[A" or key == "\033OA":
self.act_scroll(1)
elif key == "u":
# include page up
elif key == "u" or key == "\033[5":
self.act_scroll(10)
elif key == "j":
# include down arrow and scroll down
elif key == "j" or key == "\033[B" or key == "\033OB":
self.act_scroll(-1)
elif key == "d":
# include page down
elif key == "d" or key == "\033[6":
self.act_scroll(-10)
elif key == "x":
# include end key and enter
elif key == "x" or key == "\033[F" or key == "\x0d":
self.act_scroll_reset()
elif key == " ":
self.act_marker()
else:
hexKey = key.encode("utf-8").hex()
if key[0] == "\033":
# escape sequence
key = "\\033" + key[1:]
self.logger.log(
dc.fore_num(9) + dc.asbytes(f'"{key}" is not a known shortcut\n') + dc.res
dc.fore_num(9)
+ dc.asbytes(f'"{key}" is not a known shortcut (0x{hexKey})\n')
+ dc.res
)

def handle_stdin(self, ev: int, _: int) -> None:
if ev & dc.Poll.IN_FLAGS:
key = sys.stdin.read(1)
if key == "\033":
# escape sequence, read next 2 characters non-blocking
orig_fl = fcntl.fcntl(sys.stdin, fcntl.F_GETFL)
fcntl.fcntl(sys.stdin, fcntl.F_SETFL, orig_fl | os.O_NONBLOCK)
key += sys.stdin.read(2)
fcntl.fcntl(sys.stdin, fcntl.F_SETFL, orig_fl)
self.handle_key(key)
elif ev & dc.Poll.ERR_FLAGS:
raise ValueError("stdin closed!")
Expand Down