Open mskar opened 3 years ago
Similarly, would it be possible to decide the apperance of the vi mode indicator? Ideally, this would be done by having two different prompt or a function that return different string depending on the current mode. For the latter, I do not know if this is something R could access though.
@YlanAllouche, I found the answer in a related issue:
options(
radian.vi_mode_prompt = list(
"ins" = "(I) ",
"nav" = "(N) ",
"rep" = "(R) "
)
)
As for cursor shape, it might be possible to use another example from that same issue to adapt my ipython_config.py to radian. cc @petobens
Wow, I just pasted the relevant code from my ipython_config.py
into radian/settings.py
and it works! 😄
Is settings.py the right place for it? Or is it better for this to be handled by a config file?
Should I submit a pull request? I think everyone who uses the radian vi mode will want this.
import sys
from prompt_toolkit.application.current import get_app
from prompt_toolkit.key_binding.vi_state import InputMode, ViState
def get_input_mode(self):
if sys.version_info[0] == 3:
# Decrease input flush timeout from 500ms to 10ms.
app = get_app()
app.ttimeoutlen = 0.01
app.timeoutlen = 0.2
return self._input_mode
def set_input_mode(self, mode):
shape = {InputMode.NAVIGATION: 2, InputMode.REPLACE: 4}.get(mode, 6)
cursor = "\x1b[{} q".format(shape)
if hasattr(sys.stdout, "_cli"):
write = sys.stdout._cli.output.write_raw
else:
write = sys.stdout.write
write(cursor)
sys.stdout.flush()
self._input_mode = mode
ViState._input_mode = InputMode.INSERT
ViState.input_mode = property(get_input_mode, set_input_mode)
I submitted a pull request #222.
If anyone wants to install the change to try it out, run the line below.
python -m pip install git+https://github.com/mskar/radian.git@cursor
The change is a small addition to the apply_settings() function in radian/session.py.
Thanks a lot for the tip for the vi mode prompt. I tried to rebuild Radian in a container with this PR and I cannot see the cursor shape change between modes. Does it require extra configuration post installation?
I tried in both Xterm and Kitty to make sure it was not a terminal compatibility problem.
@YlanAllouche, thanks for giving it a try. Sorry to hear it didn't work for you.
There should be no additional setup required. \
Just in case, here is the .radian_profile
I am using.
In addition to using a container, you could also try a virtual environment.
pip list
after the virtual environment is activatedThe only requirements for creating the environment should be bash
and python
(for venv
and pip
).
Could you give this a try and see if it works for you?
Hey @mskar,
Thanks a lot for detailed steps. The issue was my terminal forcing a cursor shape on top of radian. This now works for me
@mskar @randy3k It looks as though the associated PR was never merged. Is there a way to get different cursor shapes based on vi mode by modifying .config/radian/profile
? Thanks!
I would like radian to have a beam cursor (
|
) in vi insert mode and a block cursor in vi navigation (normal) mode.Since both radian and IPython use prompt-toolkit, I think it will be helpful to link to the relevant prompt-toolkit issue. By including the code from the issue in my
ipython_config.py
file, i was able to set up IPython with a vi mode-dependent cursor:How could I do something similar in my
.radian_profile
?